Implement cout support for Color4, and some other minor utility.

This commit is contained in:
2025-05-22 22:34:22 -05:00
parent d8d6ad5edc
commit 18289d321c
2 changed files with 26 additions and 3 deletions

View File

@@ -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;
}