Implement cout support for Color4, and some other minor utility.
This commit is contained in:
@@ -23,7 +23,8 @@ void print_builtin_color_list();
|
||||
/// A type representing a color with alpha.
|
||||
/// Our default format is RGBA with 8 bits-per-channel.
|
||||
/// Conversions to other color formats are provided.
|
||||
class Color4 {
|
||||
class Color4
|
||||
{
|
||||
public:
|
||||
u8 r;
|
||||
u8 g;
|
||||
@@ -83,6 +84,7 @@ public:
|
||||
static Color4 FromLCH(float l, float c, float h, float alpha = 1.f);
|
||||
public:
|
||||
|
||||
/// Performs the interpolation in normalized color space (0-1) and converts it back.
|
||||
[[nodiscard]] Color4 Lerp(const Color4& rhs, float t) const;
|
||||
static Color4 Lerp(const Color4& lhs, const Color4& rhs, float t);
|
||||
|
||||
@@ -136,4 +138,12 @@ public:
|
||||
[[nodiscard]] std::string BGEscapeCode(bool bold = false);
|
||||
|
||||
|
||||
bool operator==(const Color4& rhs) const;
|
||||
|
||||
bool operator!=(const Color4& rhs) const;
|
||||
};
|
||||
|
||||
inline std::ostream& operator << (std::ostream& os, const Color4& c) {
|
||||
os << "Color4(" << c.r << "," << c.g << "," << c.b << "," << c.a << ") AKA " << c.ToHex();
|
||||
return os;
|
||||
}
|
@@ -182,7 +182,7 @@ Color4 Color4::FromNormalized(float red, float green, float blue, float alpha) {
|
||||
|
||||
Color4 Color4::Lerp(const Color4 &rhs, float t) const {
|
||||
|
||||
/// Performs the interpolation in normalized color space (0-1) and converts it back.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -342,6 +342,19 @@ std::string Color4::BGEscapeCode(bool bold) {
|
||||
return EscapeCode(true, bold);
|
||||
}
|
||||
|
||||
bool Color4::operator==(const Color4& rhs) const
|
||||
{
|
||||
return r == rhs.r
|
||||
&& g == rhs.g
|
||||
&& b == rhs.b
|
||||
&& a == rhs.a;
|
||||
}
|
||||
|
||||
bool Color4::operator!=(const Color4& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
static std::string decimal_to_hex(int dec)
|
||||
{
|
||||
if (dec < 1) return "00";
|
||||
|
Reference in New Issue
Block a user