AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
AeonGUI::Color Union Reference

Pixel Color Union. The Color union allows access to each unsigned 8 bit RGBA color component individually or as a single 32 bit unsigned integer, making possible color asignments similar to those used on the web (IE: color = 0xFF000000 with the format 0xAARRGGBB). The union type is also 32bits wide which makes it suitable to be passed as value or as reference. Wherever a Color variable can be passed it should be possible to pass a 32 bit unsigned integer value, but some compilers may complain depending on the set warning level. More...

#include <aeongui/Color.hpp>

Public Member Functions

 Color (uint32_t value)
 32 bit Unsigned integer constructor.
 Color (const std::string &value)
 Construct a Color from a CSS color string.
 Color (uint8_t A, uint8_t R, uint8_t G, uint8_t B)
 4 8 bit Unsigned integer component constructor.
void Blend (Color src)
 Blends the color with the incoming source color. To better handle transparency the blend function uses the source alpha as source factor and one minus source alpha as destination factor.
double R () const
 Get red component as a double in [0.0, 1.0].
double G () const
 Get green component as a double in [0.0, 1.0].
double B () const
 Get blue component as a double in [0.0, 1.0].
double A () const
 Get alpha component as a double in [0.0, 1.0].
std::string ToString () const
 Convert the color to a CSS-style string representation.

Static Public Member Functions

static bool IsColor (const std::string &value, uint32_t *color_value=nullptr)
 Check whether a string represents a valid CSS color.

Public Attributes

uint32_t bgra
 32 bit Unsigned integer color value.
struct { 
   uint8_t   b 
 Blue color element.
   uint8_t   g 
 Green color element.
   uint8_t   r 
 Red color element.
   uint8_t   a 
 Alpha color element.
}; 

Static Public Attributes

static const std::regex ColorRegex {"#[0-9A-Fa-f]{8}|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}|aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|grey|green|greenyellow|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|none|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|transparent|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen"}
 Regex used to parse CSS color strings.

Detailed Description

Pixel Color Union. The Color union allows access to each unsigned 8 bit RGBA color component individually or as a single 32 bit unsigned integer, making possible color asignments similar to those used on the web (IE: color = 0xFF000000 with the format 0xAARRGGBB). The union type is also 32bits wide which makes it suitable to be passed as value or as reference. Wherever a Color variable can be passed it should be possible to pass a 32 bit unsigned integer value, but some compilers may complain depending on the set warning level.

Constructor & Destructor Documentation

◆ Color() [1/3]

AeonGUI::Color::Color ( uint32_t value)
explicit

32 bit Unsigned integer constructor.

Parameters
value32 bit color value.

◆ Color() [2/3]

AeonGUI::Color::Color ( const std::string & value)

Construct a Color from a CSS color string.

Parameters
valueA CSS color string (e.g. "#FF0000" or "red").

◆ Color() [3/3]

AeonGUI::Color::Color ( uint8_t A,
uint8_t R,
uint8_t G,
uint8_t B )

4 8 bit Unsigned integer component constructor.

Parameters
AAlpha color value.
RRed color value.
GGreen color value.
BBlue color value.

Member Function Documentation

◆ A()

double AeonGUI::Color::A ( ) const

Get alpha component as a double in [0.0, 1.0].

Returns
The alpha component.

◆ B()

double AeonGUI::Color::B ( ) const

Get blue component as a double in [0.0, 1.0].

Returns
The blue component.

◆ Blend()

void AeonGUI::Color::Blend ( Color src)

Blends the color with the incoming source color. To better handle transparency the blend function uses the source alpha as source factor and one minus source alpha as destination factor.

Parameters
srcIncomming source color.

◆ G()

double AeonGUI::Color::G ( ) const

Get green component as a double in [0.0, 1.0].

Returns
The green component.

◆ IsColor()

bool AeonGUI::Color::IsColor ( const std::string & value,
uint32_t * color_value = nullptr )
static

Check whether a string represents a valid CSS color.

Parameters
valueThe string to test.
color_valueOptional output for the parsed color.
Returns
true if the string is a valid color.

◆ R()

double AeonGUI::Color::R ( ) const

Get red component as a double in [0.0, 1.0].

Returns
The red component.

◆ ToString()

std::string AeonGUI::Color::ToString ( ) const

Convert the color to a CSS-style string representation.

Returns
A string such as "rgba(255,0,0,1)".

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