18namespace Experimental {
34 R__ATTR_CLASS(
RColor,
"color_", AddString(
"rgb",
"").AddString(
"a",
"").AddString(
"name",
"").AddBool(
"auto",
false));
36 using RGB_t = std::array<int, 3>;
40 static std::string
toHex(
int v);
45 return SetRGB(
int(
r*255),
int(
g*255),
int(
b*255));
81 std::string
GetHex()
const {
return GetValue<std::string>(
"rgb"); }
83 bool GetRGB(
int &
r,
int &
g,
int &
b)
const;
109 std::string
GetName()
const {
return GetValue<std::string>(
"name"); }
120 return std::strtol(hex.c_str(),
nullptr, 16) / 255.;
124 std::string
GetAlphaHex()
const {
return GetValue<std::string>(
"a"); }
143 bool IsAuto()
const {
return GetValue<bool>(
"auto"); }
156 bool GetHLS(
float &hue,
float &light,
float &satur)
const;
Base class for all attributes, used with RDrawable.
bool HasValue(const std::string &name, bool check_defaults=false) const
void ClearValue(const std::string &name)
void SetValue(const std::string &name, bool value)
int GetColorComponent(int indx) const
Decodes color component and returns integer from 0 to 255 Values of indx 0: Red, 1: Green,...
std::string GetName() const
Returns color as plain SVG name like "white" or "lightblue".
static constexpr RGB_t kRed
bool GetRGB(int &r, int &g, int &b) const
Decodes hex color value into RGB - each color component as integer from 0 to 255 If color was not spe...
friend bool operator==(const RColor &lhs, const RColor &rhs)
std::string AsSVG() const
Returns color value as it will be used in SVG drawing It either include hex format #66FF66 or just pl...
static std::string toHex(int v)
Converts integer from 0 to 255 into hex format with two digits like 00.
float GetAlpha() const
Returns color alpha (opacity) as float from 0.
RColor & SetRGBFloat(float r, float g, float b)
Set RGB values as floats, each from 0..1.
bool IsAuto() const
Returns true if color should get auto value when primitive drawing is performed.
static constexpr RGB_t kGreen
RColor(int r, int g, int b, float alpha)
Construct color with provided r,g,b and alpha values.
void ClearRGB()
Clear RGB color value (if any)
RColor & SetName(const std::string &_name)
Set color as plain SVG name like "white" or "lightblue".
bool GetHLS(float &hue, float &light, float &satur) const
Return the Hue, Light, Saturation (HLS) definition of this RColor.
bool GetRGBFloat(float &r, float &g, float &b) const
Decodes hex color value into RGB - each color component as float from 0.
static constexpr double kOpaque
void ClearAlpha()
Clear alpha value of the color.
static constexpr RGB_t kWhite
std::string GetHex() const
Return color as hex string like 00FF00.
RColor(const RGB_t &rgb)
Construct color with provided RGB_t value.
RColor & SetRGB(const RGB_t &rgb)
Set r/g/b/ components of color as hex code, default for the color.
static constexpr double kTransparent
RColor & SetAuto(bool on=true)
Set automatic mode for RColor, will be assigned before primitive painted on the canvas.
static constexpr RGB_t kBlack
static constexpr RGB_t kBlue
RColor(int r, int g, int b)
Construct color with provided r,g,b values.
std::string GetAlphaHex() const
Returns color alpha (opacity) as hex string like FF.
RColor & SetAlpha(float _alpha)
Set color alpha (opacity) value - from 0 to 1.
bool HasAlpha() const
Returns true if color alpha (opacity) was specified.
RColor & SetRGB(int r, int g, int b)
Set r/g/b/ components of color as hex code, default for the color.
RColor & SetAlphaHex(const std::string &_alfa)
Set color alpha (opacity) value as hex string.
int GetRed() const
Returns red color component 0..255.
RColor & SetHLS(float hue, float light, float satur)
Set the Red Green and Blue (RGB) values from the Hue, Light, Saturation (HLS).
R__ATTR_CLASS(RColor, "color_", AddString("rgb", "").AddString("a", "").AddString("name", "").AddBool("auto", false))
std::array< int, 3 > RGB_t
int GetBlue() const
Returns blue color component 0..255.
int GetGreen() const
Returns green color component 0..255.
void ClearAuto()
Clear auto flag of the RColor.
void ClearName()
Clear color plain SVG name (if any)
RColor & SetHex(const std::string &_hex)
Set color as hex string like 00FF00.