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-2018 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 
44 {
45  public:
47  static const Color BLACK;
48 
50 
51 
60  const Color &getCharColor(const signed char c,
61  bool &valid) const A_WARN_UNUSED;
62 
70  inline char getColorChar(const int type) const A_WARN_UNUSED
71  { return mColors[CAST_SIZE(type)].ch; }
72 
76  static void advanceGradients();
77 
78  protected:
80  static const Color RAINBOW_COLORS[7];
81  static const int RAINBOW_COLOR_COUNT;
82 
85 
86  typedef std::set<Palette*> Palettes;
87  static Palettes mInstances;
88 
92  explicit Palette(const int size);
93 
97  virtual ~Palette();
98 
99  void advanceGradient();
100 
102  {
104  type(0),
105  color(0),
106  testColor(0),
107  committedColor(0),
108  text(),
109  ch(0),
112  gradientIndex(0),
113  delay(0),
114  committedDelay(0)
115  {
116  }
117 
119 
120  int type;
124  std::string text;
125  signed char ch;
129  int delay;
131 
132  void set(const int type0,
133  const Color &color0,
134  const GradientTypeT grad0,
135  const int delay0)
136  {
137  type = type0;
138  color = color0;
139  testColor = color0;
140  grad = grad0;
141  delay = delay0;
142  gradientIndex = rand();
143  }
144 
145  inline unsigned int getRGB() const noexcept2 A_WARN_UNUSED
146  {
147  return (committedColor.r << 16) | (committedColor.g << 8) |
149  }
150  };
151  typedef STD_VECTOR<ColorElem> Colors;
152  typedef std::map<unsigned char, int> CharColors;
155  STD_VECTOR<ColorElem*> mGradVector;
156 };
157 
158 #endif // GUI_PALETTE_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
void advanceGradient()
Definition: palette.cpp:84
static Palettes mInstances
Definition: palette.h:87
virtual ~Palette()
Definition: palette.cpp:60
std::set< Palette * > Palettes
Definition: palette.h:86
GradientType ::T GradientTypeT
Definition: gradienttype.h:37
static void advanceGradients()
Definition: palette.cpp:78
unsigned int g
Definition: color.h:239
#define A_WARN_UNUSED
Definition: localconsts.h:152
GradientTypeT grad
Definition: palette.h:126
#define final
Definition: localconsts.h:45
static const Color BLACK
Definition: palette.h:47
signed char ch
Definition: palette.h:125
std::vector< ColorElem * > mGradVector
Definition: palette.h:155
std::string text
Definition: palette.h:124
static const Color RAINBOW_COLORS[7]
Definition: palette.h:80
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
unsigned int b
Definition: color.h:244
#define notfinal
Definition: localconsts.h:252
Colors mColors
Definition: palette.h:153
const Color & getCharColor(const signed char c, bool &valid) const
Definition: palette.cpp:65
void set(const int type0, const Color &color0, const GradientTypeT grad0, const int delay0)
Definition: palette.h:132
char getColorChar(const int type) const
Definition: palette.h:70
static const int RAINBOW_COLOR_COUNT
Definition: palette.h:81
std::vector< ColorElem > Colors
Definition: palette.h:151
CharColors mCharColors
Definition: palette.h:154
Definition: color.h:74
std::map< unsigned char, int > CharColors
Definition: palette.h:152
#define CAST_SIZE
Definition: cast.h:33
GradientTypeT committedGrad
Definition: palette.h:127
Palette(const int size)
Definition: palette.cpp:51
Color committedColor
Definition: palette.h:123
int mRainbowTime
Definition: palette.h:84
#define noexcept2
Definition: localconsts.h:49
unsigned int getRGB() const
Definition: palette.h:145
unsigned int r
Definition: color.h:234