Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Color Struct Reference

RGBA color utility storing normalized floating components. More...

#include <spk_color.hpp>

Collaboration diagram for spk::Color:
Collaboration graph

Public Member Functions

 Color ()
 Builds an opaque black color.
 Color (int p_value)
 Builds a grayscale color from an 8-bit value.
 Color (int p_r, int p_g, int p_b, int p_a=255)
 Builds a color from 8-bit per channel components.
 Color (float p_r, float p_g, float p_b, float p_a=1.0f)
 Builds a color from normalized floating values.
Color operator+ (const Color &p_other) const
 Adds channel values component-wise.
Color operator- (const Color &p_other) const
 Subtracts channel values component-wise.
bool operator== (const Color &p_other) const
 Equality comparison on every component.
bool operator!= (const Color &p_other) const
 Inequality comparison on every component.
uint32_t toInt () const
 Packs the color into 0xRRGGBBAA integer format.

Public Attributes

float r
 Red component in [0,1].
float g
 Green component in [0,1].
float b
 Blue component in [0,1].
float a
 Alpha component in [0,1].

Static Public Attributes

static const Color red = Color(0xFF0000FF)
 Predefined opaque red color.
static const Color blue = Color(0x0000FFFF)
 Predefined opaque blue color.
static const Color green = Color(0x00FF00FF)
 Predefined opaque green color.
static const Color yellow = Color(0xFFFF00FF)
 Predefined opaque yellow color.
static const Color purple = Color(0x7F00FFFF)
 Predefined opaque purple color.
static const Color cyan = Color(0x00FFFFFF)
 Predefined opaque cyan color.
static const Color orange = Color(0xFF8000FF)
 Predefined opaque orange color.
static const Color magenta = Color(0xFF007FFF)
 Predefined opaque magenta color.
static const Color pink = Color(0xFF00FFFF)
 Predefined opaque pink color.
static const Color black = Color(0x000000FF)
 Predefined opaque black color.
static const Color white = Color(0xFFFFFFFF)
 Predefined opaque white color.
static const Color grey = Color(0x7F7F7FFF)
 Predefined opaque grey color.

Friends

std::ostream & operator<< (std::ostream &p_os, const spk::Color &p_other)
 Streams a color to an ASCII output stream.
std::wostream & operator<< (std::wostream &p_os, const spk::Color &p_other)
 Streams a color to a wide-character output stream.

Detailed Description

RGBA color utility storing normalized floating components.

spk::Color tint{0.5f, 0.25f, 0.75f};
auto packed = tint.toInt();
RGBA color utility storing normalized floating components.
Definition spk_color.hpp:18
uint32_t toInt() const
Packs the color into 0xRRGGBBAA integer format.
Definition spk_color.cpp:85

Constructor & Destructor Documentation

◆ Color() [1/3]

spk::Color::Color ( int p_value)

Builds a grayscale color from an 8-bit value.

Parameters
p_valueChannel intensity in [0,255].
Here is the call graph for this function:

◆ Color() [2/3]

spk::Color::Color ( int p_r,
int p_g,
int p_b,
int p_a = 255 )

Builds a color from 8-bit per channel components.

Parameters
p_rRed channel in [0,255].
p_gGreen channel in [0,255].
p_bBlue channel in [0,255].
p_aAlpha channel in [0,255].

◆ Color() [3/3]

spk::Color::Color ( float p_r,
float p_g,
float p_b,
float p_a = 1.0f )

Builds a color from normalized floating values.

Parameters
p_rRed component in [0,1].
p_gGreen component in [0,1].
p_bBlue component in [0,1].
p_aAlpha component in [0,1].

Member Function Documentation

◆ operator!=()

bool spk::Color::operator!= ( const Color & p_other) const

Inequality comparison on every component.

Parameters
p_otherColor to compare.
Returns
true when any channel differs.
Here is the call graph for this function:

◆ operator+()

Color spk::Color::operator+ ( const Color & p_other) const

Adds channel values component-wise.

Parameters
p_otherColor to add.
Returns
Sum of the two colors.
Here is the call graph for this function:

◆ operator-()

Color spk::Color::operator- ( const Color & p_other) const

Subtracts channel values component-wise.

Parameters
p_otherColor to subtract.
Returns
Difference of the two colors.
Here is the call graph for this function:

◆ operator==()

bool spk::Color::operator== ( const Color & p_other) const

Equality comparison on every component.

Parameters
p_otherColor to compare.
Returns
true when all channels match.
Here is the call graph for this function:

◆ toInt()

uint32_t spk::Color::toInt ( ) const

Packs the color into 0xRRGGBBAA integer format.

Returns
Packed 32-bit representation.

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & p_os,
const spk::Color & p_other )
friend

Streams a color to an ASCII output stream.

Parameters
p_osOutput stream receiving the formatted color.
p_otherColor to serialize.
Returns
Reference to the updated stream.

◆ operator<< [2/2]

std::wostream & operator<< ( std::wostream & p_os,
const spk::Color & p_other )
friend

Streams a color to a wide-character output stream.

Parameters
p_osOutput stream receiving the formatted color.
p_otherColor to serialize.
Returns
Reference to the updated stream.

The documentation for this struct was generated from the following files:
  • includes/structure/graphics/spk_color.hpp
  • srcs/structure/graphics/spk_color.cpp