The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
color_t Struct Reference

#include <color.hpp>

Public Member Functions

 color_t ()
 
 color_t (uint8_t r_val, uint8_t g_val, uint8_t b_val, uint8_t a_val=ALPHA_OPAQUE)
 
 color_t (const SDL_Color &c)
 
std::string to_hex_string () const
 Returns the stored color in rrggbb hex format. More...
 
uint32_t to_rgba_bytes () const
 Returns the stored color as a uint32_t, in RGBA format. More...
 
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...
 
SDL_Color to_sdl () const
 Returns the stored color as an color_t object. More...
 
bool null () const
 
bool operator== (const color_t &c) const
 
bool operator!= (const color_t &c) const
 
color_t blend_add (const color_t &c) const
 
color_t blend_lighten (const color_t &c) const
 
color_t inverse () const
 

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 color_t from_rgba_bytes (uint32_t c)
 Creates a new color_t object from a uint32_t variable. More...
 
static color_t from_argb_bytes (uint32_t c)
 Creates a new color_t object from a uint32_t variable. More...
 
static color_t null_color ()
 Definition of a 'null' color - fully transparent black. More...
 

Public Attributes

uint8_t r
 Red value. More...
 
uint8_t g
 Green value. More...
 
uint8_t b
 Blue value. More...
 
uint8_t a
 Alpha value. More...
 

Detailed Description

Definition at line 50 of file color.hpp.

Constructor & Destructor Documentation

color_t::color_t ( )
inline

Definition at line 52 of file color.hpp.

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

Definition at line 59 of file color.hpp.

color_t::color_t ( const SDL_Color &  c)
explicit

Definition at line 2367 of file utils.cpp.

Member Function Documentation

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

Definition at line 203 of file color.hpp.

References a, b, g, and r.

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

Definition at line 216 of file color.hpp.

References a, b, g, and r.

color_t color_t::from_argb_bytes ( uint32_t  c)
static

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

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(), and help::string_to_color().

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

References ALPHA_OPAQUE.

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

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

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

Referenced by game_lua_kernel::intf_float_label(), game_lua_kernel::intf_print(), theme::label::label(), terrain_label::read(), and theme::status_item::status_item().

color_t color_t::from_rgba_bytes ( uint32_t  c)
static

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

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.

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

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

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

color_t color_t::inverse ( ) const
inline

Definition at line 226 of file color.hpp.

References b, and r.

bool color_t::null ( ) const
inline
static color_t color_t::null_color ( )
inlinestatic

Definition of a 'null' color - fully transparent black.

Definition at line 236 of file color.hpp.

Referenced by from_rgb_string(), from_rgba_string(), and null().

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

Definition at line 198 of file color.hpp.

References c.

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

Definition at line 193 of file color.hpp.

References a, b, g, and r.

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 145 of file color.hpp.

References a, b, g, r, 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.

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

Definition at line 97 of file color.cpp.

References b, g, h, and r.

Referenced by color_range::debug(), team::get_side_highlight_pango(), font::pango_text::handle_token(), and font::span_color().

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

References b, g, and r.

Referenced by terrain_label::write().

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 131 of file color.hpp.

References a, b, g, r, RGBA_ALPHA_BITSHIFT, RGBA_BLUE_BITSHIFT, RGBA_GREEN_BITSHIFT, and RGBA_RED_BITSHIFT.

Referenced by std::hash< color_t >::operator()(), and color_range::operator<().

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

References a, b, g, and r.

Referenced by gui2::dialogs::attack_predictions::draw_hp_graph().

SDL_Color color_t::to_sdl ( ) const

Returns the stored color as an color_t object.

Returns
The new color_t object.

Definition at line 2363 of file utils.cpp.

References a, b, g, and r.

Referenced by font::text_surface::get_surfaces().

Member Data Documentation

uint8_t color_t::a
uint8_t color_t::b
uint8_t color_t::g
uint8_t color_t::r

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