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 39 of file userpalette.h.

Constructor & Destructor Documentation

◆ UserPalette()

UserPalette::UserPalette ( )

Constructor

Definition at line 128 of file userpalette.cpp.

128  :
130  ListModel()
131 {
132  mColors[CAST_SIZE(UserColorId::BEING)] = ColorElem();
133  mColors[CAST_SIZE(UserColorId::PC)] = ColorElem();
134  mColors[CAST_SIZE(UserColorId::SELF)] = ColorElem();
135  mColors[CAST_SIZE(UserColorId::GM)] = ColorElem();
136  mColors[CAST_SIZE(UserColorId::NPC)] = ColorElem();
137  mColors[CAST_SIZE(UserColorId::MONSTER)] = ColorElem();
138 
140  // TRANSLATORS: palette label
141  _("Beings"));
143  0xffffff,
145  // TRANSLATORS: palette color
146  _("Being"),
149  0xb0ffb0,
151  // TRANSLATORS: palette color
152  _("Friend names"),
155  0xa00000,
157  // TRANSLATORS: palette color
158  _("Disregarded names"),
161  0xff0000,
163  // TRANSLATORS: palette color
164  _("Ignored names"),
167  0xff0000,
169  // TRANSLATORS: palette color
170  _("Erased names"),
173  0xff4040,
175  // TRANSLATORS: palette color
176  _("Enemy"),
179  0xffffff,
181  // TRANSLATORS: palette color
182  _("Other players names"),
185  0xff8040,
187  // TRANSLATORS: palette color
188  _("Own name"),
191  0x00ff00,
193  // TRANSLATORS: palette color
194  _("GM names"),
197  0xc8c8ff,
199  // TRANSLATORS: palette color
200  _("NPCs"),
203  0xff4040,
205  // TRANSLATORS: palette color
206  _("Monsters"),
209  0xffffff,
211  // TRANSLATORS: palette color
212  _("Pets"),
215  0xffffff,
217  // TRANSLATORS: palette color
218  _("Mercenary"),
221  0xffffff,
223  // TRANSLATORS: palette color
224  _("Homunculus"),
227  0xffffff,
229  // TRANSLATORS: palette color
230  _("Skill unit"),
233  0xff00d8,
235  // TRANSLATORS: palette color
236  _("Party members"),
239  0xff00d8,
241  // TRANSLATORS: palette color
242  _("Guild members"),
245  0x0000ff,
247  // TRANSLATORS: palette color
248  strprintf(_("Team %d"), 1),
251  0x00a020,
253  // TRANSLATORS: palette color
254  strprintf(_("Team %d"), 2),
257  0xffff20,
259  // TRANSLATORS: palette color
260  strprintf(_("Team %d"), 3),
263  // TRANSLATORS: palette label
264  _("Particles"));
266  0xffffff,
268  // TRANSLATORS: palette color
269  _("Particle effects"),
272  0x28dc28,
274  // TRANSLATORS: palette color
275  _("Pickup notification"),
278  0xffff00,
280  // TRANSLATORS: palette color
281  _("Exp notification"),
284  // TRANSLATORS: palette label
285  _("Hp bars"));
287  0x00ff00,
289  // TRANSLATORS: palette color
290  _("Player HP bar"), 50);
292  0xff0000,
294  // TRANSLATORS: palette color
295  _("Player HP bar (second color)"),
296  50);
298  0x00ff00,
300  // TRANSLATORS: palette color
301  _("Monster HP bar"),
302  50);
304  0xff0000,
306  // TRANSLATORS: palette color
307  _("Monster HP bar (second color)"),
308  50);
310  0x00ff00,
312  // TRANSLATORS: palette color
313  _("Homunculus HP bar"),
314  50);
316  0xff0000,
318  // TRANSLATORS: palette color
319  _("Homunculus HP bar (second color)"),
320  50);
322  0x00ff00,
324  // TRANSLATORS: palette color
325  _("Mercenary HP bar"),
326  50);
328  0xff0000,
330  // TRANSLATORS: palette color
331  _("Mercenary HP bar (second color)"),
332  50);
333 
335  0x00ff00,
337  // TRANSLATORS: palette color
338  _("Elemental HP bar"),
339  50);
341  0xff0000,
343  // TRANSLATORS: palette color
344  _("Elemental HP bar (second color)"),
345  50);
347  // TRANSLATORS: palette label
348  _("Hits"));
350  0x0064ff,
352  // TRANSLATORS: palette color
353  _("Player hits monster"),
356  0xff3232,
358  // TRANSLATORS: palette color
359  _("Monster hits player"),
362  0xff5050,
364  // TRANSLATORS: palette color
365  _("Other player hits local player"),
368  0xff0000,
370  // TRANSLATORS: palette color
371  _("Critical Hit"),
374  0x00ff00,
376  // TRANSLATORS: palette color
377  _("Local player hits monster"),
380  0xff0000,
382  // TRANSLATORS: palette color
383  _("Local player critical hit"),
386  0x00ffa6,
388  // TRANSLATORS: palette color
389  _("Local player miss"),
391  addColor(UserColorId::MISS, 0xffff00,
393  // TRANSLATORS: palette color
394  _("Misses"),
397  // TRANSLATORS: palette label
398  _("Tiles"));
400  0xC80000,
402  // TRANSLATORS: palette color
403  _("Portal highlight"),
406  0x0000C8,
408  // TRANSLATORS: palette color
409  _("Default collision highlight"),
410  64);
412  0xe0e0ff,
414  // TRANSLATORS: palette color
415  _("Air collision highlight"),
416  64);
418  0x2050e0,
420  // TRANSLATORS: palette color
421  _("Water collision highlight"),
422  64);
424  0x2050e0,
426  // TRANSLATORS: palette color
427  _("Monster collision highlight"),
428  64);
430  0xffff00,
432  // TRANSLATORS: palette color
433  _("Special ground collision highlight"),
434  20);
436  0x00D000,
438  // TRANSLATORS: palette color
439  _("Walkable highlight"),
440  255);
442  0x000000,
444  // TRANSLATORS: palette color
445  _("Tiles border"), 64);
447  // TRANSLATORS: palette label
448  _("Ranges"));
450  0xffffff,
452  // TRANSLATORS: palette color
453  _("Local player attack range"),
454  5);
456  0x0,
458  // TRANSLATORS: palette color
459  _("Local player attack range border"),
460  76);
462  0xff0000,
464  // TRANSLATORS: palette color
465  _("Monster attack range"),
466  20);
468  0x0,
470  // TRANSLATORS: palette color
471  _("Skill attack range border"),
472  76);
474  // TRANSLATORS: palette label
475  _("Other"));
477  0xffffff,
479  // TRANSLATORS: palette color
480  _("Floor item amount color"),
481  100);
483  0xffffff,
485  // TRANSLATORS: palette color
486  _("Home place"),
487  20);
489  0xffff00,
491  // TRANSLATORS: palette color
492  _("Home place border"),
493  200);
495  0x000000,
497  // TRANSLATORS: palette color
498  _("Road point"), 100);
499  commit(true);
500 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34
ListModel()
Definition: listmodel.h:82
Colors mColors
Definition: palette.h:154
Palette(const int size)
Definition: palette.cpp:52
void addLabel(const UserColorIdT type, const std::string &text)
void commit()
Definition: userpalette.h:133
void addColor(const UserColorIdT type, const unsigned rgb, GradientTypeT grad, const std::string &text, int delay)
#define _(s)
Definition: gettext.h:35
@ HIT_PLAYER_PLAYER
Definition: usercolorid.h:72
@ AIR_COLLISION_HIGHLIGHT
Definition: usercolorid.h:81
@ HIT_PLAYER_MONSTER
Definition: usercolorid.h:70
@ MONSTER_COLLISION_HIGHLIGHT
Definition: usercolorid.h:83
@ HOME_PLACE_BORDER
Definition: usercolorid.h:95
@ GROUNDTOP_COLLISION_HIGHLIGHT
Definition: usercolorid.h:84
@ HIT_LOCAL_PLAYER_MONSTER
Definition: usercolorid.h:74
@ HIT_LOCAL_PLAYER_MISS
Definition: usercolorid.h:76
@ HIT_MONSTER_PLAYER
Definition: usercolorid.h:71
@ MONSTER_ATTACK_RANGE
Definition: usercolorid.h:90
@ HIT_LOCAL_PLAYER_CRITICAL
Definition: usercolorid.h:75
@ ATTACK_RANGE_BORDER
Definition: usercolorid.h:89
@ SKILL_ATTACK_RANGE
Definition: usercolorid.h:91
@ COLLISION_HIGHLIGHT
Definition: usercolorid.h:80
@ WATER_COLLISION_HIGHLIGHT
Definition: usercolorid.h:82
@ PORTAL_HIGHLIGHT
Definition: usercolorid.h:79
@ WALKABLE_HIGHLIGHT
Definition: usercolorid.h:85
#define GRADIENT_DELAY
Definition: palette.h:39
std::string strprintf(const char *const format,...)

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.

◆ ~UserPalette()

UserPalette::~UserPalette ( )

Destructor

Definition at line 502 of file userpalette.cpp.

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

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

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 616 of file userpalette.cpp.

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

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

Referenced by UserPalette().

◆ addLabel()

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

Definition at line 653 of file userpalette.cpp.

655 {
656  const unsigned maxType = sizeof(ColorTypeNames)
657  / sizeof(ColorTypeNames[0]);
658 
659  if (CAST_U32(type) >= maxType)
660  return;
661 
662 
663  mColors[CAST_SIZE(type)] = ColorElem();
664  const std::string str(" \342\200\225\342\200\225\342\200\225"
665  "\342\200\225\342\200\225 ");
666  mColors[CAST_SIZE(type)].grad = GradientType::LABEL;
667  mColors[CAST_SIZE(type)].text =
668  std::string(str).append(text).append(str);
669 }

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

Referenced by UserPalette().

◆ commit() [1/2]

void UserPalette::commit ( )
inline

Commit the colors

Definition at line 133 of file userpalette.h.

134  { commit(false); }

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

◆ 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 570 of file userpalette.cpp.

571 {
572  FOR_EACH (Colors::iterator, i, mColors)
573  {
574  i->committedGrad = i->grad;
575  i->committedDelay = i->delay;
576  if (commitNonStatic || i->grad == GradientType::STATIC)
577  i->committedColor = i->color;
578  else if (i->grad == GradientType::PULSE)
579  i->committedColor = i->testColor;
580  }
581 }

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

◆ 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 160 of file userpalette.h.

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  }
unsigned int a
Definition: color.h:251
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References Color::a, UserColorId::BEING, CAST_S32, CAST_SIZE, CAST_U32, Logger::log(), logger, and Palette::mColors.

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().

◆ 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 608 of file userpalette.cpp.

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

References getNumberOfElements(), and Palette::mColors.

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

◆ getColorWithAlpha()

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

◆ 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 61 of file userpalette.h.

63  {
64  return mColors[CAST_SIZE(type)].committedColor;
65  }

References CAST_SIZE, and Palette::mColors.

Referenced by Setup_Colors::valueChanged().

◆ 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 105 of file userpalette.cpp.

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

References CAST_S8.

◆ 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 562 of file userpalette.cpp.

563 {
564  if (i < 0 || i >= getNumberOfElements())
565  return "";
566 
567  return mColors[i].text;
568 }

References getNumberOfElements(), and Palette::mColors.

◆ 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 196 of file userpalette.h.

198  { return mColors[CAST_SIZE(type)].delay; }

References CAST_SIZE, and Palette::mColors.

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

◆ 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 185 of file userpalette.h.

187  { return mColors[CAST_SIZE(type)].grad; }

References CAST_SIZE, and Palette::mColors.

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

◆ getIdByChar()

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

Definition at line 671 of file userpalette.cpp.

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

References Palette::mCharColors, and anonymous_namespace{libxml.cpp}::valid.

◆ getNumberOfElements()

int UserPalette::getNumberOfElements ( )
inlinevirtual

Returns the number of colors known.

Returns
the number of colors known

Implements ListModel.

Definition at line 118 of file userpalette.h.

119  { return CAST_S32(mColors.size()); }

References CAST_S32, and Palette::mColors.

Referenced by getColorTypeAt(), and getElementAt().

◆ 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 74 of file userpalette.h.

76  { return mColors[CAST_SIZE(type)].testColor; }

References CAST_SIZE, and Palette::mColors.

Referenced by Setup_Colors::valueChanged().

◆ rollback()

void UserPalette::rollback ( )

Rollback the colors

Definition at line 583 of file userpalette.cpp.

584 {
585  FOR_EACH (Colors::iterator, i, mColors)
586  {
587  if (i->grad != i->committedGrad)
588  setGradient(static_cast<UserColorIdT>(i->type), i->committedGrad);
589 
590  const Color &committedColor = i->committedColor;
591  setGradientDelay(static_cast<UserColorIdT>(i->type),
592  i->committedDelay);
593  setColor(static_cast<UserColorIdT>(i->type),
594  committedColor.r,
595  committedColor.g,
596  committedColor.b);
597 
598  if (i->grad == GradientType::PULSE)
599  {
600  Color &testColor = i->testColor;
601  testColor.r = committedColor.r;
602  testColor.g = committedColor.g;
603  testColor.b = committedColor.b;
604  }
605  }
606 }
unsigned int b
Definition: color.h:245
unsigned int r
Definition: color.h:235
unsigned int g
Definition: color.h:240
void setColor(const UserColorIdT type, const int r, const int g, const int b)
void setGradientDelay(const UserColorIdT type, const int delay)
Definition: userpalette.h:109
void setGradient(const UserColorIdT type, const GradientTypeT grad)
UserColorId ::T UserColorIdT
Definition: usercolorid.h:99

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

Referenced by Setup_Colors::cancel().

◆ 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 524 of file userpalette.cpp.

528 {
529  Color &color = mColors[CAST_SIZE(type)].color;
530  color.r = r;
531  color.g = g;
532  color.b = b;
533 }

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

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

◆ 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

◆ 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 535 of file userpalette.cpp.

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

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

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

◆ setGradientDelay()

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

Definition at line 109 of file userpalette.h.

111  { mColors[CAST_SIZE(type)].delay = delay; }

References CAST_SIZE, and Palette::mColors.

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

◆ 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 84 of file userpalette.h.

86  { mColors[CAST_SIZE(type)].testColor = color; }

References CAST_SIZE, and Palette::mColors.

Referenced by Setup_Colors::updateColor().


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