template class EE::System::tColor¶
Overview¶
Template class for a RGBA color. More…
#include <color.hpp> template <typename T> class tColor { public: // typedefs typedef std::conditional_t<std::is_same_v<T, Uint8>, Uint32, std::array<T, 4>> ValueType; // fields ValueType Value; T r; T g; T b; T a; T h; T s; T v; struct EE::System::tColor::@4::@8 hsv; T l; struct EE::System::tColor::@4::@9 hsl; // construction tColor(); tColor(T r, T g, T b, T a); tColor(const tRGB<T>& Col); tColor(const tRGB<T>& Col, T a); tColor(const tColor<T>& Col); template <typename U = T, std::enable_if_t<std::is_same_v<U, Uint8>, int> = 0> tColor(const Uint32& Col); // methods ValueType getValue() const; void assign(T r, T g, T b, T a); void assign(const tColor<T>& Col); bool operator==(const tColor<T>& Col) const; bool operator!=(const tColor<T>& Col) const; tColor<T> operator+(const tColor<T>& Col) const; tColor<T> operator-(const tColor<T>& Col) const; tColor<T> operator*(const tColor<T>& Col) const; tRGB<T> toRGB(); T perceivedLuminance() const; };
Detailed Documentation¶
Template class for a RGBA color.
Construction¶
tColor(T r, T g, T b, T a)
Creates an RGBA color from each component.
Parameters:
r |
Red component |
g |
Green component |
b |
Blue component |
a |
Alpha component |
tColor(const tRGB<T>& Col)
Creates a RGBA color from a RGB color, the Alpha component is set as non-transparent.
tColor(const tRGB<T>& Col, T a)
Creates a RGBA color from a RGB color.
Parameters:
Col |
The RGB color |
a |
The Alpha component value |
template <typename U = T, std::enable_if_t<std::is_same_v<U, Uint8>, int> = 0> tColor(const Uint32& Col)
From a 32 bits value with RGBA byte order
Methods¶
ValueType getValue() const
Returns:
The color represented as an Uint32 ( as 0xRRGGBBAA for Little Endian )
void assign(T r, T g, T b, T a)
Assign the RGBA colors, from each component.
void assign(const tColor<T>& Col)
Assign the color value from other RGBA color.
T perceivedLuminance() const
Calculates the perceived luminance (Luma) of the color. Uses the Rec. 601 luma formula: L = 0.299*R + 0.587*G + 0.114*B. Perceived luminance aligns with human vision, making it ideal for UI contrast.
Note
Note on HSL (Colorf): If this object is being used to store HSL values (for instance, a Colorf returned by Color::toHsl()), do NOT call this method directly. Perceived luminance mathematically requires RGB components. You must either call this on the original RGB object, or convert the HSL Colorf back to RGB first (e.g., using Color::fromHsl(hslColor)).