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.
 
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 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 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 11 of file color.h.

Constructor & Destructor Documentation

◆ Color() [1/2]

asw::Color::Color ( )
inline

Construct a default Color (black, fully opaque).

Definition at line 18 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 33 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 104 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 93 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 49 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 60 of file color.h.

◆ grayscale()

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

Convert a color to grayscale.

Parameters
colorThe color to convert.

Definition at line 124 of file color.h.

◆ invert()

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

Invert a color.

Returns
The inverted color.

Definition at line 115 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 82 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 135 of file color.h.

Member Data Documentation

◆ a

uint8_t asw::Color::a

Definition at line 15 of file color.h.

◆ b

uint8_t asw::Color::b

Definition at line 14 of file color.h.

◆ g

uint8_t asw::Color::g

Definition at line 13 of file color.h.

◆ r

uint8_t asw::Color::r

Definition at line 12 of file color.h.


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