GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/palette.h Lines: 11 11 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008  Douglas Boffey <[email protected]>
4
 *  Copyright (C) 2009  The Mana World Development Team
5
 *  Copyright (C) 2009-2010  The Mana Developers
6
 *  Copyright (C) 2011-2017  The ManaPlus Developers
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#ifndef GUI_PALETTE_H
25
#define GUI_PALETTE_H
26
27
#include "enums/gui/gradienttype.h"
28
29
#include "gui/color.h"
30
31
#include "utils/vector.h"
32
33
#include <map>
34
#include <set>
35
#include <string>
36
37
// Default Gradient Delay
38
#define GRADIENT_DELAY 40
39
40
/**
41
 * Class controlling the game's color palette.
42
 */
43
class Palette notfinal
44
{
45
    public:
46
        /** Black Color Constant */
47
        static const Color BLACK;
48
49
        A_DELETE_COPY(Palette)
50
51
        /**
52
         * Returns the color associated with a character, if it exists. Returns
53
         * Palette::BLACK if the character is not found.
54
         *
55
         * @param c character requested
56
         * @param valid indicate whether character is known
57
         *
58
         * @return the requested color or Palette::BLACK
59
         */
60
        const Color &getCharColor(const signed char c,
61
                                  bool &valid) const A_WARN_UNUSED;
62
63
        /**
64
         * Get the character used by the specified color.
65
         *
66
         * @param type the color type of the color
67
         *
68
         * @return the color char of the color with the given index
69
         */
70
        inline char getColorChar(const int type) const A_WARN_UNUSED
71
        { return mColors[CAST_SIZE(type)].ch; }
72
73
        /**
74
         * Updates all colors, that are non-static.
75
         */
76
        static void advanceGradients();
77
78
    protected:
79
        /** Colors used for the rainbow gradient */
80
        static const Color RAINBOW_COLORS[7];
81
        static const int RAINBOW_COLOR_COUNT;
82
83
        /** Time tick, that gradient-type colors were updated the last time. */
84
        int mRainbowTime;
85
86
        typedef std::set<Palette*> Palettes;
87
        static Palettes mInstances;
88
89
        /**
90
         * Constructor
91
         */
92
        explicit Palette(const int size);
93
94
        /**
95
         * Destructor
96
         */
97
        virtual ~Palette();
98
99
        void advanceGradient();
100
101
1113302
        struct ColorElem final
102
        {
103
473978
            ColorElem() :
104
                type(0),
105
                color(0),
106
                testColor(0),
107
                committedColor(0),
108
                text(),
109
                ch(0),
110
                grad(GradientType::STATIC),
111
                committedGrad(GradientType::STATIC),
112
                gradientIndex(0),
113
                delay(0),
114
2369890
                committedDelay(0)
115
            {
116
            }
117
118
            A_DEFAULT_COPY(ColorElem)
119
120
            int type;
121
            Color color;
122
            Color testColor;
123
            Color committedColor;
124
            std::string text;
125
            signed char ch;
126
            GradientTypeT grad;
127
            GradientTypeT committedGrad;
128
            int gradientIndex;
129
            int delay;
130
            int committedDelay;
131
132
            void set(const int type0,
133
                     const Color &color0,
134
                     const GradientTypeT grad0,
135
                     const int delay0)
136
            {
137
195138
                type = type0;
138
195138
                color = color0;
139
195138
                testColor = color0;
140
195138
                grad = grad0;
141
195138
                delay = delay0;
142
195138
                gradientIndex = rand();
143
            }
144
145
            inline unsigned int getRGB() const noexcept2 A_WARN_UNUSED
146
            {
147
15070
                return (committedColor.r << 16) | (committedColor.g << 8) |
148
15070
                        committedColor.b;
149
            }
150
        };
151
        typedef STD_VECTOR<ColorElem> Colors;
152
        typedef std::map<unsigned char, int> CharColors;
153
        Colors mColors;
154
        CharColors mCharColors;
155
        STD_VECTOR<ColorElem*> mGradVector;
156
};
157
158
#endif  // GUI_PALETTE_H