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