ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::Color Struct Reference

RGBA color struct with 8-bit channels. More...

#include <color.h>

Public Member Functions

 Color ()
 Construct a default Color (black, fully opaque).
 
 Color (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Construct a Color from RGBA values.
 
FColor to_fcolor () const
 To a float colour, with each channel from 0.0 to 1.0.
 
Color lighten (float percentage) const
 Lighten a color by a given percentage.
 
Color darken (float percentage) const
 Darken a color by a given percentage.
 
Color blend (const Color &color) const
 Blend two colors together using alpha blending.
 
Color lerp (const Color &color, float t) const
 Mix towards another color, including alpha.
 
Color invert () const
 Invert a color.
 
Color grayscale () const
 Convert a color to grayscale.
 
Color with_alpha (uint8_t alpha) const
 Adjust the alpha of a color.
 

Static Public Member Functions

static uint8_t to_channel (float value)
 Round a 0-255 channel value and clamp it into range. Casting an out of range float straight to uint8_t is undefined.
 
static Color from_float (float r, float g, float b, float a=1.0F)
 From float RGBA values (0.0-1.0) to Color.
 
static Color from_hex (const std::string &hex)
 From a hex string (e.g. "#RRGGBBAA") to a Color.
 

Public Attributes

uint8_t r
 
uint8_t g
 
uint8_t b
 
uint8_t a
 

Detailed Description

RGBA color struct with 8-bit channels.

Definition at line 18 of file color.h.

Constructor & Destructor Documentation

◆ Color() [1/2]

asw::Color::Color ( )
inline

Construct a default Color (black, fully opaque).

Definition at line 36 of file color.h.

◆ Color() [2/2]

asw::Color::Color ( uint8_t r,
uint8_t g,
uint8_t b,
uint8_t a = 255 )
inline

Construct a Color from RGBA values.

Parameters
rRed channel (0-255).
gGreen channel (0-255).
bBlue channel (0-255).
aAlpha channel (0-255, default 255).

Definition at line 51 of file color.h.

Member Function Documentation

◆ blend()

Color asw::Color::blend ( const Color & color) const
inline

Blend two colors together using alpha blending.

Parameters
colorThe color to blend with.
Returns
The blended color.

Definition at line 138 of file color.h.

◆ darken()

Color asw::Color::darken ( float percentage) const
inline

Darken a color by a given percentage.

Parameters
percentageThe percentage to darken (0.0-1.0).
Returns
The darkened color.

Definition at line 128 of file color.h.

◆ from_float()

static Color asw::Color::from_float ( float r,
float g,
float b,
float a = 1.0F )
inlinestatic

From float RGBA values (0.0-1.0) to Color.

Parameters
rRed channel (0.0-1.0).
gGreen channel (0.0-1.0).
bBlue channel (0.0-1.0).
aAlpha channel (0.0-1.0, default 1.0).
Returns
The equivalent Color.

Definition at line 67 of file color.h.

◆ from_hex()

static Color asw::Color::from_hex ( const std::string & hex)
inlinestatic

From a hex string (e.g. "#RRGGBBAA") to a Color.

Parameters
hexThe hex string to convert.
Returns
The equivalent Color.

Definition at line 88 of file color.h.

◆ grayscale()

Color asw::Color::grayscale ( ) const
inline

Convert a color to grayscale.

Parameters
colorThe color to convert.

Definition at line 171 of file color.h.

◆ invert()

Color asw::Color::invert ( ) const
inline

Invert a color.

Returns
The inverted color.

Definition at line 162 of file color.h.

◆ lerp()

Color asw::Color::lerp ( const Color & color,
float t ) const
inline

Mix towards another color, including alpha.

Parameters
colorThe color to mix towards.
tHow far to mix (0.0-1.0). 0 gives this color, 1 gives color.
Returns
The mixed color.

Definition at line 152 of file color.h.

◆ lighten()

Color asw::Color::lighten ( float percentage) const
inline

Lighten a color by a given percentage.

Parameters
percentageThe percentage to lighten (0.0-1.0).
Returns
The lightened color.

Definition at line 117 of file color.h.

◆ to_channel()

static uint8_t asw::Color::to_channel ( float value)
inlinestatic

Round a 0-255 channel value and clamp it into range. Casting an out of range float straight to uint8_t is undefined.

Parameters
valueThe channel value.
Returns
The channel as a byte.

Definition at line 25 of file color.h.

◆ to_fcolor()

FColor asw::Color::to_fcolor ( ) const
inline

To a float colour, with each channel from 0.0 to 1.0.

Returns
The equivalent FColor.

Definition at line 77 of file color.h.

◆ with_alpha()

Color asw::Color::with_alpha ( uint8_t alpha) const
inline

Adjust the alpha of a color.

Parameters
colorThe color to adjust.
alphaThe new alpha value (0-255).
Returns
The color with the adjusted alpha.

Definition at line 182 of file color.h.

Member Data Documentation

◆ a

uint8_t asw::Color::a

Definition at line 33 of file color.h.

◆ b

uint8_t asw::Color::b

Definition at line 32 of file color.h.

◆ g

uint8_t asw::Color::g

Definition at line 31 of file color.h.

◆ r

uint8_t asw::Color::r

Definition at line 30 of file color.h.


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