The Battle for Wesnoth  1.19.7+dev
Public Member Functions | Static Public Member Functions | List of all members
color_t Struct Reference

The basic class for representing 8-bit RGB or RGBA colour values. More...

#include <color.hpp>

Inheritance diagram for color_t:

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...
 

Detailed Description

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.

Definition at line 58 of file color.hpp.

Constructor & Destructor Documentation

◆ color_t() [1/3]

constexpr color_t::color_t ( )
inlineconstexpr

color_t initializes to fully opaque white by default.

Definition at line 61 of file color.hpp.

◆ color_t() [2/3]

constexpr color_t::color_t ( uint8_t  r_val,
uint8_t  g_val,
uint8_t  b_val,
uint8_t  a_val = ALPHA_OPAQUE 
)
inlineconstexpr

Basic RGB or RGBA constructor.

Definition at line 64 of file color.hpp.

◆ color_t() [3/3]

constexpr color_t::color_t ( const SDL_Color &  c)
inlineconstexpr

This is a thin wrapper.

There is nothing extra to do here.

Definition at line 69 of file color.hpp.

Member Function Documentation

◆ blend_add()

constexpr color_t color_t::blend_add ( const color_t c) const
inlineconstexpr

Definition at line 201 of file color.hpp.

References b, c, and g.

◆ blend_lighten()

constexpr color_t color_t::blend_lighten ( const color_t c) const
inlineconstexpr

Definition at line 214 of file color.hpp.

References b, c, and g.

◆ from_argb_bytes()

static constexpr color_t color_t::from_argb_bytes ( uint32_t  c)
inlinestaticconstexpr

Creates a new color_t object from a uint32_t variable.

Parameters
cA uint32_t variable, in ARGB format.
Returns
A new color_t object.

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().

◆ from_hex_string()

color_t color_t::from_hex_string ( std::string_view  c)
static

Creates a new color_t object from a string variable in hex format.

Parameters
cA string variable, in rrggbb hex format.
Returns
A new color_t object.
Exceptions
std::invalid_argumentif 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().

◆ from_rgb_string()

color_t color_t::from_rgb_string ( std::string_view  c)
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.

Parameters
cA string variable, in "R,G,B" format.
Returns
A new color_t object.
Exceptions
std::invalid_argumentif 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().

◆ from_rgba_bytes()

static constexpr color_t color_t::from_rgba_bytes ( uint32_t  c)
inlinestaticconstexpr

Creates a new color_t object from a uint32_t variable.

Parameters
cA uint32_t variable, in RGBA format.
Returns
A new color_t object.

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.

◆ from_rgba_string()

color_t color_t::from_rgba_string ( std::string_view  c)
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.

Parameters
cA string variable, in "R,G,B,A" format.
Returns
A new color_t object.
Exceptions
std::invalid_argumentif 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().

◆ inverse()

constexpr color_t color_t::inverse ( ) const
inlineconstexpr

Definition at line 224 of file color.hpp.

References b, and g.

◆ null()

constexpr bool color_t::null ( ) const
inlineconstexpr

◆ null_color()

static constexpr color_t color_t::null_color ( )
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().

◆ operator!=()

constexpr bool color_t::operator!= ( const color_t c) const
inlineconstexpr

Definition at line 196 of file color.hpp.

References c.

◆ operator==()

constexpr bool color_t::operator== ( const color_t c) const
inlineconstexpr

Definition at line 191 of file color.hpp.

References b, c, and g.

◆ smooth_blend()

constexpr color_t color_t::smooth_blend ( const color_t c,
uint8_t  p 
) const
inlineconstexpr

Blend smoothly with another color_t.

Parameters
cThe color to blend with.
pThe 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().

◆ to_argb_bytes()

constexpr uint32_t color_t::to_argb_bytes ( ) const
inlineconstexpr

Returns the stored color as a uint32_t, an ARGB format.

Returns
The new uint32_t object.

Definition at line 163 of file color.hpp.

References b, g, SDL_ALPHA_BITSHIFT, SDL_BLUE_BITSHIFT, SDL_GREEN_BITSHIFT, and SDL_RED_BITSHIFT.

◆ to_hex_string()

std::string color_t::to_hex_string ( ) const

Returns the stored color in rrggbb hex format.

Returns
The string in hex format. The preceding '#' needed for pango markup is prepended.

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().

◆ to_rgb_string()

std::string color_t::to_rgb_string ( ) const

Returns the stored color as an "R,G,B" string.

Returns
The new color string.

Definition at line 117 of file color.cpp.

References b, and g.

Referenced by terrain_label::write().

◆ to_rgba_bytes()

constexpr uint32_t color_t::to_rgba_bytes ( ) const
inlineconstexpr

Returns the stored color as a uint32_t, in RGBA format.

Returns
The new uint32_t object.

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<().

◆ to_rgba_string()

std::string color_t::to_rgba_string ( ) const

Returns the stored color as an "R,G,B,A" string.

Returns
The new color string.

Definition at line 105 of file color.cpp.

References b, and g.

Referenced by gui2::rich_label::default_text_config(), and gui2::dialogs::attack_predictions::draw_hp_graph().


The documentation for this struct was generated from the following files: