1.10 |
32 bit RGBA color. More...
#include <color.h>
Public Types | |
using | ComponentType = uint32_t |
Single component of Red/Green/Blue/Alpha type. | |
using | RGBAType = uint32_t |
Red/Green/Blue/Alpha type. | |
using | RGBType = uint32_t |
Red/Green/Blue type. | |
Public Member Functions | |
constexpr | Color ()=default |
constexpr | Color (ComponentType r, ComponentType g, ComponentType b, ComponentType a=255) noexcept |
Create a color with the specified RGBA component values. | |
constexpr | Color (const Color &color, ComponentType alpha) noexcept |
Create a color from an existing color, but with the specified alpha value. | |
constexpr | Color (RGBAType c) noexcept |
Create a color with the specified RGBA value. | |
EGT_NODISCARD constexpr ComponentType | alpha () const |
constexpr void | alpha (ComponentType a) |
EGT_NODISCARD constexpr float | alphaf () const |
constexpr void | alphaf (float v) |
EGT_NODISCARD constexpr ComponentType | blue () const |
constexpr void | blue (ComponentType b) |
EGT_NODISCARD constexpr float | bluef () const |
constexpr void | bluef (float v) |
void | get_hslf (float &h, float &s, float &l, float *alpha=nullptr) |
Get the hue, saturation, lightness, and alpha channel components of the color. | |
void | get_hsvf (float &h, float &s, float &v, float *alpha=nullptr) |
Get the hue, saturation, value, and alpha channel components of the color. | |
void | get_rgbaf (float &r, float &g, float &b, float *alpha=nullptr) |
Get the red, green, blue, and alpha channel components of the color. | |
EGT_NODISCARD constexpr ComponentType | green () const |
constexpr void | green (ComponentType g) |
EGT_NODISCARD constexpr float | greenf () const |
constexpr void | greenf (float v) |
EGT_NODISCARD std::string | hex () const |
Return a string hex representation of the color. | |
EGT_NODISCARD Color | hue (float h) const |
Create a new color by applying a hue value. | |
Color | operator* (const Color &rhs) const |
Color operator. | |
template<class T > | |
constexpr Color | operator* (T scalar) const |
Color operator. | |
constexpr Color | operator+ (const Color &rhs) const |
Color operator. | |
template<class T > | |
constexpr Color | operator+ (T scalar) const |
Color operator. | |
constexpr Color | operator- (const Color &rhs) const |
Color operator. | |
template<class T > | |
constexpr Color | operator- (T scalar) const |
Color operator. | |
constexpr Color | operator/ (const Color &rhs) const |
Color operator. | |
template<class T > | |
constexpr Color | operator/ (T scalar) const |
Color operator. | |
Color & | operator= (RGBAType c) |
Assign an RGBA value. | |
EGT_NODISCARD constexpr uint16_t | pixel16 () const |
Get a 16 bit pixel representation of the Color. | |
EGT_NODISCARD constexpr RGBAType | pixel24 () const |
Get a 24 bit pixel representation of the Color. | |
EGT_NODISCARD constexpr RGBAType | pixel32 () const |
Get a 32 bit pixel representation of the Color. | |
EGT_NODISCARD constexpr ComponentType | red () const |
Get RGBA component value as value from 0 to 255. | |
constexpr void | red (ComponentType r) |
Set RGBA component value individually from 0 to 255. | |
EGT_NODISCARD constexpr float | redf () const |
Get RGBA component value as a float from 0.0 to 1.0. | |
constexpr void | redf (float v) |
Set RGBA component value as a float from 0.0 to 1.0. | |
EGT_NODISCARD constexpr Color | shade (float factor) const |
Create a shade (darker) color based off this color given a factor. | |
EGT_NODISCARD constexpr Color | tint (float factor) const |
Create a tint (lighter) color based off this color given a factor. | |
Static Public Member Functions | |
EGT_NODISCARD static constexpr Color | css (const char *hex) |
static EGT_NODISCARD Color | css (const std::string &hex) |
Create a Color with a hex CSS string. | |
static EGT_NODISCARD Color | hslf (float h, float s, float l, float alpha=1.0) |
Create a color from HSL values. | |
static EGT_NODISCARD Color | hsvf (float h, float s, float v, float alpha=1.0) |
Create a color from HSV values. | |
static Color | interp_hsl (const Color &a, const Color &b, float t) |
Perform linear interpolation between two colors in the HSL color space. | |
static Color | interp_hsv (const Color &a, const Color &b, float t) |
Perform linear interpolation between two colors in the HSV color space. | |
static Color | interp_rgba (const Color &a, const Color &b, float t) |
Perform linear interpolation between two colors in the RGB color space. | |
static EGT_NODISCARD constexpr Color | pixel16 (uint16_t c) |
Create a Color from a 16 bit pixel representation. | |
static EGT_NODISCARD constexpr Color | pixel24 (RGBAType c) |
Create a Color from a 24 bit pixel representation. | |
static EGT_NODISCARD constexpr Color | pixel32 (RGBAType c) |
Create a Color from a 24 bit pixel representation. | |
static EGT_NODISCARD constexpr Color | rgb (RGBType c, ComponentType alpha=255) noexcept |
Create a color from only a RGB value with separate alpha channel component. | |
static EGT_NODISCARD constexpr Color | rgbaf (float r, float g, float b, float a=1.0) |
Create a color from float values. | |
Protected Attributes | |
ComponentType | m_rgba [4] {} |
RGBA value. | |
32 bit RGBA color.
This manages the definition of a color, internally stored as separate red, green, blue, and alpha components.
using ComponentType = uint32_t |
Single component of Red/Green/Blue/Alpha type.
using RGBAType = uint32_t |
Red/Green/Blue/Alpha type.
using RGBType = uint32_t |
Red/Green/Blue type.
|
constexprdefault |
Create a color with the specified RGBA value.
Example
[in] | c | RGBA value. |
|
inlineconstexprnoexcept |
Create a color from an existing color, but with the specified alpha value.
[in] | color | Pre-existing color. |
[in] | alpha | Specific alpha value. |
|
inlineexplicitconstexprnoexcept |
Create a color with the specified RGBA component values.
[in] | r | Red component in range 0 - 255. |
[in] | g | Green component in range 0 - 255. |
[in] | b | Blue component in range 0 - 255. |
[in] | a | Alpha component in range 0 - 255. |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlinestaticconstexpr |
|
inlinestatic |
Create a Color with a hex CSS string.
For example, the string #0074D9 can be used to specify a blue-like color from red, green, blue values. Alpha is not included.
Example
void get_hslf | ( | float & | h, |
float & | s, | ||
float & | l, | ||
float * | alpha = nullptr |
||
) |
Get the hue, saturation, lightness, and alpha channel components of the color.
[out] | h | Hue component in range 0 - 1. |
[out] | s | Saturation component in range 0 - 1. |
[out] | l | Lightness component in range 0 - 1. |
[out] | alpha | Alpha component in range 0 - 1. |
void get_hsvf | ( | float & | h, |
float & | s, | ||
float & | v, | ||
float * | alpha = nullptr |
||
) |
Get the hue, saturation, value, and alpha channel components of the color.
[out] | h | Hue component in range 0 - 1. |
[out] | s | Saturation component in range 0 - 1. |
[out] | v | Value component in range 0 - 1. |
[out] | alpha | Alpha component in range 0 - 1. |
void get_rgbaf | ( | float & | r, |
float & | g, | ||
float & | b, | ||
float * | alpha = nullptr |
||
) |
Get the red, green, blue, and alpha channel components of the color.
[out] | r | Red component in range 0 - 1. |
[out] | g | Green component in range 0 - 1. |
[out] | b | Blue component in range 0 - 1. |
[out] | alpha | Alpha component in range 0 - 1. |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
EGT_NODISCARD std::string hex | ( | ) | const |
Return a string hex representation of the color.
|
static |
Create a color from HSL values.
[in] | h | Hue component in range 0 - 1. |
[in] | s | Saturation component in range 0 - 1. |
[in] | l | Lightness component in range 0 - 1. |
[in] | alpha | Alpha component in range 0 - 1. |
|
static |
Create a color from HSV values.
[in] | h | Hue component in range 0 - 1. |
[in] | s | Saturation component in range 0 - 1. |
[in] | v | Value component in range 0 - 1. |
[in] | alpha | Alpha component in range 0 - 1. |
|
inline |
Create a new color by applying a hue value.
Perform linear interpolation between two colors in the HSL color space.
a | The first color. |
b | The second color. |
t | Value from 0 to 1. |
Perform linear interpolation between two colors in the HSV color space.
a | The first color. |
b | The second color. |
t | Value from 0 to 1. |
Perform linear interpolation between two colors in the RGB color space.
a | The first color. |
b | The second color. |
t | Value from 0 to 1. |
|
inlineconstexpr |
Get a 16 bit pixel representation of the Color.
|
inlinestaticconstexpr |
Create a Color from a 16 bit pixel representation.
|
inlineconstexpr |
Get a 24 bit pixel representation of the Color.
Create a Color from a 24 bit pixel representation.
|
inlineconstexpr |
Get a 32 bit pixel representation of the Color.
Create a Color from a 24 bit pixel representation.
|
inlineconstexpr |
Get RGBA component value as value from 0 to 255.
|
inlineconstexpr |
Set RGBA component value individually from 0 to 255.
|
inlineconstexpr |
Get RGBA component value as a float from 0.0 to 1.0.
|
inlineconstexpr |
Set RGBA component value as a float from 0.0 to 1.0.
|
inlinestaticconstexprnoexcept |
Create a color from only a RGB value with separate alpha channel component.
Example
[in] | c | RGB value. |
[in] | alpha | Alpha component in range 0 - 255. |
|
inlinestaticconstexpr |
Create a color from float values.
[in] | r | Component value as a float from 0.0 to 1.0. |
[in] | g | Component value as a float from 0.0 to 1.0. |
[in] | b | Component value as a float from 0.0 to 1.0. |
[in] | a | Component value as a float from 0.0 to 1.0. |
|
inlineconstexpr |
Create a shade (darker) color based off this color given a factor.
The larger the factor, the darker the shade.
[in] | factor | Value from 0.0 to 1.0. |
|
inlineconstexpr |
Create a tint (lighter) color based off this color given a factor.
The larger the factor the lighter the tint.
[in] | factor | Value from 0.0 to 1.0. |
|
protected |
RGBA value.
red[0], green[1], blue[2], alpha[3]