2012-09-17 21:01:13 +04:00
|
|
|
#ifndef color_hh_INCLUDED
|
|
|
|
#define color_hh_INCLUDED
|
|
|
|
|
2014-12-16 21:57:19 +03:00
|
|
|
#include "hash.hh"
|
|
|
|
|
2012-09-17 21:01:13 +04:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2013-03-26 02:35:59 +04:00
|
|
|
class String;
|
2014-08-20 02:16:21 +04:00
|
|
|
class StringView;
|
2013-03-26 02:35:59 +04:00
|
|
|
|
2013-05-07 20:52:23 +04:00
|
|
|
struct Color
|
|
|
|
{
|
2015-04-25 12:47:39 +03:00
|
|
|
enum NamedColor : char
|
|
|
|
{
|
|
|
|
Default,
|
|
|
|
Black,
|
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
Yellow,
|
|
|
|
Blue,
|
|
|
|
Magenta,
|
|
|
|
Cyan,
|
|
|
|
White,
|
2017-10-22 21:30:49 +03:00
|
|
|
BrBlack,
|
|
|
|
BrRed,
|
|
|
|
BrGreen,
|
|
|
|
BrYellow,
|
|
|
|
BrBlue,
|
|
|
|
BrMagenta,
|
|
|
|
BrCyan,
|
|
|
|
BrWhite,
|
2015-04-25 12:47:39 +03:00
|
|
|
RGB,
|
|
|
|
};
|
|
|
|
|
|
|
|
NamedColor color;
|
|
|
|
unsigned char r = 0;
|
|
|
|
unsigned char g = 0;
|
|
|
|
unsigned char b = 0;
|
2013-05-07 20:52:23 +04:00
|
|
|
|
2015-04-25 12:47:39 +03:00
|
|
|
constexpr Color() : Color{Default} {}
|
|
|
|
constexpr Color(NamedColor c) : color{c} {}
|
2015-03-21 19:32:07 +03:00
|
|
|
constexpr Color(unsigned char r, unsigned char g, unsigned char b)
|
2015-04-25 12:47:39 +03:00
|
|
|
: color{RGB}, r{r}, g{g}, b{b} {}
|
2012-09-17 21:01:13 +04:00
|
|
|
};
|
|
|
|
|
2015-03-20 22:03:41 +03:00
|
|
|
constexpr bool operator==(Color lhs, Color rhs)
|
2014-12-16 21:57:19 +03:00
|
|
|
{
|
|
|
|
return lhs.color == rhs.color and
|
|
|
|
lhs.r == rhs.r and lhs.g == rhs.g and lhs.b == rhs.b;
|
|
|
|
}
|
|
|
|
|
2015-03-20 22:03:41 +03:00
|
|
|
constexpr bool operator!=(Color lhs, Color rhs)
|
2014-12-16 21:57:19 +03:00
|
|
|
{
|
|
|
|
return not (lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2014-08-20 02:16:21 +04:00
|
|
|
Color str_to_color(StringView color);
|
2017-09-12 06:31:57 +03:00
|
|
|
String to_string(Color color);
|
2013-03-26 02:35:59 +04:00
|
|
|
|
2013-07-26 02:26:43 +04:00
|
|
|
String option_to_string(Color color);
|
2014-08-20 02:16:21 +04:00
|
|
|
void option_from_string(StringView str, Color& color);
|
|
|
|
|
|
|
|
bool is_color_name(StringView color);
|
2013-03-29 22:31:06 +04:00
|
|
|
|
2017-10-17 17:45:17 +03:00
|
|
|
constexpr size_t hash_value(const Color& val)
|
2014-12-16 21:57:19 +03:00
|
|
|
{
|
2015-04-25 12:47:39 +03:00
|
|
|
return val.color == Color::RGB ?
|
2015-02-11 01:53:37 +03:00
|
|
|
hash_values(val.color, val.r, val.g, val.b)
|
|
|
|
: hash_value(val.color);
|
2014-12-16 21:57:19 +03:00
|
|
|
}
|
|
|
|
|
2012-09-17 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // color_hh_INCLUDED
|