PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
pixelbullet::Color Class Reference

A polished Color class storing RGBA values in a glm::vec4. More...

#include <color.h>

Public Types

enum class  Packing { Rgba , Argb , Rgb }

Public Member Functions

constexpr Color (float r, float g, float b, float a=1.0f) noexcept
 Constructs a Color from individual float components (0.0f to 1.0f).
constexpr Color (uint32_t i, Packing packing=Packing::Rgb)
 Constructs a Color from a packed 32-bit integer. The 'packing' parameter defines the component order.
 Color (std::string hex, float a=1.0f)
 Constructs a Color from a hexadecimal string (e.g. "#FF00FF").
constexpr Color lerp (const Color &other, float t) const noexcept
 Returns a color that is the linear interpolation between this and another color.
Color normalized () const
 Normalizes this color (treating it as a 4D vector).
constexpr float length_squared () const noexcept
 Returns the squared length of the color vector.
float length () const noexcept
 Returns the length of the color vector.
constexpr uint32_t packed (Packing packing=Packing::Rgba) const
 Returns the packed 32-bit integer representation.
std::string to_hex () const
 Returns the hexadecimal string representation (e.g. "#FF00FF").
constexpr float operator[] (uint32_t i) const noexcept
 Component access (0: red, 1: green, 2: blue, 3: alpha).
constexpr float & operator[] (uint32_t i)
constexpr bool operator== (const Color &rhs) const noexcept
constexpr bool operator!= (const Color &rhs) const noexcept
constexpr Color & operator+= (const Color &rhs) noexcept
constexpr Color & operator-= (const Color &rhs) noexcept
constexpr Color & operator*= (const Color &rhs) noexcept
constexpr Color & operator/= (const Color &rhs) noexcept
constexpr Color & operator+= (float rhs) noexcept
constexpr Color & operator-= (float rhs) noexcept
constexpr Color & operator*= (float rhs) noexcept
constexpr Color & operator/= (float rhs) noexcept

Static Public Attributes

static const Color clear = Color(0x00000000, Color::Packing::Rgba)
static const Color black = Color(0x000000FF, Color::Packing::Rgba)
static const Color grey = Color(0x808080, Color::Packing::Rgb)
static const Color silver = Color(0xC0C0C0, Color::Packing::Rgb)
static const Color white = Color(0xFFFFFF, Color::Packing::Rgb)
static const Color maroon = Color(0x800000, Color::Packing::Rgb)
static const Color red = Color(0xFF0000, Color::Packing::Rgb)
static const Color olive = Color(0x808000, Color::Packing::Rgb)
static const Color yellow = Color(0xFFFF00, Color::Packing::Rgb)
static const Color green = Color(0x008000, Color::Packing::Rgb)
static const Color lime = Color(0x00FF00, Color::Packing::Rgb)
static const Color teal = Color(0x008080, Color::Packing::Rgb)
static const Color aqua = Color(0x00FFFF, Color::Packing::Rgb)
static const Color navy = Color(0x000080, Color::Packing::Rgb)
static const Color blue = Color(0x0000FF, Color::Packing::Rgb)
static const Color purple = Color(0x800080, Color::Packing::Rgb)
static const Color fuchsia = Color(0xFF00FF, Color::Packing::Rgb)

Friends

constexpr Color operator+ (const Color &lhs, const Color &rhs) noexcept
constexpr Color operator- (const Color &lhs, const Color &rhs) noexcept
constexpr Color operator* (const Color &lhs, const Color &rhs) noexcept
constexpr Color operator/ (const Color &lhs, const Color &rhs) noexcept
constexpr Color operator* (float lhs, const Color &rhs) noexcept
constexpr Color operator* (const Color &lhs, float rhs) noexcept
constexpr Color operator/ (const Color &lhs, float rhs) noexcept
constexpr Color operator+ (const Color &lhs, float rhs) noexcept
constexpr Color operator- (const Color &lhs, float rhs) noexcept
const Nodeoperator>> (const Node &node, Color &color)
Nodeoperator<< (Node &node, const Color &color)

Detailed Description

A polished Color class storing RGBA values in a glm::vec4.

Constructor & Destructor Documentation

◆ Color() [1/3]

pixelbullet::Color::Color ( float r,
float g,
float b,
float a = 1.0f )
inlineconstexprnoexcept

Constructs a Color from individual float components (0.0f to 1.0f).

◆ Color() [2/3]

pixelbullet::Color::Color ( uint32_t i,
Packing packing = Packing::Rgb )
inlineconstexpr

Constructs a Color from a packed 32-bit integer. The 'packing' parameter defines the component order.

◆ Color() [3/3]

pixelbullet::Color::Color ( std::string hex,
float a = 1.0f )
inlineexplicit

Constructs a Color from a hexadecimal string (e.g. "#FF00FF").

Member Function Documentation

◆ length()

float pixelbullet::Color::length ( ) const
inlinenoexcept

Returns the length of the color vector.

◆ length_squared()

float pixelbullet::Color::length_squared ( ) const
inlineconstexprnoexcept

Returns the squared length of the color vector.

◆ lerp()

Color pixelbullet::Color::lerp ( const Color & other,
float t ) const
inlineconstexprnoexcept

Returns a color that is the linear interpolation between this and another color.

◆ normalized()

Color pixelbullet::Color::normalized ( ) const
inline

Normalizes this color (treating it as a 4D vector).

◆ operator[]()

float pixelbullet::Color::operator[] ( uint32_t i) const
inlineconstexprnoexcept

Component access (0: red, 1: green, 2: blue, 3: alpha).

◆ packed()

uint32_t pixelbullet::Color::packed ( Packing packing = Packing::Rgba) const
inlineconstexpr

Returns the packed 32-bit integer representation.

◆ to_hex()

std::string pixelbullet::Color::to_hex ( ) const
inline

Returns the hexadecimal string representation (e.g. "#FF00FF").


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