30 if(fields.size() != 3 && fields.size() != 4) {
31 throw std::invalid_argument(
"Wrong number of components for RGBA color");
35 static_cast<uint8_t
>(std::stoul(fields[0])),
36 static_cast<uint8_t
>(std::stoul(fields[1])),
37 static_cast<uint8_t
>(std::stoul(fields[2])),
38 static_cast<uint8_t
>(fields.size() == 4 ? std::stoul(fields[3]) :
ALPHA_OPAQUE)
50 if(fields.size() != 3) {
51 throw std::invalid_argument(
"Wrong number of components for RGB color");
55 static_cast<uint8_t
>(std::stoul(fields[0])),
56 static_cast<uint8_t
>(std::stoul(fields[1])),
57 static_cast<uint8_t
>(std::stoul(fields[2])),
65 throw std::invalid_argument(
"Color hex string should be exactly 6 digits");
68 unsigned long temp_c = std::strtol(
c.c_str(),
nullptr, 16);
71 static_cast<uint8_t
>((0x00FFFFFF & temp_c) >> 16),
72 static_cast<uint8_t
>((0x00FFFFFF & temp_c) >> 8),
73 static_cast<uint8_t
>((0x00FFFFFF & temp_c)),
83 << std::hex << std::setfill(
'0')
84 << std::setw(2) <<
static_cast<int>(r)
85 << std::setw(2) <<
static_cast<int>(
g)
86 << std::setw(2) <<
static_cast<int>(
b);
89 h << std::setw(2) << static_cast<int>(
a);
97 std::ostringstream color;
99 color << static_cast<int>(r) <<
','
100 <<
static_cast<int>(
g) <<
','
101 <<
static_cast<int>(
b) <<
','
102 <<
static_cast<int>(
a);
109 std::ostringstream color;
111 color << static_cast<int>(r) <<
','
112 <<
static_cast<int>(
g) <<
','
113 <<
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.