47 inline Color(
const unsigned int rgb,
unsigned char alpha = 255);
48 inline Color(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha = 255);
49 inline Color(
unsigned char gray,
unsigned char alpha = 255);
51 static inline Color fromRGBf(
float red,
float green,
float blue,
float alpha = 1.0f);
58 inline Color(
const std::string & htmlColor,
unsigned char alpha);
64 inline Color(
const std::string & htmlColor);
66 inline Color(
const char * htmlColor,
unsigned char alpha = 255);
71 inline Color(std::nullptr_t);
73 inline void red(
unsigned char red);
74 inline void green(
unsigned char green);
75 inline void blue(
unsigned char blue);
76 inline void alpha(
unsigned char alpha);
78 inline unsigned char red()
const;
79 inline unsigned char green()
const;
80 inline unsigned char blue()
const;
81 inline unsigned char alpha()
const;
91 inline Color &
setRGBi(
const unsigned char red,
const unsigned char green,
const unsigned char blue,
const unsigned char alpha = 255);
101 Color &
setHSV(
float hue,
float saturation,
float value,
float alpha = 1.0);
103 Color & setRGBf(
float red,
float green,
float blue,
float alpha = 1.0);
105 bool operator==(
const Color & other)
const;
107 bool operator!=(
const Color & other)
const;
109 bool operator<(
const Color & other)
const;
111 void flushPostscript(std::ostream &)
const;
113 std::string svg()
const;
115 inline bool isNull()
const;
117 inline bool isValid()
const;
126 std::string
svgAlpha(
const char * prefix)
const;
128 std::string postscript()
const;
138 std::string
tikz()
const;
140 void toHSV(
float & hue,
float & saturation,
float & value,
float & alpha)
const;
142 inline bool valid()
const {
return (*
this) != Color::Null; }
144 static Color fromHSV(
float hue,
float saturation,
float value,
float alpha = 1.0f);
150 static Color fromHueColormap(
float t);
152 std::ostream & flush(std::ostream & out)
const;
155 static const Color Null;
156 static const Color Black;
157 static const Color Brown;
158 static const Color Pink;
159 static const Color Gray;
160 static const Color White;
161 static const Color Red;
162 static const Color Green;
163 static const Color DarkGreen;
164 static const Color Lime;
165 static const Color Blue;
166 static const Color Cyan;
167 static const Color DarkCyan;
168 static const Color Magenta;
169 static const Color Yellow;
170 static const Color Silver;
171 static const Color Purple;
172 static const Color Navy;
173 static const Color Aqua;
182 std::ostream & operator<<(std::ostream & out,
const Color & color);
186 Color &
Color::setRGBi(
const unsigned char red,
const unsigned char green,
const unsigned char blue,
const unsigned char alpha)
195 bool Color::isNull()
const
197 return _red == -1 && _green == -1 && _blue == -1;
200 bool Color::isValid()
const
205 Color::Color() : _red(0), _green(0), _blue(0), _alpha(255) {}
207 Color::Color(std::nullptr_t)
209 _red = _green = _blue = -1;
213 Color::Color(
const unsigned int rgb,
unsigned char alpha) : _alpha(alpha)
215 _red = (rgb & 0xFF0000u) >> 16;
216 _green = (rgb & 0xFF00u) >> 8;
220 Color::Color(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha) : _red(red), _green(green), _blue(blue), _alpha(alpha) {}
222 Color::Color(
unsigned char gray,
unsigned char alpha) : _red(gray), _green(gray), _blue(gray), _alpha(alpha) {}
224 Color Color::fromRGBf(
float red,
float green,
float blue,
float alpha)
226 return Color(
static_cast<unsigned char>(red * 255),
static_cast<unsigned char>(green * 255),
static_cast<unsigned char>(blue * 255),
static_cast<unsigned char>(alpha * 255));
230 Color::Color(
const std::string & htmlColor,
unsigned char alpha) :
Color(htmlColor.c_str(), alpha) {}
232 Color::Color(
const std::string & htmlColor) :
Color(htmlColor.c_str(), 255) {}
234 Color::Color(
const char * htmlColor,
unsigned char alpha) : _alpha(alpha)
236 unsigned int r, g, b, a = alpha;
237 if (!htmlColor || *htmlColor ==
'\0') {
241 if (strlen(htmlColor) == 7 && sscanf(htmlColor,
"#%2x%2x%2x", &r, &g, &b) == 3) {
246 }
else if (strlen(htmlColor) == 9 && sscanf(htmlColor,
"#%2x%2x%2x%2x", &r, &g, &b, &a) == 4) {
253 Tools::error <<
"Color::Color(htmlcolor): cannot parse color string\n";
257 void Color::red(
const unsigned char red)
262 void Color::green(
unsigned char green)
267 void Color::blue(
unsigned char blue)
272 void Color::alpha(
unsigned char alpha)
277 unsigned char Color::red()
const
279 return static_cast<unsigned char>(_red);
282 unsigned char Color::green()
const
284 return static_cast<unsigned char>(_green);
287 unsigned char Color::blue()
const
289 return static_cast<unsigned char>(_blue);
292 unsigned char Color::alpha()
const
294 return static_cast<unsigned char>(_alpha);
298 #endif // BOARD_COLOR_H