ManaPlus
colormodel.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "gui/models/colormodel.h"
23 
24 #include "gui/widgets/widget2.h"
25 
26 #include "utils/gettext.h"
27 
28 #include "debug.h"
29 
31  ListModel(),
32  mNames(),
33  mColors()
34 {
35 }
36 
38 {
39 }
40 
42 {
43  return CAST_S32(mNames.size());
44 }
45 
46 std::string ColorModel::getElementAt(int i)
47 {
48  if (i >= getNumberOfElements() || i < 0)
49  return "???";
50  return mNames[CAST_SIZE(i)];
51 }
52 
53 const ColorPair *ColorModel::getColorAt(const int i) const
54 {
55  if (i >= CAST_S32(mColors.size()) || i < 0)
56  return &mColors[0];
57 
58  return &mColors[CAST_SIZE(i)];
59 }
60 
61 void ColorModel::add(const std::string &name, const Color *const color1,
62  const Color *const color2)
63 {
64  mNames.push_back(name);
65  mColors.push_back(ColorPair(color1, color2));
66 }
67 
68 #define addColor(name, color) \
69  model->add(name, &widget->getThemeColor(ThemeColorId::color, 255U), \
70  &widget->getThemeColor(ThemeColorId::color##_OUTLINE, 255U))
71 
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 CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34
std::vector< ColorPair > mColors
Definition: colormodel.h:67
void add(const std::string &name, const Color *const color1, const Color *const color2)
Definition: colormodel.cpp:61
StringVect mNames
Definition: colormodel.h:66
static ColorModel * createDefault(const Widget2 *const widget)
Definition: colormodel.cpp:72
int getNumberOfElements()
Definition: colormodel.cpp:41
const ColorPair * getColorAt(const int i) const
Definition: colormodel.cpp:53
std::string getElementAt(int i)
Definition: colormodel.cpp:46
Definition: color.h:76
#define addColor(name, color)
Definition: colormodel.cpp:68
#define _(s)
Definition: gettext.h:35
std::map< std::string, DyeColor > mColors
Definition: palettedb.cpp:37