-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colors.h
93 lines (90 loc) · 2.13 KB
/
Colors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
class Color
{
public:
unsigned int dword;
public:
constexpr Color() : dword() {}
constexpr Color( const Color& col )
:
dword( col.dword )
{}
constexpr Color( unsigned int dw )
:
dword( dw )
{}
constexpr Color( unsigned char x,unsigned char r,unsigned char g,unsigned char b )
:
dword( (x << 24u) | (r << 16u) | (g << 8u) | b )
{}
constexpr Color( unsigned char r,unsigned char g,unsigned char b )
:
dword( (r << 16u) | (g << 8u) | b )
{}
constexpr Color( Color col,unsigned char x )
:
Color( (x << 24u) | col.dword )
{}
Color& operator =( Color color )
{
dword = color.dword;
return *this;
}
constexpr unsigned char GetX() const
{
return dword >> 24u;
}
constexpr unsigned char GetA() const
{
return GetX();
}
constexpr unsigned char GetR() const
{
return (dword >> 16u) & 0xFFu;
}
constexpr unsigned char GetG() const
{
return (dword >> 8u) & 0xFFu;
}
constexpr unsigned char GetB() const
{
return dword & 0xFFu;
}
void SetX( unsigned char x )
{
dword = (dword & 0xFFFFFFu) | (x << 24u);
}
void SetA( unsigned char a )
{
SetX( a );
}
void SetR( unsigned char r )
{
dword = (dword & 0xFF00FFFFu) | (r << 16u);
}
void SetG( unsigned char g )
{
dword = (dword & 0xFFFF00FFu) | (g << 8u);
}
void SetB( unsigned char b )
{
dword = (dword & 0xFFFFFF00u) | b;
}
};
namespace Colors
{
static constexpr Color MakeRGB( unsigned char r,unsigned char g,unsigned char b )
{
return (r << 16) | (g << 8) | b;
}
static constexpr Color White = MakeRGB( 255u,255u,255u );
static constexpr Color Black = MakeRGB( 0u,0u,0u );
static constexpr Color Gray = MakeRGB( 0x80u,0x80u,0x80u );
static constexpr Color LightGray = MakeRGB( 0xD3u,0xD3u,0xD3u );
static constexpr Color Red = MakeRGB( 255u,0u,0u );
static constexpr Color Green = MakeRGB( 0u,255u,0u );
static constexpr Color Blue = MakeRGB( 0u,0u,255u );
static constexpr Color Yellow = MakeRGB( 255u,255u,0u );
static constexpr Color Cyan = MakeRGB( 0u,255u,255u );
static constexpr Color Magenta = MakeRGB( 255u,0u,255u );
}