ManaPlus
userpalette.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-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_USERPALETTE_H
25 #define GUI_USERPALETTE_H
26 
27 #include "logger.h"
28 
29 #include "enums/gui/usercolorid.h"
30 
31 #include "gui/palette.h"
32 
33 #include "gui/models/listmodel.h"
34 
38 class UserPalette final : public Palette, public ListModel
39 {
40  public:
44  UserPalette();
45 
47 
48 
51  ~UserPalette();
52 
60  inline const Color &getCommittedColor(const UserColorIdT type)
61  const A_WARN_UNUSED
62  {
63  return mColors[CAST_SIZE(type)].committedColor;
64  }
65 
73  inline const Color &getTestColor(const UserColorIdT type)
74  const A_WARN_UNUSED
75  { return mColors[CAST_SIZE(type)].testColor; }
76 
83  inline void setTestColor(const UserColorIdT type,
84  const Color &color)
85  { mColors[CAST_SIZE(type)].testColor = color; }
86 
95  void setColor(const UserColorIdT type,
96  const int r,
97  const int g,
98  const int b);
99 
105  void setGradient(const UserColorIdT type,
106  const GradientTypeT grad);
107 
109  const int delay)
110  { mColors[CAST_SIZE(type)].delay = delay; }
111 
118  { return CAST_S32(mColors.size()); }
119 
127  std::string getElementAt(int i) override final A_WARN_UNUSED;
128 
132  inline void commit()
133  { commit(false); }
134 
138  void rollback();
139 
148  int getColorTypeAt(const int i) A_WARN_UNUSED;
149 
159  inline const Color &getColor(UserColorIdT type,
160  const unsigned int alpha = 255U)
161  A_WARN_UNUSED
162  {
163  if (CAST_SIZE(type) >= mColors.size())
164  {
165  logger->log("incorrect color request type: %d from %u",
166  CAST_S32(type),
167  CAST_U32(mColors.size()));
168  type = UserColorId::BEING;
169  }
170  Color* col = &mColors[CAST_SIZE(type)].color;
171  col->a = alpha;
172  return *col;
173  }
174 
175  int getIdByChar(const signed char c, bool &valid) const A_WARN_UNUSED;
176 
185  const A_WARN_UNUSED
186  { return mColors[CAST_SIZE(type)].grad; }
187 
195  inline int getGradientDelay(const UserColorIdT type)
196  const A_WARN_UNUSED
197  { return mColors[CAST_SIZE(type)].delay; }
198 
199  inline const Color &getColorWithAlpha(const UserColorIdT type)
200  A_WARN_UNUSED
201  {
202  Color *const col = &mColors[CAST_SIZE(type)].color;
203  col->a = CAST_U32(
204  mColors[CAST_SIZE(type)].delay);
205  return *col;
206  }
207 
208  private:
217  void setColorAt(int i, int r, int g, int b);
218 
223  void commit(const bool commitNonStatic);
224 
235  static std::string getConfigName(const std::string &typeName)
237 
238  void addColor(const UserColorIdT type,
239  const unsigned rgb,
240  GradientTypeT grad,
241  const std::string &text,
242  int delay = GRADIENT_DELAY);
243 
244  void addLabel(const UserColorIdT type,
245  const std::string &text);
246 };
247 
248 extern UserPalette *userPalette;
249 
250 #endif // GUI_USERPALETTE_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
#define CAST_U32
Definition: cast.h:30
const Color & getColor(UserColorIdT type, const unsigned int alpha=255U)
Definition: userpalette.h:159
int getGradientDelay(const UserColorIdT type) const
Definition: userpalette.h:195
void setGradientDelay(const UserColorIdT type, const int delay)
Definition: userpalette.h:108
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
unsigned int a
Definition: color.h:250
void rollback()
GradientType ::T GradientTypeT
Definition: gradienttype.h:37
void setGradient(const UserColorIdT type, const GradientTypeT grad)
#define A_WARN_UNUSED
Definition: localconsts.h:172
#define final
Definition: localconsts.h:45
#define GRADIENT_DELAY
Definition: palette.h:38
int getIdByChar(const signed char c, bool &valid) const
static std::string getConfigName(const std::string &typeName)
const Color & getTestColor(const UserColorIdT type) const
Definition: userpalette.h:73
void setColorAt(int i, int r, int g, int b)
Logger * logger
Definition: logger.cpp:95
int getNumberOfElements()
Definition: userpalette.h:117
#define CAST_S32
Definition: cast.h:29
void addColor(const UserColorIdT type, const unsigned rgb, GradientTypeT grad, const std::string &text, int delay=40)
UserPalette * userPalette
Definition: userpalette.cpp:33
void setColor(const UserColorIdT type, const int r, const int g, const int b)
void addLabel(const UserColorIdT type, const std::string &text)
Colors mColors
Definition: palette.h:153
void commit()
Definition: userpalette.h:132
const Color & getCommittedColor(const UserColorIdT type) const
Definition: userpalette.h:60
void setTestColor(const UserColorIdT type, const Color &color)
Definition: userpalette.h:83
std::string getElementAt(int i)
GradientTypeT getGradientType(const UserColorIdT type) const
Definition: userpalette.h:184
Definition: color.h:74
#define CAST_SIZE
Definition: cast.h:33
int getColorTypeAt(const int i)
#define override
Definition: localconsts.h:46
void log(const char *const log_text,...)
Definition: logger.cpp:243
UserColorId ::T UserColorIdT
Definition: usercolorid.h:98