guillaume 1.0.0
Guillaume is a component-based UI framework library built around a primitive rendering system. It's designed for building user interfaces across XR platforms and traditional platforms with custom rendering backends and input handling. The framework is lightweight, flexible, and easy to integrate into existing projects.
Loading...
Searching...
No Matches
Color Class Reference

Represents an RGBA color with floating-point channels in [0, 1]. More...

#include <color.hpp>

Classes

struct  RGBA8
 8-bit RGBA packed representation. More...
 

Public Member Functions

 Color (void)
 Construct a fully-opaque black color (0,0,0,1).
 
 Color (float r, float g, float b)
 Construct from RGB, alpha defaults to 1.0.
 
 Color (float r, float g, float b, float a)
 Construct from RGBA.
 
float r (void) const
 Red component in [0,1].
 
float g (void) const
 Green component in [0,1].
 
float b (void) const
 Blue component in [0,1].
 
float a (void) const
 Alpha component in [0,1].
 
void setR (float v)
 Setters (values are clamped to [0,1]).
 
void setG (float v)
 Set green component.
 
void setB (float v)
 Set blue component.
 
void setA (float v)
 Set alpha component.
 
Color withAlpha (float alpha) const
 Return a copy with a different alpha (keeps RGB).
 
Color lerp (const Color &to, float t) const
 Linear interpolation between two colors (component-wise).
 
Color premultiplied () const
 Premultiplied alpha representation.
 
Color over (const Color &bg) const
 Alpha blend this color over a background color. Uses standard source-over compositing in linear space.
 
RGBA8 toRGBA8 () const
 Convert to 8-bit per channel RGBA.
 
std::string toHex (bool includeAlphaIfOpaque=false) const
 Convert to hexadecimal string. Formats as "#RRGGBB" if a==1 else "#RRGGBBAA".
 
bool operator== (const Color &other) const
 Equality operators (exact component-wise equality).
 
bool operator!= (const Color &other) const
 Inequality operator.
 
Color operator+ (const Color &o) const
 Component-wise addition (clamped).
 
Color operator- (const Color &o) const
 Component-wise subtraction (clamped to [0,1]).
 
Color operator* (float s) const
 Scalar multiplication (scales RGB; alpha unchanged by default).
 

Static Public Member Functions

static Color fromRGBA8 (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Create from 8-bit per channel RGBA values.
 
static Color fromHex (const std::string &hex)
 Parse from hexadecimal string.
 
static Color Black ()
 Common named colors (opaque unless specified).
 
static Color White ()
 Opaque white (1,1,1,1)
 
static Color Red ()
 Opaque red (1,0,0,1)
 
static Color Green ()
 Opaque green (0,1,0,1)
 
static Color Blue ()
 Opaque blue (0,0,1,1)
 
static Color Transparent ()
 Fully transparent black (0,0,0,0)
 

Detailed Description

Represents an RGBA color with floating-point channels in [0, 1].

The Color class stores red, green, blue, and alpha components as floats clamped to the [0,1] range. It provides convenient constructors, conversion utilities to and from 8-bit channel values and hexadecimal strings, as well as basic color operations.

Definition at line 42 of file color.hpp.

Constructor & Destructor Documentation

◆ Color() [1/3]

Color::Color ( void  )
inline

Construct a fully-opaque black color (0,0,0,1).

Definition at line 57 of file color.hpp.

Here is the caller graph for this function:

◆ Color() [2/3]

Color::Color ( float  r,
float  g,
float  b 
)
inline

Construct from RGB, alpha defaults to 1.0.

Definition at line 62 of file color.hpp.

◆ Color() [3/3]

Color::Color ( float  r,
float  g,
float  b,
float  a 
)
inline

Construct from RGBA.

Definition at line 68 of file color.hpp.

Member Function Documentation

◆ a()

float Color::a ( void  ) const
inline

Alpha component in [0,1].

Definition at line 86 of file color.hpp.

Here is the caller graph for this function:

◆ b()

float Color::b ( void  ) const
inline

Blue component in [0,1].

Definition at line 82 of file color.hpp.

Here is the caller graph for this function:

◆ Black()

static Color Color::Black ( )
inlinestatic

Common named colors (opaque unless specified).

Opaque black (0,0,0,1)

Definition at line 294 of file color.hpp.

Here is the call graph for this function:

◆ Blue()

static Color Color::Blue ( )
inlinestatic

Opaque blue (0,0,1,1)

Definition at line 302 of file color.hpp.

Here is the call graph for this function:

◆ fromHex()

static Color Color::fromHex ( const std::string &  hex)
inlinestatic

Parse from hexadecimal string.

Accepts formats (leading '#' is optional):

  • RGB
  • RRGGBB
  • RGBA
  • RRGGBBAA

Throws std::invalid_argument on invalid format.

Definition at line 214 of file color.hpp.

Here is the call graph for this function:

◆ fromRGBA8()

static Color Color::fromRGBA8 ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)
inlinestatic

Create from 8-bit per channel RGBA values.

Definition at line 180 of file color.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ g()

float Color::g ( void  ) const
inline

Green component in [0,1].

Definition at line 78 of file color.hpp.

Here is the caller graph for this function:

◆ Green()

static Color Color::Green ( )
inlinestatic

Opaque green (0,1,0,1)

Definition at line 300 of file color.hpp.

Here is the call graph for this function:

◆ lerp()

Color Color::lerp ( const Color to,
float  t 
) const
inline

Linear interpolation between two colors (component-wise).

Parameters
toTarget color
tInterpolation factor in [0,1]

Definition at line 122 of file color.hpp.

Here is the call graph for this function:

◆ operator!=()

bool Color::operator!= ( const Color other) const
inline

Inequality operator.

Returns
true if any component differs, false otherwise.

Definition at line 265 of file color.hpp.

◆ operator*()

Color Color::operator* ( float  s) const
inline

Scalar multiplication (scales RGB; alpha unchanged by default).

Definition at line 286 of file color.hpp.

Here is the call graph for this function:

◆ operator+()

Color Color::operator+ ( const Color o) const
inline

Component-wise addition (clamped).

Definition at line 270 of file color.hpp.

Here is the call graph for this function:

◆ operator-()

Color Color::operator- ( const Color o) const
inline

Component-wise subtraction (clamped to [0,1]).

Definition at line 278 of file color.hpp.

Here is the call graph for this function:

◆ operator==()

bool Color::operator== ( const Color other) const
inline

Equality operators (exact component-wise equality).

Definition at line 258 of file color.hpp.

◆ over()

Color Color::over ( const Color bg) const
inline

Alpha blend this color over a background color. Uses standard source-over compositing in linear space.

Definition at line 138 of file color.hpp.

Here is the call graph for this function:

◆ premultiplied()

Color Color::premultiplied ( ) const
inline

Premultiplied alpha representation.

Returns
Color where rgb are multiplied by alpha, alpha unchanged.

Definition at line 132 of file color.hpp.

Here is the call graph for this function:

◆ r()

float Color::r ( void  ) const
inline

Red component in [0,1].

Definition at line 74 of file color.hpp.

Here is the caller graph for this function:

◆ Red()

static Color Color::Red ( )
inlinestatic

Opaque red (1,0,0,1)

Definition at line 298 of file color.hpp.

Here is the call graph for this function:

◆ setA()

void Color::setA ( float  v)
inline

Set alpha component.

Parameters
vAlpha value, clamped to [0,1]

Definition at line 110 of file color.hpp.

◆ setB()

void Color::setB ( float  v)
inline

Set blue component.

Parameters
vBlue value, clamped to [0,1]

Definition at line 105 of file color.hpp.

◆ setG()

void Color::setG ( float  v)
inline

Set green component.

Parameters
vGreen value, clamped to [0,1]

Definition at line 100 of file color.hpp.

◆ setR()

void Color::setR ( float  v)
inline

Setters (values are clamped to [0,1]).

Set red component.

Parameters
vRed value, clamped to [0,1]

Definition at line 95 of file color.hpp.

◆ toHex()

std::string Color::toHex ( bool  includeAlphaIfOpaque = false) const
inline

Convert to hexadecimal string. Formats as "#RRGGBB" if a==1 else "#RRGGBBAA".

Definition at line 191 of file color.hpp.

Here is the call graph for this function:

◆ toRGBA8()

RGBA8 Color::toRGBA8 ( ) const
inline

Convert to 8-bit per channel RGBA.

Returns
An RGBA8 struct containing channels in 0..255.

Definition at line 169 of file color.hpp.

Here is the caller graph for this function:

◆ Transparent()

static Color Color::Transparent ( )
inlinestatic

Fully transparent black (0,0,0,0)

Definition at line 304 of file color.hpp.

Here is the call graph for this function:

◆ White()

static Color Color::White ( )
inlinestatic

Opaque white (1,1,1,1)

Definition at line 296 of file color.hpp.

Here is the call graph for this function:

◆ withAlpha()

Color Color::withAlpha ( float  alpha) const
inline

Return a copy with a different alpha (keeps RGB).

Definition at line 115 of file color.hpp.

Here is the call graph for this function:

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