ManaPlus
Public Member Functions | Private Member Functions | Static Private Member Functions
UserPalette Class Reference

#include <userpalette.h>

Inheritance diagram for UserPalette:
Palette ListModel

Public Member Functions

 UserPalette ()
 
 ~UserPalette ()
 
const ColorgetCommittedColor (const UserColorIdT type) const
 
const ColorgetTestColor (const UserColorIdT type) const
 
void setTestColor (const UserColorIdT type, const Color &color)
 
void setColor (const UserColorIdT type, const int r, const int g, const int b)
 
void setGradient (const UserColorIdT type, const GradientTypeT grad)
 
void setGradientDelay (const UserColorIdT type, const int delay)
 
int getNumberOfElements ()
 
std::string getElementAt (int i)
 
void commit ()
 
void rollback ()
 
int getColorTypeAt (const int i)
 
const ColorgetColor (UserColorIdT type, const unsigned int alpha)
 
int getIdByChar (const signed char c, bool &valid) const
 
GradientTypeT getGradientType (const UserColorIdT type) const
 
int getGradientDelay (const UserColorIdT type) const
 
const ColorgetColorWithAlpha (const UserColorIdT type)
 
- Public Member Functions inherited from Palette
const ColorgetCharColor (const signed char c, bool &valid) const
 
char getColorChar (const int type) const
 
- Public Member Functions inherited from ListModel
 ListModel ()
 
virtual ~ListModel ()
 

Private Member Functions

void setColorAt (int i, int r, int g, int b)
 
void commit (const bool commitNonStatic)
 
void addColor (const UserColorIdT type, const unsigned rgb, GradientTypeT grad, const std::string &text, int delay)
 
void addLabel (const UserColorIdT type, const std::string &text)
 

Static Private Member Functions

static std::string getConfigName (const std::string &typeName)
 

Additional Inherited Members

- Static Public Member Functions inherited from Palette
static void advanceGradients ()
 
- Static Public Attributes inherited from Palette
static const Color BLACK = Color(0, 0, 0, 255)
 
- Protected Types inherited from Palette
typedef std::set< Palette * > Palettes
 
typedef std::vector< ColorElemColors
 
typedef std::map< unsigned char, int > CharColors
 
- Protected Member Functions inherited from Palette
 Palette (const int size)
 
virtual ~Palette ()
 
void advanceGradient ()
 
- Protected Attributes inherited from Palette
int mRainbowTime
 
Colors mColors
 
CharColors mCharColors
 
std::vector< ColorElem * > mGradVector
 
- Static Protected Attributes inherited from Palette
static const Color RAINBOW_COLORS [7]
 
static const int RAINBOW_COLOR_COUNT = 7
 
static Palettes mInstances
 

Detailed Description

Class controlling the game's color palette.

Definition at line 38 of file userpalette.h.

Constructor & Destructor Documentation

◆ UserPalette()

UserPalette::UserPalette ( )

Constructor

Definition at line 127 of file userpalette.cpp.

References _, addColor(), addLabel(), UserColorId::AIR_COLLISION_HIGHLIGHT, UserColorId::ATTACK_RANGE, UserColorId::ATTACK_RANGE_BORDER, UserColorId::BEING, CAST_SIZE, UserColorId::COLLISION_HIGHLIGHT, commit(), UserColorId::DISREGARDED, UserColorId::ELEMENTAL_HP, UserColorId::ELEMENTAL_HP2, UserColorId::ENEMY, UserColorId::ERASED, UserColorId::EXP_INFO, UserColorId::FLOOR_ITEM_TEXT, UserColorId::FRIEND, UserColorId::GM, GRADIENT_DELAY, UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT, UserColorId::GUILD, UserColorId::HIT_CRITICAL, UserColorId::HIT_LOCAL_PLAYER_CRITICAL, UserColorId::HIT_LOCAL_PLAYER_MISS, UserColorId::HIT_LOCAL_PLAYER_MONSTER, UserColorId::HIT_MONSTER_PLAYER, UserColorId::HIT_PLAYER_MONSTER, UserColorId::HIT_PLAYER_PLAYER, UserColorId::HOME_PLACE, UserColorId::HOME_PLACE_BORDER, UserColorId::HOMUN_HP, UserColorId::HOMUN_HP2, UserColorId::HOMUNCULUS, UserColorId::IGNORED, UserColorId::LABEL_BEING, UserColorId::LABEL_HITS, UserColorId::LABEL_HP, UserColorId::LABEL_OTHER, UserColorId::LABEL_PARTICLES, UserColorId::LABEL_RANGES, UserColorId::LABEL_TILES, Palette::mColors, UserColorId::MERC_HP, UserColorId::MERC_HP2, UserColorId::MERCENARY, UserColorId::MISS, UserColorId::MONSTER, UserColorId::MONSTER_ATTACK_RANGE, UserColorId::MONSTER_COLLISION_HIGHLIGHT, UserColorId::MONSTER_HP, UserColorId::MONSTER_HP2, UserColorId::NET, UserColorId::NPC, UserColorId::PARTICLE, UserColorId::PARTY, UserColorId::PC, UserColorId::PET, UserColorId::PICKUP_INFO, UserColorId::PLAYER_HP, UserColorId::PLAYER_HP2, UserColorId::PORTAL_HIGHLIGHT, GradientType::RAINBOW, UserColorId::ROAD_POINT, UserColorId::SELF, UserColorId::SKILL_ATTACK_RANGE, UserColorId::SKILLUNIT, GradientType::STATIC, strprintf(), UserColorId::TEAM1, UserColorId::TEAM2, UserColorId::TEAM3, UserColorId::WALKABLE_HIGHLIGHT, and UserColorId::WATER_COLLISION_HIGHLIGHT.

127  :
129  ListModel()
130 {
131  mColors[CAST_SIZE(UserColorId::BEING)] = ColorElem();
132  mColors[CAST_SIZE(UserColorId::PC)] = ColorElem();
133  mColors[CAST_SIZE(UserColorId::SELF)] = ColorElem();
134  mColors[CAST_SIZE(UserColorId::GM)] = ColorElem();
135  mColors[CAST_SIZE(UserColorId::NPC)] = ColorElem();
136  mColors[CAST_SIZE(UserColorId::MONSTER)] = ColorElem();
137 
139  // TRANSLATORS: palette label
140  _("Beings"));
142  0xffffff,
144  // TRANSLATORS: palette color
145  _("Being"),
148  0xb0ffb0,
150  // TRANSLATORS: palette color
151  _("Friend names"),
154  0xa00000,
156  // TRANSLATORS: palette color
157  _("Disregarded names"),
160  0xff0000,
162  // TRANSLATORS: palette color
163  _("Ignored names"),
166  0xff0000,
168  // TRANSLATORS: palette color
169  _("Erased names"),
172  0xff4040,
174  // TRANSLATORS: palette color
175  _("Enemy"),
178  0xffffff,
180  // TRANSLATORS: palette color
181  _("Other players names"),
184  0xff8040,
186  // TRANSLATORS: palette color
187  _("Own name"),
190  0x00ff00,
192  // TRANSLATORS: palette color
193  _("GM names"),
196  0xc8c8ff,
198  // TRANSLATORS: palette color
199  _("NPCs"),
202  0xff4040,
204  // TRANSLATORS: palette color
205  _("Monsters"),
208  0xffffff,
210  // TRANSLATORS: palette color
211  _("Pets"),
214  0xffffff,
216  // TRANSLATORS: palette color
217  _("Mercenary"),
220  0xffffff,
222  // TRANSLATORS: palette color
223  _("Homunculus"),
226  0xffffff,
228  // TRANSLATORS: palette color
229  _("Skill unit"),
232  0xff00d8,
234  // TRANSLATORS: palette color
235  _("Party members"),
238  0xff00d8,
240  // TRANSLATORS: palette color
241  _("Guild members"),
244  0x0000ff,
246  // TRANSLATORS: palette color
247  strprintf(_("Team %d"), 1),
250  0x00a020,
252  // TRANSLATORS: palette color
253  strprintf(_("Team %d"), 2),
256  0xffff20,
258  // TRANSLATORS: palette color
259  strprintf(_("Team %d"), 3),
262  // TRANSLATORS: palette label
263  _("Particles"));
265  0xffffff,
267  // TRANSLATORS: palette color
268  _("Particle effects"),
271  0x28dc28,
273  // TRANSLATORS: palette color
274  _("Pickup notification"),
277  0xffff00,
279  // TRANSLATORS: palette color
280  _("Exp notification"),
283  // TRANSLATORS: palette label
284  _("Hp bars"));
286  0x00ff00,
288  // TRANSLATORS: palette color
289  _("Player HP bar"), 50);
291  0xff0000,
293  // TRANSLATORS: palette color
294  _("Player HP bar (second color)"),
295  50);
297  0x00ff00,
299  // TRANSLATORS: palette color
300  _("Monster HP bar"),
301  50);
303  0xff0000,
305  // TRANSLATORS: palette color
306  _("Monster HP bar (second color)"),
307  50);
309  0x00ff00,
311  // TRANSLATORS: palette color
312  _("Homunculus HP bar"),
313  50);
315  0xff0000,
317  // TRANSLATORS: palette color
318  _("Homunculus HP bar (second color)"),
319  50);
321  0x00ff00,
323  // TRANSLATORS: palette color
324  _("Mercenary HP bar"),
325  50);
327  0xff0000,
329  // TRANSLATORS: palette color
330  _("Mercenary HP bar (second color)"),
331  50);
332 
334  0x00ff00,
336  // TRANSLATORS: palette color
337  _("Elemental HP bar"),
338  50);
340  0xff0000,
342  // TRANSLATORS: palette color
343  _("Elemental HP bar (second color)"),
344  50);
346  // TRANSLATORS: palette label
347  _("Hits"));
349  0x0064ff,
351  // TRANSLATORS: palette color
352  _("Player hits monster"),
355  0xff3232,
357  // TRANSLATORS: palette color
358  _("Monster hits player"),
361  0xff5050,
363  // TRANSLATORS: palette color
364  _("Other player hits local player"),
367  0xff0000,
369  // TRANSLATORS: palette color
370  _("Critical Hit"),
373  0x00ff00,
375  // TRANSLATORS: palette color
376  _("Local player hits monster"),
379  0xff0000,
381  // TRANSLATORS: palette color
382  _("Local player critical hit"),
385  0x00ffa6,
387  // TRANSLATORS: palette color
388  _("Local player miss"),
390  addColor(UserColorId::MISS, 0xffff00,
392  // TRANSLATORS: palette color
393  _("Misses"),
396  // TRANSLATORS: palette label
397  _("Tiles"));
399  0xC80000,
401  // TRANSLATORS: palette color
402  _("Portal highlight"),
405  0x0000C8,
407  // TRANSLATORS: palette color
408  _("Default collision highlight"),
409  64);
411  0xe0e0ff,
413  // TRANSLATORS: palette color
414  _("Air collision highlight"),
415  64);
417  0x2050e0,
419  // TRANSLATORS: palette color
420  _("Water collision highlight"),
421  64);
423  0x2050e0,
425  // TRANSLATORS: palette color
426  _("Monster collision highlight"),
427  64);
429  0xffff00,
431  // TRANSLATORS: palette color
432  _("Special ground collision highlight"),
433  20);
435  0x00D000,
437  // TRANSLATORS: palette color
438  _("Walkable highlight"),
439  255);
441  0x000000,
443  // TRANSLATORS: palette color
444  _("Tiles border"), 64);
446  // TRANSLATORS: palette label
447  _("Ranges"));
449  0xffffff,
451  // TRANSLATORS: palette color
452  _("Local player attack range"),
453  5);
455  0x0,
457  // TRANSLATORS: palette color
458  _("Local player attack range border"),
459  76);
461  0xff0000,
463  // TRANSLATORS: palette color
464  _("Monster attack range"),
465  20);
467  0x0,
469  // TRANSLATORS: palette color
470  _("Skill attack range border"),
471  76);
473  // TRANSLATORS: palette label
474  _("Other"));
476  0xffffff,
478  // TRANSLATORS: palette color
479  _("Floor item amount color"),
480  100);
482  0xffffff,
484  // TRANSLATORS: palette color
485  _("Home place"),
486  20);
488  0xffff00,
490  // TRANSLATORS: palette color
491  _("Home place border"),
492  200);
494  0x000000,
496  // TRANSLATORS: palette color
497  _("Road point"), 100);
498  commit(true);
499 }
#define _(s)
Definition: gettext.h:34
ListModel()
Definition: listmodel.h:81
#define GRADIENT_DELAY
Definition: palette.h:38
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void addLabel(const UserColorIdT type, const std::string &text)
Colors mColors
Definition: palette.h:153
void commit()
Definition: userpalette.h:132
#define CAST_SIZE
Definition: cast.h:33
Palette(const int size)
Definition: palette.cpp:51
void addColor(const UserColorIdT type, const unsigned rgb, GradientTypeT grad, const std::string &text, int delay)

◆ ~UserPalette()

UserPalette::~UserPalette ( )

Destructor

Definition at line 501 of file userpalette.cpp.

References CAST_S32, ColorTypeNames, config, FOR_EACH, GradientType::LABEL, Palette::mColors, GradientType::PULSE, Configuration::setValue(), and GradientType::STATIC.

502 {
503  FOR_EACH (Colors::const_iterator, col, mColors)
504  {
505  if (col->grad == GradientType::LABEL)
506  continue;
507  const std::string &configName = ColorTypeNames[col->type];
508  config.setValue(configName + "Gradient",
509  CAST_S32(col->committedGrad));
510  config.setValue(configName + "Delay", col->delay);
511 
512  if (col->grad == GradientType::STATIC ||
513  col->grad == GradientType::PULSE)
514  {
515  char buffer[20];
516  snprintf(buffer, sizeof(buffer), "0x%06x", col->getRGB());
517  buffer[19] = 0;
518  config.setValue(configName, std::string(buffer));
519  }
520  }
521 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Configuration config
#define CAST_S32
Definition: cast.h:29
const std::string ColorTypeNames[static_cast< size_t >(UserColorId::USER_COLOR_LAST)]
Definition: userpalette.cpp:36
Colors mColors
Definition: palette.h:153
void setValue(const std::string &key, const std::string &value)

Member Function Documentation

◆ addColor()

void UserPalette::addColor ( const UserColorIdT  type,
const unsigned  rgb,
GradientTypeT  grad,
const std::string &  text,
int  delay 
)
private

Definition at line 615 of file userpalette.cpp.

References atox(), CAST_S32, CAST_SIZE, CAST_U32, ColorTypeNames, config, ConfigurationObject::getValue(), ConfigurationObject::getValueInt(), Palette::mColors, Palette::mGradVector, GradientType::STATIC, and SetupActionData::text.

Referenced by getColorWithAlpha(), and UserPalette().

620 {
621  const unsigned maxType = sizeof(ColorTypeNames)
622  / sizeof(ColorTypeNames[0]);
623 
624  if (CAST_U32(type) >= maxType)
625  return;
626 
627  const std::string &configName = ColorTypeNames[CAST_SIZE(type)];
628  char buffer[20];
629  snprintf(buffer, sizeof(buffer), "0x%06x", rgb);
630  buffer[19] = 0;
631 
632  const std::string rgbString = config.getValue(
633  configName, std::string(buffer));
634  unsigned int rgbValue = 0;
635  if (rgbString.length() == 8 && rgbString[0] == '0' && rgbString[1] == 'x')
636  rgbValue = atox(rgbString);
637  else
638  rgbValue = atoi(rgbString.c_str());
639  const Color &trueCol = Color(rgbValue);
640  grad = static_cast<GradientTypeT>(config.getValue(
641  configName + "Gradient",
642  CAST_S32(grad)));
643  delay = config.getValueInt(configName + "Delay", delay);
644  mColors[CAST_SIZE(type)].set(CAST_S32(type),
645  trueCol, grad, delay);
646  mColors[CAST_SIZE(type)].text = text;
647 
648  if (grad != GradientType::STATIC)
649  mGradVector.push_back(&mColors[CAST_SIZE(type)]);
650 }
#define CAST_U32
Definition: cast.h:30
GradientType ::T GradientTypeT
Definition: gradienttype.h:37
Configuration config
std::vector< ColorElem * > mGradVector
Definition: palette.h:155
#define CAST_S32
Definition: cast.h:29
const std::string ColorTypeNames[static_cast< size_t >(UserColorId::USER_COLOR_LAST)]
Definition: userpalette.cpp:36
Colors mColors
Definition: palette.h:153
unsigned int atox(const std::string &str)
Definition: stringutils.cpp:77
std::string getValue(const std::string &key, const std::string &deflt) const
Definition: color.h:74
#define CAST_SIZE
Definition: cast.h:33
int getValueInt(const std::string &key, const int deflt) const

◆ addLabel()

void UserPalette::addLabel ( const UserColorIdT  type,
const std::string &  text 
)
private

Definition at line 652 of file userpalette.cpp.

References CAST_SIZE, CAST_U32, ColorTypeNames, GradientType::LABEL, Palette::mColors, and ServerCommandType::str.

Referenced by getColorWithAlpha(), and UserPalette().

654 {
655  const unsigned maxType = sizeof(ColorTypeNames)
656  / sizeof(ColorTypeNames[0]);
657 
658  if (CAST_U32(type) >= maxType)
659  return;
660 
661 
662  mColors[CAST_SIZE(type)] = ColorElem();
663  const std::string str(" \342\200\225\342\200\225\342\200\225"
664  "\342\200\225\342\200\225 ");
665  mColors[CAST_SIZE(type)].grad = GradientType::LABEL;
666  mColors[CAST_SIZE(type)].text =
667  std::string(str).append(text).append(str);
668 }
#define CAST_U32
Definition: cast.h:30
const std::string ColorTypeNames[static_cast< size_t >(UserColorId::USER_COLOR_LAST)]
Definition: userpalette.cpp:36
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

◆ commit() [1/2]

void UserPalette::commit ( )
inline

Commit the colors

Definition at line 132 of file userpalette.h.

References A_WARN_UNUSED, getColorTypeAt(), and rollback().

Referenced by Setup_Colors::apply(), getColorWithAlpha(), and UserPalette().

133  { commit(false); }
void commit()
Definition: userpalette.h:132

◆ commit() [2/2]

void UserPalette::commit ( const bool  commitNonStatic)
private

Commit the colors. Commit the non-static color values, if commitNonStatic is true. Only needed in the constructor.

Definition at line 569 of file userpalette.cpp.

References FOR_EACH, Palette::mColors, GradientType::PULSE, and GradientType::STATIC.

570 {
571  FOR_EACH (Colors::iterator, i, mColors)
572  {
573  i->committedGrad = i->grad;
574  i->committedDelay = i->delay;
575  if (commitNonStatic || i->grad == GradientType::STATIC)
576  i->committedColor = i->color;
577  else if (i->grad == GradientType::PULSE)
578  i->committedColor = i->testColor;
579  }
580 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Colors mColors
Definition: palette.h:153

◆ getColor()

const Color& UserPalette::getColor ( UserColorIdT  type,
const unsigned int  alpha 
)
inline

Gets the color associated with the type. Sets the alpha channel before returning.

Parameters
typethe color type requested
alphaalpha channel to use
Returns
the requested color

Definition at line 159 of file userpalette.h.

References Color::a, A_WARN_UNUSED, UserColorId::BEING, CAST_S32, CAST_SIZE, CAST_U32, getIdByChar(), Logger::log(), logger, Palette::mColors, and anonymous_namespace{libxml.cpp}::valid.

Referenced by Setup_Colors::cancel(), FloorItem::draw(), MapItem::draw(), Minimap::draw2(), Being::drawPortalSpriteAt(), LocalPlayer::LocalPlayer(), LocalPlayer::logic(), Being::setDefaultNameColor(), Being::setSpeech(), Being::takeDamage(), Being::updateColors(), and Setup_Colors::valueChanged().

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  }
#define CAST_U32
Definition: cast.h:30
unsigned int a
Definition: color.h:250
Logger * logger
Definition: logger.cpp:88
#define CAST_S32
Definition: cast.h:29
Colors mColors
Definition: palette.h:153
Definition: color.h:74
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ getColorTypeAt()

int UserPalette::getColorTypeAt ( const int  i)

Gets the ColorType used by the color for the element at index i in the current color model.

Parameters
ithe index of the color
Returns
the color type of the color with the given index

Definition at line 607 of file userpalette.cpp.

References getNumberOfElements(), and Palette::mColors.

Referenced by Setup_Colors::cancel(), commit(), Setup_Colors::updateColor(), Setup_Colors::updateGradType(), and Setup_Colors::valueChanged().

608 {
609  if (i < 0 || i >= getNumberOfElements())
610  return 0;
611 
612  return mColors[i].type;
613 }
int getNumberOfElements()
Definition: userpalette.h:117
Colors mColors
Definition: palette.h:153

◆ getColorWithAlpha()

const Color& UserPalette::getColorWithAlpha ( const UserColorIdT  type)
inline

Definition at line 199 of file userpalette.h.

References Color::a, A_WARN_UNUSED, addColor(), addLabel(), CAST_SIZE, CAST_U32, commit(), getConfigName(), Palette::mColors, setColorAt(), and userPalette.

Referenced by CastingEffect::draw(), MapItem::draw(), Map::draw(), Map::drawCollision(), Being::drawElementalSpriteAt(), MapLayer::drawFringe(), Being::drawHomunculusSpriteAt(), Being::drawHpBar(), Being::drawMercenarySpriteAt(), and Being::drawMonsterSpriteAt().

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  }
#define CAST_U32
Definition: cast.h:30
unsigned int a
Definition: color.h:250
Colors mColors
Definition: palette.h:153
Definition: color.h:74
#define CAST_SIZE
Definition: cast.h:33

◆ getCommittedColor()

const Color& UserPalette::getCommittedColor ( const UserColorIdT  type) const
inline

Gets the committed color associated with the specified type.

Parameters
typethe color type requested
Returns
the requested committed color

Definition at line 60 of file userpalette.h.

References CAST_SIZE, and Palette::mColors.

Referenced by Setup_Colors::valueChanged().

62  {
63  return mColors[CAST_SIZE(type)].committedColor;
64  }
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

◆ getConfigName()

std::string UserPalette::getConfigName ( const std::string &  typeName)
staticprivate

Prefixes the given string with "Color", lowercases all letters but the first and all following a '_'. All '_'s will be removed.

E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster

Parameters
typeNamestring to transform
Returns
the transformed string

Definition at line 104 of file userpalette.cpp.

References CAST_S8.

Referenced by getColorWithAlpha().

105 {
106  std::string res("Color" + typeName);
107  size_t pos = 5;
108  for (size_t i = 0; i < typeName.length(); i++)
109  {
110  if (i == 0 || typeName[i] == '_')
111  {
112  if (i > 0)
113  i++;
114 
115  res[pos] = typeName[i];
116  }
117  else
118  {
119  res[pos] = CAST_S8(tolower(typeName[i]));
120  }
121  pos ++;
122  }
123  res.erase(pos, res.length() - pos);
124  return res;
125 }
#define CAST_S8
Definition: cast.h:25

◆ getElementAt()

std::string UserPalette::getElementAt ( int  i)
virtual

Returns the name of the ith color.

Parameters
iindex of color interested in
Returns
the name of the color

Implements ListModel.

Definition at line 561 of file userpalette.cpp.

References getNumberOfElements(), and Palette::mColors.

Referenced by getNumberOfElements().

562 {
563  if (i < 0 || i >= getNumberOfElements())
564  return "";
565 
566  return mColors[i].text;
567 }
int getNumberOfElements()
Definition: userpalette.h:117
Colors mColors
Definition: palette.h:153

◆ getGradientDelay()

int UserPalette::getGradientDelay ( const UserColorIdT  type) const
inline

Gets the gradient delay for the specified type.

Parameters
typethe color type of the color
Returns
the gradient delay of the color with the given index

Definition at line 195 of file userpalette.h.

References CAST_SIZE, and Palette::mColors.

Referenced by Setup_Colors::cancel(), and Setup_Colors::valueChanged().

197  { return mColors[CAST_SIZE(type)].delay; }
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

◆ getGradientType()

GradientTypeT UserPalette::getGradientType ( const UserColorIdT  type) const
inline

Gets the GradientType associated with the specified type.

Parameters
typethe color type of the color
Returns
the gradient type of the color with the given index

Definition at line 184 of file userpalette.h.

References CAST_SIZE, and Palette::mColors.

Referenced by Setup_Colors::cancel(), Setup_Colors::updateGradType(), and Setup_Colors::valueChanged().

186  { return mColors[CAST_SIZE(type)].grad; }
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

◆ getIdByChar()

int UserPalette::getIdByChar ( const signed char  c,
bool valid 
) const

Definition at line 670 of file userpalette.cpp.

References Palette::mCharColors.

Referenced by getColor().

671 {
672  const CharColors::const_iterator it = mCharColors.find(c);
673  if (it != mCharColors.end())
674  {
675  valid = true;
676  return (*it).second;
677  }
678 
679  valid = false;
680  return 0;
681 }
CharColors mCharColors
Definition: palette.h:154

◆ getNumberOfElements()

int UserPalette::getNumberOfElements ( )
inlinevirtual

Returns the number of colors known.

Returns
the number of colors known

Implements ListModel.

Definition at line 117 of file userpalette.h.

References A_WARN_UNUSED, CAST_S32, getElementAt(), and Palette::mColors.

Referenced by getColorTypeAt(), and getElementAt().

118  { return CAST_S32(mColors.size()); }
#define CAST_S32
Definition: cast.h:29
Colors mColors
Definition: palette.h:153

◆ getTestColor()

const Color& UserPalette::getTestColor ( const UserColorIdT  type) const
inline

Gets the test color associated with the specified type.

Parameters
typethe color type requested
Returns
the requested test color

Definition at line 73 of file userpalette.h.

References CAST_SIZE, and Palette::mColors.

Referenced by Setup_Colors::valueChanged().

75  { return mColors[CAST_SIZE(type)].testColor; }
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

◆ rollback()

void UserPalette::rollback ( )

Rollback the colors

Definition at line 582 of file userpalette.cpp.

References Color::b, FOR_EACH, Color::g, Palette::mColors, GradientType::PULSE, Color::r, setColor(), setGradient(), and setGradientDelay().

Referenced by Setup_Colors::cancel(), and commit().

583 {
584  FOR_EACH (Colors::iterator, i, mColors)
585  {
586  if (i->grad != i->committedGrad)
587  setGradient(static_cast<UserColorIdT>(i->type), i->committedGrad);
588 
589  const Color &committedColor = i->committedColor;
590  setGradientDelay(static_cast<UserColorIdT>(i->type),
591  i->committedDelay);
592  setColor(static_cast<UserColorIdT>(i->type),
593  committedColor.r,
594  committedColor.g,
595  committedColor.b);
596 
597  if (i->grad == GradientType::PULSE)
598  {
599  Color &testColor = i->testColor;
600  testColor.r = committedColor.r;
601  testColor.g = committedColor.g;
602  testColor.b = committedColor.b;
603  }
604  }
605 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void setGradientDelay(const UserColorIdT type, const int delay)
Definition: userpalette.h:108
void setGradient(const UserColorIdT type, const GradientTypeT grad)
unsigned int g
Definition: color.h:239
unsigned int b
Definition: color.h:244
void setColor(const UserColorIdT type, const int r, const int g, const int b)
Colors mColors
Definition: palette.h:153
Definition: color.h:74
unsigned int r
Definition: color.h:234

◆ setColor()

void UserPalette::setColor ( const UserColorIdT  type,
const int  r,
const int  g,
const int  b 
)

Sets the color for the specified type.

Parameters
typecolor to be set
rred component
ggreen component
bblue component

Definition at line 523 of file userpalette.cpp.

References Color::b, CAST_SIZE, Color::g, Palette::mColors, and Color::r.

Referenced by rollback(), setTestColor(), and Setup_Colors::updateColor().

527 {
528  Color &color = mColors[CAST_SIZE(type)].color;
529  color.r = r;
530  color.g = g;
531  color.b = b;
532 }
unsigned int g
Definition: color.h:239
unsigned int b
Definition: color.h:244
Colors mColors
Definition: palette.h:153
Definition: color.h:74
#define CAST_SIZE
Definition: cast.h:33
unsigned int r
Definition: color.h:234

◆ setColorAt()

void UserPalette::setColorAt ( int  i,
int  r,
int  g,
int  b 
)
private

Define a color replacement.

Parameters
ithe index of the color to replace
rred component
ggreen component
bblue component

Referenced by getColorWithAlpha().

◆ setGradient()

void UserPalette::setGradient ( const UserColorIdT  type,
const GradientTypeT  grad 
)

Sets the gradient type for the specified color.

Parameters
gradgradient type to set

Definition at line 534 of file userpalette.cpp.

References CAST_SIZE, Palette::ColorElem::grad, Palette::mColors, Palette::mGradVector, and GradientType::STATIC.

Referenced by rollback(), setTestColor(), and Setup_Colors::updateColor().

536 {
537  ColorElem *const elem = &mColors[CAST_SIZE(type)];
538 
539  if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC)
540  {
541  const size_t sz = mGradVector.size();
542  for (size_t i = 0; i < sz; i++)
543  {
544  if (mGradVector[i] == elem)
545  {
546  mGradVector.erase(mGradVector.begin() + i);
547  break;
548  }
549  }
550  }
551  else if (elem->grad == GradientType::STATIC &&
552  grad != GradientType::STATIC)
553  {
554  mGradVector.push_back(elem);
555  }
556 
557  if (elem->grad != grad)
558  elem->grad = grad;
559 }
std::vector< ColorElem * > mGradVector
Definition: palette.h:155
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

◆ setGradientDelay()

void UserPalette::setGradientDelay ( const UserColorIdT  type,
const int  delay 
)
inline

Definition at line 108 of file userpalette.h.

References CAST_SIZE, and Palette::mColors.

Referenced by rollback(), and Setup_Colors::updateColor().

110  { mColors[CAST_SIZE(type)].delay = delay; }
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

◆ setTestColor()

void UserPalette::setTestColor ( const UserColorIdT  type,
const Color color 
)
inline

Sets the test color associated with the specified type.

Parameters
typethe color type requested
colorthe color that should be tested

Definition at line 83 of file userpalette.h.

References CAST_SIZE, Palette::mColors, setColor(), and setGradient().

Referenced by Setup_Colors::updateColor().

85  { mColors[CAST_SIZE(type)].testColor = color; }
Colors mColors
Definition: palette.h:153
#define CAST_SIZE
Definition: cast.h:33

The documentation for this class was generated from the following files: