forked from icantstandpeople/potassium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.h
More file actions
113 lines (96 loc) · 2.58 KB
/
Color.h
File metadata and controls
113 lines (96 loc) · 2.58 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef COLOR_H
#define COLOR_H
#ifdef _WIN32
#pragma once
#endif
//-----------------------------------------------------------------------------
// Purpose: Basic handler for an rgb set of colors
// This class is fully inline
//-----------------------------------------------------------------------------
class Color
{
public:
// constructors
Color()
{
*((int *)this) = 0;
}
Color(int _r, int _g, int _b)
{
SetColor(_r, _g, _b, 0);
}
Color(int _r, int _g, int _b, int _a)
{
SetColor(_r, _g, _b, _a);
}
// set the color
// r - red component (0-255)
// g - green component (0-255)
// b - blue component (0-255)
// a - alpha component, controls transparency (0 - transparent, 255 - opaque);
void SetColor(int _r, int _g, int _b, int _a = 0)
{
_color[0] = (unsigned char)_r;
_color[1] = (unsigned char)_g;
_color[2] = (unsigned char)_b;
_color[3] = (unsigned char)_a;
}
void GetColor(int &_r, int &_g, int &_b, int &_a) const
{
_r = _color[0];
_g = _color[1];
_b = _color[2];
_a = _color[3];
}
void SetRawColor(int color32)
{
*((int *)this) = color32;
}
int GetRawColor() const
{
return *((int *)this);
}
static Color White() { return Color(255, 255, 255, 255); }
static Color Black() { return Color(0, 0, 0, 255); }
static Color Red() { return Color(255, 0, 0, 255); }
static Color Orange() { return Color(255, 165, 0, 255); }
static Color Yellow() { return Color(255, 255, 0, 255); }
static Color Green() { return Color(0, 255, 0, 255); }
static Color Blue() { return Color(0, 0, 255, 255); }
static Color Indigo() { return Color(75, 0, 130, 255); }
static Color Violet() { return Color(128, 66, 244, 255); }
inline int r() const { return _color[0]; }
inline int g() const { return _color[1]; }
inline int b() const { return _color[2]; }
inline int a() const { return _color[3]; }
unsigned char &operator[](int index)
{
return _color[index];
}
const unsigned char &operator[](int index) const
{
return _color[index];
}
bool operator == (const Color &rhs) const
{
return (*((int *)this) == *((int *)&rhs));
}
bool operator != (const Color &rhs) const
{
return !(operator==(rhs));
}
Color &operator=(const Color &rhs)
{
SetRawColor(rhs.GetRawColor());
return *this;
}
private:
unsigned char _color[4];
};
#endif // COLOR_H