ManaPlus
palette.h
Go to the documentation of this file.
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 
45 {
46  public:
48  static const Color BLACK;
49 
51 
52 
61  const Color &getCharColor(const signed char c,
62  bool &valid) const A_WARN_UNUSED;
63 
71  inline char getColorChar(const int type) const A_WARN_UNUSED
72  { return mColors[CAST_SIZE(type)].ch; }
73 
77  static void advanceGradients();
78 
79  protected:
81  static const Color RAINBOW_COLORS[7];
82  static const int RAINBOW_COLOR_COUNT;
83 
86 
87  typedef std::set<Palette*> Palettes;
89 
93  explicit Palette(const int size);
94 
98  virtual ~Palette();
99 
100  void advanceGradient();
101 
103  {
105  type(0),
106  color(0),
107  testColor(0),
108  committedColor(0),
109  text(),
110  ch(0),
113  gradientIndex(0),
114  delay(0),
115  committedDelay(0)
116  {
117  }
118 
120 
121  int type;
125  std::string text;
126  signed char ch;
130  int delay;
132 
133  void set(const int type0,
134  const Color &color0,
135  const GradientTypeT grad0,
136  const int delay0)
137  {
138  type = type0;
139  color = color0;
140  testColor = color0;
141  grad = grad0;
142  delay = delay0;
143  gradientIndex = rand();
144  }
145 
146  inline unsigned int getRGB() const noexcept2 A_WARN_UNUSED
147  {
148  return (committedColor.r << 16) | (committedColor.g << 8) |
150  }
151  };
152  typedef STD_VECTOR<ColorElem> Colors;
153  typedef std::map<unsigned char, int> CharColors;
156  STD_VECTOR<ColorElem*> mGradVector;
157 };
158 
159 #endif // GUI_PALETTE_H
#define CAST_SIZE
Definition: cast.h:34
Definition: color.h:76
unsigned int b
Definition: color.h:245
unsigned int r
Definition: color.h:235
unsigned int g
Definition: color.h:240
Colors mColors
Definition: palette.h:154
Palette(const int size)
Definition: palette.cpp:52
void advanceGradient()
Definition: palette.cpp:85
virtual ~Palette()
Definition: palette.cpp:61
const Color & getCharColor(const signed char c, bool &valid) const
Definition: palette.cpp:66
std::set< Palette * > Palettes
Definition: palette.h:87
static const Color RAINBOW_COLORS[7]
Definition: palette.h:81
static const int RAINBOW_COLOR_COUNT
Definition: palette.h:82
char getColorChar(const int type) const
Definition: palette.h:71
static Palettes mInstances
Definition: palette.h:88
static void advanceGradients()
Definition: palette.cpp:79
std::map< unsigned char, int > CharColors
Definition: palette.h:153
CharColors mCharColors
Definition: palette.h:155
static const Color BLACK
Definition: palette.h:48
std::vector< ColorElem * > mGradVector
Definition: palette.h:156
int mRainbowTime
Definition: palette.h:85
std::vector< ColorElem > Colors
Definition: palette.h:152
GradientType ::T GradientTypeT
Definition: gradienttype.h:38
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:41
int size()
Definition: emotedb.cpp:306
void set(const int type0, const Color &color0, const GradientTypeT grad0, const int delay0)
Definition: palette.h:133
std::string text
Definition: palette.h:125
GradientTypeT committedGrad
Definition: palette.h:128
Color committedColor
Definition: palette.h:124
signed char ch
Definition: palette.h:126
GradientTypeT grad
Definition: palette.h:127
unsigned int getRGB() const
Definition: palette.h:146