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 <vector>
23#include "aeongui/Platform.hpp"
24namespace AeonGUI
25{
27 enum CSS3Color : uint32_t
28 {
29 aliceblue = 0xfff0f8ff,
30 antiquewhite = 0xfffaebd7,
31 aqua = 0xff00ffff,
32 aquamarine = 0xff7fffd4,
33 azure = 0xfff0ffff,
34 beige = 0xfff5f5dc,
35 bisque = 0xffffe4c4,
36 black = 0xff000000,
37 blanchedalmond = 0xffffebcd,
38 blue = 0xff0000ff,
39 blueviolet = 0xff8a2be2,
40 brown = 0xffa52a2a,
41 burlywood = 0xffdeb887,
42 cadetblue = 0xff5f9ea0,
43 chartreuse = 0xff7fff00,
44 chocolate = 0xffd2691e,
45 coral = 0xffff7f50,
46 cornflowerblue = 0xff6495ed,
47 cornsilk = 0xfffff8dc,
48 crimson = 0xffdc143c,
49 cyan = 0xff00ffff,
50 darkblue = 0xff00008b,
51 darkcyan = 0xff008b8b,
52 darkgoldenrod = 0xffb8860b,
53 darkgray = 0xffa9a9a9,
54 darkgreen = 0xff006400,
55 darkgrey = 0xffa9a9a9,
56 darkkhaki = 0xffbdb76b,
57 darkmagenta = 0xff8b008b,
58 darkolivegreen = 0xff556b2f,
59 darkorange = 0xffff8c00,
60 darkorchid = 0xff9932cc,
61 darkred = 0xff8b0000,
62 darksalmon = 0xffe9967a,
63 darkseagreen = 0xff8fbc8f,
64 darkslateblue = 0xff483d8b,
65 darkslategray = 0xff2f4f4f,
66 darkslategrey = 0xff2f4f4f,
67 darkturquoise = 0xff00ced1,
68 darkviolet = 0xff9400d3,
69 deeppink = 0xffff1493,
70 deepskyblue = 0xff00bfff,
71 dimgray = 0xff696969,
72 dimgrey = 0xff696969,
73 dodgerblue = 0xff1e90ff,
74 firebrick = 0xffb22222,
75 floralwhite = 0xfffffaf0,
76 forestgreen = 0xff228b22,
77 fuchsia = 0xffff00ff,
78 gainsboro = 0xffdcdcdc,
79 ghostwhite = 0xfff8f8ff,
80 gold = 0xffffd700,
81 goldenrod = 0xffdaa520,
82 gray = 0xff808080,
83 grey = 0xff808080,
84 green = 0xff008000,
85 greenyellow = 0xffadff2f,
86 honeydew = 0xfff0fff0,
87 hotpink = 0xffff69b4,
88 indianred = 0xffcd5c5c,
89 indigo = 0xff4b0082,
90 ivory = 0xfffffff0,
91 khaki = 0xfff0e68c,
92 lavender = 0xffe6e6fa,
93 lavenderblush = 0xfffff0f5,
94 lawngreen = 0xff7cfc00,
95 lemonchiffon = 0xfffffacd,
96 lightblue = 0xffadd8e6,
97 lightcoral = 0xfff08080,
98 lightcyan = 0xffe0ffff,
99 lightgoldenrodyellow = 0xfffafad2,
100 lightgray = 0xffd3d3d3,
101 lightgreen = 0xff90ee90,
102 lightgrey = 0xffd3d3d3,
103 lightpink = 0xffffb6c1,
104 lightsalmon = 0xffffa07a,
105 lightseagreen = 0xff20b2aa,
106 lightskyblue = 0xff87cefa,
107 lightslategray = 0xff778899,
108 lightslategrey = 0xff778899,
109 lightsteelblue = 0xffb0c4de,
110 lightyellow = 0xffffffe0,
111 lime = 0xff00ff00,
112 limegreen = 0xff32cd32,
113 linen = 0xfffaf0e6,
114 magenta = 0xffff00ff,
115 maroon = 0xff800000,
116 mediumaquamarine = 0xff66cdaa,
117 mediumblue = 0xff0000cd,
118 mediumorchid = 0xffba55d3,
119 mediumpurple = 0xff9370db,
120 mediumseagreen = 0xff3cb371,
121 mediumslateblue = 0xff7b68ee,
122 mediumspringgreen = 0xff00fa9a,
123 mediumturquoise = 0xff48d1cc,
124 mediumvioletred = 0xffc71585,
125 midnightblue = 0xff191970,
126 mintcream = 0xfff5fffa,
127 mistyrose = 0xffffe4e1,
128 moccasin = 0xffffe4b5,
129 navajowhite = 0xffffdead,
130 navy = 0xff000080,
131 oldlace = 0xfffdf5e6,
132 olive = 0xff808000,
133 olivedrab = 0xff6b8e23,
134 orange = 0xffffa500,
135 orangered = 0xffff4500,
136 orchid = 0xffda70d6,
137 palegoldenrod = 0xffeee8aa,
138 palegreen = 0xff98fb98,
139 paleturquoise = 0xffafeeee,
140 palevioletred = 0xffdb7093,
141 papayawhip = 0xffffefd5,
142 peachpuff = 0xffffdab9,
143 peru = 0xffcd853f,
144 pink = 0xffffc0cb,
145 plum = 0xffdda0dd,
146 powderblue = 0xffb0e0e6,
147 purple = 0xff800080,
148 red = 0xffff0000,
149 rosybrown = 0xffbc8f8f,
150 royalblue = 0xff4169e1,
151 saddlebrown = 0xff8b4513,
152 salmon = 0xfffa8072,
153 sandybrown = 0xfff4a460,
154 seagreen = 0xff2e8b57,
155 seashell = 0xfffff5ee,
156 sienna = 0xffa0522d,
157 silver = 0xffc0c0c0,
158 skyblue = 0xff87ceeb,
159 slateblue = 0xff6a5acd,
160 slategray = 0xff708090,
161 slategrey = 0xff708090,
162 snow = 0xfffffafa,
163 springgreen = 0xff00ff7f,
164 steelblue = 0xff4682b4,
165 tan = 0xffd2b48c,
166 teal = 0xff008080,
167 thistle = 0xffd8bfd8,
168 tomato = 0xffff6347,
169 transparent = 0x00000000,
170 turquoise = 0xff40e0d0,
171 violet = 0xffee82ee,
172 wheat = 0xfff5deb3,
173 white = 0xffffffff,
174 whitesmoke = 0xfff5f5f5,
175 yellow = 0xffffff00,
176 yellowgreen = 0xff9acd32
177 };
184 union Color
185 {
191 DLL static bool IsColor ( const std::string& value, uint32_t* color_value = nullptr );
193 DLL static const std::regex ColorRegex;
194 DLL Color();
198 DLL explicit Color ( uint32_t value );
199
203 DLL Color ( const std::string& value );
210 DLL Color ( uint8_t A, uint8_t R, uint8_t G, uint8_t B );
211
216 DLL void Blend ( Color src );
217
221 DLL double R() const;
225 DLL double G() const;
229 DLL double B() const;
233 DLL double A() const;
237 DLL std::string ToString() const;
238 uint32_t bgra;
239 struct
240 {
241#if 0
242 uint8_t r;
243 uint8_t g;
244 uint8_t b;
245 uint8_t a;
246#else
247 uint8_t b;
248 uint8_t g;
249 uint8_t r;
250 uint8_t a;
251#endif
252 };
253 };
254
255 using none = std::monostate;
256
259 {
260 double offset;
262 };
263
266 {
267 double x1{0};
268 double y1{0};
269 double x2{1};
270 double y2{0};
271 std::vector<GradientStop> stops;
272 bool objectBoundingBox{true};
273 };
274
276 using ColorAttr = std::variant<none, Color, LinearGradient>;
277}
278#endif
Platform-specific DLL import/export macros and compiler helpers.
A single color stop in a gradient.
Definition Color.hpp:259
Color color
Stop color.
Definition Color.hpp:261
double offset
Position along the gradient [0.0, 1.0].
Definition Color.hpp:260
A linear gradient paint.
Definition Color.hpp:266
bool objectBoundingBox
True if coords are relative to the element bounding box.
Definition Color.hpp:272
double x2
End X of the gradient vector.
Definition Color.hpp:269
double y2
End Y of the gradient vector.
Definition Color.hpp:270
double y1
Start Y of the gradient vector.
Definition Color.hpp:268
std::vector< GradientStop > stops
Color stops.
Definition Color.hpp:271
double x1
Start X of the gradient vector.
Definition Color.hpp:267
Pixel Color Union. The Color union allows access to each unsigned 8 bit RGBA color component individu...
Definition Color.hpp:185
std::string ToString() const
Convert the color to a CSS-style string representation.
Definition Color.cpp:282
uint32_t bgra
32 bit Unsigned integer color value.
Definition Color.hpp:238
double G() const
Get green component as a double in [0.0, 1.0].
Definition Color.cpp:243
double B() const
Get blue component as a double in [0.0, 1.0].
Definition Color.cpp:247
double A() const
Get alpha component as a double in [0.0, 1.0].
Definition Color.cpp:251
void Blend(Color src)
Blends the color with the incoming source color. To better handle transparency the blend function use...
Definition Color.cpp:256
double R() const
Get red component as a double in [0.0, 1.0].
Definition Color.cpp:239
uint8_t a
Alpha color element.
Definition Color.hpp:250
uint8_t r
Red color element.
Definition Color.hpp:249
static bool IsColor(const std::string &value, uint32_t *color_value=nullptr)
Check whether a string represents a valid CSS color.
Definition Color.cpp:186
uint8_t g
Green color element.
Definition Color.hpp:248
uint8_t b
Blue color element.
Definition Color.hpp:247
static const std::regex ColorRegex
Regex used to parse CSS color strings.
Definition Color.hpp:193