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(const 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()));
143  Color *const col = &mColors[CAST_SIZE(
144  ThemeColorId::BROWSERBOX)].color;
145  col->a = alpha;
146  return *col;
147  }
148  else
149  {
150  Color *const col = &mColors[CAST_SIZE(type)].color;
151  col->a = alpha;
152  return *col;
153  }
154  }
155 
156  ThemeColorIdT getIdByChar(const signed char c,
157  bool &valid) const A_WARN_UNUSED;
158 
163  void setMinimumOpacity(const float minimumOpacity);
164 
165  void optionChanged(const std::string &name) override final;
166 
167  void loadRect(ImageRect &image,
168  const std::string &name,
169  const std::string &name2,
170  const int start,
171  const int end);
172 
173  static void unloadRect(const ImageRect &rect,
174  const int start,
175  const int end);
176 
177  static Image *getImageFromThemeXml(const std::string &name,
178  const std::string &name2)
180 
181  static ThemeInfo *loadInfo(const std::string &themeName) A_WARN_UNUSED;
182 
183  private:
184  Skin *readSkin(const std::string &filename0,
185  const bool full) A_WARN_UNUSED;
186 
187  // Map containing all window skins
188  typedef std::map<std::string, Skin*> Skins;
189  typedef Skins::iterator SkinIterator;
190 
191  Skins mSkins;
192 
193  static std::string mThemePath;
194  static std::string mThemeName;
195  static std::string mScreenDensity;
196 
197  static bool tryThemePath(const std::string &themePath) A_WARN_UNUSED;
198 
199  void loadColors(std::string file);
200 
206 
207  typedef STD_VECTOR<DyePalette*> ProgressColors;
208  ProgressColors mProgressColors;
209 };
210 
211 #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:882
static ImageSet * getImageSetFromThemeXml(const std::string &name, const std::string &name2, const int w, const int h)
Definition: theme.cpp:950
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:925
float getMinimumOpacity() const
Definition: theme.h:123
Skins mSkins
Definition: theme.h:191
#define A_WARN_UNUSED
Definition: localconsts.h:152
std::map< std::string, Skin * > Skins
Definition: theme.h:188
#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:189
static void selectSkin()
Definition: theme.cpp:597
Theme()
Definition: theme.cpp:77
ThemeColorIdT getIdByChar(const signed char c, bool &valid) const
Definition: theme.cpp:1074
static void prepareThemePath()
Definition: theme.cpp:603
std::vector< std::string > StringVect
Definition: stringvector.h:28
static std::string mThemePath
Definition: theme.h:193
ProgressColors mProgressColors
Definition: theme.h:208
~Theme()
Definition: theme.cpp:146
Logger * logger
Definition: logger.cpp:88
static void fillFontsList(StringVect &list)
Definition: theme.cpp:569
ThemeColorId ::T ThemeColorIdT
Definition: themecolorid.h:34
float mMinimumOpacity
Definition: theme.h:205
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:207
static bool tryThemePath(const std::string &themePath)
Definition: theme.cpp:545
#define CAST_S32
Definition: cast.h:29
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:135
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:899
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
void setMinimumOpacity(const float minimumOpacity)
Definition: theme.cpp:271
static std::string mScreenDensity
Definition: theme.h:195
static ThemeInfo * loadInfo(const std::string &themeName)
Definition: theme.cpp:1005
Skin * readSkin(const std::string &filename0, const bool full)
Definition: theme.cpp:393
static std::string mThemeName
Definition: theme.h:194
Definition: image.h:61
Definition: color.h:74
#define restrict
Definition: localconsts.h:156
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:264
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:914
#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:790