The Battle for Wesnoth  1.17.8+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 (const std::string &c)
 Creates a new color_t object from a string variable in "R,G,B,A" format. More...
 
static color_t from_rgb_string (const std::string &c)
 Creates a new opaque color_t object from a string variable in "R,G,B" format. More...
 
static color_t from_hex_string (const std::string &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 ( )
inline

color_t initializes to fully opaque white by default.

Definition at line 61 of file color.hpp.

References ALPHA_OPAQUE.

◆ 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 
)
inline

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)
inline

This is a thin wrapper.

There is nothing extra to do here.

Definition at line 69 of file color.hpp.

References c, from_hex_string(), from_rgb_string(), and from_rgba_string().

Member Function Documentation

◆ blend_add()

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

Definition at line 201 of file color.hpp.

References a, b, and g.

◆ blend_lighten()

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

Definition at line 214 of file color.hpp.

References a, b, and g.

◆ from_argb_bytes()

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

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, SDL_RED_MASK, and to_hex_string().

Referenced by recolor_image().

◆ from_hex_string()

color_t color_t::from_hex_string ( const std::string &  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 62 of file color.cpp.

References ALPHA_OPAQUE.

Referenced by game_config::add_color_info(), game_config::color_info(), color_t(), gui2::styled_widget::get_link_color(), game_config::load_config(), help::string_to_color(), and game_config::tc_info().

◆ from_rgb_string()

color_t color_t::from_rgb_string ( const std::string &  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 42 of file color.cpp.

References ALPHA_OPAQUE, null_color(), and utils::split().

Referenced by color_t(), 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)
inlinestatic

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 ( const std::string &  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 21 of file color.cpp.

References ALPHA_OPAQUE, null_color(), and utils::split().

Referenced by color_t(), gui2::typed_formula< bool >::convert(), gui2::decode_color(), and terrain_label::read().

◆ inverse()

constexpr color_t color_t::inverse ( ) const
inline

Definition at line 224 of file color.hpp.

References a, b, and g.

◆ null()

constexpr bool color_t::null ( ) const
inline

◆ null_color()

static constexpr color_t color_t::null_color ( )
inlinestatic

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
inline

Definition at line 196 of file color.hpp.

References c.

◆ operator==()

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

Definition at line 191 of file color.hpp.

References a, b, and g.

◆ smooth_blend()

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

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 a, b, color_blend(), and g.

Referenced by display::fade_to().

◆ to_argb_bytes()

constexpr uint32_t color_t::to_argb_bytes ( ) const
inline

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 a, b, g, SDL_ALPHA_BITSHIFT, SDL_BLUE_BITSHIFT, SDL_GREEN_BITSHIFT, SDL_RED_BITSHIFT, to_rgb_string(), and to_rgba_string().

◆ 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 78 of file color.cpp.

References a, ALPHA_OPAQUE, b, g, and h.

Referenced by attack_info(), color_range::debug(), font::format_as_link(), from_argb_bytes(), gui2::get_mp_tooltip(), team::get_side_highlight_pango(), impl_color_get(), help::unit_topic_generator::operator()(), operator<<(), unit_helper::resistance_color(), font::span_color(), and unit_moves().

◆ 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 107 of file color.cpp.

References b, and g.

Referenced by to_argb_bytes(), and terrain_label::write().

◆ to_rgba_bytes()

constexpr uint32_t color_t::to_rgba_bytes ( ) const
inline

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 a, b, g, RGBA_ALPHA_BITSHIFT, RGBA_BLUE_BITSHIFT, RGBA_GREEN_BITSHIFT, and RGBA_RED_BITSHIFT.

Referenced by std::hash< font::pango_text >::operator()(), and 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 95 of file color.cpp.

References a, b, and g.

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


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