Practical Tools for Simple Design
Loading...
Searching...
No Matches
Color.hpp
1#ifndef UTIL_COLOR_HPP
2#define UTIL_COLOR_HPP
3
4#include "pch.hpp" // IWYU pragma: export
5#include <spdlog/fmt/bundled/format.h>
6namespace Util {
11enum class Colors : Uint32;
19class Color : public glm::vec4 {
20public:
21 using glm::vec4::vec;
22
23 /*
24 * @brief Parameterized constructor.
25 *
26 * @param vec The color in glm::vec4 format.
27 */
28 Color(const glm::vec4 &vec)
29 : glm::vec4(vec) {}
30
31 /*
32 * @brief Parameterized constructor.
33 *
34 * @param r The red component of the color.
35 * @param g The green component of the color.
36 * @param b The blue component of the color.
37 * @param a The alpha component of the color.
38 */
39 Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255)
40 : glm::vec4(r, g, b, a) {}
41
42 /*
43 * @brief Parameterized constructor.
44 */
45 Color(glm::vec4 &&vec)
46 : glm::vec4(std::move(vec)) {}
47
48 /*
49 * @brief Parameterized constructor.
50 *
51 * @param color The color in SDL_Color format.
52 */
53 Color(const SDL_Color &color)
54 : glm::vec4({
55 color.r,
56 color.g,
57 color.b,
58 color.a,
59 }) {}
60
66 SDL_Color ToSdlColor() const {
67 return SDL_Color{
68 static_cast<Uint8>(r),
69 static_cast<Uint8>(g),
70 static_cast<Uint8>(b),
71 static_cast<Uint8>(a),
72 };
73 }
83 std::string ToString() const {
84 return fmt::v8::format("Color({},{},{},{})", r, g, b, a);
85 }
86
95 static Color FromRGB(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255);
96
105 static Color FromHSL(float h, float s, float l, float a = 1.0F);
106
115 static Color FromHSV(float h, float s, float v, float a = 1.0F);
116
122 static Color FromHex(Uint32 hex);
123
129 static Color FromHex(const std::string &hex);
130
137 static Color FromName(const Util::Colors &name);
138};
139
140enum class Colors : Uint32 {
141 ALICE_BLUE = 0xF0F8FF,
142 ANTIQUE_WHITE = 0xFAEBD7,
143 AQUA = 0x00FFFF,
144 AQUAMARINE = 0x7FFFD4,
145 AZURE = 0xF0FFFF,
146 BEIGE = 0xF5F5DC,
147 BISQUE = 0xFFE4C4,
148 BLACK = 0x000000,
149 BLANCHED_ALMOND = 0xFFEBCD,
150 BLUE = 0x0000FF,
151 BLUE_VIOLET = 0x8A2BE2,
152 BROWN = 0xA52A2A,
153 BURLY_WOOD = 0xDEB887,
154 CADET_BLUE = 0x5F9EA0,
155 CHARTREUSE = 0x7FFF00,
156 CHOCOLATE = 0xD2691E,
157 CORAL = 0xFF7F50,
158 CORNFLOWER_BLUE = 0x6495ED,
159 CORNSILK = 0xFFF8DC,
160 CRIMSON = 0xDC143C,
161 CYAN = 0x00FFFF,
162 DARK_BLUE = 0x00008B,
163 DARK_CYAN = 0x008B8B,
164 DARK_GOLDENROD = 0xB8860B,
165 DARK_GRAY = 0xA9A9A9,
166 DARK_GREEN = 0x006400,
167 DARK_KHAKI = 0xBDB76B,
168 DARK_MAGENTA = 0x8B008B,
169 DARK_OLIVE_GREEN = 0x556B2F,
170 DARK_ORANGE = 0xFF8C00,
171 DARK_ORCHID = 0x9932CC,
172 DARK_RED = 0x8B0000,
173 DARK_SALMON = 0xE9967A,
174 DARK_SEA_GREEN = 0x8FBC8F,
175 DARK_SLATE_BLUE = 0x483D8B,
176 DARK_SLATE_GRAY = 0x2F4F4F,
177 DARK_TURQUOISE = 0x00CED1,
178 DARK_VIOLET = 0x9400D3,
179 DEEP_PINK = 0xFF1493,
180 DEEP_SKY_BLUE = 0x00BFFF,
181 DIM_GRAY = 0x696969,
182 DODGER_BLUE = 0x1E90FF,
183 FIREBRICK = 0xB22222,
184 FLORAL_WHITE = 0xFFFAF0,
185 FOREST_GREEN = 0x228B22,
186 FUCHSIA = 0xFF00FF,
187 GAINSBORO = 0xDCDCDC,
188 GHOST_WHITE = 0xF8F8FF,
189 GOLD = 0xFFD700,
190 GOLDENROD = 0xDAA520,
191 GRAY = 0x808080,
192 GREEN = 0x008000,
193 GREEN_YELLOW = 0xADFF2F,
194 HONEYDEW = 0xF0FFF0,
195 HOT_PINK = 0xFF69B4,
196 INDIAN_RED = 0xCD5C5C,
197 INDIGO = 0x4B0082,
198 IVORY = 0xFFFFF0,
199 KHAKI = 0xF0E68C,
200 LAVENDER = 0xE6E6FA,
201 LAVENDER_BLUSH = 0xFFF0F5,
202 LAWN_GREEN = 0x7CFC00,
203 LEMON_CHIFFON = 0xFFFACD,
204 LIGHT_BLUE = 0xADD8E6,
205 LIGHT_CORAL = 0xF08080,
206 LIGHT_CYAN = 0xE0FFFF,
207 LIGHT_GOLDENROD_YELLOW = 0xFAFAD2,
208 LIGHT_GRAY = 0xD3D3D3,
209 LIGHT_GREEN = 0x90EE90,
210 LIGHT_PINK = 0xFFB6C1,
211 LIGHT_SALMON = 0xFFA07A,
212 LIGHT_SEA_GREEN = 0x20B2AA,
213 LIGHT_SKY_BLUE = 0x87CEFA,
214 LIGHT_SLATE_GRAY = 0x778899,
215 LIGHT_STEEL_BLUE = 0xB0C4DE,
216 LIGHT_YELLOW = 0xFFFFE0,
217 LIME = 0x00FF00,
218 LIME_GREEN = 0x32CD32,
219 LINEN = 0xFAF0E6,
220 MAGENTA = 0xFF00FF,
221 MAROON = 0x800000,
222 MEDIUM_AQUAMARINE = 0x66CDAA,
223 MEDIUM_BLUE = 0x0000CD,
224 MEDIUM_ORCHID = 0xBA55D3,
225 MEDIUM_PURPLE = 0x9370DB,
226 MEDIUM_SEA_GREEN = 0x3CB371,
227 MEDIUM_SLATE_BLUE = 0x7B68EE,
228 MEDIUM_SPRING_GREEN = 0x00FA9A,
229 MEDIUM_TURQUOISE = 0x48D1CC,
230 MEDIUM_VIOLET_RED = 0xC71585,
231 MIDNIGHT_BLUE = 0x191970,
232 MINT_CREAM = 0xF5FFFA,
233 MISTY_ROSE = 0xFFE4E1,
234 MOCCASIN = 0xFFE4B5,
235 NAVAJO_WHITE = 0xFFDEAD,
236 NAVY = 0x000080,
237 OLD_LACE = 0xFDF5E6,
238 OLIVE = 0x808000,
239 OLIVE_DRAB = 0x6B8E23,
240 ORANGE = 0xFFA500,
241 ORANGE_RED = 0xFF4500,
242 ORCHID = 0xDA70D6,
243 PALE_GOLDENROD = 0xEEE8AA,
244 PALE_GREEN = 0x98FB98,
245 PALE_TURQUOISE = 0xAFEEEE,
246 PALE_VIOLET_RED = 0xDB7093,
247 PAPAYA_WHIP = 0xFFEFD5,
248 PEACH_PUFF = 0xFFDAB9,
249 PERU = 0xCD853F,
250 PINK = 0xFFC0CB,
251 PLUM = 0xDDA0DD,
252 POWDER_BLUE = 0xB0E0E6,
253 PURPLE = 0x800080,
254 REBECCA_PURPLE = 0x663399,
255 RED = 0xFF0000,
256 ROSY_BROWN = 0xBC8F8F,
257 ROYAL_BLUE = 0x4169E1,
258 SADDLE_BROWN = 0x8B4513,
259 SALMON = 0xFA8072,
260 SANDY_BROWN = 0xF4A460,
261 SEA_GREEN = 0x2E8B57,
262 SEASHELL = 0xFFF5EE,
263 SIENNA = 0xA0522D,
264 SILVER = 0xC0C0C0,
265 SKY_BLUE = 0x87CEEB,
266 SLATE_BLUE = 0x6A5ACD,
267 SLATE_GRAY = 0x708090,
268 SNOW = 0xFFFAFA,
269 SPRING_GREEN = 0x00FF7F,
270 STEEL_BLUE = 0x4682B4,
271 TAN = 0xD2B48C,
272 TEAL = 0x008080,
273 THISTLE = 0xD8BFD8,
274 TOMATO = 0xFF6347,
275 TURQUOISE = 0x40E0D0,
276 VIOLET = 0xEE82EE,
277 WHEAT = 0xF5DEB3,
278 WHITE = 0xFFFFFF,
279 WHITE_SMOKE = 0xF5F5F5,
280 YELLOW = 0xFFFF00,
281 YELLOW_GREEN = 0x9ACD32
282};
283} // namespace Util
284
285#endif
A class representing a color.
Definition: Color.hpp:19
static Color FromHSV(float h, float s, float v, float a=1.0F)
Get Color From HSV Values.
static Color FromName(const Util::Colors &name)
Get Color From name within Util::Colors.
std::string ToString() const
Converts the color to a string representation.
Definition: Color.hpp:83
SDL_Color ToSdlColor() const
Converts the color to SDL_Color format.
Definition: Color.hpp:66
static Color FromRGB(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255)
Get Color From RGB Values.
static Color FromHex(const std::string &hex)
Get Color From Hex RGB String, alpha value is necessary.
static Color FromHex(Uint32 hex)
Get Color From Hex RGB Value, alpha value is necessary.
static Color FromHSL(float h, float s, float l, float a=1.0F)
Get Color From HSL Values.
Useful tools for development.
Definition: Animation.hpp:12
Colors
A enum class that includes common colors.
Definition: Color.hpp:140