qxLib
color.h
Go to the documentation of this file.
1 /**
2 
3  @file color.h
4  @author Khrapov
5  @date 2.11.2020
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
15 #include <qx/patterns/singleton.h>
16 
17 #include <algorithm>
18 #include <unordered_map>
19 
20 QX_PUSH_SUPPRESS_ALL_WARNINGS();
21 #include <glm/vec3.hpp>
22 #include <glm/vec4.hpp>
23 QX_POP_SUPPRESS_WARNINGS();
24 
25 namespace qx
26 {
27 
28 /**
29 
30  @class color
31  @brief RGBA color
32  @author Khrapov
33  @date 10.04.2021
34 
35 **/
36 class color
37 {
38 public:
39  QX_COPYMOVABLE(color);
40 
41  constexpr color() noexcept = default;
42 
43  /**
44  @brief color object constructor
45  @details out of bound values will be clamped
46  @param fRed - red component [0.f, 1.f]
47  @param fGreen - green component [0.f, 1.f]
48  @param fBlue - blue component [0.f, 1.f]
49  @param fAlpha - alpha component [0.f, 1.f]
50  **/
51  constexpr color(float fRed, float fGreen, float fBlue, float fAlpha = 1.f) noexcept;
52 
53  /**
54  @brief color object constructor
55  @details out of bound values will be clamped
56  @param nRed - red component [0, 255]
57  @param nGreen - green component [0, 255]
58  @param nBlue - blue component [0, 255]
59  @param nAlpha - alpha component [0, 255]
60  **/
61  constexpr color(int nRed, int nGreen, int nBlue, int nAlpha = 255) noexcept;
62 
63  /**
64  @brief color object constructor
65  @param nHexValue - hex color value in 0xRRGGBBAA format
66  **/
67  constexpr explicit color(u64 nHexValue) noexcept;
68 
69  /**
70  @brief color object constructor
71  @param vec3 - int vector
72  **/
73  constexpr explicit color(const glm::ivec3& vec3) noexcept;
74 
75  /**
76  @brief color object constructor
77  @param vec4 - int vector
78  **/
79  constexpr explicit color(const glm::ivec4& vec4) noexcept;
80 
81  /**
82  @brief Get red component
83  @retval - red component
84  **/
85  constexpr float r() const noexcept;
86 
87  /**
88  @brief Get green component
89  @retval - green component
90  **/
91  constexpr float g() const noexcept;
92 
93  /**
94  @brief Get blue component
95  @retval - blue component
96  **/
97  constexpr float b() const noexcept;
98 
99  /**
100  @brief Get alpha component
101  @retval - alpha component
102  **/
103  constexpr float a() const noexcept;
104 
105  /**
106  @brief Get color component
107  @param i - component number [0, 3]
108  @retval - component value
109  **/
110  constexpr float& operator[](size_t i) noexcept;
111 
112  /**
113  @brief Get color component
114  @param i - component number [0, 3]
115  @retval - component value
116  **/
117  constexpr const float& operator[](size_t i) const noexcept;
118 
119  /**
120  @brief Get red component as decimal
121  @retval - red component as decimal
122  **/
123  constexpr int r_dec() const noexcept;
124 
125  /**
126  @brief Get green component as decimal
127  @retval - green component as decimal
128  **/
129  constexpr int g_dec() const noexcept;
130 
131  /**
132  @brief Get blue component as decimal
133  @retval - blue component as decimal
134  **/
135  constexpr int b_dec() const noexcept;
136 
137  /**
138  @brief Get alpha component as decimal
139  @retval - alpha component as decimal
140  **/
141  constexpr int a_dec() const noexcept;
142 
143  /**
144  @brief Get pointer to the first component
145  @retval - pointer to the first component
146  **/
147  constexpr const float* data() const noexcept;
148 
149  /**
150  @brief Get color as hex
151  @retval - hex color value in 0xRRGGBB format
152  **/
153  constexpr unsigned int hex_rgb() const noexcept;
154 
155  /**
156  @brief Get color as hex
157  @retval - hex color value in 0xRRGGBBAA format
158  **/
159  constexpr unsigned int hex_rgba() const noexcept;
160 
161  /**
162  @brief Get color as hex
163  @retval - hex color value in 0xAARRGGBB format
164  **/
165  constexpr unsigned int hex_argb() const noexcept;
166 
167  constexpr bool operator==(const color& other) const noexcept;
168  constexpr operator glm::vec3() const noexcept;
169  constexpr operator glm::vec4() const noexcept;
170 
171  /**
172  @brief Add value to red component
173  @details if the new value goes out of range, it will be clamped
174  @param fDeltaValue - delta value
175  **/
176  constexpr void update_r(float fDeltaValue) noexcept;
177 
178  /**
179  @brief Add value to green component
180  @details if the new value goes out of range, it will be clamped
181  @param fDeltaValue - delta value
182  **/
183  constexpr void update_g(float fDeltaValue) noexcept;
184 
185  /**
186  @brief Add value to blue component
187  @details if the new value goes out of range, it will be clamped
188  @param fDeltaValue - delta value
189  **/
190  constexpr void update_b(float fDeltaValue) noexcept;
191 
192  /**
193  @brief Add value to alpha component
194  @details if the new value goes out of range, it will be clamped
195  @param fDeltaValue - delta value
196  **/
197  constexpr void update_a(float fDeltaValue) noexcept;
198 
199  /**
200  @brief Add value to red component
201  @details if the new value goes out of range, it will be clamped
202  @param nDeltaValue - delta value
203  **/
204  constexpr void update_r_dec(int nDeltaValue) noexcept;
205 
206  /**
207  @brief Add value to green component
208  @details if the new value goes out of range, it will be clamped
209  @param nDeltaValue - delta value
210  **/
211  constexpr void update_g_dec(int nDeltaValue) noexcept;
212 
213  /**
214  @brief Add value to blue component
215  @details if the new value goes out of range, it will be clamped
216  @param nDeltaValue - delta value
217  **/
218  constexpr void update_b_dec(int nDeltaValue) noexcept;
219 
220  /**
221  @brief Add value to alpha component
222  @details if the new value goes out of range, it will be clamped
223  @param nDeltaValue - delta value
224  **/
225  constexpr void update_a_dec(int nDeltaValue) noexcept;
226 
227  /**
228  @brief Set new value of red component
229  @details if the new value goes out of range, it will be clamped
230  @param fValue - new value of component
231  **/
232  constexpr void set_r(float fValue) noexcept;
233 
234  /**
235  @brief Set new value of green component
236  @details if the new value goes out of range, it will be clamped
237  @param fValue - new value of component
238  **/
239  constexpr void set_g(float fValue) noexcept;
240 
241  /**
242  @brief Set new value of blue component
243  @details if the new value goes out of range, it will be clamped
244  @param fValue - new value of component
245  **/
246  constexpr void set_b(float fValue) noexcept;
247 
248  /**
249  @brief Set new value of alpha component
250  @details if the new value goes out of range, it will be clamped
251  @param fValue - new value of component
252  **/
253  constexpr void set_a(float fValue) noexcept;
254 
255  /**
256  @brief Set new value of red component
257  @details if the new value goes out of range, it will be clamped
258  @param nValue - new value of component
259  **/
260  constexpr void set_r_dec(int nValue) noexcept;
261 
262  /**
263  @brief Set new value of green component
264  @details if the new value goes out of range, it will be clamped
265  @param nValue - new value of component
266  **/
267  constexpr void set_g_dec(int nValue) noexcept;
268 
269  /**
270  @brief Set new value of blue component
271  @details if the new value goes out of range, it will be clamped
272  @param nValue - new value of component
273  **/
274  constexpr void set_b_dec(int nValue) noexcept;
275 
276  /**
277  @brief Set new value of alpha component
278  @details if the new value goes out of range, it will be clamped
279  @param nValue - new value of component
280  **/
281  constexpr void set_a_dec(int nValue) noexcept;
282 
283  /**
284  @brief Make color darker
285  @param fPercent - dark factor
286  **/
287  constexpr void darken(float fPercent) noexcept;
288 
289  /**
290  @brief Make color brighter
291  @param fPercent - brighter factor
292  **/
293  constexpr void brighten(float fPercent) noexcept;
294 
295  /**
296  @brief Make darker color
297  @param other - original color
298  @param fPercent - dark factor
299  @retval - darker color
300  **/
301  constexpr static color darken(const color& other, float fPercent) noexcept;
302 
303  /**
304  @brief Make brighter color
305  @param other - original color
306  @param fPercent - brighter factor
307  @retval - brighter color
308  **/
309  constexpr static color brighten(const color& other, float fPercent) noexcept;
310 
311 private:
312  /**
313  @brief Add color for string -> color mapping
314  @param svColorName - color name
315  @param nRed - red component
316  @param nGreen - green component
317  @param nBlue - blue component
318  @retval - always true
319  **/
320  static bool add_color_to_mapping(string_view svColorName, int nRed, int nGreen, int nBlue) noexcept;
321 
322 #define _QX_DEFINE_COLOR(snakeCaseName, pascalCaseName, r, g, b) \
323  static constexpr auto snakeCaseName(float fAlpha = 1.f) noexcept \
324  { \
325  return color(r, g, b, float_to_dec(fAlpha)); \
326  } \
327  inline static const volatile bool QX_LINE_NAME(_stub1) = add_color_to_mapping(QX_TEXT(#snakeCaseName), r, g, b); \
328  inline static const volatile bool QX_LINE_NAME(_stub2) = add_color_to_mapping(QX_TEXT(#pascalCaseName), r, g, b)
329 
330 public:
331  /// Color functions
332  /// @see https://www.cssportal.com/html-colors/x11-colors.php
333 
334  // clang-format off
335  _QX_DEFINE_COLOR(alice_blue , AliceBlue , 240, 248, 255);
336  _QX_DEFINE_COLOR(antique_white , AntiqueWhite , 250, 235, 215);
337  _QX_DEFINE_COLOR(aqua , Aqua , 0, 255, 255);
338  _QX_DEFINE_COLOR(aquamarine , Aquamarine , 127, 255, 212);
339  _QX_DEFINE_COLOR(azure , Azure , 240, 255, 255);
340  _QX_DEFINE_COLOR(beige , Beige , 245, 245, 220);
341  _QX_DEFINE_COLOR(bisque , Bisque , 255, 228, 196);
342  _QX_DEFINE_COLOR(black , Black , 0, 0, 0);
343  _QX_DEFINE_COLOR(blanched_almond , BlanchedAlmond , 255, 235, 205);
344  _QX_DEFINE_COLOR(blue , Blue , 0, 0, 255);
345  _QX_DEFINE_COLOR(blue_violet , BlueViolet , 138, 43, 226);
346  _QX_DEFINE_COLOR(brown , Brown , 165, 42, 42);
347  _QX_DEFINE_COLOR(burly_wood , BurlyWood , 222, 184, 135);
348  _QX_DEFINE_COLOR(cadet_blue , CadetBlue , 95, 158, 160);
349  _QX_DEFINE_COLOR(chartreuse , Chartreuse , 127, 255, 0);
350  _QX_DEFINE_COLOR(chocolate , Chocolate , 210, 105, 30);
351  _QX_DEFINE_COLOR(coral , Coral , 255, 127, 80);
352  _QX_DEFINE_COLOR(cornflower_blue , CornflowerBlue , 100, 149, 237);
353  _QX_DEFINE_COLOR(cornsilk , Cornsilk , 255, 248, 220);
354  _QX_DEFINE_COLOR(crimson , Crimson , 220, 20, 60);
355  _QX_DEFINE_COLOR(cyan , Cyan , 0, 255, 255);
356  _QX_DEFINE_COLOR(dark_blue , DarkBlue , 0, 0, 139);
357  _QX_DEFINE_COLOR(dark_cyan , DarkCyan , 0, 139, 139);
358  _QX_DEFINE_COLOR(dark_goldenrod , DarkGoldenrod , 184, 134, 11);
359  _QX_DEFINE_COLOR(dark_gray , DarkGray , 169, 169, 169);
360  _QX_DEFINE_COLOR(dark_green , DarkGreen , 0, 100, 0);
361  _QX_DEFINE_COLOR(dark_khaki , DarkKhaki , 189, 183, 107);
362  _QX_DEFINE_COLOR(dark_magenta , DarkMagenta , 139, 0, 139);
363  _QX_DEFINE_COLOR(dark_olive_green , DarkOliveGreen , 85, 107, 47);
364  _QX_DEFINE_COLOR(dark_orange , DarkOrange , 255, 140, 0);
365  _QX_DEFINE_COLOR(dark_orchid , DarkOrchid , 153, 50, 204);
366  _QX_DEFINE_COLOR(dark_red , DarkRed , 139, 0, 0);
367  _QX_DEFINE_COLOR(dark_salmon , DarkSalmon , 233, 150, 122);
368  _QX_DEFINE_COLOR(dark_sea_green , DarkSeaGreen , 143, 188, 143);
369  _QX_DEFINE_COLOR(dark_slate_blue , DarkSlateBlue , 72, 61, 139);
370  _QX_DEFINE_COLOR(dark_slate_gray , DarkSlateGray , 47, 79, 79);
371  _QX_DEFINE_COLOR(dark_turquoise , DarkTurquoise , 0, 206, 209);
372  _QX_DEFINE_COLOR(dark_violet , DarkViolet , 148, 0, 211);
373  _QX_DEFINE_COLOR(deep_pink , DeepPink , 255, 20, 147);
374  _QX_DEFINE_COLOR(deep_sky_blue , DeepSkyBlue , 0, 191, 255);
375  _QX_DEFINE_COLOR(dim_gray , DimGray , 105, 105, 105);
376  _QX_DEFINE_COLOR(dodger_blue , DodgerBlue , 30, 144, 255);
377  _QX_DEFINE_COLOR(fire_brick , FireBrick , 178, 34, 34);
378  _QX_DEFINE_COLOR(floral_white , FloralWhite , 255, 250, 240);
379  _QX_DEFINE_COLOR(forest_green , ForestGreen , 34, 139, 34);
380  _QX_DEFINE_COLOR(fuchsia , Fuchsia , 255, 0, 255);
381  _QX_DEFINE_COLOR(gainsboro , Gainsboro , 220, 220, 220);
382  _QX_DEFINE_COLOR(ghost_white , GhostWhite , 248, 248, 255);
383  _QX_DEFINE_COLOR(gold , Gold , 255, 215, 0);
384  _QX_DEFINE_COLOR(goldenrod , Goldenrod , 218, 165, 32);
385  _QX_DEFINE_COLOR(gray , Gray , 128, 128, 128);
386  _QX_DEFINE_COLOR(green , Green , 0, 128, 0);
387  _QX_DEFINE_COLOR(green_yellow , GreenYellow , 173, 255, 47);
388  _QX_DEFINE_COLOR(honeydew , Honeydew , 240, 255, 240);
389  _QX_DEFINE_COLOR(hot_pink , HotPink , 255, 105, 180);
390  _QX_DEFINE_COLOR(indian_red , IndianRed , 205, 92, 92);
391  _QX_DEFINE_COLOR(indigo , Indigo , 75, 0, 130);
392  _QX_DEFINE_COLOR(ivory , Ivory , 255, 255, 240);
393  _QX_DEFINE_COLOR(khaki , Khaki , 240, 230, 140);
394  _QX_DEFINE_COLOR(lavender , Lavender , 230, 230, 250);
395  _QX_DEFINE_COLOR(lavender_blush , LavenderBlush , 255, 240, 245);
396  _QX_DEFINE_COLOR(lawn_green , LawnGreen , 124, 252, 0);
397  _QX_DEFINE_COLOR(lemon_chiffon , LemonChiffon , 255, 250, 205);
398  _QX_DEFINE_COLOR(light_blue , LightBlue , 173, 216, 230);
399  _QX_DEFINE_COLOR(light_coral , LightCoral , 240, 128, 128);
400  _QX_DEFINE_COLOR(light_cyan , LightCyan , 224, 255, 255);
401  _QX_DEFINE_COLOR(light_goldenrod_yellow , LightGoldenrodYellow , 250, 250, 210);
402  _QX_DEFINE_COLOR(light_green , LightGreen , 144, 238, 144);
403  _QX_DEFINE_COLOR(light_grey , LightGrey , 211, 211, 211);
404  _QX_DEFINE_COLOR(light_pink , LightPink , 255, 182, 193);
405  _QX_DEFINE_COLOR(light_salmon , LightSalmon , 255, 160, 122);
406  _QX_DEFINE_COLOR(light_sea_green , LightSeaGreen , 32, 178, 170);
407  _QX_DEFINE_COLOR(light_sky_blue , LightSkyBlue , 135, 206, 250);
408  _QX_DEFINE_COLOR(light_slate_gray , LightSlateGray , 119, 136, 153);
409  _QX_DEFINE_COLOR(light_steel_blue , LightSteelBlue , 176, 196, 222);
410  _QX_DEFINE_COLOR(light_yellow , LightYellow , 255, 255, 224);
411  _QX_DEFINE_COLOR(lime , Lime , 0, 255, 0);
412  _QX_DEFINE_COLOR(lime_green , LimeGreen , 50, 205, 50);
413  _QX_DEFINE_COLOR(linen , Linen , 250, 240, 230);
414  _QX_DEFINE_COLOR(magenta , Magenta , 255, 0, 255);
415  _QX_DEFINE_COLOR(maroon , Maroon , 128, 0, 0);
416  _QX_DEFINE_COLOR(medium_aquamarine , MediumAquamarine , 102, 205, 170);
417  _QX_DEFINE_COLOR(medium_blue , MediumBlue , 0, 0, 205);
418  _QX_DEFINE_COLOR(medium_orchid , MediumOrchid , 186, 85, 211);
419  _QX_DEFINE_COLOR(medium_purple , MediumPurple , 147, 112, 219);
420  _QX_DEFINE_COLOR(medium_sea_green , MediumSeaGreen , 60, 179, 113);
421  _QX_DEFINE_COLOR(medium_slate_blue , MediumSlateBlue , 123, 104, 238);
422  _QX_DEFINE_COLOR(medium_spring_green , MediumSpringGreen , 0, 250, 154);
423  _QX_DEFINE_COLOR(medium_turquoise , MediumTurquoise , 72, 209, 204);
424  _QX_DEFINE_COLOR(medium_violet_red , MediumVioletRed , 199, 21, 133);
425  _QX_DEFINE_COLOR(midnight_blue , MidnightBlue , 25, 25, 112);
426  _QX_DEFINE_COLOR(mint_cream , MintCream , 245, 255, 250);
427  _QX_DEFINE_COLOR(misty_rose , MistyRose , 255, 228, 225);
428  _QX_DEFINE_COLOR(moccasin , Moccasin , 255, 228, 181);
429  _QX_DEFINE_COLOR(navajo_white , NavajoWhite , 255, 222, 173);
430  _QX_DEFINE_COLOR(navy , Navy , 0, 0, 128);
431  _QX_DEFINE_COLOR(old_lace , OldLace , 253, 245, 230);
432  _QX_DEFINE_COLOR(olive , Olive , 128, 128, 0);
433  _QX_DEFINE_COLOR(olive_drab , OliveDrab , 107, 142, 35);
434  _QX_DEFINE_COLOR(orange , Orange , 255, 165, 0);
435  _QX_DEFINE_COLOR(orange_red , OrangeRed , 255, 69, 0);
436  _QX_DEFINE_COLOR(orchid , Orchid , 218, 112, 214);
437  _QX_DEFINE_COLOR(pale_goldenrod , PaleGoldenrod , 238, 232, 170);
438  _QX_DEFINE_COLOR(pale_green , PaleGreen , 152, 251, 152);
439  _QX_DEFINE_COLOR(pale_turquoise , PaleTurquoise , 175, 238, 238);
440  _QX_DEFINE_COLOR(pale_violet_red , PaleVioletRed , 219, 112, 147);
441  _QX_DEFINE_COLOR(papaya_whip , PapayaWhip , 255, 239, 213);
442  _QX_DEFINE_COLOR(peach_puff , PeachPuff , 255, 218, 185);
443  _QX_DEFINE_COLOR(peru , Peru , 205, 133, 63);
444  _QX_DEFINE_COLOR(pink , Pink , 255, 192, 203);
445  _QX_DEFINE_COLOR(plum , Plum , 221, 160, 221);
446  _QX_DEFINE_COLOR(powder_blue , PowderBlue , 176, 224, 230);
447  _QX_DEFINE_COLOR(purple , Purple , 128, 0, 128);
448  _QX_DEFINE_COLOR(red , Red , 255, 0, 0);
449  _QX_DEFINE_COLOR(rosy_brown , RosyBrown , 188, 143, 143);
450  _QX_DEFINE_COLOR(royal_blue , RoyalBlue , 65, 105, 225);
451  _QX_DEFINE_COLOR(saddle_brown , SaddleBrown , 139, 69, 19);
452  _QX_DEFINE_COLOR(salmon , Salmon , 250, 128, 114);
453  _QX_DEFINE_COLOR(sandy_brown , SandyBrown , 244, 164, 96);
454  _QX_DEFINE_COLOR(sea_green , SeaGreen , 46, 139, 87);
455  _QX_DEFINE_COLOR(seashell , Seashell , 255, 245, 238);
456  _QX_DEFINE_COLOR(sienna , Sienna , 160, 82, 45);
457  _QX_DEFINE_COLOR(silver , Silver , 192, 192, 192);
458  _QX_DEFINE_COLOR(sky_blue , SkyBlue , 135, 206, 235);
459  _QX_DEFINE_COLOR(slate_blue , SlateBlue , 106, 90, 205);
460  _QX_DEFINE_COLOR(slate_gray , SlateGray , 112, 128, 144);
461  _QX_DEFINE_COLOR(snow , Snow , 255, 250, 250);
462  _QX_DEFINE_COLOR(spring_green , SpringGreen , 0, 255, 127);
463  _QX_DEFINE_COLOR(steel_blue , SteelBlue , 70, 130, 180);
464  _QX_DEFINE_COLOR(tan , Tan , 210, 180, 140);
465  _QX_DEFINE_COLOR(teal , Teal , 0, 128, 128);
466  _QX_DEFINE_COLOR(thistle , Thistle , 216, 191, 216);
467  _QX_DEFINE_COLOR(tomato , Tomato , 255, 99, 71);
468  _QX_DEFINE_COLOR(turquoise , Turquoise , 64, 224, 208);
469  _QX_DEFINE_COLOR(violet , Violet , 238, 130, 238);
470  _QX_DEFINE_COLOR(wheat , Wheat , 245, 222, 179);
471  _QX_DEFINE_COLOR(white , White , 255, 255, 255);
472  _QX_DEFINE_COLOR(white_smoke , WhiteSmoke , 245, 245, 245);
473  _QX_DEFINE_COLOR(yellow , Yellow , 255, 255, 0);
474  _QX_DEFINE_COLOR(yellow_green , YellowGreen , 154, 205, 50);
475  // clang-format on
476 
477  /**
478  @brief Try to create color from string
479  @param svColorName - color name: css style (alice_blue, AliceBlue, aliceblue) or #F0F8FF or 0xF0F8FFFF(0xRRGGBBAA) or 0xF0F8FF(0xRRGGBB)
480  @retval - found color or nullopt
481  **/
482  static std::optional<color> from_string(string_view svColorName) noexcept;
483 
484  /**
485  @brief Get empty color (0, 0, 0, 0)
486  @details - empty color can be useful for out of border values
487  as they won't affect calc result
488  @retval - empty color
489  **/
490  static constexpr color empty() noexcept;
491 
492  /**
493  @brief Get number of float components
494  @retval - number of float components
495  **/
496  static constexpr size_t size() noexcept;
497 
498 private:
499  /**
500  @brief Clamp a value to a valid range
501  @param fValue - input value
502  @retval - clamped value [0.f, 1.f]
503  **/
504  static constexpr float clamp_value(float fValue) noexcept;
505 
506  /**
507  @brief Convert decimal value to float
508  @param nValue - decimal value [0, 255]
509  @retval - float value [0.f, 1.f]
510  **/
511  static constexpr float dec_to_float(int nValue) noexcept;
512 
513  /**
514  @brief Convert float value to decimal
515  @param fValue - float value [0.f, 1.f]
516  @retval - decimal value [0, 255]
517  **/
518  static constexpr int float_to_dec(float fValue) noexcept;
519 
520  /**
521  @brief Clamp all vector components and assign
522  @param other - color vector
523  **/
524  constexpr void assign_checked(const glm::vec4& other) noexcept;
525 
526  /**
527  @brief Clamp component and assign
528  @param pComponent - component field
529  @param fValue - new component value
530  **/
531  static constexpr void assign_component_checked(float& pComponent, float fValue) noexcept;
532 
533 private:
534  glm::vec4 m_Color = glm::vec4(1.f);
535 };
536 
537 } // namespace qx
538 
539 #include <qx/render/color.inl>
RGBA color.
Definition: color.h:37
constexpr float g() const noexcept
Get green component.
Definition: color.inl:94
constexpr void update_r_dec(int nDeltaValue) noexcept
Add value to red component.
Definition: color.inl:208
constexpr void update_a(float fDeltaValue) noexcept
Add value to alpha component.
Definition: color.inl:203
constexpr int r_dec() const noexcept
Get red component as decimal.
Definition: color.inl:119
static std::optional< color > from_string(string_view svColorName) noexcept
Try to create color from string.
Definition: color.inl:305
constexpr void update_g(float fDeltaValue) noexcept
Add value to green component.
Definition: color.inl:193
constexpr void update_b(float fDeltaValue) noexcept
Add value to blue component.
Definition: color.inl:198
constexpr void darken(float fPercent) noexcept
Make color darker.
Definition: color.inl:268
constexpr int g_dec() const noexcept
Get green component as decimal.
Definition: color.inl:124
constexpr float a() const noexcept
Get alpha component.
Definition: color.inl:104
constexpr const float * data() const noexcept
Get pointer to the first component.
Definition: color.inl:139
constexpr float b() const noexcept
Get blue component.
Definition: color.inl:99
constexpr float r() const noexcept
Get red component.
Definition: color.inl:89
constexpr void set_g(float fValue) noexcept
Set new value of green component.
Definition: color.inl:233
constexpr float & operator[](size_t i) noexcept
Get color component.
Definition: color.inl:109
constexpr void set_b(float fValue) noexcept
Set new value of blue component.
Definition: color.inl:238
constexpr int b_dec() const noexcept
Get blue component as decimal.
Definition: color.inl:129
static constexpr color empty() noexcept
Get empty color (0, 0, 0, 0)
Definition: color.inl:345
constexpr void update_g_dec(int nDeltaValue) noexcept
Add value to green component.
Definition: color.inl:213
constexpr void set_r(float fValue) noexcept
Set new value of red component.
Definition: color.inl:228
constexpr unsigned int hex_rgba() const noexcept
Get color as hex.
Definition: color.inl:153
constexpr unsigned int hex_rgb() const noexcept
Get color as hex.
Definition: color.inl:144
constexpr void update_r(float fDeltaValue) noexcept
Add value to red component.
Definition: color.inl:188
constexpr int a_dec() const noexcept
Get alpha component as decimal.
Definition: color.inl:134
constexpr void set_g_dec(int nValue) noexcept
Set new value of green component.
Definition: color.inl:253
_QX_DEFINE_COLOR(alice_blue, AliceBlue, 240, 248, 255)
static constexpr size_t size() noexcept
Get number of float components.
Definition: color.inl:350
constexpr void brighten(float fPercent) noexcept
Make color brighter.
Definition: color.inl:273
constexpr unsigned int hex_argb() const noexcept
Get color as hex.
Definition: color.inl:163
constexpr void update_b_dec(int nDeltaValue) noexcept
Add value to blue component.
Definition: color.inl:218
constexpr void set_r_dec(int nValue) noexcept
Set new value of red component.
Definition: color.inl:248
constexpr void set_b_dec(int nValue) noexcept
Set new value of blue component.
Definition: color.inl:258
constexpr void update_a_dec(int nDeltaValue) noexcept
Add value to alpha component.
Definition: color.inl:223
constexpr void set_a(float fValue) noexcept
Set new value of alpha component.
Definition: color.inl:243
constexpr void set_a_dec(int nValue) noexcept
Set new value of alpha component.
Definition: color.inl:263
std::uint64_t u64
Definition: typedefs.h:26