diff --git a/OpenTESArena/src/Utilities/Color.cpp b/OpenTESArena/src/Utilities/Color.cpp index f2dca936f..29c6eca0f 100644 --- a/OpenTESArena/src/Utilities/Color.cpp +++ b/OpenTESArena/src/Utilities/Color.cpp @@ -14,35 +14,21 @@ const Color Color::White(255, 255, 255, 255); const Color Color::Gray(127, 127, 127, 255); const Color Color::Transparent(0, 0, 0, 0); -Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) -{ - this->r = r; - this->g = g; - this->b = b; - this->a = a; -} - -Color::Color(uint8_t r, uint8_t g, uint8_t b) - : Color(r, g, b, 255) { } - -Color::Color() - : Color(0, 0, 0) { } - Color Color::randomRGBA(Random &random) { - uint8_t r = static_cast(random.next(256)); - uint8_t g = static_cast(random.next(256)); - uint8_t b = static_cast(random.next(256)); - uint8_t a = static_cast(random.next(256)); - return Color(r, g, b, a); + return Color( + static_cast(random.next(256)), + static_cast(random.next(256)), + static_cast(random.next(256)), + static_cast(random.next(256))); } Color Color::randomRGB(Random &random) { - uint8_t r = static_cast(random.next(256)); - uint8_t g = static_cast(random.next(256)); - uint8_t b = static_cast(random.next(256)); - return Color(r, g, b); + return Color( + static_cast(random.next(256)), + static_cast(random.next(256)), + static_cast(random.next(256))); } Color Color::fromARGB(uint32_t argb) @@ -80,42 +66,37 @@ std::string Color::toString() const uint32_t Color::toARGB() const { - return static_cast( - (this->r << 16) | (this->g << 8) | (this->b) | (this->a << 24)); + return static_cast((this->r << 16) | (this->g << 8) | (this->b) | (this->a << 24)); } uint32_t Color::toRGBA() const { - return static_cast( - (this->r << 24) | (this->g << 16) | (this->b << 8) | (this->a)); + return static_cast((this->r << 24) | (this->g << 16) | (this->b << 8) | (this->a)); } uint32_t Color::toRGB() const { - return static_cast( - (this->r << 16) | (this->g << 8) | (this->b)); + return static_cast((this->r << 16) | (this->g << 8) | (this->b)); } -Color Color::operator+(const Color &c) const +Color Color::operator+(const Color &other) const { - return Color(this->r + c.r, this->g + c.g, this->b + c.b, this->a + c.a); + return Color(this->r + other.r, this->g + other.g, this->b + other.b, this->a + other.a); } -Color Color::operator-(const Color &c) const +Color Color::operator-(const Color &other) const { - return Color(this->r - c.r, this->g - c.g, this->b - c.b, this->a - c.a); + return Color(this->r - other.r, this->g - other.g, this->b - other.b, this->a - other.a); } -bool Color::operator==(const Color &c) const +bool Color::operator==(const Color &other) const { - return (this->r == c.r) && (this->g == c.g) && (this->b == c.b) && - (this->a == c.a); + return (this->r == other.r) && (this->g == other.g) && (this->b == other.b) && (this->a == other.a); } -bool Color::operator!=(const Color &c) const +bool Color::operator!=(const Color &other) const { - return (this->r != c.r) || (this->g != c.g) || (this->b != c.b) || - (this->a != c.a); + return (this->r != other.r) || (this->g != other.g) || (this->b != other.b) || (this->a != other.a); } Color Color::clamped(uint8_t low, uint8_t high) const @@ -126,10 +107,3 @@ Color Color::clamped(uint8_t low, uint8_t high) const (this->b > high) ? high : ((this->b < low) ? low : this->b), (this->a > high) ? high : ((this->a < low) ? low : this->a)); } - -Color Color::clamped() const -{ - const uint8_t low = 0; - const uint8_t high = 255; - return this->clamped(low, high); -} diff --git a/OpenTESArena/src/Utilities/Color.h b/OpenTESArena/src/Utilities/Color.h index e591f3ab9..b12506f5f 100644 --- a/OpenTESArena/src/Utilities/Color.h +++ b/OpenTESArena/src/Utilities/Color.h @@ -6,15 +6,34 @@ class Random; -class Color +struct Color { -public: - Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); - Color(uint8_t r, uint8_t g, uint8_t b); - Color(); - uint8_t r, g, b, a; + constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + { + this->r = r; + this->g = g; + this->b = b; + this->a = a; + } + + constexpr Color(uint8_t r, uint8_t g, uint8_t b) + { + this->r = r; + this->g = g; + this->b = b; + this->a = 255; + } + + constexpr Color() + { + this->r = 0; + this->g = 0; + this->b = 0; + this->a = 255; + } + static const Color Red; static const Color Green; static const Color Blue; @@ -32,17 +51,16 @@ class Color static Color fromRGBA(uint32_t rgba); static Color fromRGB(uint32_t rgb); - Color operator+(const Color &c) const; - Color operator-(const Color &c) const; - bool operator==(const Color &c) const; - bool operator!=(const Color &c) const; + Color operator+(const Color &other) const; + Color operator-(const Color &other) const; + bool operator==(const Color &other) const; + bool operator!=(const Color &other) const; std::string toString() const; uint32_t toARGB() const; uint32_t toRGBA() const; uint32_t toRGB() const; Color clamped(uint8_t low, uint8_t high) const; - Color clamped() const; }; #endif