ManaPlus
theme.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008 The Legend of Mazzeroth Development Team
4  * Copyright (C) 2009 Aethyra Development Team
5  * Copyright (C) 2009 The Mana World Development Team
6  * Copyright (C) 2009-2010 The Mana Developers
7  * Copyright (C) 2011-2018 The ManaPlus Developers
8  *
9  * This file is part of The ManaPlus Client.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef GUI_THEME_H
26 #define GUI_THEME_H
27 
28 #include "logger.h"
29 
31 #include "enums/gui/themecolorid.h"
32 
34 
35 #include "gui/palette.h"
36 
37 #include "utils/stringvector.h"
38 
39 #include "localconsts.h"
40 
41 class DyePalette;
42 class Image;
43 class ImageRect;
44 class ImageSet;
45 class Skin;
46 class Theme;
47 
48 struct ThemeInfo;
49 
50 extern Theme *theme;
51 
52 class Theme final : public Palette,
53  public ConfigListener
54 {
55  public:
56  Theme();
57 
58  ~Theme() override final;
59 
61 
62  static void prepareThemePath();
63 
64  static void selectSkin();
65 
66  static std::string getThemePath() A_WARN_UNUSED
67  { return mThemePath; }
68 
69  static std::string getThemeName() A_WARN_UNUSED
70  { return mThemeName; }
71 
72  static void fillSkinsList(StringVect &list);
73 
74  static void fillFontsList(StringVect &list);
75 
76  static void fillSoundsList(StringVect &list);
77 
82  static std::string resolveThemePath(const std::string &path)
84 
85  static Image *getImageFromTheme(const std::string &path) A_WARN_UNUSED;
86 
87  static ImageSet *getImageSetFromTheme(const std::string &path,
88  const int w,
89  const int h) A_WARN_UNUSED;
90 
91  static ImageSet *getImageSetFromThemeXml(const std::string &name,
92  const std::string &name2,
93  const int w,
94  const int h)A_WARN_UNUSED;
95 
96  static Color getProgressColor(const ProgressColorIdT type,
97  const float progress) A_WARN_UNUSED;
98 
102  Skin *load(const std::string &filename,
103  const std::string &filename2,
104  const bool full,
105  const std::string &restrict defaultPath) A_WARN_UNUSED;
106 
107  Skin *loadSkinRect(ImageRect &image,
108  const std::string &name,
109  const std::string &name2,
110  const int start,
111  const int end) A_WARN_UNUSED;
112 
113  void unload(Skin *const skin);
114 
118  void updateAlpha();
119 
123  float getMinimumOpacity() const noexcept2 A_WARN_UNUSED
124  { return mMinimumOpacity; }
125 
135  inline const Color &getColor(ThemeColorIdT type,
136  const unsigned int alpha) A_WARN_UNUSED
137  {
138  if (CAST_SIZE(type) >= mColors.size())
139  {
140  logger->log("incorrect color request type: %d from %u",
141  CAST_S32(type),
142  CAST_U32(mColors.size()));
144  }
145  Color *const col = &mColors[CAST_SIZE(type)].color;
146  col->a = alpha;
147  return *col;
148  }
149 
150  ThemeColorIdT getIdByChar(const signed char c,
151  bool &valid) const A_WARN_UNUSED;
152 
157  void setMinimumOpacity(const float minimumOpacity);
158 
159  void optionChanged(const std::string &name) override final;
160 
161  void loadRect(ImageRect &image,
162  const std::string &name,
163  const std::string &name2,
164  const int start,
165  const int end);
166 
167  static void unloadRect(const ImageRect &rect,
168  const int start,
169  const int end);
170 
171  static Image *getImageFromThemeXml(const std::string &name,
172  const std::string &name2)
174 
175  static ThemeInfo *loadInfo(const std::string &themeName) A_WARN_UNUSED;
176 
177  private:
178  Skin *readSkin(const std::string &filename0,
179  const bool full) A_WARN_UNUSED;
180 
181  // Map containing all window skins
182  typedef std::map<std::string, Skin*> Skins;
183  typedef Skins::iterator SkinIterator;
184 
185  Skins mSkins;
186 
187  static std::string mThemePath;
188  static std::string mThemeName;
189  static std::string mScreenDensity;
190 
191  static bool tryThemePath(const std::string &themePath) A_WARN_UNUSED;
192 
193  void loadColors(std::string file);
194 
200 
201  typedef STD_VECTOR<DyePalette*> ProgressColors;
202  ProgressColors mProgressColors;
203 };
204 
205 #endif // GUI_THEME_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
#define CAST_U32
Definition: cast.h:30
ProgressColorId ::T ProgressColorIdT
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:1092
static ImageSet * getImageSetFromThemeXml(const std::string &name, const std::string &name2, const int w, const int h)
Definition: theme.cpp:1160
static void fillSkinsList(StringVect &list)
Definition: theme.cpp:563
Definition: skin.h:35
void unload(Skin *const skin)
Definition: theme.cpp:249
unsigned int a
Definition: color.h:250
static Image * getImageFromThemeXml(const std::string &name, const std::string &name2)
Definition: theme.cpp:1135
float getMinimumOpacity() const
Definition: theme.h:123
Skins mSkins
Definition: theme.h:185
#define A_WARN_UNUSED
Definition: localconsts.h:172
std::map< std::string, Skin * > Skins
Definition: theme.h:182
#define final
Definition: localconsts.h:45
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
Skins::iterator SkinIterator
Definition: theme.h:183
static void selectSkin()
Definition: theme.cpp:597
Theme()
Definition: theme.cpp:77
ThemeColorIdT getIdByChar(const signed char c, bool &valid) const
Definition: theme.cpp:1284
static void prepareThemePath()
Definition: theme.cpp:603
std::vector< std::string > StringVect
Definition: stringvector.h:28
static std::string mThemePath
Definition: theme.h:187
ProgressColors mProgressColors
Definition: theme.h:202
~Theme()
Definition: theme.cpp:146
Logger * logger
Definition: logger.cpp:95
static void fillFontsList(StringVect &list)
Definition: theme.cpp:569
ThemeColorId ::T ThemeColorIdT
Definition: themecolorid.h:256
float mMinimumOpacity
Definition: theme.h:199
static ImageSet * getImageSetFromTheme(const std::string &path, const int w, const int h)
Definition: theme.cpp:659
void updateAlpha()
Definition: theme.cpp:280
std::vector< DyePalette * > ProgressColors
Definition: theme.h:201
static bool tryThemePath(const std::string &themePath)
Definition: theme.cpp:545
#define CAST_S32
Definition: cast.h:29
void optionChanged(const std::string &name)
Definition: theme.cpp:290
Skin * loadSkinRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:1109
static Image * getImageFromTheme(const std::string &path)
Definition: theme.cpp:654
Colors mColors
Definition: palette.h:153
static std::string getThemeName()
Definition: theme.h:69
Definition: theme.h:52
static void fillSoundsList(StringVect &list)
Definition: theme.cpp:577
Theme * theme
Definition: theme.cpp:61
const Color & getColor(ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:135
void setMinimumOpacity(const float minimumOpacity)
Definition: theme.cpp:271
static std::string mScreenDensity
Definition: theme.h:189
static ThemeInfo * loadInfo(const std::string &themeName)
Definition: theme.cpp:1215
Skin * readSkin(const std::string &filename0, const bool full)
Definition: theme.cpp:393
static std::string mThemeName
Definition: theme.h:188
Definition: image.h:61
Definition: color.h:74
#define restrict
Definition: localconsts.h:176
static Color getProgressColor(const ProgressColorIdT type, const float progress)
Definition: theme.cpp:154
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:243
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:1124
#define noexcept2
Definition: localconsts.h:49
static std::string resolveThemePath(const std::string &path)
Definition: theme.cpp:626
void loadColors(std::string file)
Definition: theme.cpp:1000