Struct Color

Struct Documentation

struct Color

Store for a floating point rgba color Each component should be in the inclusive range [0, 1] in-order for the color to be considered valid

Public Functions

inline Color()

Default constructor, initialises to white

inline Color(float _r, float _g, float _b, float _a = 1.0f)

Construct a color with red, green, blue (and alpha) components Each component should be in the range [0, 1]

inline Color(double _r, double _g, double _b, double _a = 1.0)
inline Color(int _r, int _g, int _b, int _a = 255)

Construct a color with red, green, blue (and alpha) components Each component should be in the range [0, 255]

inline explicit Color(const std::array<float, 3> &rgb)

Construct a color with red, green and blue components Each component should be in the range [0, 1]

inline explicit Color(const std::array<float, 4> &rgba)

Construct a color with red, green, blue and alpha components Each component should be in the range [0, 1]

inline explicit Color(const std::array<int, 3> &rgb)

Construct a color with red, green and blue components Each component should be in the range [0, 255]

inline explicit Color(const std::array<int, 4> &rgba)

Construct a color with red, green, blue and alpha components Each component should be in the range [0, 255]

inline explicit Color(const char *hex)

Construct a color from a hexcode Supported formats: #abcdef #abc abcdef abc

Throws:

exception::InvalidArgument – If parsing fails

inline Color &operator=(const char *hex)

Construct a color from a hexcode Supported formats: #abcdef #abc abcdef abc

Throws:

exception::InvalidArgument – If parsing fails

inline float &operator[](unsigned int index)

Access the color component at index

inline float operator[](unsigned int index) const

Access the color component at index

inline bool validate() const

Return true if all color components are in the inclusive range [0.0, 1.0]

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

Equality operator

Note

It performs equality comparison on floats, this isn’t too useful as very similar floats can be deemed different

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

Inequality operator

Note

It performs equality comparison on floats, this isn’t too useful as very similar floats can be deemed different

inline Color operator+(const Color &other) const noexcept

Add the components of 2 colors

inline Color operator*(const float &i) const noexcept

Multiple the components of a color by i

operator StaticColor() const

Implicit conversion function, allowing Color to be implicitly converted to StaticColor Defined in StaticColor.cpp

Public Members

float r

Color components: red, green, blue, alpha

float g
float b
float a