32 if(fields.size() != 3 && fields.size() != 4) {
33 throw std::invalid_argument(
"Wrong number of components for RGBA color");
37 *utils::from_chars<uint8_t>(fields[0]),
38 *utils::from_chars<uint8_t>(fields[1]),
39 *utils::from_chars<uint8_t>(fields[2]),
40 fields.size() == 4 ? *utils::from_chars<uint8_t>(fields[3]) :
ALPHA_OPAQUE
52 if(fields.size() != 3) {
53 throw std::invalid_argument(
"Wrong number of components for RGB color");
57 *utils::from_chars<uint8_t>(fields[0]),
58 *utils::from_chars<uint8_t>(fields[1]),
59 *utils::from_chars<uint8_t>(fields[2]),
67 throw std::invalid_argument(
"Color hex string should be exactly 6 digits");
70 if(std::any_of(
c.begin(),
c.end(), [](
const char& ch) { return std::isxdigit(ch) == 0; })) {
71 throw std::invalid_argument(
"Color hex string contains invalid characters");
74 auto temp_c = *utils::from_chars<uint32_t>(
c, 16);
77 static_cast<uint8_t
>((0x00FFFFFF & temp_c) >> 16),
78 static_cast<uint8_t
>((0x00FFFFFF & temp_c) >> 8),
79 static_cast<uint8_t
>((0x00FFFFFF & temp_c)),
89 << std::hex << std::setfill(
'0')
90 << std::setw(2) <<
static_cast<int>(r)
91 << std::setw(2) <<
static_cast<int>(
g)
92 << std::setw(2) <<
static_cast<int>(
b);
95 h << std::setw(2) << static_cast<int>(
a);
103 std::ostringstream color;
105 color << static_cast<int>(r) <<
','
106 <<
static_cast<int>(
g) <<
','
107 <<
static_cast<int>(
b) <<
','
108 <<
static_cast<int>(
a);
115 std::ostringstream color;
117 color << static_cast<int>(r) <<
','
118 <<
static_cast<int>(
g) <<
','
119 <<
static_cast<int>(
b);
constexpr uint8_t ALPHA_OPAQUE
std::vector< std::string > split(const config_attribute_value &val)
The basic class for representing 8-bit RGB or RGBA colour values.
static color_t from_rgb_string(const std::string &c)
Creates a new opaque color_t object from a string variable in "R,G,B" format.
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
static constexpr color_t null_color()
Definition of a 'null' color - fully transparent black.
std::string to_rgb_string() const
Returns the stored color as an "R,G,B" string.
static color_t from_rgba_string(const std::string &c)
Creates a new color_t object from a string variable in "R,G,B,A" format.
std::string to_rgba_string() const
Returns the stored color as an "R,G,B,A" string.
static color_t from_hex_string(const std::string &c)
Creates a new color_t object from a string variable in hex format.