mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
27f699ef0c
These types can be picked up by including <AK/Types.h>: * u8, u16, u32, u64 (unsigned) * i8, i16, i32, i64 (signed)
81 lines
1.6 KiB
C++
81 lines
1.6 KiB
C++
#include "Color.h"
|
|
#include <AK/Assertions.h>
|
|
|
|
Color::Color(NamedColor named)
|
|
{
|
|
struct {
|
|
u8 r;
|
|
u8 g;
|
|
u8 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;
|
|
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;
|
|
case WarmGray:
|
|
rgb = { 212, 208, 200 };
|
|
break;
|
|
default:
|
|
ASSERT_NOT_REACHED();
|
|
break;
|
|
}
|
|
|
|
m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b;
|
|
}
|
|
|
|
String Color::to_string() const
|
|
{
|
|
return String::format("#%b%b%b%b", red(), green(), blue(), alpha());
|
|
}
|