19 #include <unordered_map>
21 QX_PUSH_SUPPRESS_ALL_WARNINGS();
22 #include <glm/vec3.hpp>
23 #include <glm/vec4.hpp>
24 QX_POP_SUPPRESS_WARNINGS();
28 #define _QX_COLORS(macro)\
29 macro(alice_blue , AliceBlue , 240, 248, 255) \
30 macro(antique_white , AntiqueWhite , 250, 235, 215) \
31 macro(aqua , Aqua , 0, 255, 255) \
32 macro(aquamarine , Aquamarine , 127, 255, 212) \
33 macro(azure , Azure , 240, 255, 255) \
34 macro(beige , Beige , 245, 245, 220) \
35 macro(bisque , Bisque , 255, 228, 196) \
36 macro(black , Black , 0, 0, 0) \
37 macro(blanched_almond , BlanchedAlmond , 255, 235, 205) \
38 macro(blue , Blue , 0, 0, 255) \
39 macro(blue_violet , BlueViolet , 138, 43, 226) \
40 macro(brown , Brown , 165, 42, 42) \
41 macro(burly_wood , BurlyWood , 222, 184, 135) \
42 macro(cadet_blue , CadetBlue , 95, 158, 160) \
43 macro(chartreuse , Chartreuse , 127, 255, 0) \
44 macro(chocolate , Chocolate , 210, 105, 30) \
45 macro(coral , Coral , 255, 127, 80) \
46 macro(cornflower_blue , CornflowerBlue , 100, 149, 237) \
47 macro(cornsilk , Cornsilk , 255, 248, 220) \
48 macro(crimson , Crimson , 220, 20, 60) \
49 macro(cyan , Cyan , 0, 255, 255) \
50 macro(dark_blue , DarkBlue , 0, 0, 139) \
51 macro(dark_cyan , DarkCyan , 0, 139, 139) \
52 macro(dark_goldenrod , DarkGoldenrod , 184, 134, 11) \
53 macro(dark_gray , DarkGray , 169, 169, 169) \
54 macro(dark_green , DarkGreen , 0, 100, 0); \
55 macro(dark_khaki , DarkKhaki , 189, 183, 107) \
56 macro(dark_magenta , DarkMagenta , 139, 0, 139) \
57 macro(dark_olive_green , DarkOliveGreen , 85, 107, 47) \
58 macro(dark_orange , DarkOrange , 255, 140, 0) \
59 macro(dark_orchid , DarkOrchid , 153, 50, 204) \
60 macro(dark_red , DarkRed , 139, 0, 0) \
61 macro(dark_salmon , DarkSalmon , 233, 150, 122) \
62 macro(dark_sea_green , DarkSeaGreen , 143, 188, 143) \
63 macro(dark_slate_blue , DarkSlateBlue , 72, 61, 139) \
64 macro(dark_slate_gray , DarkSlateGray , 47, 79, 79) \
65 macro(dark_turquoise , DarkTurquoise , 0, 206, 209) \
66 macro(dark_violet , DarkViolet , 148, 0, 211) \
67 macro(deep_pink , DeepPink , 255, 20, 147) \
68 macro(deep_sky_blue , DeepSkyBlue , 0, 191, 255) \
69 macro(dim_gray , DimGray , 105, 105, 105) \
70 macro(dodger_blue , DodgerBlue , 30, 144, 255) \
71 macro(fire_brick , FireBrick , 178, 34, 34) \
72 macro(floral_white , FloralWhite , 255, 250, 240) \
73 macro(forest_green , ForestGreen , 34, 139, 34) \
74 macro(fuchsia , Fuchsia , 255, 0, 255) \
75 macro(gainsboro , Gainsboro , 220, 220, 220) \
76 macro(ghost_white , GhostWhite , 248, 248, 255) \
77 macro(gold , Gold , 255, 215, 0) \
78 macro(goldenrod , Goldenrod , 218, 165, 32) \
79 macro(gray , Gray , 128, 128, 128) \
80 macro(green , Green , 0, 128, 0) \
81 macro(green_yellow , GreenYellow , 173, 255, 47) \
82 macro(honeydew , Honeydew , 240, 255, 240) \
83 macro(hot_pink , HotPink , 255, 105, 180) \
84 macro(indian_red , IndianRed , 205, 92, 92) \
85 macro(indigo , Indigo , 75, 0, 130) \
86 macro(ivory , Ivory , 255, 255, 240) \
87 macro(khaki , Khaki , 240, 230, 140) \
88 macro(lavender , Lavender , 230, 230, 250) \
89 macro(lavender_blush , LavenderBlush , 255, 240, 245) \
90 macro(lawn_green , LawnGreen , 124, 252, 0) \
91 macro(lemon_chiffon , LemonChiffon , 255, 250, 205) \
92 macro(light_blue , LightBlue , 173, 216, 230) \
93 macro(light_coral , LightCoral , 240, 128, 128) \
94 macro(light_cyan , LightCyan , 224, 255, 255) \
95 macro(light_goldenrod_yellow , LightGoldenrodYellow , 250, 250, 210) \
96 macro(light_green , LightGreen , 144, 238, 144) \
97 macro(light_grey , LightGrey , 211, 211, 211) \
98 macro(light_pink , LightPink , 255, 182, 193) \
99 macro(light_salmon , LightSalmon , 255, 160, 122) \
100 macro(light_sea_green , LightSeaGreen , 32, 178, 170) \
101 macro(light_sky_blue , LightSkyBlue , 135, 206, 250) \
102 macro(light_slate_gray , LightSlateGray , 119, 136, 153) \
103 macro(light_steel_blue , LightSteelBlue , 176, 196, 222) \
104 macro(light_yellow , LightYellow , 255, 255, 224) \
105 macro(lime , Lime , 0, 255, 0) \
106 macro(lime_green , LimeGreen , 50, 205, 50) \
107 macro(linen , Linen , 250, 240, 230) \
108 macro(magenta , Magenta , 255, 0, 255) \
109 macro(maroon , Maroon , 128, 0, 0) \
110 macro(medium_aquamarine , MediumAquamarine , 102, 205, 170) \
111 macro(medium_blue , MediumBlue , 0, 0, 205) \
112 macro(medium_orchid , MediumOrchid , 186, 85, 211) \
113 macro(medium_purple , MediumPurple , 147, 112, 219) \
114 macro(medium_sea_green , MediumSeaGreen , 60, 179, 113) \
115 macro(medium_slate_blue , MediumSlateBlue , 123, 104, 238) \
116 macro(medium_spring_green , MediumSpringGreen , 0, 250, 154) \
117 macro(medium_turquoise , MediumTurquoise , 72, 209, 204) \
118 macro(medium_violet_red , MediumVioletRed , 199, 21, 133) \
119 macro(midnight_blue , MidnightBlue , 25, 25, 112) \
120 macro(mint_cream , MintCream , 245, 255, 250) \
121 macro(misty_rose , MistyRose , 255, 228, 225) \
122 macro(moccasin , Moccasin , 255, 228, 181) \
123 macro(navajo_white , NavajoWhite , 255, 222, 173) \
124 macro(navy , Navy , 0, 0, 128) \
125 macro(old_lace , OldLace , 253, 245, 230) \
126 macro(olive , Olive , 128, 128, 0) \
127 macro(olive_drab , OliveDrab , 107, 142, 35) \
128 macro(orange , Orange , 255, 165, 0) \
129 macro(orange_red , OrangeRed , 255, 69, 0) \
130 macro(orchid , Orchid , 218, 112, 214) \
131 macro(pale_goldenrod , PaleGoldenrod , 238, 232, 170) \
132 macro(pale_green , PaleGreen , 152, 251, 152) \
133 macro(pale_turquoise , PaleTurquoise , 175, 238, 238) \
134 macro(pale_violet_red , PaleVioletRed , 219, 112, 147) \
135 macro(papaya_whip , PapayaWhip , 255, 239, 213) \
136 macro(peach_puff , PeachPuff , 255, 218, 185) \
137 macro(peru , Peru , 205, 133, 63) \
138 macro(pink , Pink , 255, 192, 203) \
139 macro(plum , Plum , 221, 160, 221) \
140 macro(powder_blue , PowderBlue , 176, 224, 230) \
141 macro(purple , Purple , 128, 0, 128) \
142 macro(red , Red , 255, 0, 0) \
143 macro(rosy_brown , RosyBrown , 188, 143, 143) \
144 macro(royal_blue , RoyalBlue , 65, 105, 225) \
145 macro(saddle_brown , SaddleBrown , 139, 69, 19) \
146 macro(salmon , Salmon , 250, 128, 114) \
147 macro(sandy_brown , SandyBrown , 244, 164, 96) \
148 macro(sea_green , SeaGreen , 46, 139, 87) \
149 macro(seashell , Seashell , 255, 245, 238) \
150 macro(sienna , Sienna , 160, 82, 45) \
151 macro(silver , Silver , 192, 192, 192) \
152 macro(sky_blue , SkyBlue , 135, 206, 235) \
153 macro(slate_blue , SlateBlue , 106, 90, 205) \
154 macro(slate_gray , SlateGray , 112, 128, 144) \
155 macro(snow , Snow , 255, 250, 250) \
156 macro(spring_green , SpringGreen , 0, 255, 127) \
157 macro(steel_blue , SteelBlue , 70, 130, 180) \
158 macro(tan , Tan , 210, 180, 140) \
159 macro(teal , Teal , 0, 128, 128) \
160 macro(thistle , Thistle , 216, 191, 216) \
161 macro(tomato , Tomato , 255, 99, 71) \
162 macro(turquoise , Turquoise , 64, 224, 208) \
163 macro(violet , Violet , 238, 130, 238) \
164 macro(wheat , Wheat , 245, 222, 179) \
165 macro(white , White , 255, 255, 255) \
166 macro(white_smoke , WhiteSmoke , 245, 245, 245) \
167 macro(yellow , Yellow , 255, 255, 0) \
168 macro(yellow_green , YellowGreen , 154, 205, 50)
175 enum class color_name_type
194 QX_COPYMOVABLE(
color);
197 constexpr
color() noexcept =
default;
207 constexpr
color(
float fRed,
float fGreen,
float fBlue,
float fAlpha = 1.f) noexcept;
217 constexpr
color(
int nRed,
int nGreen,
int nBlue,
int nAlpha = 255) noexcept;
223 constexpr
explicit color(
u64 nHexValue) noexcept;
229 constexpr
explicit color(
const glm::ivec3& vec3) noexcept;
235 constexpr
explicit color(
const glm::ivec4& vec4) noexcept;
241 constexpr
float r()
const noexcept;
247 constexpr
float g()
const noexcept;
253 constexpr
float b()
const noexcept;
259 constexpr
float a()
const noexcept;
266 constexpr
float&
operator[](
size_t i) noexcept;
273 constexpr
const float&
operator[](
size_t i)
const noexcept;
279 constexpr
int r_dec()
const noexcept;
285 constexpr
int g_dec()
const noexcept;
291 constexpr
int b_dec()
const noexcept;
297 constexpr
int a_dec()
const noexcept;
303 constexpr
const float*
data()
const noexcept;
309 constexpr
unsigned int hex_rgb()
const noexcept;
315 constexpr
unsigned int hex_rgba()
const noexcept;
321 constexpr
unsigned int hex_argb()
const noexcept;
323 constexpr
bool operator==(
const color& other)
const noexcept;
324 constexpr
operator glm::vec3()
const noexcept;
325 constexpr
operator glm::vec4()
const noexcept;
332 constexpr
void update_r(
float fDeltaValue) noexcept;
339 constexpr
void update_g(
float fDeltaValue) noexcept;
346 constexpr
void update_b(
float fDeltaValue) noexcept;
353 constexpr
void update_a(
float fDeltaValue) noexcept;
388 constexpr
void set_r(
float fValue) noexcept;
395 constexpr
void set_g(
float fValue) noexcept;
402 constexpr
void set_b(
float fValue) noexcept;
409 constexpr
void set_a(
float fValue) noexcept;
416 constexpr
void set_r_dec(
int nValue) noexcept;
423 constexpr
void set_g_dec(
int nValue) noexcept;
430 constexpr
void set_b_dec(
int nValue) noexcept;
437 constexpr
void set_a_dec(
int nValue) noexcept;
443 constexpr
void darken(
float fPercent) noexcept;
449 constexpr
void brighten(
float fPercent) noexcept;
467 #define _QX_COLOR_METHOD(snakeCaseName, pascalCaseName, r, g, b) \
468 static constexpr auto snakeCaseName(float fAlpha = 1.f) noexcept \
470 return color(r, g, b, float_to_dec(fAlpha)); \
481 static std::optional<color>
from_string(string_view svColorName) noexcept;
495 static constexpr
size_t size() noexcept;
503 static constexpr
float clamp_value(
float fValue) noexcept;
510 static constexpr
float dec_to_float(
int nValue) noexcept;
517 static constexpr
int float_to_dec(
float fValue) noexcept;
523 constexpr
void assign_checked(const glm::vec4& other) noexcept;
530 static constexpr
void assign_component_checked(
float& pComponent,
float fValue) noexcept;
533 glm::vec4 m_Color = glm::vec4(1.f);
538 #include <qx/render/color.inl>
constexpr float g() const noexcept
Get green component.
constexpr void update_r_dec(int nDeltaValue) noexcept
Add value to red component.
constexpr void update_a(float fDeltaValue) noexcept
Add value to alpha component.
constexpr int r_dec() const noexcept
Get red component as decimal.
static std::optional< color > from_string(string_view svColorName) noexcept
Try to create color from string.
constexpr void update_g(float fDeltaValue) noexcept
Add value to green component.
constexpr void update_b(float fDeltaValue) noexcept
Add value to blue component.
constexpr void darken(float fPercent) noexcept
Make color darker.
constexpr int g_dec() const noexcept
Get green component as decimal.
constexpr float a() const noexcept
Get alpha component.
constexpr const float * data() const noexcept
Get pointer to the first component.
constexpr float b() const noexcept
Get blue component.
constexpr float r() const noexcept
Get red component.
constexpr void set_g(float fValue) noexcept
Set new value of green component.
constexpr float & operator[](size_t i) noexcept
Get color component.
constexpr void set_b(float fValue) noexcept
Set new value of blue component.
constexpr int b_dec() const noexcept
Get blue component as decimal.
static constexpr color empty() noexcept
Get empty color (0, 0, 0, 0)
constexpr void update_g_dec(int nDeltaValue) noexcept
Add value to green component.
constexpr void set_r(float fValue) noexcept
Set new value of red component.
constexpr unsigned int hex_rgba() const noexcept
Get color as hex.
constexpr unsigned int hex_rgb() const noexcept
Get color as hex.
constexpr void update_r(float fDeltaValue) noexcept
Add value to red component.
constexpr int a_dec() const noexcept
Get alpha component as decimal.
constexpr void set_g_dec(int nValue) noexcept
Set new value of green component.
static constexpr size_t size() noexcept
Get number of float components.
_QX_COLORS(_QX_COLOR_METHOD)
Color functions.
constexpr void brighten(float fPercent) noexcept
Make color brighter.
constexpr unsigned int hex_argb() const noexcept
Get color as hex.
constexpr void update_b_dec(int nDeltaValue) noexcept
Add value to blue component.
constexpr void set_r_dec(int nValue) noexcept
Set new value of red component.
constexpr void set_b_dec(int nValue) noexcept
Set new value of blue component.
constexpr void update_a_dec(int nDeltaValue) noexcept
Add value to alpha component.
constexpr void set_a(float fValue) noexcept
Set new value of alpha component.
constexpr void set_a_dec(int nValue) noexcept
Set new value of alpha component.