1 /* 2 * Copyright (C) 2017-2020 by the Widelands Development Team 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * 18 */ 19 20 #ifndef WL_GRAPHIC_STYLE_MANAGER_H 21 #define WL_GRAPHIC_STYLE_MANAGER_H 22 23 #include <map> 24 #include <memory> 25 26 #include "graphic/styles/building_statistics_style.h" 27 #include "graphic/styles/button_style.h" 28 #include "graphic/styles/font_style.h" 29 #include "graphic/styles/panel_styles.h" 30 #include "graphic/styles/progress_bar_style.h" 31 #include "graphic/styles/statistics_plot_style.h" 32 #include "graphic/styles/table_style.h" 33 #include "graphic/styles/text_panel_style.h" 34 #include "graphic/styles/ware_info_style.h" 35 #include "scripting/lua_table.h" 36 37 static const std::string kTemplateDir = "templates/default/"; 38 39 class StyleManager { 40 public: 41 StyleManager() = default; 42 ~StyleManager() = default; 43 44 // Late initialization, because Graphics needs to load the image files first. 45 void init(); 46 47 const UI::BuildingStatisticsStyleInfo& building_statistics_style() const; 48 const UI::ButtonStyleInfo& button_style(UI::ButtonStyle) const; 49 const UI::TextPanelStyleInfo& slider_style(UI::SliderStyle) const; 50 const UI::PanelStyleInfo* tabpanel_style(UI::TabPanelStyle) const; 51 const UI::TextPanelStyleInfo& editbox_style(UI::PanelStyle) const; 52 const UI::PanelStyleInfo* dropdown_style(UI::PanelStyle) const; 53 const UI::PanelStyleInfo* scrollbar_style(UI::PanelStyle) const; 54 const UI::ProgressbarStyleInfo& progressbar_style(UI::PanelStyle) const; 55 const UI::StatisticsPlotStyleInfo& statistics_plot_style() const; 56 const UI::TableStyleInfo& table_style(UI::PanelStyle) const; 57 const UI::WareInfoStyleInfo& ware_info_style(UI::WareInfoStyle) const; 58 const UI::FontStyleInfo& font_style(UI::FontStyle style) const; 59 60 // Special elements 61 int minimum_font_size() const; 62 const RGBColor& minimap_icon_frame() const; 63 static std::string color_tag(const std::string& text, const RGBColor& color); 64 65 private: 66 using PanelStyleMap = std::map<UI::PanelStyle, std::unique_ptr<const UI::PanelStyleInfo>>; 67 void add_button_style(UI::ButtonStyle style, const LuaTable& table); 68 void add_slider_style(UI::SliderStyle style, const LuaTable& table); 69 void add_editbox_style(UI::PanelStyle style, const LuaTable& table); 70 void add_tabpanel_style(UI::TabPanelStyle style, const LuaTable& table); 71 void add_progressbar_style(UI::PanelStyle style, const LuaTable& table); 72 void add_table_style(UI::PanelStyle style, const LuaTable& table); 73 void set_statistics_plot_style(const LuaTable& table); 74 void set_building_statistics_style(const LuaTable& table); 75 void add_ware_info_style(UI::WareInfoStyle style, const LuaTable& table); 76 void add_style(UI::PanelStyle style, const LuaTable& table, PanelStyleMap* map); 77 void add_font_style(UI::FontStyle font, const LuaTable& table, const std::string& key); 78 79 std::map<UI::ButtonStyle, std::unique_ptr<const UI::ButtonStyleInfo>> buttonstyles_; 80 std::map<UI::PanelStyle, std::unique_ptr<const UI::TextPanelStyleInfo>> editboxstyles_; 81 std::map<UI::SliderStyle, std::unique_ptr<const UI::TextPanelStyleInfo>> sliderstyles_; 82 std::map<UI::TabPanelStyle, std::unique_ptr<const UI::PanelStyleInfo>> tabpanelstyles_; 83 PanelStyleMap dropdownstyles_; 84 PanelStyleMap scrollbarstyles_; 85 86 int minimum_font_size_; 87 RGBColor minimap_icon_frame_; 88 std::map<UI::FontStyle, std::unique_ptr<const UI::FontStyleInfo>> fontstyles_; 89 std::unique_ptr<const UI::BuildingStatisticsStyleInfo> building_statistics_style_; 90 std::map<UI::PanelStyle, std::unique_ptr<const UI::ProgressbarStyleInfo>> progressbar_styles_; 91 std::unique_ptr<const UI::StatisticsPlotStyleInfo> statistics_plot_style_; 92 std::map<UI::PanelStyle, std::unique_ptr<const UI::TableStyleInfo>> table_styles_; 93 std::map<UI::WareInfoStyle, std::unique_ptr<const UI::WareInfoStyleInfo>> ware_info_styles_; 94 95 DISALLOW_COPY_AND_ASSIGN(StyleManager); 96 }; 97 98 #endif // end of include guard: WL_GRAPHIC_STYLE_MANAGER_H 99