1.10
palette.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_PALETTE_H
7#define EGT_PALETTE_H
8
14#include <egt/color.h>
15#include <egt/detail/meta.h>
16#include <egt/fixedvector.h>
17#include <egt/pattern.h>
18#include <egt/serialize.h>
19#include <initializer_list>
20#include <iosfwd>
21#include <memory>
22#include <string>
23
24namespace egt
25{
26inline namespace v1
27{
28
39class EGT_API Palette
40{
41public:
42
59 constexpr static Color transparent = Color(0x00000000);
60 constexpr static Color aliceblue = Color::rgb(0xf0f8ff);
61 constexpr static Color antiquewhite = Color::rgb(0xfaebd7);
62 constexpr static Color aqua = Color::rgb(0x00ffff);
63 constexpr static Color aquamarine = Color::rgb(0x7fffd4);
64 constexpr static Color azure = Color::rgb(0xf0ffff);
65 constexpr static Color beige = Color::rgb(0xf5f5dc);
66 constexpr static Color bisque = Color::rgb(0xffe4c4);
67 constexpr static Color black = Color::rgb(0x000000);
68 constexpr static Color blanchedalmond = Color::rgb(0xffebcd);
69 constexpr static Color blue = Color::rgb(0x0000ff);
70 constexpr static Color blueviolet = Color::rgb(0x8a2be2);
71 constexpr static Color brown = Color::rgb(0xa52a2a);
72 constexpr static Color burlywood = Color::rgb(0xdeb887);
73 constexpr static Color cadetblue = Color::rgb(0x5f9ea0);
74 constexpr static Color chartreuse = Color::rgb(0x7fff00);
75 constexpr static Color chocolate = Color::rgb(0xd2691e);
76 constexpr static Color coral = Color::rgb(0xff7f50);
77 constexpr static Color cornflowerblue = Color::rgb(0x6495ed);
78 constexpr static Color cornsilk = Color::rgb(0xfff8dc);
79 constexpr static Color crimson = Color::rgb(0xdc143c);
80 constexpr static Color cyan = Color::rgb(0x00ffff);
81 constexpr static Color darkblue = Color::rgb(0x00008b);
82 constexpr static Color darkcyan = Color::rgb(0x008b8b);
83 constexpr static Color darkgoldenrod = Color::rgb(0xb8860b);
84 constexpr static Color darkgray = Color::rgb(0xa9a9a9);
85 constexpr static Color darkgreen = Color::rgb(0x006400);
86 constexpr static Color darkgrey = Color::rgb(0xa9a9a9);
87 constexpr static Color darkkhaki = Color::rgb(0xbdb76b);
88 constexpr static Color darkmagenta = Color::rgb(0x8b008b);
89 constexpr static Color darkolivegreen = Color::rgb(0x556b2f);
90 constexpr static Color darkorange = Color::rgb(0xff8c00);
91 constexpr static Color darkorchid = Color::rgb(0x9932cc);
92 constexpr static Color darkred = Color::rgb(0x8b0000);
93 constexpr static Color darksalmon = Color::rgb(0xe9967a);
94 constexpr static Color darkseagreen = Color::rgb(0x8fbc8f);
95 constexpr static Color darkslateblue = Color::rgb(0x483d8b);
96 constexpr static Color darkslategray = Color::rgb(0x2f4f4f);
97 constexpr static Color darkslategrey = Color::rgb(0x2f4f4f);
98 constexpr static Color darkturquoise = Color::rgb(0x00ced1);
99 constexpr static Color darkviolet = Color::rgb(0x9400d3);
100 constexpr static Color deeppink = Color::rgb(0xff1493);
101 constexpr static Color deepskyblue = Color::rgb(0x00bfff);
102 constexpr static Color dimgray = Color::rgb(0x696969);
103 constexpr static Color dimgrey = Color::rgb(0x696969);
104 constexpr static Color dodgerblue = Color::rgb(0x1e90ff);
105 constexpr static Color firebrick = Color::rgb(0xb22222);
106 constexpr static Color floralwhite = Color::rgb(0xfffaf0);
107 constexpr static Color forestgreen = Color::rgb(0x228b22);
108 constexpr static Color fuchsia = Color::rgb(0xff00ff);
109 constexpr static Color gainsboro = Color::rgb(0xdcdcdc);
110 constexpr static Color ghostwhite = Color::rgb(0xf8f8ff);
111 constexpr static Color gold = Color::rgb(0xffd700);
112 constexpr static Color goldenrod = Color::rgb(0xdaa520);
113 constexpr static Color gray = Color::rgb(0x808080);
114 constexpr static Color green = Color::rgb(0x008000);
115 constexpr static Color greenyellow = Color::rgb(0xadff2f);
116 constexpr static Color grey = Color::rgb(0x808080);
117 constexpr static Color honeydew = Color::rgb(0xf0fff0);
118 constexpr static Color hotpink = Color::rgb(0xff69b4);
119 constexpr static Color indianred = Color::rgb(0xcd5c5c);
120 constexpr static Color indigo = Color::rgb(0x4b0082);
121 constexpr static Color ivory = Color::rgb(0xfffff0);
122 constexpr static Color khaki = Color::rgb(0xf0e68c);
123 constexpr static Color lavender = Color::rgb(0xe6e6fa);
124 constexpr static Color lavenderblush = Color::rgb(0xfff0f5);
125 constexpr static Color lawngreen = Color::rgb(0x7cfc00);
126 constexpr static Color lemonchiffon = Color::rgb(0xfffacd);
127 constexpr static Color lightblue = Color::rgb(0xadd8e6);
128 constexpr static Color lightcoral = Color::rgb(0xf08080);
129 constexpr static Color lightcyan = Color::rgb(0xe0ffff);
130 constexpr static Color lightgoldenrodyellow = Color::rgb(0xfafad2);
131 constexpr static Color lightgray = Color::rgb(0xd3d3d3);
132 constexpr static Color lightgreen = Color::rgb(0x90ee90);
133 constexpr static Color lightgrey = Color::rgb(0xd3d3d3);
134 constexpr static Color lightpink = Color::rgb(0xffb6c1);
135 constexpr static Color lightsalmon = Color::rgb(0xffa07a);
136 constexpr static Color lightseagreen = Color::rgb(0x20b2aa);
137 constexpr static Color lightskyblue = Color::rgb(0x87cefa);
138 constexpr static Color lightslategray = Color::rgb(0x778899);
139 constexpr static Color lightslategrey = Color::rgb(0x778899);
140 constexpr static Color lightsteelblue = Color::rgb(0xb0c4de);
141 constexpr static Color lightyellow = Color::rgb(0xffffe0);
142 constexpr static Color lime = Color::rgb(0x00ff00);
143 constexpr static Color limegreen = Color::rgb(0x32cd32);
144 constexpr static Color linen = Color::rgb(0xfaf0e6);
145 constexpr static Color magenta = Color::rgb(0xff00ff);
146 constexpr static Color maroon = Color::rgb(0x800000);
147 constexpr static Color mediumaquamarine = Color::rgb(0x66cdaa);
148 constexpr static Color mediumblue = Color::rgb(0x0000cd);
149 constexpr static Color mediumorchid = Color::rgb(0xba55d3);
150 constexpr static Color mediumpurple = Color::rgb(0x9370db);
151 constexpr static Color mediumseagreen = Color::rgb(0x3cb371);
152 constexpr static Color mediumslateblue = Color::rgb(0x7b68ee);
153 constexpr static Color mediumspringgreen = Color::rgb(0x00fa9a);
154 constexpr static Color mediumturquoise = Color::rgb(0x48d1cc);
155 constexpr static Color mediumvioletred = Color::rgb(0xc71585);
156 constexpr static Color midnightblue = Color::rgb(0x191970);
157 constexpr static Color mintcream = Color::rgb(0xf5fffa);
158 constexpr static Color mistyrose = Color::rgb(0xffe4e1);
159 constexpr static Color moccasin = Color::rgb(0xffe4b5);
160 constexpr static Color navajowhite = Color::rgb(0xffdead);
161 constexpr static Color navy = Color::rgb(0x000080);
162 constexpr static Color oldlace = Color::rgb(0xfdf5e6);
163 constexpr static Color olive = Color::rgb(0x808000);
164 constexpr static Color olivedrab = Color::rgb(0x6b8e23);
165 constexpr static Color orange = Color::rgb(0xffa500);
166 constexpr static Color orangered = Color::rgb(0xff4500);
167 constexpr static Color orchid = Color::rgb(0xda70d6);
168 constexpr static Color palegoldenrod = Color::rgb(0xeee8aa);
169 constexpr static Color palegreen = Color::rgb(0x98fb98);
170 constexpr static Color paleturquoise = Color::rgb(0xafeeee);
171 constexpr static Color palevioletred = Color::rgb(0xdb7093);
172 constexpr static Color papayawhip = Color::rgb(0xffefd5);
173 constexpr static Color peachpuff = Color::rgb(0xffdab9);
174 constexpr static Color peru = Color::rgb(0xcd853f);
175 constexpr static Color pink = Color::rgb(0xffc0cb);
176 constexpr static Color plum = Color::rgb(0xdda0dd);
177 constexpr static Color powderblue = Color::rgb(0xb0e0e6);
178 constexpr static Color purple = Color::rgb(0x800080);
179 constexpr static Color red = Color::rgb(0xff0000);
180 constexpr static Color rosybrown = Color::rgb(0xbc8f8f);
181 constexpr static Color royalblue = Color::rgb(0x4169e1);
182 constexpr static Color saddlebrown = Color::rgb(0x8b4513);
183 constexpr static Color salmon = Color::rgb(0xfa8072);
184 constexpr static Color sandybrown = Color::rgb(0xf4a460);
185 constexpr static Color seagreen = Color::rgb(0x2e8b57);
186 constexpr static Color seashell = Color::rgb(0xfff5ee);
187 constexpr static Color sienna = Color::rgb(0xa0522d);
188 constexpr static Color silver = Color::rgb(0xc0c0c0);
189 constexpr static Color skyblue = Color::rgb(0x87ceeb);
190 constexpr static Color slateblue = Color::rgb(0x6a5acd);
191 constexpr static Color slategray = Color::rgb(0x708090);
192 constexpr static Color slategrey = Color::rgb(0x708090);
193 constexpr static Color snow = Color::rgb(0xfffafa);
194 constexpr static Color springgreen = Color::rgb(0x00ff7f);
195 constexpr static Color steelblue = Color::rgb(0x4682b4);
196 constexpr static Color tan = Color::rgb(0xd2b48c);
197 constexpr static Color teal = Color::rgb(0x008080);
198 constexpr static Color thistle = Color::rgb(0xd8bfd8);
199 constexpr static Color tomato = Color::rgb(0xff6347);
200 constexpr static Color turquoise = Color::rgb(0x40e0d0);
201 constexpr static Color violet = Color::rgb(0xee82ee);
202 constexpr static Color wheat = Color::rgb(0xf5deb3);
203 constexpr static Color white = Color::rgb(0xffffff);
204 constexpr static Color whitesmoke = Color::rgb(0xf5f5f5);
205 constexpr static Color yellow = Color::rgb(0xffff00);
206 constexpr static Color yellowgreen = Color::rgb(0x9acd32);
218 enum class GroupId
219 {
221 normal = 1,
222
224 active = 2,
225
227 disabled = 3,
228
230 checked = 4
231 };
232
238 enum class ColorId
239 {
241 bg = 1,
242
244 text,
245
247 text_highlight,
248
250 cursor,
251
253 border,
254
256 button_bg,
257
259 button_fg,
260
262 button_text,
263
265 label_bg,
266
268 label_text,
269 };
270
273
274 Palette() = default;
275
276 explicit constexpr Palette(std::initializer_list<PatternArray::value_type> colors) noexcept
277 : m_colors(colors)
278 {}
279
281
289 EGT_NODISCARD const Pattern& color(ColorId id, GroupId group = GroupId::normal) const;
290
299 void set(ColorId id, GroupId group, const Pattern& color);
300
309 void set(ColorId id, const Pattern& color, GroupId group = GroupId::normal);
310
317 void clear(ColorId id, GroupId group = GroupId::normal);
318
322 void clear();
323
327 EGT_NODISCARD bool empty() const
328 {
329 return m_colors.empty();
330 }
331
339 EGT_NODISCARD bool exists(ColorId id, GroupId group = GroupId::normal) const;
340
349 EGT_NODISCARD bool exists(ColorId id, GroupId group, const Pattern** color) const;
350
354 void serialize(const std::string& name, Serializer& serializer) const;
355
359 void deserialize(const std::string& name, const std::string& value,
360 const Serializer::Attributes& attrs);
361
362protected:
363
365 PatternArray m_colors{};
366};
367
368static_assert(detail::rule_of_5<Palette>(), "must fulfill rule of 5");
369
371EGT_API std::ostream& operator<<(std::ostream& os, const Palette::ColorId& color);
373EGT_API std::ostream& operator<<(std::ostream& os, const Palette::GroupId& group);
374
380EGT_API const Palette* global_palette();
381
385EGT_API void global_palette(std::unique_ptr<Palette>&& palette);
386
390EGT_API void reset_global_palette();
391
392}
393}
394
395#endif
32 bit RGBA color.
Definition color.h:41
Color palette that contains a 2 dimensional array of colors.
Definition palette.h:40
GroupId
Used to define a category of patterns that usually relate to the state of a widget.
Definition palette.h:219
constexpr Palette(std::initializer_list< PatternArray::value_type > colors) noexcept
Definition palette.h:276
void deserialize(const std::string &name, const std::string &value, const Serializer::Attributes &attrs)
Deserialize.
Palette()=default
void set(ColorId id, GroupId group, const Pattern &color)
Set a color in the Palette.
void serialize(const std::string &name, Serializer &serializer) const
Serialize to the specified serializer.
void clear(ColorId id, GroupId group=GroupId::normal)
Remove a color from the Palette.
void set(ColorId id, const Pattern &color, GroupId group=GroupId::normal)
Set a color in a Palette.
EGT_NODISCARD bool exists(ColorId id, GroupId group=GroupId::normal) const
Check if a color exists in the palette.
ColorId
The Pattern identifier in the Palette.
Definition palette.h:239
EGT_NODISCARD bool exists(ColorId id, GroupId group, const Pattern **color) const
Check if a color exists in the palette and get the color.
EGT_NODISCARD bool empty() const
Returns true if the palette is empty.
Definition palette.h:327
void clear()
Remove all colors from the Palette.
Palette & operator=(const PatternArray &colors)
EGT_NODISCARD const Pattern & color(ColorId id, GroupId group=GroupId::normal) const
Get a color.
A Pattern which can store one or more colors at different offsets (steps) which can be used to create...
Definition pattern.h:55
Abstract base serializer class.
Definition serialize.h:34
std::list< std::pair< std::string, std::string > > Attributes
Attributes array type.
Definition serialize.h:45
EGT_API const Palette * global_palette()
Get the global Palette.
EGT_API std::ostream & operator<<(std::ostream &os, const Color &color)
Overloaded std::ostream insertion operator.
EGT_API void reset_global_palette()
Reset the global Palette.
EGT framework namespace.
Definition animation.h:24