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=255U)
 
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=40)
 
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)
 
- 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, 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"));
147  0xb0ffb0,
149  // TRANSLATORS: palette color
150  _("Friend names"));
152  0xa00000,
154  // TRANSLATORS: palette color
155  _("Disregarded names"));
157  0xff0000,
159  // TRANSLATORS: palette color
160  _("Ignored names"));
162  0xff0000,
164  // TRANSLATORS: palette color
165  _("Erased names"));
167  0xff4040,
169  // TRANSLATORS: palette color
170  _("Enemy"));
172  0xffffff,
174  // TRANSLATORS: palette color
175  _("Other players names"));
177  0xff8040,
179  // TRANSLATORS: palette color
180  _("Own name"));
182  0x00ff00,
184  // TRANSLATORS: palette color
185  _("GM names"));
187  0xc8c8ff,
189  // TRANSLATORS: palette color
190  _("NPCs"));
192  0xff4040,
194  // TRANSLATORS: palette color
195  _("Monsters"));
197  0xffffff,
199  // TRANSLATORS: palette color
200  _("Pets"));
202  0xffffff,
204  // TRANSLATORS: palette color
205  _("Mercenary"));
207  0xffffff,
209  // TRANSLATORS: palette color
210  _("Homunculus"));
212  0xffffff,
214  // TRANSLATORS: palette color
215  _("Skill unit"));
217  0xff00d8,
219  // TRANSLATORS: palette color
220  _("Party members"));
222  0xff00d8,
224  // TRANSLATORS: palette color
225  _("Guild members"));
227  0x0000ff,
229  // TRANSLATORS: palette color
230  strprintf(_("Team %d"), 1));
232  0x00a020,
234  // TRANSLATORS: palette color
235  strprintf(_("Team %d"), 2));
237  0xffff20,
239  // TRANSLATORS: palette color
240  strprintf(_("Team %d"), 3));
242  // TRANSLATORS: palette label
243  _("Particles"));
245  0xffffff,
247  // TRANSLATORS: palette color
248  _("Particle effects"));
250  0x28dc28,
252  // TRANSLATORS: palette color
253  _("Pickup notification"));
255  0xffff00,
257  // TRANSLATORS: palette color
258  _("Exp notification"));
260  // TRANSLATORS: palette label
261  _("Hp bars"));
263  0x00ff00,
265  // TRANSLATORS: palette color
266  _("Player HP bar"), 50);
268  0xff0000,
270  // TRANSLATORS: palette color
271  _("Player HP bar (second color)"),
272  50);
274  0x00ff00,
276  // TRANSLATORS: palette color
277  _("Monster HP bar"),
278  50);
280  0xff0000,
282  // TRANSLATORS: palette color
283  _("Monster HP bar (second color)"),
284  50);
286  0x00ff00,
288  // TRANSLATORS: palette color
289  _("Homunculus HP bar"),
290  50);
292  0xff0000,
294  // TRANSLATORS: palette color
295  _("Homunculus HP bar (second color)"),
296  50);
298  0x00ff00,
300  // TRANSLATORS: palette color
301  _("Mercenary HP bar"),
302  50);
304  0xff0000,
306  // TRANSLATORS: palette color
307  _("Mercenary HP bar (second color)"),
308  50);
309 
311  0x00ff00,
313  // TRANSLATORS: palette color
314  _("Elemental HP bar"),
315  50);
317  0xff0000,
319  // TRANSLATORS: palette color
320  _("Elemental HP bar (second color)"),
321  50);
323  // TRANSLATORS: palette label
324  _("Hits"));
326  0x0064ff,
328  // TRANSLATORS: palette color
329  _("Player hits monster"));
331  0xff3232,
333  // TRANSLATORS: palette color
334  _("Monster hits player"));
336  0xff5050,
338  // TRANSLATORS: palette color
339  _("Other player hits local player"));
341  0xff0000,
343  // TRANSLATORS: palette color
344  _("Critical Hit"));
346  0x00ff00,
348  // TRANSLATORS: palette color
349  _("Local player hits monster"));
351  0xff0000,
353  // TRANSLATORS: palette color
354  _("Local player critical hit"));
356  0x00ffa6,
358  // TRANSLATORS: palette color
359  _("Local player miss"));
360  addColor(UserColorId::MISS, 0xffff00,
362  // TRANSLATORS: palette color
363  _("Misses"));
365  // TRANSLATORS: palette label
366  _("Tiles"));
368  0xC80000,
370  // TRANSLATORS: palette color
371  _("Portal highlight"));
373  0x0000C8,
375  // TRANSLATORS: palette color
376  _("Default collision highlight"),
377  64);
379  0xe0e0ff,
381  // TRANSLATORS: palette color
382  _("Air collision highlight"),
383  64);
385  0x2050e0,
387  // TRANSLATORS: palette color
388  _("Water collision highlight"),
389  64);
391  0x2050e0,
393  // TRANSLATORS: palette color
394  _("Monster collision highlight"),
395  64);
397  0xffff00,
399  // TRANSLATORS: palette color
400  _("Special ground collision highlight"),
401  20);
403  0x00D000,
405  // TRANSLATORS: palette color
406  _("Walkable highlight"),
407  255);
409  0x000000,
411  // TRANSLATORS: palette color
412  _("Tiles border"), 64);
414  // TRANSLATORS: palette label
415  _("Ranges"));
417  0xffffff,
419  // TRANSLATORS: palette color
420  _("Local player attack range"),
421  5);
423  0x0,
425  // TRANSLATORS: palette color
426  _("Local player attack range border"),
427  76);
429  0xff0000,
431  // TRANSLATORS: palette color
432  _("Monster attack range"),
433  20);
435  0x0,
437  // TRANSLATORS: palette color
438  _("Skill attack range border"),
439  76);
441  // TRANSLATORS: palette label
442  _("Other"));
444  0xffffff,
446  // TRANSLATORS: palette color
447  _("Floor item amount color"),
448  100);
450  0xffffff,
452  // TRANSLATORS: palette color
453  _("Home place"),
454  20);
456  0xffff00,
458  // TRANSLATORS: palette color
459  _("Home place border"),
460  200);
462  0x000000,
464  // TRANSLATORS: palette color
465  _("Road point"), 100);
466  commit(true);
467 }
#define _(s)
Definition: gettext.h:34
ListModel()
Definition: listmodel.h:81
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void addColor(const UserColorIdT type, const unsigned rgb, GradientTypeT grad, const std::string &text, int delay=40)
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

◆ ~UserPalette()

UserPalette::~UserPalette ( )

Destructor

Definition at line 469 of file userpalette.cpp.

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

470 {
471  FOR_EACH (Colors::const_iterator, col, mColors)
472  {
473  if (col->grad == GradientType::LABEL)
474  continue;
475  const std::string &configName = ColorTypeNames[col->type];
476  config.setValue(configName + "Gradient",
477  CAST_S32(col->committedGrad));
478  config.setValue(configName + "Delay", col->delay);
479 
480  if (col->grad == GradientType::STATIC ||
481  col->grad == GradientType::PULSE)
482  {
483  char buffer[20];
484  snprintf(buffer, sizeof(buffer), "0x%06x", col->getRGB());
485  buffer[19] = 0;
486  config.setValue(configName, std::string(buffer));
487  }
488  }
489 }
#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 = 40 
)
private

Definition at line 583 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().

588 {
589  const unsigned maxType = sizeof(ColorTypeNames)
590  / sizeof(ColorTypeNames[0]);
591 
592  if (CAST_U32(type) >= maxType)
593  return;
594 
595  const std::string &configName = ColorTypeNames[CAST_SIZE(type)];
596  char buffer[20];
597  snprintf(buffer, sizeof(buffer), "0x%06x", rgb);
598  buffer[19] = 0;
599 
600  const std::string rgbString = config.getValue(
601  configName, std::string(buffer));
602  unsigned int rgbValue = 0;
603  if (rgbString.length() == 8 && rgbString[0] == '0' && rgbString[1] == 'x')
604  rgbValue = atox(rgbString);
605  else
606  rgbValue = atoi(rgbString.c_str());
607  const Color &trueCol = Color(rgbValue);
608  grad = static_cast<GradientTypeT>(config.getValue(
609  configName + "Gradient",
610  CAST_S32(grad)));
611  delay = config.getValueInt(configName + "Delay", delay);
612  mColors[CAST_SIZE(type)].set(CAST_S32(type),
613  trueCol, grad, delay);
614  mColors[CAST_SIZE(type)].text = text;
615 
616  if (grad != GradientType::STATIC)
617  mGradVector.push_back(&mColors[CAST_SIZE(type)]);
618 }
#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 620 of file userpalette.cpp.

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

Referenced by getColorWithAlpha(), and UserPalette().

622 {
623  const unsigned maxType = sizeof(ColorTypeNames)
624  / sizeof(ColorTypeNames[0]);
625 
626  if (CAST_U32(type) >= maxType)
627  return;
628 
629 
630  mColors[CAST_SIZE(type)] = ColorElem();
631  const std::string str(" \342\200\225\342\200\225\342\200\225"
632  "\342\200\225\342\200\225 ");
633  mColors[CAST_SIZE(type)].grad = GradientType::LABEL;
634  mColors[CAST_SIZE(type)].text =
635  std::string(str).append(text).append(str);
636 }
#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 537 of file userpalette.cpp.

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

538 {
539  FOR_EACH (Colors::iterator, i, mColors)
540  {
541  i->committedGrad = i->grad;
542  i->committedDelay = i->delay;
543  if (commitNonStatic || i->grad == GradientType::STATIC)
544  i->committedColor = i->color;
545  else if (i->grad == GradientType::PULSE)
546  i->committedColor = i->testColor;
547  }
548 }
#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 = 255U 
)
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:95
#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:243

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

576 {
577  if (i < 0 || i >= getNumberOfElements())
578  return 0;
579 
580  return mColors[i].type;
581 }
int getNumberOfElements()
Definition: userpalette.h:117
Colors mColors
Definition: palette.h:153

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

References getNumberOfElements(), and Palette::mColors.

Referenced by getNumberOfElements().

530 {
531  if (i < 0 || i >= getNumberOfElements())
532  return "";
533 
534  return mColors[i].text;
535 }
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 638 of file userpalette.cpp.

References Palette::mCharColors.

Referenced by getColor().

639 {
640  const CharColors::const_iterator it = mCharColors.find(c);
641  if (it != mCharColors.end())
642  {
643  valid = true;
644  return (*it).second;
645  }
646 
647  valid = false;
648  return 0;
649 }
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 550 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().

551 {
552  FOR_EACH (Colors::iterator, i, mColors)
553  {
554  if (i->grad != i->committedGrad)
555  setGradient(static_cast<UserColorIdT>(i->type), i->committedGrad);
556 
557  const Color &committedColor = i->committedColor;
558  setGradientDelay(static_cast<UserColorIdT>(i->type),
559  i->committedDelay);
560  setColor(static_cast<UserColorIdT>(i->type),
561  committedColor.r,
562  committedColor.g,
563  committedColor.b);
564 
565  if (i->grad == GradientType::PULSE)
566  {
567  Color &testColor = i->testColor;
568  testColor.r = committedColor.r;
569  testColor.g = committedColor.g;
570  testColor.b = committedColor.b;
571  }
572  }
573 }
#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 491 of file userpalette.cpp.

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

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

495 {
496  Color &color = mColors[CAST_SIZE(type)].color;
497  color.r = r;
498  color.g = g;
499  color.b = b;
500 }
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 502 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().

504 {
505  ColorElem *const elem = &mColors[CAST_SIZE(type)];
506 
507  if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC)
508  {
509  const size_t sz = mGradVector.size();
510  for (size_t i = 0; i < sz; i++)
511  {
512  if (mGradVector[i] == elem)
513  {
514  mGradVector.erase(mGradVector.begin() + i);
515  break;
516  }
517  }
518  }
519  else if (elem->grad == GradientType::STATIC &&
520  grad != GradientType::STATIC)
521  {
522  mGradVector.push_back(elem);
523  }
524 
525  if (elem->grad != grad)
526  elem->grad = grad;
527 }
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: