4#include <bugui/concepts/color.hpp>
13template <
typename Value_t>
16 using color_value_t = Value_t;
25 return other == original;
30 return other != original;
34 Value_t
get()
const {
return value; }
37 {
return original.get_state(); }
53template <
typename T,
typename Value_t = u
int8_t>
58 color_converter() =
default;
60 ~color_converter() =
default;
64 if (this->original ==
color)
return;
66 this->original =
color;
67 auto c{this->original.get()};
69 float factor{
static_cast<float>(c[3] / 255)};
70 uint8_t r = c[0] * factor;
71 uint8_t g = c[1] * factor;
72 uint8_t b = c[2] * factor;
73 int min_d{std::numeric_limits<int>::max()};
78 for (
const auto& [rgb, val] : palette<T>::value)
83 auto d = dr*dr + dg*dg + db*db;
94 this->value = clear_value;
95 this->original.clear();
100 return this->original.is_clear()
101 && this->value == clear_value;
104 static const Value_t clear_value;
107template <
typename T,
typename Value_t>
108 requires (has_color_palette<T> && integral_no_bool<Value_t>)
109inline const Value_t color_converter<T, Value_t>::clear_value
110 {color_converter<T, Value_t>({0, 0, 0}).get()};
115struct color_converter<T, color::rgba>
121 value = original.
get();
135 return original.is_clear()
142 static const color::rgba clear_value;
146 requires (!has_color_palette<T>)
147inline const color::rgba color_converter<T, color::rgba>
148 ::clear_value{0, 0, 0};
154struct color_converter<T, uint8_t>
159 if (original ==
color)
return;
162 auto c{original.get()};
164 float factor{
static_cast<float>(c[3] / 255)};
165 uint8_t r = c[0] * factor;
166 uint8_t g = c[1] * factor;
167 uint8_t b = c[2] * factor;
171 value = 0.299 * r + 0.587 * g + 0.114 * b;
182 return original.is_clear()
183 && value == clear_value;
186 static const uint8_t clear_value;
190 requires (!has_color_palette<T>)
191inline const uint8_t color_converter<T, uint8_t>::clear_value
192 {color_converter<T, uint8_t>({0, 0, 0}).get()};
Provides base functionalities for converting color objects to devices specific colour values.
Definition color_converter.hpp:15
color::states get_state() const
Retrives the current state.
Definition color_converter.hpp:36
virtual bool is_clear()=0
Checks that the original and device specific colour are set to their initial value.
Value_t get() const
Retrives the main device specific colour value.
Definition color_converter.hpp:34
bool operator==(const color &other) const
Determines equality between the original color and another.
Definition color_converter.hpp:23
virtual void clear()=0
Resets the original and the device specific colour to their initial value.
virtual void set(const color &color)=0
Sets the original color.
void clear() override
Resets the original and the device specific colour to their initial value.
Definition color_converter.hpp:124
void set(const color &color) override
Sets the original color.
Definition color_converter.hpp:118
bool is_clear() override
Checks that the original and device specific colour are set to their initial value.
Definition color_converter.hpp:133
void clear() override
Resets the original and the device specific colour to their initial value.
Definition color_converter.hpp:174
bool is_clear() override
Checks that the original and device specific colour are set to their initial value.
Definition color_converter.hpp:180
void set(const color &color) override
Sets the original color.
Definition color_converter.hpp:157
void clear() override
Resets the original and the device specific colour to their initial value.
Definition color_converter.hpp:92
bool is_clear() override
Checks that the original and device specific colour are set to their initial value.
Definition color_converter.hpp:98
void set(const color &color) override
Sets the original color.
Definition color_converter.hpp:62
Generic colour class holding RGBA coloour values. The blinking and pulsing states indicate discrete o...
Definition color.hpp:14
states
Definition color.hpp:18
rgba get() const noexcept
Retrieves the primary colour as rgba values.
Definition color.hpp:53