5 #include <unordered_map>
11 #define GL_FORCE_INTO_RANGE(VAR, LOWER, UPPER) \
12 VAR < LOWER ? LOWER : (VAR > UPPER ? UPPER : VAR)
64 explicit Color(
const unsigned int hex,
const unsigned int a=0x64) :
66 r_((hex >> 16) & 0xFF),
67 g_((hex >> 8) & 0xFF),
78 const std::unordered_map<std::string, std::function<void()>> map{
79 {
"black", [&]() {
hex(0x000000); }},
80 {
"gray", [&]() {
hex(0x808080); }},
81 {
"silver", [&]() {
hex(0xC0C0C0); }},
82 {
"white", [&]() {
hex(0xFFFFFF); }},
83 {
"orange", [&]() {
hex(0xED9121); }},
84 {
"maroon", [&]() {
hex(0x800000); }},
85 {
"red", [&]() {
hex(0xFF0000); }},
86 {
"olive", [&]() {
hex(0x808000); }},
87 {
"yellow", [&]() {
hex(0xFFFF00); }},
88 {
"green", [&]() {
hex(0x008000); }},
89 {
"lime", [&]() {
hex(0x00FF00); }},
90 {
"teal", [&]() {
hex(0x008080); }},
91 {
"aqua", [&]() {
hex(0x00FFFF); }},
92 {
"navy", [&]() {
hex(0x000080); }},
93 {
"blue", [&]() {
hex(0x0000FF); }},
94 {
"purple", [&]() {
hex(0x800080); }},
95 {
"fuchsia", [&]() {
hex(0xFF00FF); }},
97 auto it = map.find(name);
111 Color &operator=(
Color &&) noexcept = default;
118 bool operator== (const
Color& rhs)
const
141 inline std::string
RGBA()
const
143 std::stringstream ss;
144 ss << std::setfill(
'0') << std::setw(8) << std::hex << (
hex() | 0);
150 inline std::string
RGB()
const
152 std::stringstream ss;
153 int val = (
hex() >> 8) & 0xffffff;
154 ss << std::setfill(
'0') << std::setw(6) << std::hex << (val | 0);
162 return (
r_ << 24) | (
g_ << 16) | (
b_ << 8) |
a_;
194 r_ = (hex >> 16) & 0xFF;
195 g_ = (hex >> 8) & 0xFF;
203 inline void hex(
const int hex,
const unsigned int a)
205 r_ = (hex >> 16) & 0xFF;
206 g_ = (hex >> 8) & 0xFF;
237 #undef GL_FORCE_INTO_RANGE
239 #endif // GL_COLOR_HPP
color_val_t b_
Blue value. .
Definition: Color.hpp:229
Color(const int r, const int g, const int b, const int a=100)
Constructor for integer R,G,B,A values.
Definition: Color.hpp:42
Stores an RGBA Color.
Definition: Color.hpp:21
color_val_t a_
Alpha/opacity value. .
Definition: Color.hpp:229
void b(color_val_t b)
Sets the blue value of the RGBA color.
Definition: Color.hpp:221
#define GL_FORCE_INTO_RANGE(VAR, LOWER, UPPER)
Definition: Color.hpp:11
Color(const char *name, color_val_t a=100)
Constructor for combined hexadecimal R,G,B,A values.
Definition: Color.hpp:76
bool operator==(const Color &rhs) const
Check whether two colors are equal.
Definition: Color.hpp:118
bool operator!=(const Color &rhs) const
Check whether two colors are not equal.
Definition: Color.hpp:129
int hex() const
Gets the hexadecimal value of the RGBA color.
Definition: Color.hpp:160
void g(color_val_t g)
Sets the green value of the RGBA color.
Definition: Color.hpp:217
Color(const unsigned int hex, const unsigned int a=0x64)
Constructor for combined hexadecimal R,G,B,A values.
Definition: Color.hpp:64
Color()
Default constructor.
Definition: Color.hpp:34
void hex(const int hex)
Sets all values of the RGBA color.
Definition: Color.hpp:192
void a(color_val_t a)
Sets the alpha/opacity value of the RGBA color.
Definition: Color.hpp:225
color_val_t b() const
Gets the blue value of the RGBA color.
Definition: Color.hpp:175
void r(color_val_t r)
Sets the red value of the RGBA color.
Definition: Color.hpp:213
color_val_t r_
Red value. .
Definition: Color.hpp:229
color_val_t g() const
Gets the green value of the RGBA color.
Definition: Color.hpp:171
unsigned char color_val_t
Definition: Color.hpp:24
void hex(const int hex, const unsigned int a)
Sets all values of the RGBA color.
Definition: Color.hpp:203
std::string RGB() const
Gets the hexadecimal value of the RGB color as a string.
Definition: Color.hpp:150
color_val_t a() const
Gets the alpha/opacity value of the RGBA color.
Definition: Color.hpp:179
color_val_t g_
Green value. .
Definition: Color.hpp:229
std::string RGBA() const
Gets the hexadecimal value of the RGBA color as a string.
Definition: Color.hpp:141
Color(const double r, const double g, const double b, const double a=1.0)
Constructor for separate double R,G,B,A values.
Definition: Color.hpp:54
color_val_t r() const
Gets the red value of the RGBA color.
Definition: Color.hpp:167