11#if __has_include(<format>) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 170000)
28 constexpr Rgb(
float red,
float green,
float blue) : red(red), green(green), blue(blue) {
31 constexpr static Rgb u8(uint8_t red, uint8_t green, uint8_t blue) {
32 return Rgb{
static_cast<float>(red) / 255.f,
static_cast<float>(green) / 255.f,
33 static_cast<float>(blue) / 255.f };
70 explicit operator Color()
const;
82[[deprecated(
"Use mix instead")]]
100#if __has_include(<format>) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 170000)
115namespace jngl::internal {
118void invalid_hex_character_in_color_literal();
119void invalid_rgb_color_literal_expected_format_hash_rrggbb();
121consteval uint8_t hexVal(
char c) {
122 if (c >=
'0' && c <=
'9') {
123 return static_cast<uint8_t
>(c -
'0');
125 if (c >=
'a' && c <=
'f') {
126 return static_cast<uint8_t
>(c -
'a' + 10);
128 if (c >=
'A' && c <=
'F') {
129 return static_cast<uint8_t
>(c -
'A' + 10);
131 invalid_hex_character_in_color_literal();
134consteval uint8_t hexByte(
const char* s) {
135 return static_cast<uint8_t
>(hexVal(s[0]) * 16 + hexVal(s[1]));
140consteval jngl::Rgb operator""_rgb(
const char* hex,
size_t length) {
141 using jngl::internal::hexByte;
142 if (length == 7 && hex[0] ==
'#') {
143 return jngl::Rgb::u8(hexByte(hex + 1), hexByte(hex + 3), hexByte(hex + 5));
145 jngl::internal::invalid_rgb_color_literal_expected_format_hash_rrggbb();
Object representing a RGB color.
Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future)
uint8_t getGreen_u8() const
0 ... 255
uint8_t getRed_u8() const
0 ... 255
void setBlue(float)
0.0f ... 1.0f
constexpr float getGreen() const
0.0f ... 1.0f
constexpr float getRed() const
0.0f ... 1.0f
void setRed(float)
0.0f ... 1.0f
void setGreen(float)
0.0f ... 1.0f
constexpr float getBlue() const
0.0f ... 1.0f
Rgb(Color)
Implicit conversion for backwards compatibility.
constexpr Rgb(float red, float green, float blue)
uint8_t getBlue_u8() const
0 ... 255
Color interpolate(Color a, Color b, float t)
Returns a color mix between a (t == 0) and b (t == 1)
Rgb getBackgroundColor()
Returns the screen's background color which is visible when nothing is drawn and also used by jngl::F...
bool operator==(Rgb a, Rgb b)
Returns true if the two colors are equal in 24 bit SDR space, i.e.
Rgb mix(Rgb a, Rgb b, float t)
Returns a color mix between a (t == 0) and b (t == 1)
std::ostream & operator<<(std::ostream &os, Rgb color)
Prints the color as jngl::Rgb{ red, green, blue }