AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
Color.hpp
1/*
2Copyright (C) 2010-2012,2019,2020,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGUI_COLOR_H
17#define AEONGUI_COLOR_H
18#include <string>
19#include <cstdint>
20#include <regex>
21#include <variant>
22#include "aeongui/Platform.hpp"
23namespace AeonGUI
24{
26 enum CSS3Color : uint32_t
27 {
28 aliceblue = 0xfff0f8ff,
29 antiquewhite = 0xfffaebd7,
30 aqua = 0xff00ffff,
31 aquamarine = 0xff7fffd4,
32 azure = 0xfff0ffff,
33 beige = 0xfff5f5dc,
34 bisque = 0xffffe4c4,
35 black = 0xff000000,
36 blanchedalmond = 0xffffebcd,
37 blue = 0xff0000ff,
38 blueviolet = 0xff8a2be2,
39 brown = 0xffa52a2a,
40 burlywood = 0xffdeb887,
41 cadetblue = 0xff5f9ea0,
42 chartreuse = 0xff7fff00,
43 chocolate = 0xffd2691e,
44 coral = 0xffff7f50,
45 cornflowerblue = 0xff6495ed,
46 cornsilk = 0xfffff8dc,
47 crimson = 0xffdc143c,
48 cyan = 0xff00ffff,
49 darkblue = 0xff00008b,
50 darkcyan = 0xff008b8b,
51 darkgoldenrod = 0xffb8860b,
52 darkgray = 0xffa9a9a9,
53 darkgreen = 0xff006400,
54 darkgrey = 0xffa9a9a9,
55 darkkhaki = 0xffbdb76b,
56 darkmagenta = 0xff8b008b,
57 darkolivegreen = 0xff556b2f,
58 darkorange = 0xffff8c00,
59 darkorchid = 0xff9932cc,
60 darkred = 0xff8b0000,
61 darksalmon = 0xffe9967a,
62 darkseagreen = 0xff8fbc8f,
63 darkslateblue = 0xff483d8b,
64 darkslategray = 0xff2f4f4f,
65 darkslategrey = 0xff2f4f4f,
66 darkturquoise = 0xff00ced1,
67 darkviolet = 0xff9400d3,
68 deeppink = 0xffff1493,
69 deepskyblue = 0xff00bfff,
70 dimgray = 0xff696969,
71 dimgrey = 0xff696969,
72 dodgerblue = 0xff1e90ff,
73 firebrick = 0xffb22222,
74 floralwhite = 0xfffffaf0,
75 forestgreen = 0xff228b22,
76 fuchsia = 0xffff00ff,
77 gainsboro = 0xffdcdcdc,
78 ghostwhite = 0xfff8f8ff,
79 gold = 0xffffd700,
80 goldenrod = 0xffdaa520,
81 gray = 0xff808080,
82 grey = 0xff808080,
83 green = 0xff008000,
84 greenyellow = 0xffadff2f,
85 honeydew = 0xfff0fff0,
86 hotpink = 0xffff69b4,
87 indianred = 0xffcd5c5c,
88 indigo = 0xff4b0082,
89 ivory = 0xfffffff0,
90 khaki = 0xfff0e68c,
91 lavender = 0xffe6e6fa,
92 lavenderblush = 0xfffff0f5,
93 lawngreen = 0xff7cfc00,
94 lemonchiffon = 0xfffffacd,
95 lightblue = 0xffadd8e6,
96 lightcoral = 0xfff08080,
97 lightcyan = 0xffe0ffff,
98 lightgoldenrodyellow = 0xfffafad2,
99 lightgray = 0xffd3d3d3,
100 lightgreen = 0xff90ee90,
101 lightgrey = 0xffd3d3d3,
102 lightpink = 0xffffb6c1,
103 lightsalmon = 0xffffa07a,
104 lightseagreen = 0xff20b2aa,
105 lightskyblue = 0xff87cefa,
106 lightslategray = 0xff778899,
107 lightslategrey = 0xff778899,
108 lightsteelblue = 0xffb0c4de,
109 lightyellow = 0xffffffe0,
110 lime = 0xff00ff00,
111 limegreen = 0xff32cd32,
112 linen = 0xfffaf0e6,
113 magenta = 0xffff00ff,
114 maroon = 0xff800000,
115 mediumaquamarine = 0xff66cdaa,
116 mediumblue = 0xff0000cd,
117 mediumorchid = 0xffba55d3,
118 mediumpurple = 0xff9370db,
119 mediumseagreen = 0xff3cb371,
120 mediumslateblue = 0xff7b68ee,
121 mediumspringgreen = 0xff00fa9a,
122 mediumturquoise = 0xff48d1cc,
123 mediumvioletred = 0xffc71585,
124 midnightblue = 0xff191970,
125 mintcream = 0xfff5fffa,
126 mistyrose = 0xffffe4e1,
127 moccasin = 0xffffe4b5,
128 navajowhite = 0xffffdead,
129 navy = 0xff000080,
130 oldlace = 0xfffdf5e6,
131 olive = 0xff808000,
132 olivedrab = 0xff6b8e23,
133 orange = 0xffffa500,
134 orangered = 0xffff4500,
135 orchid = 0xffda70d6,
136 palegoldenrod = 0xffeee8aa,
137 palegreen = 0xff98fb98,
138 paleturquoise = 0xffafeeee,
139 palevioletred = 0xffdb7093,
140 papayawhip = 0xffffefd5,
141 peachpuff = 0xffffdab9,
142 peru = 0xffcd853f,
143 pink = 0xffffc0cb,
144 plum = 0xffdda0dd,
145 powderblue = 0xffb0e0e6,
146 purple = 0xff800080,
147 red = 0xffff0000,
148 rosybrown = 0xffbc8f8f,
149 royalblue = 0xff4169e1,
150 saddlebrown = 0xff8b4513,
151 salmon = 0xfffa8072,
152 sandybrown = 0xfff4a460,
153 seagreen = 0xff2e8b57,
154 seashell = 0xfffff5ee,
155 sienna = 0xffa0522d,
156 silver = 0xffc0c0c0,
157 skyblue = 0xff87ceeb,
158 slateblue = 0xff6a5acd,
159 slategray = 0xff708090,
160 slategrey = 0xff708090,
161 snow = 0xfffffafa,
162 springgreen = 0xff00ff7f,
163 steelblue = 0xff4682b4,
164 tan = 0xffd2b48c,
165 teal = 0xff008080,
166 thistle = 0xffd8bfd8,
167 tomato = 0xffff6347,
168 transparent = 0x00000000,
169 turquoise = 0xff40e0d0,
170 violet = 0xffee82ee,
171 wheat = 0xfff5deb3,
172 white = 0xffffffff,
173 whitesmoke = 0xfff5f5f5,
174 yellow = 0xffffff00,
175 yellowgreen = 0xff9acd32
176 };
183 union Color
184 {
190 DLL static bool IsColor ( const std::string& value, uint32_t* color_value = nullptr );
192 DLL static const std::regex ColorRegex;
193 DLL Color();
197 DLL explicit Color ( uint32_t value );
198
202 DLL Color ( const std::string& value );
209 DLL Color ( uint8_t A, uint8_t R, uint8_t G, uint8_t B );
210
215 DLL void Blend ( Color src );
216
220 DLL double R() const;
224 DLL double G() const;
228 DLL double B() const;
232 DLL double A() const;
236 DLL std::string ToString() const;
237 uint32_t bgra;
238 struct
239 {
240#if 0
241 uint8_t r;
242 uint8_t g;
243 uint8_t b;
244 uint8_t a;
245#else
246 uint8_t b;
247 uint8_t g;
248 uint8_t r;
249 uint8_t a;
250#endif
251 };
252 };
253
254 using none = std::monostate;
256 using ColorAttr = std::variant<none, Color>;
257}
258#endif
Platform-specific DLL import/export macros and compiler helpers.
std::string ToString() const
Convert the color to a CSS-style string representation.
Definition Color.cpp:280
uint32_t bgra
32 bit Unsigned integer color value.
Definition Color.hpp:237
double G() const
Get green component as a double in [0.0, 1.0].
Definition Color.cpp:241
double B() const
Get blue component as a double in [0.0, 1.0].
Definition Color.cpp:245
double A() const
Get alpha component as a double in [0.0, 1.0].
Definition Color.cpp:249
void Blend(Color src)
Blends the color with the incoming source color. To better handle transparency the blend function use...
Definition Color.cpp:254
double R() const
Get red component as a double in [0.0, 1.0].
Definition Color.cpp:237
uint8_t a
Alpha color element.
Definition Color.hpp:249
uint8_t r
Red color element.
Definition Color.hpp:248
static bool IsColor(const std::string &value, uint32_t *color_value=nullptr)
Check whether a string represents a valid CSS color.
Definition Color.cpp:185
uint8_t g
Green color element.
Definition Color.hpp:247
uint8_t b
Blue color element.
Definition Color.hpp:246
static const std::regex ColorRegex
Regex used to parse CSS color strings.
Definition Color.hpp:192