Files
mcolor/include/Color3.hpp

42 lines
1.3 KiB
C++

#pragma once
#include <string>
#include <cstdint>
using u8 = uint8_t;
/// Represents a 3-channel color value, with Red, Green and Blue components.
class Color3 {
public:
u8 r; // Red value 0-255
u8 g; // Green value 0-255
u8 b; // Blue value 0-255
public:
/// Explicitly constructs a Color3 from the given Red, Green, and Blue values.
Color3(u8 R, u8 G, u8 B);
/// Returns a Color3 parsed from the given hexadecimal string.
static Color3 FromHex(const std::string& hexCode);
static Color3 FromHSL(u8 hue, u8 saturation, u8 lightness);
Color3() = default;
public:
/// Returns a Color3 that is somewhere in-between this and the given Color3, determined by the alpha [0-1].
Color3 Lerp(const Color3& rhs, float t) const;
/// Returns the red channel [0-255].
u8 RedChannel () const;
/// Returns the green channel [0-255].
u8 GreenChannel() const;
/// Returns the blue channel [0-255].
u8 BlueChannel () const;
/// Returns the red channel normalized from [0-255] to [0-1].
float RedChannelNormalized () const;
/// Returns the green channel normalized from [0-255] to [0-1].
float GreenChannelNormalized() const;
/// Returns the blue channel normalized from [0-255] to [0-1].
float BlueChannelNormalized() const;
u8* ptr();
[[nodiscard]] const u8* ptr() const;
};