/
Color.h
103 lines (87 loc) · 2.06 KB
/
Color.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
94
95
96
97
98
99
100
101
102
103
//========= Copyright © 1996-2005, 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);
}
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