summaryrefslogtreecommitdiffstats
path: root/src/Color.cpp
blob: f2180e2d9b88a2b4c5254dfd1133ef3b6becb355 (plain) (blame)
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
#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include "Color.h"





#define COLOR_RED_BITS     0x00FF0000
#define COLOR_GREEN_BITS   0x0000FF00
#define COLOR_BLUE_BITS    0x000000FF
#define COLOR_RED_OFFSET   16
#define COLOR_GREEN_OFFSET 8





void cColor::SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue)
{
	m_Color = (static_cast<unsigned int>(a_Red) << COLOR_RED_OFFSET) + (static_cast<unsigned int>(a_Green) << COLOR_GREEN_OFFSET) + (static_cast<unsigned int>(a_Blue));
}





void cColor::SetRed(unsigned char a_Red)
{
	m_Color = (static_cast<unsigned int>(a_Red) << COLOR_RED_OFFSET) + ((COLOR_GREEN_BITS | COLOR_BLUE_BITS) & m_Color);
}





void cColor::SetGreen(unsigned char a_Green)
{
	m_Color = (static_cast<unsigned int>(a_Green) << COLOR_GREEN_OFFSET) + ((COLOR_RED_BITS | COLOR_BLUE_BITS) & m_Color);
}





void cColor::SetBlue(unsigned char a_Blue)
{
	m_Color = static_cast<unsigned int>(a_Blue) + ((COLOR_RED_BITS | COLOR_GREEN_BITS) & m_Color);
}





unsigned char cColor::GetRed() const
{
	return (m_Color & COLOR_RED_BITS) >> COLOR_RED_OFFSET;
}





unsigned char cColor::GetGreen() const
{
	return (m_Color & COLOR_GREEN_BITS) >> COLOR_GREEN_OFFSET;
}





unsigned char cColor::GetBlue() const
{
	return m_Color & COLOR_BLUE_BITS;
}