2018-10-10 16:49:36 +02:00
|
|
|
#include "Color.h"
|
2019-01-14 15:25:34 +01:00
|
|
|
#include <AK/Assertions.h>
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2018-10-12 20:05:11 +02:00
|
|
|
Color::Color(NamedColor named)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
byte r;
|
|
|
|
byte g;
|
|
|
|
byte b;
|
|
|
|
} rgb;
|
|
|
|
|
|
|
|
switch (named) {
|
2019-06-07 11:46:55 +02:00
|
|
|
case Black:
|
|
|
|
rgb = { 0, 0, 0 };
|
|
|
|
break;
|
|
|
|
case White:
|
|
|
|
rgb = { 255, 255, 255 };
|
|
|
|
break;
|
|
|
|
case Red:
|
|
|
|
rgb = { 255, 0, 0 };
|
|
|
|
break;
|
|
|
|
case Green:
|
|
|
|
rgb = { 0, 255, 0 };
|
|
|
|
break;
|
|
|
|
case Cyan:
|
|
|
|
rgb = { 0, 255, 255 };
|
|
|
|
break;
|
|
|
|
case Blue:
|
|
|
|
rgb = { 0, 0, 255 };
|
|
|
|
break;
|
|
|
|
case Yellow:
|
|
|
|
rgb = { 255, 255, 0 };
|
|
|
|
break;
|
|
|
|
case Magenta:
|
|
|
|
rgb = { 255, 0, 255 };
|
|
|
|
break;
|
|
|
|
case DarkGray:
|
|
|
|
rgb = { 64, 64, 64 };
|
|
|
|
break;
|
|
|
|
case MidGray:
|
|
|
|
rgb = { 127, 127, 127 };
|
|
|
|
break;
|
|
|
|
case LightGray:
|
|
|
|
rgb = { 192, 192, 192 };
|
|
|
|
break;
|
|
|
|
case MidGreen:
|
|
|
|
rgb = { 0, 192, 0 };
|
|
|
|
break;
|
|
|
|
case MidBlue:
|
|
|
|
rgb = { 0, 0, 192 };
|
|
|
|
break;
|
|
|
|
case MidRed:
|
|
|
|
rgb = { 192, 0, 0 };
|
|
|
|
break;
|
|
|
|
case MidMagenta:
|
|
|
|
rgb = { 192, 0, 192 };
|
|
|
|
break;
|
|
|
|
case DarkGreen:
|
|
|
|
rgb = { 0, 128, 0 };
|
|
|
|
break;
|
|
|
|
case DarkBlue:
|
|
|
|
rgb = { 0, 0, 128 };
|
|
|
|
break;
|
|
|
|
case DarkRed:
|
|
|
|
rgb = { 128, 0, 0 };
|
|
|
|
break;
|
2019-06-30 09:23:16 +02:00
|
|
|
case WarmGray:
|
|
|
|
rgb = { 212, 208, 200 };
|
|
|
|
break;
|
2019-06-07 11:46:55 +02:00
|
|
|
default:
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
break;
|
2018-10-12 20:05:11 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 01:42:53 +01:00
|
|
|
m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b;
|
2018-10-12 20:05:11 +02:00
|
|
|
}
|
2019-03-18 04:53:09 +01:00
|
|
|
|
|
|
|
String Color::to_string() const
|
|
|
|
{
|
2019-04-12 14:49:45 +02:00
|
|
|
return String::format("#%b%b%b%b", red(), green(), blue(), alpha());
|
2019-03-18 04:53:09 +01:00
|
|
|
}
|