The basic class for representing 8-bit RGB or RGBA colour values. More...
#include <color.hpp>
Public Member Functions | |
constexpr | color_t () |
color_t initializes to fully opaque white by default. More... | |
constexpr | color_t (uint8_t r_val, uint8_t g_val, uint8_t b_val, uint8_t a_val=ALPHA_OPAQUE) |
Basic RGB or RGBA constructor. More... | |
constexpr | color_t (const SDL_Color &c) |
This is a thin wrapper. More... | |
std::string | to_hex_string () const |
Returns the stored color in rrggbb hex format. More... | |
constexpr uint32_t | to_rgba_bytes () const |
Returns the stored color as a uint32_t, in RGBA format. More... | |
constexpr uint32_t | to_argb_bytes () const |
Returns the stored color as a uint32_t, an ARGB format. More... | |
std::string | to_rgba_string () const |
Returns the stored color as an "R,G,B,A" string. More... | |
std::string | to_rgb_string () const |
Returns the stored color as an "R,G,B" string. More... | |
constexpr bool | null () const |
constexpr bool | operator== (const color_t &c) const |
constexpr bool | operator!= (const color_t &c) const |
constexpr color_t | blend_add (const color_t &c) const |
constexpr color_t | blend_lighten (const color_t &c) const |
constexpr color_t | inverse () const |
constexpr color_t | smooth_blend (const color_t &c, uint8_t p) const |
Blend smoothly with another color_t. More... | |
Static Public Member Functions | |
static color_t | from_rgba_string (std::string_view c) |
Creates a new color_t object from a string variable in "R,G,B,A" format. More... | |
static color_t | from_rgb_string (std::string_view c) |
Creates a new opaque color_t object from a string variable in "R,G,B" format. More... | |
static color_t | from_hex_string (std::string_view c) |
Creates a new color_t object from a string variable in hex format. More... | |
static constexpr color_t | from_rgba_bytes (uint32_t c) |
Creates a new color_t object from a uint32_t variable. More... | |
static constexpr color_t | from_argb_bytes (uint32_t c) |
Creates a new color_t object from a uint32_t variable. More... | |
static constexpr color_t | null_color () |
Definition of a 'null' color - fully transparent black. More... | |
The basic class for representing 8-bit RGB or RGBA colour values.
This is a thin wrapper over SDL_Color, and can be used interchangeably.
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlinestaticconstexpr |
Creates a new color_t object from a uint32_t variable.
c | A uint32_t variable, in ARGB format. |
Definition at line 126 of file color.hpp.
References c, SDL_ALPHA_BITSHIFT, SDL_ALPHA_MASK, SDL_BLUE_BITSHIFT, SDL_BLUE_MASK, SDL_GREEN_BITSHIFT, SDL_GREEN_MASK, SDL_RED_BITSHIFT, and SDL_RED_MASK.
Referenced by recolor_image().
|
static |
Creates a new color_t object from a string variable in hex format.
c | A string variable, in rrggbb hex format. |
std::invalid_argument | if the string is not correctly formatted |
Definition at line 64 of file color.cpp.
References ALPHA_OPAQUE, and c.
Referenced by game_config::add_color_info(), game_config::color_info(), gui2::styled_widget::get_link_color(), game_lua_kernel::intf_set_floating_label(), font::string_to_color(), and game_config::tc_info().
|
static |
Creates a new opaque color_t object from a string variable in "R,G,B" format.
An empty string results in white. Otherwise, omitting components is an error.
c | A string variable, in "R,G,B" format. |
std::invalid_argument | if the string is not correctly formatted |
Definition at line 44 of file color.cpp.
References ALPHA_OPAQUE, c, null_color(), and utils::split_view().
Referenced by frame_builder::frame_builder(), game_lua_kernel::intf_float_label(), theme::label::label(), terrain_label::read(), and theme::status_item::status_item().
|
inlinestaticconstexpr |
Creates a new color_t object from a uint32_t variable.
c | A uint32_t variable, in RGBA format. |
Definition at line 110 of file color.hpp.
References c, RGBA_ALPHA_BITSHIFT, RGBA_ALPHA_MASK, RGBA_BLUE_BITSHIFT, RGBA_BLUE_MASK, RGBA_GREEN_BITSHIFT, RGBA_GREEN_MASK, RGBA_RED_BITSHIFT, and RGBA_RED_MASK.
|
static |
Creates a new color_t object from a string variable in "R,G,B,A" format.
An empty string results in white. Otherwise, omitting components other than alpha is an error.
c | A string variable, in "R,G,B,A" format. |
std::invalid_argument | if the string is not correctly formatted |
Definition at line 23 of file color.cpp.
References ALPHA_OPAQUE, c, null_color(), and utils::split_view().
Referenced by gui2::typed_formula< T >::convert(), gui2::decode_color(), and terrain_label::read().
|
inlineconstexpr |
|
inlineconstexpr |
Definition at line 186 of file color.hpp.
References null_color().
Referenced by gui2::rectangle_shape::draw(), gui2::round_rectangle_shape::draw(), and gui2::circle_shape::draw().
|
inlinestaticconstexpr |
Definition of a 'null' color - fully transparent black.
Definition at line 251 of file color.hpp.
Referenced by from_rgb_string(), from_rgba_string(), and null().
|
inlineconstexpr |
|
inlineconstexpr |
Blend smoothly with another color_t.
c | The color to blend with. |
p | The proportion of the other color to blend. 0 will return the original color, 255 the blending color. |
Definition at line 240 of file color.hpp.
References b, c, color_blend(), g, and p.
Referenced by display::fade_to().
|
inlineconstexpr |
Returns the stored color as a uint32_t, an ARGB format.
Definition at line 163 of file color.hpp.
References b, g, SDL_ALPHA_BITSHIFT, SDL_BLUE_BITSHIFT, SDL_GREEN_BITSHIFT, and SDL_RED_BITSHIFT.
std::string color_t::to_hex_string | ( | ) | const |
Returns the stored color in rrggbb hex format.
Definition at line 88 of file color.cpp.
References ALPHA_OPAQUE, b, g, and h.
Referenced by gui2::rich_label::add_link(), color_range::debug(), font::format_as_link(), team::get_side_highlight_pango(), unit_helper::resistance_color(), and markup::span_color().
std::string color_t::to_rgb_string | ( | ) | const |
Returns the stored color as an "R,G,B" string.
Definition at line 117 of file color.cpp.
Referenced by terrain_label::write().
|
inlineconstexpr |
Returns the stored color as a uint32_t, in RGBA format.
Definition at line 149 of file color.hpp.
References b, g, RGBA_ALPHA_BITSHIFT, RGBA_BLUE_BITSHIFT, RGBA_GREEN_BITSHIFT, and RGBA_RED_BITSHIFT.
Referenced by color_range::operator<().
std::string color_t::to_rgba_string | ( | ) | const |
Returns the stored color as an "R,G,B,A" string.
Definition at line 105 of file color.cpp.
Referenced by gui2::dialogs::attack_predictions::draw_hp_graph().