-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.cpp
128 lines (119 loc) · 2.63 KB
/
Color.cpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "Color.h"
void Color::SetValue(int value) {
this->value = value;
short uValue = 255;
this->value &= uValue;
B = this->value;
this->value = value;
this->value >>= 8;
this->value &= uValue;
G = this->value;
this->value = value;
this->value >>= 16;
this->value &= uValue;
R = this->value;
}
void Color::SetName(const char *name) {
this->name = name;
}
unsigned char Color::GetR() const {
return R;
}
unsigned char Color::GetG() const {
return G;
}
unsigned char Color::GetB() const {
return B;
}
string Color::GetName() const {
return this->name;
}
string Color::GetHexValue() const {
string hexValue;
string R1 = to_string(GetR() / 16);
if (R1 == "10") {
R1 = "A";
} else if (R1 == "11") {
R1 = "B";
} else if (R1 == "12") {
R1 = "C";
} else if (R1 == "13") {
R1 = "D";
} else if (R1 == "14") {
R1 = "E";
} else if (R1 == "15") {
R1 = "F";
}
string R2 = to_string(GetR() % 16);
if (R2 == "10") {
R2 = "A";
} else if (R2 == "11") {
R2 = "B";
} else if (R2 == "12") {
R2 = "C";
} else if (R2 == "13") {
R2 = "D";
} else if (R2 == "14") {
R2 = "E";
} else if (R2 == "15") {
R2 = "F";
}
string G1 = to_string(GetG() / 16);
if (G1 == "10") {
G1 = "A";
} else if (G1 == "11") {
G1 = "B";
} else if (G1 == "12") {
G1 = "C";
} else if (G1 == "13") {
G1 = "D";
} else if (G1 == "14") {
G1 = "E";
} else if (G1 == "15") {
G1 = "F";
}
string G2 = to_string(GetG() % 16);
if (G2 == "10") {
G2 = "A";
} else if (G2 == "11") {
G2 = "B";
} else if (G2 == "12") {
G2 = "C";
} else if (G2 == "13") {
G2 = "D";
} else if (G2 == "14") {
G2 = "E";
} else if (G2 == "15") {
G2 = "F";
}
string B1 = to_string(GetB() / 16);
if (B1 == "10") {
B1 = "A";
} else if (B1 == "11") {
B1 = "B";
} else if (B1 == "12") {
B1 = "C";
} else if (B1 == "13") {
B1 = "D";
} else if (B1 == "14") {
B1 = "E";
} else if (B1 == "15") {
B1 = "F";
}
string B2 = to_string(GetB() % 16);
if (B2 == "10") {
B2 = "A";
} else if (B2 == "11") {
B2 = "B";
} else if (B2 == "12") {
B2 = "C";
} else if (B2 == "13") {
B2 = "D";
} else if (B2 == "14") {
B2 = "E";
} else if (B2 == "15") {
B2 = "F";
}
hexValue = "0x" + R1 + R2 + G1 + G2 + B1 + B2;
return hexValue;
}