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-2019 The ManaPlus Developers |
7 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
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_PALETTE_H |
26 |
|
|
#define GUI_PALETTE_H |
27 |
|
|
|
28 |
|
|
#include "enums/gui/gradienttype.h" |
29 |
|
|
|
30 |
|
|
#include "gui/color.h" |
31 |
|
|
|
32 |
|
|
#include "utils/vector.h" |
33 |
|
|
|
34 |
|
|
#include <map> |
35 |
|
|
#include <set> |
36 |
|
|
#include <string> |
37 |
|
|
|
38 |
|
|
// Default Gradient Delay |
39 |
|
|
#define GRADIENT_DELAY 40 |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* Class controlling the game's color palette. |
43 |
|
|
*/ |
44 |
|
|
class Palette notfinal |
45 |
|
|
{ |
46 |
|
|
public: |
47 |
|
|
/** Black Color Constant */ |
48 |
|
|
static const Color BLACK; |
49 |
|
|
|
50 |
|
|
A_DELETE_COPY(Palette) |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* Returns the color associated with a character, if it exists. Returns |
54 |
|
|
* Palette::BLACK if the character is not found. |
55 |
|
|
* |
56 |
|
|
* @param c character requested |
57 |
|
|
* @param valid indicate whether character is known |
58 |
|
|
* |
59 |
|
|
* @return the requested color or Palette::BLACK |
60 |
|
|
*/ |
61 |
|
|
const Color &getCharColor(const signed char c, |
62 |
|
|
bool &valid) const A_WARN_UNUSED; |
63 |
|
|
|
64 |
|
|
/** |
65 |
|
|
* Get the character used by the specified color. |
66 |
|
|
* |
67 |
|
|
* @param type the color type of the color |
68 |
|
|
* |
69 |
|
|
* @return the color char of the color with the given index |
70 |
|
|
*/ |
71 |
|
|
inline char getColorChar(const int type) const A_WARN_UNUSED |
72 |
|
|
{ return mColors[CAST_SIZE(type)].ch; } |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* Updates all colors, that are non-static. |
76 |
|
|
*/ |
77 |
|
|
static void advanceGradients(); |
78 |
|
|
|
79 |
|
|
protected: |
80 |
|
|
/** Colors used for the rainbow gradient */ |
81 |
|
|
static const Color RAINBOW_COLORS[7]; |
82 |
|
|
static const int RAINBOW_COLOR_COUNT; |
83 |
|
|
|
84 |
|
|
/** Time tick, that gradient-type colors were updated the last time. */ |
85 |
|
|
int mRainbowTime; |
86 |
|
|
|
87 |
|
|
typedef std::set<Palette*> Palettes; |
88 |
|
|
static Palettes mInstances; |
89 |
|
|
|
90 |
|
|
/** |
91 |
|
|
* Constructor |
92 |
|
|
*/ |
93 |
|
|
explicit Palette(const int size); |
94 |
|
|
|
95 |
|
|
/** |
96 |
|
|
* Destructor |
97 |
|
|
*/ |
98 |
|
|
virtual ~Palette(); |
99 |
|
|
|
100 |
|
|
void advanceGradient(); |
101 |
|
|
|
102 |
|
637794 |
struct ColorElem final |
103 |
|
|
{ |
104 |
|
270946 |
ColorElem() : |
105 |
|
|
type(0), |
106 |
|
|
color(0), |
107 |
|
|
testColor(0), |
108 |
|
|
committedColor(0), |
109 |
|
|
text(), |
110 |
|
|
ch(0), |
111 |
|
|
grad(GradientType::STATIC), |
112 |
|
|
committedGrad(GradientType::STATIC), |
113 |
|
|
gradientIndex(0), |
114 |
|
|
delay(0), |
115 |
|
1354730 |
committedDelay(0) |
116 |
|
|
{ |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
A_DEFAULT_COPY(ColorElem) |
120 |
|
|
|
121 |
|
|
int type; |
122 |
|
|
Color color; |
123 |
|
|
Color testColor; |
124 |
|
|
Color committedColor; |
125 |
|
|
std::string text; |
126 |
|
|
signed char ch; |
127 |
|
|
GradientTypeT grad; |
128 |
|
|
GradientTypeT committedGrad; |
129 |
|
|
int gradientIndex; |
130 |
|
|
int delay; |
131 |
|
|
int committedDelay; |
132 |
|
|
|
133 |
|
|
void set(const int type0, |
134 |
|
|
const Color &color0, |
135 |
|
|
const GradientTypeT grad0, |
136 |
|
|
const int delay0) |
137 |
|
|
{ |
138 |
|
110248 |
type = type0; |
139 |
|
110248 |
color = color0; |
140 |
|
110248 |
testColor = color0; |
141 |
|
110248 |
grad = grad0; |
142 |
|
110248 |
delay = delay0; |
143 |
|
110248 |
gradientIndex = rand(); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
inline unsigned int getRGB() const noexcept2 A_WARN_UNUSED |
147 |
|
|
{ |
148 |
|
8690 |
return (committedColor.r << 16) | (committedColor.g << 8) | |
149 |
|
8690 |
committedColor.b; |
150 |
|
|
} |
151 |
|
|
}; |
152 |
|
|
typedef STD_VECTOR<ColorElem> Colors; |
153 |
|
|
typedef std::map<unsigned char, int> CharColors; |
154 |
|
|
Colors mColors; |
155 |
|
|
CharColors mCharColors; |
156 |
|
|
STD_VECTOR<ColorElem*> mGradVector; |
157 |
|
|
}; |
158 |
|
|
|
159 |
|
|
#endif // GUI_PALETTE_H |