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) {
|
|
|
|
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;
|
2019-05-06 00:59:33 +02:00
|
|
|
case Cyan: rgb = { 0, 255, 255 }; break;
|
2018-10-12 20:05:11 +02:00
|
|
|
case Blue: rgb = { 0, 0, 255}; break;
|
2019-01-12 04:02:36 +01:00
|
|
|
case Yellow: rgb = { 255, 255, 0 }; break;
|
|
|
|
case Magenta: rgb = { 255, 0, 255 }; break;
|
2018-10-12 23:02:23 +02:00
|
|
|
case DarkGray: rgb = { 64, 64, 64 }; break;
|
|
|
|
case MidGray: rgb = { 127, 127, 127 }; break;
|
|
|
|
case LightGray: rgb = { 192, 192, 192 }; break;
|
2019-03-20 04:21:58 +01:00
|
|
|
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;
|
2019-03-18 20:56:45 +01:00
|
|
|
case DarkGreen: rgb = { 0, 128, 0 }; break;
|
|
|
|
case DarkBlue: rgb = { 0, 0, 128 }; break;
|
|
|
|
case DarkRed: rgb = { 128, 0, 0 }; break;
|
2018-10-12 20:05:11 +02:00
|
|
|
default: ASSERT_NOT_REACHED(); break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|