19 #include <unordered_map>
22 #include <glm/vec3.hpp>
23 #include <glm/vec4.hpp>
28 #define _QX_COLORS(macro)\
29 macro(alice_blue , AliceBlue , aliceblue , 240, 248, 255) \
30 macro(antique_white , AntiqueWhite , antiquewhite , 250, 235, 215) \
31 macro(aqua , Aqua , aqua , 0, 255, 255) \
32 macro(aquamarine , Aquamarine , aquamarine , 127, 255, 212) \
33 macro(azure , Azure , azure , 240, 255, 255) \
34 macro(beige , Beige , beige , 245, 245, 220) \
35 macro(bisque , Bisque , bisque , 255, 228, 196) \
36 macro(black , Black , black , 0, 0, 0) \
37 macro(blanched_almond , BlanchedAlmond , blanchedalmond , 255, 235, 205) \
38 macro(blue , Blue , blue , 0, 0, 255) \
39 macro(blue_violet , BlueViolet , blueviolet , 138, 43, 226) \
40 macro(brown , Brown , brown , 165, 42, 42) \
41 macro(burly_wood , BurlyWood , burlywood , 222, 184, 135) \
42 macro(cadet_blue , CadetBlue , cadetblue , 95, 158, 160) \
43 macro(chartreuse , Chartreuse , chartreuse , 127, 255, 0) \
44 macro(chocolate , Chocolate , chocolate , 210, 105, 30) \
45 macro(coral , Coral , coral , 255, 127, 80) \
46 macro(cornflower_blue , CornflowerBlue , cornflowerblue , 100, 149, 237) \
47 macro(cornsilk , Cornsilk , cornsilk , 255, 248, 220) \
48 macro(crimson , Crimson , crimson , 220, 20, 60) \
49 macro(cyan , Cyan , cyan , 0, 255, 255) \
50 macro(dark_blue , DarkBlue , darkblue , 0, 0, 139) \
51 macro(dark_cyan , DarkCyan , darkcyan , 0, 139, 139) \
52 macro(dark_goldenrod , DarkGoldenrod , darkgoldenrod , 184, 134, 11) \
53 macro(dark_gray , DarkGray , darkgray , 169, 169, 169) \
54 macro(dark_green , DarkGreen , darkgreen , 0, 100, 0) \
55 macro(dark_khaki , DarkKhaki , darkkhaki , 189, 183, 107) \
56 macro(dark_magenta , DarkMagenta , darkmagenta , 139, 0, 139) \
57 macro(dark_olive_green , DarkOliveGreen , darkolivegreen , 85, 107, 47) \
58 macro(dark_orange , DarkOrange , darkorange , 255, 140, 0) \
59 macro(dark_orchid , DarkOrchid , darkorchid , 153, 50, 204) \
60 macro(dark_red , DarkRed , darkred , 139, 0, 0) \
61 macro(dark_salmon , DarkSalmon , darksalmon , 233, 150, 122) \
62 macro(dark_sea_green , DarkSeaGreen , darkseagreen , 143, 188, 143) \
63 macro(dark_slate_blue , DarkSlateBlue , darkslateblue , 72, 61, 139) \
64 macro(dark_slate_gray , DarkSlateGray , darkslategray , 47, 79, 79) \
65 macro(dark_turquoise , DarkTurquoise , darkturquoise , 0, 206, 209) \
66 macro(dark_violet , DarkViolet , darkviolet , 148, 0, 211) \
67 macro(deep_pink , DeepPink , deeppink , 255, 20, 147) \
68 macro(deep_sky_blue , DeepSkyBlue , deepskyblue , 0, 191, 255) \
69 macro(dim_gray , DimGray , dimgray , 105, 105, 105) \
70 macro(dodger_blue , DodgerBlue , dodgerblue , 30, 144, 255) \
71 macro(fire_brick , FireBrick , firebrick , 178, 34, 34) \
72 macro(floral_white , FloralWhite , floralwhite , 255, 250, 240) \
73 macro(forest_green , ForestGreen , forestgreen , 34, 139, 34) \
74 macro(fuchsia , Fuchsia , fuchsia , 255, 0, 255) \
75 macro(gainsboro , Gainsboro , gainsboro , 220, 220, 220) \
76 macro(ghost_white , GhostWhite , ghostwhite , 248, 248, 255) \
77 macro(gold , Gold , gold , 255, 215, 0) \
78 macro(goldenrod , Goldenrod , goldenrod , 218, 165, 32) \
79 macro(gray , Gray , gray , 128, 128, 128) \
80 macro(green , Green , green , 0, 128, 0) \
81 macro(green_yellow , GreenYellow , greenyellow , 173, 255, 47) \
82 macro(honeydew , Honeydew , honeydew , 240, 255, 240) \
83 macro(hot_pink , HotPink , hotpink , 255, 105, 180) \
84 macro(indian_red , IndianRed , indianred , 205, 92, 92) \
85 macro(indigo , Indigo , indigo , 75, 0, 130) \
86 macro(ivory , Ivory , ivory , 255, 255, 240) \
87 macro(khaki , Khaki , khaki , 240, 230, 140) \
88 macro(lavender , Lavender , lavender , 230, 230, 250) \
89 macro(lavender_blush , LavenderBlush , lavenderblush , 255, 240, 245) \
90 macro(lawn_green , LawnGreen , lawngreen , 124, 252, 0) \
91 macro(lemon_chiffon , LemonChiffon , lemonchiffon , 255, 250, 205) \
92 macro(light_blue , LightBlue , lightblue , 173, 216, 230) \
93 macro(light_coral , LightCoral , lightcoral , 240, 128, 128) \
94 macro(light_cyan , LightCyan , lightcyan , 224, 255, 255) \
95 macro(light_goldenrod_yellow , LightGoldenrodYellow , lightgoldenrodyellow , 250, 250, 210) \
96 macro(light_green , LightGreen , lightgreen , 144, 238, 144) \
97 macro(light_grey , LightGrey , lightgrey , 211, 211, 211) \
98 macro(light_pink , LightPink , lightpink , 255, 182, 193) \
99 macro(light_salmon , LightSalmon , lightsalmon , 255, 160, 122) \
100 macro(light_sea_green , LightSeaGreen , lightseagreen , 32, 178, 170) \
101 macro(light_sky_blue , LightSkyBlue , lightskyblue , 135, 206, 250) \
102 macro(light_slate_gray , LightSlateGray , lightslategray , 119, 136, 153) \
103 macro(light_steel_blue , LightSteelBlue , lightsteelblue , 176, 196, 222) \
104 macro(light_yellow , LightYellow , lightyellow , 255, 255, 224) \
105 macro(lime , Lime , lime , 0, 255, 0) \
106 macro(lime_green , LimeGreen , limegreen , 50, 205, 50) \
107 macro(linen , Linen , linen , 250, 240, 230) \
108 macro(magenta , Magenta , magenta , 255, 0, 255) \
109 macro(maroon , Maroon , maroon , 128, 0, 0) \
110 macro(medium_aquamarine , MediumAquamarine , mediumaquamarine , 102, 205, 170) \
111 macro(medium_blue , MediumBlue , mediumblue , 0, 0, 205) \
112 macro(medium_orchid , MediumOrchid , mediumorchid , 186, 85, 211) \
113 macro(medium_purple , MediumPurple , mediumpurple , 147, 112, 219) \
114 macro(medium_sea_green , MediumSeaGreen , mediumseagreen , 60, 179, 113) \
115 macro(medium_slate_blue , MediumSlateBlue , mediumslateblue , 123, 104, 238) \
116 macro(medium_spring_green , MediumSpringGreen , mediumspringgreen , 0, 250, 154) \
117 macro(medium_turquoise , MediumTurquoise , mediumturquoise , 72, 209, 204) \
118 macro(medium_violet_red , MediumVioletRed , mediumvioletred , 199, 21, 133) \
119 macro(midnight_blue , MidnightBlue , midnightblue , 25, 25, 112) \
120 macro(mint_cream , MintCream , mintcream , 245, 255, 250) \
121 macro(misty_rose , MistyRose , mistyrose , 255, 228, 225) \
122 macro(moccasin , Moccasin , moccasin , 255, 228, 181) \
123 macro(navajo_white , NavajoWhite , navajowhite , 255, 222, 173) \
124 macro(navy , Navy , navy , 0, 0, 128) \
125 macro(old_lace , OldLace , oldlace , 253, 245, 230) \
126 macro(olive , Olive , olive , 128, 128, 0) \
127 macro(olive_drab , OliveDrab , olivedrab , 107, 142, 35) \
128 macro(orange , Orange , orange , 255, 165, 0) \
129 macro(orange_red , OrangeRed , orangered , 255, 69, 0) \
130 macro(orchid , Orchid , orchid , 218, 112, 214) \
131 macro(pale_goldenrod , PaleGoldenrod , palegoldenrod , 238, 232, 170) \
132 macro(pale_green , PaleGreen , palegreen , 152, 251, 152) \
133 macro(pale_turquoise , PaleTurquoise , paleturquoise , 175, 238, 238) \
134 macro(pale_violet_red , PaleVioletRed , palevioletred , 219, 112, 147) \
135 macro(papaya_whip , PapayaWhip , papayawhip , 255, 239, 213) \
136 macro(peach_puff , PeachPuff , peachpuff , 255, 218, 185) \
137 macro(peru , Peru , peru , 205, 133, 63) \
138 macro(pink , Pink , pink , 255, 192, 203) \
139 macro(plum , Plum , plum , 221, 160, 221) \
140 macro(powder_blue , PowderBlue , powderblue , 176, 224, 230) \
141 macro(purple , Purple , purple , 128, 0, 128) \
142 macro(red , Red , red , 255, 0, 0) \
143 macro(rosy_brown , RosyBrown , rosybrown , 188, 143, 143) \
144 macro(royal_blue , RoyalBlue , royalblue , 65, 105, 225) \
145 macro(saddle_brown , SaddleBrown , saddlebrown , 139, 69, 19) \
146 macro(salmon , Salmon , salmon , 250, 128, 114) \
147 macro(sandy_brown , SandyBrown , sandybrown , 244, 164, 96) \
148 macro(sea_green , SeaGreen , seagreen , 46, 139, 87) \
149 macro(seashell , Seashell , seashell , 255, 245, 238) \
150 macro(sienna , Sienna , sienna , 160, 82, 45) \
151 macro(silver , Silver , silver , 192, 192, 192) \
152 macro(sky_blue , SkyBlue , skyblue , 135, 206, 235) \
153 macro(slate_blue , SlateBlue , slateblue , 106, 90, 205) \
154 macro(slate_gray , SlateGray , slategray , 112, 128, 144) \
155 macro(snow , Snow , snow , 255, 250, 250) \
156 macro(spring_green , SpringGreen , springgreen , 0, 255, 127) \
157 macro(steel_blue , SteelBlue , steelblue , 70, 130, 180) \
158 macro(tan , Tan , tan , 210, 180, 140) \
159 macro(teal , Teal , teal , 0, 128, 128) \
160 macro(thistle , Thistle , thistle , 216, 191, 216) \
161 macro(tomato , Tomato , tomato , 255, 99, 71) \
162 macro(turquoise , Turquoise , turquoise , 64, 224, 208) \
163 macro(violet , Violet , violet , 238, 130, 238) \
164 macro(wheat , Wheat , wheat , 245, 222, 179) \
165 macro(white , White , white , 255, 255, 255) \
166 macro(white_smoke , WhiteSmoke , whitesmoke , 245, 245, 245) \
167 macro(yellow , Yellow , yellow , 255, 255, 0) \
168 macro(yellow_green , YellowGreen , yellowgreen , 154, 205, 50)
175 enum class color_name_type
197 QX_COPYMOVABLE(
color);
200 constexpr
color() noexcept =
default;
210 constexpr
color(
float fRed,
float fGreen,
float fBlue,
float fAlpha = 1.f) noexcept;
220 constexpr
color(
int nRed,
int nGreen,
int nBlue,
int nAlpha = 255) noexcept;
226 constexpr
explicit color(
u64 nHexValue) noexcept;
232 constexpr
explicit color(
const glm::ivec3& vec3) noexcept;
238 constexpr
explicit color(
const glm::ivec4& vec4) noexcept;
244 constexpr
float r()
const noexcept;
250 constexpr
float g()
const noexcept;
256 constexpr
float b()
const noexcept;
262 constexpr
float a()
const noexcept;
269 constexpr
float&
operator[](
size_t i) noexcept;
276 constexpr
const float&
operator[](
size_t i)
const noexcept;
282 constexpr
int r_dec()
const noexcept;
288 constexpr
int g_dec()
const noexcept;
294 constexpr
int b_dec()
const noexcept;
300 constexpr
int a_dec()
const noexcept;
306 constexpr
const float*
data()
const noexcept;
312 constexpr
unsigned int hex_rgb()
const noexcept;
318 constexpr
unsigned int hex_rgba()
const noexcept;
324 constexpr
unsigned int hex_argb()
const noexcept;
326 constexpr
bool operator==(
const color& other)
const noexcept;
327 constexpr
operator glm::vec3()
const noexcept;
328 constexpr
operator glm::vec4()
const noexcept;
335 constexpr
void update_r(
float fDeltaValue) noexcept;
342 constexpr
void update_g(
float fDeltaValue) noexcept;
349 constexpr
void update_b(
float fDeltaValue) noexcept;
356 constexpr
void update_a(
float fDeltaValue) noexcept;
391 constexpr
void set_r(
float fValue) noexcept;
398 constexpr
void set_g(
float fValue) noexcept;
405 constexpr
void set_b(
float fValue) noexcept;
412 constexpr
void set_a(
float fValue) noexcept;
419 constexpr
void set_r_dec(
int nValue) noexcept;
426 constexpr
void set_g_dec(
int nValue) noexcept;
433 constexpr
void set_b_dec(
int nValue) noexcept;
440 constexpr
void set_a_dec(
int nValue) noexcept;
446 constexpr
void darken(
float fPercent) noexcept;
452 constexpr
void brighten(
float fPercent) noexcept;
470 #define _QX_COLOR_METHOD(snakeCaseName, pascalCaseName, lowerCaseName, r, g, b) \
471 static constexpr auto snakeCaseName(float fAlpha = 1.f) noexcept \
473 return color(r, g, b, float_to_dec(fAlpha)); \
484 static std::optional<color>
from_string(string_view svColorName) noexcept;
505 static constexpr
size_t size() noexcept;
513 static constexpr
float clamp_value(
float fValue) noexcept;
520 static constexpr
float dec_to_float(
int nValue) noexcept;
527 static constexpr
int float_to_dec(
float fValue) noexcept;
533 constexpr
void assign_checked(const glm::vec4& other) noexcept;
540 static constexpr
void assign_component_checked(
float& pComponent,
float fValue) noexcept;
543 glm::vec4 m_Color = glm::vec4(1.f);
548 #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 from_hash(size_t nHash) noexcept
Generate a color unique for a hash value.
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.
#define QX_PUSH_SUPPRESS_ALL_WARNINGS()
Disable all warnings.
#define QX_POP_SUPPRESS_WARNINGS()
Enable all warnings.