GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/theme.h Lines: 8 11 72.7 %
Date: 2017-11-29 Branches: 1 2 50.0 %

Line Branch Exec Source
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-2017  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
30
#include "enums/gui/progresscolorid.h"
31
#include "enums/gui/themecolorid.h"
32
33
#include "listeners/configlistener.h"
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();
59
60
        A_DELETE_COPY(Theme)
61
62
        static void prepareThemePath();
63
64
        static void selectSkin();
65
66
        static std::string getThemePath() A_WARN_UNUSED
67
12314
        { return mThemePath; }
68
69
        static std::string getThemeName() A_WARN_UNUSED
70
4
        { return mThemeName; }
71
72
        static void fillSkinsList(StringVect &list);
73
74
        static void fillFontsList(StringVect &list);
75
76
        static void fillSoundsList(StringVect &list);
77
78
        /**
79
         * Returns the patch to the given gui resource relative to the theme
80
         * or, if it isn't in the theme, relative to 'graphics/gui'.
81
         */
82
        static std::string resolveThemePath(const std::string &path)
83
                                            A_WARN_UNUSED;
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
99
        /**
100
         * Loads a skin.
101
         */
102
        Skin *load(const std::string &filename,
103
                   const std::string &filename2,
104
                   const bool full = true,
105
                   const std::string
106
                   &restrict defaultPath = getThemePath()) A_WARN_UNUSED;
107
108
        Skin *loadSkinRect(ImageRect &image,
109
                           const std::string &name,
110
                           const std::string &name2,
111
                           const int start = 0,
112
                           const int end = 8) A_WARN_UNUSED;
113
114
        void unload(Skin *const skin);
115
116
        /**
117
         * Updates the alpha values of all of the skins.
118
         */
119
        void updateAlpha();
120
121
        /**
122
         * Get the minimum opacity allowed to skins.
123
         */
124
        float getMinimumOpacity() const noexcept2 A_WARN_UNUSED
125
516
        { return mMinimumOpacity; }
126
127
        /**
128
         * Gets the color associated with the type. Sets the alpha channel
129
         * before returning.
130
         *
131
         * @param type the color type requested
132
         * @param alpha alpha channel to use
133
         *
134
         * @return the requested color
135
         */
136
15280
        inline const Color &getColor(ThemeColorIdT type,
137
                                     const unsigned int alpha = 255U)
138
                                     A_WARN_UNUSED
139
        {
140
30560
            if (CAST_SIZE(type) >= mColors.size())
141
            {
142
                logger->log("incorrect color request type: %d from %u",
143
                    CAST_S32(type),
144
                    CAST_U32(mColors.size()));
145
                type = ThemeColorId::BROWSERBOX;
146
            }
147
30560
            Color *const col = &mColors[CAST_SIZE(type)].color;
148
15280
            col->a = alpha;
149
15280
            return *col;
150
        }
151
152
        ThemeColorIdT getIdByChar(const signed char c,
153
                                  bool &valid) const A_WARN_UNUSED;
154
155
        /**
156
         * Set the minimum opacity allowed to skins.
157
         * Set a negative value to free the minimum allowed.
158
         */
159
        void setMinimumOpacity(const float minimumOpacity);
160
161
        void optionChanged(const std::string &name) override final;
162
163
        void loadRect(ImageRect &image,
164
                      const std::string &name,
165
                      const std::string &name2,
166
                      const int start = 0,
167
                      const int end = 8);
168
169
        static void unloadRect(const ImageRect &rect,
170
                               const int start = 0,
171
                               const int end = 8);
172
173
        static Image *getImageFromThemeXml(const std::string &name,
174
                                           const std::string &name2)
175
                                           A_WARN_UNUSED;
176
177
        static ThemeInfo *loadInfo(const std::string &themeName) A_WARN_UNUSED;
178
179
    private:
180
        Skin *readSkin(const std::string &filename0,
181
                       const bool full) A_WARN_UNUSED;
182
183
        // Map containing all window skins
184
        typedef std::map<std::string, Skin*> Skins;
185
        typedef Skins::iterator SkinIterator;
186
187
        Skins mSkins;
188
189
        static std::string mThemePath;
190
        static std::string mThemeName;
191
        static std::string mScreenDensity;
192
193
        static bool tryThemePath(const std::string &themePath) A_WARN_UNUSED;
194
195
        void loadColors(std::string file = "");
196
197
        /**
198
         * Tells if the current skins opacity
199
         * should not get less than the given value
200
         */
201
        float mMinimumOpacity;
202
203
        typedef STD_VECTOR<DyePalette*> ProgressColors;
204
        ProgressColors mProgressColors;
205
};
206
207
#endif  // GUI_THEME_H