ManaPlus
Public Member Functions | Static Public Member Functions | Protected Attributes
ColorModel Class Reference

#include <colormodel.h>

Inheritance diagram for ColorModel:
ListModel

Public Member Functions

 ColorModel ()
 
 ~ColorModel ()
 
int getNumberOfElements ()
 
std::string getElementAt (int i)
 
const ColorPairgetColorAt (const int i) const
 
StringVectgetNames ()
 
size_t size ()
 
void add (const std::string &name, const Color *const color1, const Color *const color2)
 
- Public Member Functions inherited from ListModel
 ListModel ()
 
virtual ~ListModel ()
 

Static Public Member Functions

static ColorModelcreateDefault (const Widget2 *const widget)
 

Protected Attributes

StringVect mNames
 
std::vector< ColorPairmColors
 

Detailed Description

Definition at line 36 of file colormodel.h.

Constructor & Destructor Documentation

◆ ColorModel()

ColorModel::ColorModel ( )

Definition at line 30 of file colormodel.cpp.

30  :
31  ListModel(),
32  mNames(),
33  mColors()
34 {
35 }
std::vector< ColorPair > mColors
Definition: colormodel.h:67
StringVect mNames
Definition: colormodel.h:66
ListModel()
Definition: listmodel.h:82

Referenced by createDefault().

◆ ~ColorModel()

ColorModel::~ColorModel ( )

Definition at line 37 of file colormodel.cpp.

38 {
39 }

Member Function Documentation

◆ add()

void ColorModel::add ( const std::string &  name,
const Color *const  color1,
const Color *const  color2 
)

Definition at line 61 of file colormodel.cpp.

63 {
64  mNames.push_back(name);
65  mColors.push_back(ColorPair(color1, color2));
66 }

References mColors, and mNames.

◆ createDefault()

ColorModel * ColorModel::createDefault ( const Widget2 *const  widget)
static

Definition at line 72 of file colormodel.cpp.

73 {
74  ColorModel *const model = new ColorModel;
75  if (widget == nullptr)
76  return model;
77  // TRANSLATORS: color name
78  addColor(_("black"), BLACK);
79  // TRANSLATORS: color name
80  addColor(_("red"), RED);
81  // TRANSLATORS: color name
82  addColor(_("green"), GREEN);
83  // TRANSLATORS: color name
84  addColor(_("blue"), BLUE);
85  // TRANSLATORS: color name
86  addColor(_("gold"), ORANGE);
87  // TRANSLATORS: color name
88  addColor(_("yellow"), YELLOW);
89  // TRANSLATORS: color name
90  addColor(_("pink"), PINK);
91  // TRANSLATORS: color name
92  addColor(_("purple"), PURPLE);
93  // TRANSLATORS: color name
94  addColor(_("grey"), GRAY);
95  // TRANSLATORS: color name
96  addColor(_("brown"), BROWN);
97  return model;
98 }
#define addColor(name, color)
Definition: colormodel.cpp:68
#define _(s)
Definition: gettext.h:35

References _, addColor, ColorName::BLACK, ColorName::BLUE, ColorName::BROWN, ColorModel(), ColorName::GRAY, ColorName::GREEN, ColorName::ORANGE, ColorName::PINK, ColorName::PURPLE, ColorName::RED, and ColorName::YELLOW.

◆ getColorAt()

const ColorPair * ColorModel::getColorAt ( const int  i) const

Definition at line 53 of file colormodel.cpp.

54 {
55  if (i >= CAST_S32(mColors.size()) || i < 0)
56  return &mColors[0];
57 
58  return &mColors[CAST_SIZE(i)];
59 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34

References CAST_S32, CAST_SIZE, and mColors.

Referenced by ColorPage::draw().

◆ getElementAt()

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

Gets an element at a certain index in the list.

Parameters
iAn index in the list.
Returns
An element as a string at the a certain index.

Implements ListModel.

Definition at line 46 of file colormodel.cpp.

47 {
48  if (i >= getNumberOfElements() || i < 0)
49  return "???";
50  return mNames[CAST_SIZE(i)];
51 }
int getNumberOfElements()
Definition: colormodel.cpp:41

References CAST_SIZE, getNumberOfElements(), and mNames.

◆ getNames()

StringVect& ColorModel::getNames ( )
inline

Definition at line 52 of file colormodel.h.

53  { return mNames; }

References mNames.

◆ getNumberOfElements()

int ColorModel::getNumberOfElements ( )
virtual

Gets the number of elements in the list.

Returns
The number of elements in the list

Implements ListModel.

Definition at line 41 of file colormodel.cpp.

42 {
43  return CAST_S32(mNames.size());
44 }

References CAST_S32, and mNames.

Referenced by getElementAt().

◆ size()

size_t ColorModel::size ( )
inline

Definition at line 55 of file colormodel.h.

56  { return mNames.size(); }

References mNames.

Field Documentation

◆ mColors

std::vector<ColorPair> ColorModel::mColors
protected

Definition at line 67 of file colormodel.h.

Referenced by add(), and getColorAt().

◆ mNames

StringVect ColorModel::mNames
protected

Definition at line 66 of file colormodel.h.

Referenced by add(), getElementAt(), getNames(), getNumberOfElements(), and size().


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