SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Math::Color Class Reference

#include <Color.hpp>

Public Member Functions

constexpr Color ()=default
constexpr Color (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255) noexcept
constexpr Color clamped () const noexcept
 Clamps every channel into [0, 255].
uint8_t GetA () const
uint8_t GetB () const
uint8_t GetG () const
uint8_t GetR () const
Color linearToSrgb () const noexcept
Vector4D normalize () const noexcept
 Converts to a Vector4D with each channel in [0,1].
constexpr bool operator!= (const Color &other) const noexcept
constexpr Color operator* (float scalar) const noexcept
constexpr Color operator+ (const Color &other) const noexcept
constexpr bool operator== (const Color &other) const noexcept
Color premultiplied () const noexcept
 Scales RGB by alpha, for premultiplied-alpha blending.
Color srgbToLinear () const noexcept
std::string toString () const
constexpr Color withAlpha (uint8_t newAlpha) const noexcept
 Returns a copy with alpha replaced.

Static Public Member Functions

static Color fromHex (uint32_t hex) noexcept
 Builds a color from a 0xRRGGBB or 0xAARRGGBB packed value.
static Color fromHSV (float h, float s, float v, uint8_t a=255) noexcept
 Builds a color from hue/saturation/value in [0,1].

Static Public Attributes

static const Color Black
static const Color Blue
static const Color Green
static const Color Red
static const Color Transparent
static const Color White

Detailed Description

8-bit RGBA color. Value type, cheap to pass and store on vertices/UI.

Definition at line 16 of file Color.hpp.

Constructor & Destructor Documentation

◆ Color() [1/2]

Sleak::Math::Color::Color ( )
constexprdefault

◆ Color() [2/2]

Sleak::Math::Color::Color ( uint8_t r,
uint8_t g,
uint8_t b,
uint8_t a = 255 )
inlineconstexprnoexcept

Definition at line 26 of file Color.hpp.

Member Function Documentation

◆ clamped()

Color Sleak::Math::Color::clamped ( ) const
inlinenodiscardconstexprnoexcept

Clamps every channel into [0, 255].

Definition at line 30 of file Color.hpp.

◆ fromHex()

Color Sleak::Math::Color::fromHex ( uint32_t hex)
staticnodiscardnoexcept

Builds a color from a 0xRRGGBB or 0xAARRGGBB packed value.

Definition at line 84 of file Color.cpp.

◆ fromHSV()

Color Sleak::Math::Color::fromHSV ( float h,
float s,
float v,
uint8_t a = 255 )
staticnodiscardnoexcept

Builds a color from hue/saturation/value in [0,1].

Definition at line 56 of file Color.cpp.

◆ GetA()

uint8_t Sleak::Math::Color::GetA ( ) const
inline

Definition at line 90 of file Color.hpp.

◆ GetB()

uint8_t Sleak::Math::Color::GetB ( ) const
inline

Definition at line 89 of file Color.hpp.

◆ GetG()

uint8_t Sleak::Math::Color::GetG ( ) const
inline

Definition at line 88 of file Color.hpp.

◆ GetR()

uint8_t Sleak::Math::Color::GetR ( ) const
inline

Definition at line 87 of file Color.hpp.

◆ linearToSrgb()

Color Sleak::Math::Color::linearToSrgb ( ) const
nodiscardnoexcept

Definition at line 22 of file Color.cpp.

◆ normalize()

Vector4D Sleak::Math::Color::normalize ( ) const
inlinenodiscardnoexcept

Converts to a Vector4D with each channel in [0,1].

Definition at line 93 of file Color.hpp.

◆ operator!=()

bool Sleak::Math::Color::operator!= ( const Color & other) const
inlineconstexprnoexcept

Definition at line 65 of file Color.hpp.

◆ operator*()

Color Sleak::Math::Color::operator* ( float scalar) const
inlineconstexprnoexcept

Definition at line 76 of file Color.hpp.

◆ operator+()

Color Sleak::Math::Color::operator+ ( const Color & other) const
inlineconstexprnoexcept

Definition at line 69 of file Color.hpp.

◆ operator==()

bool Sleak::Math::Color::operator== ( const Color & other) const
inlineconstexprnoexcept

Definition at line 61 of file Color.hpp.

◆ premultiplied()

Color Sleak::Math::Color::premultiplied ( ) const
nodiscardnoexcept

Scales RGB by alpha, for premultiplied-alpha blending.

Definition at line 13 of file Color.cpp.

◆ srgbToLinear()

Color Sleak::Math::Color::srgbToLinear ( ) const
nodiscardnoexcept

Definition at line 39 of file Color.cpp.

◆ toString()

std::string Sleak::Math::Color::toString ( ) const
inlinenodiscard

Definition at line 54 of file Color.hpp.

◆ withAlpha()

Color Sleak::Math::Color::withAlpha ( uint8_t newAlpha) const
inlinenodiscardconstexprnoexcept

Returns a copy with alpha replaced.

Definition at line 38 of file Color.hpp.

Member Data Documentation

◆ Black

const Color Sleak::Math::Color::Black
static

Definition at line 22 of file Color.hpp.

◆ Blue

const Color Sleak::Math::Color::Blue
static

Definition at line 20 of file Color.hpp.

◆ Green

const Color Sleak::Math::Color::Green
static

Definition at line 19 of file Color.hpp.

◆ Red

const Color Sleak::Math::Color::Red
static

Definition at line 18 of file Color.hpp.

◆ Transparent

const Color Sleak::Math::Color::Transparent
static

Definition at line 23 of file Color.hpp.

◆ White

const Color Sleak::Math::Color::White
static

Definition at line 21 of file Color.hpp.