-
Notifications
You must be signed in to change notification settings - Fork 1
/
Color.h
301 lines (287 loc) · 6.77 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//
// Color.h
// Termin8or
//
// Created by Rasmus Anthin on 2024-06-20.
//
#pragma once
#include <Core/Rand.h>
#include <string>
enum class Color
{
Transparent = -1,
Transparent2 = -2,
Default = 0,
Black, // 1
DarkRed, // 2
DarkGreen, // 3
DarkYellow, // 4
DarkBlue, // 5
DarkMagenta, // 6
DarkCyan, // 7
LightGray, // 8
DarkGray, // 9
Red, // 10
Green, // 11
Yellow, // 12
Blue, // 13
Magenta, // 14
Cyan, // 15
White // 16
};
namespace color
{
Color string2color(const std::string& str)
{
if (str == "Transparent")
return Color::Transparent;
if (str == "Transparent2")
return Color::Transparent2;
if (str == "Default")
return Color::Default;
if (str == "Black")
return Color::Black;
if (str == "DarkRed")
return Color::DarkRed;
if (str == "DarkGreen")
return Color::DarkGreen;
if (str == "DarkYellow")
return Color::DarkYellow;
if (str == "DarkBlue")
return Color::DarkBlue;
if (str == "DarkMagenta")
return Color::DarkMagenta;
if (str == "DarkCyan")
return Color::DarkCyan;
if (str == "LightGray")
return Color::LightGray;
if (str == "DarkGray")
return Color::DarkGray;
if (str == "Red")
return Color::Red;
if (str == "Green")
return Color::Green;
if (str == "Yellow")
return Color::Yellow;
if (str == "Blue")
return Color::Blue;
if (str == "Magenta")
return Color::Magenta;
if (str == "Cyan")
return Color::Cyan;
if (str == "White")
return Color::White;
return Color::Default;
}
std::string color2string(Color color)
{
switch (color)
{
case Color::Transparent:
return "Transparent";
case Color::Transparent2:
return "Transparent2";
case Color::Default:
return "Default";
case Color::Black:
return "Black";
case Color::DarkRed:
return "DarkRed";
case Color::DarkGreen:
return "DarkGreen";
case Color::DarkYellow:
return "DarkYellow";
case Color::DarkBlue:
return "DarkBlue";
case Color::DarkMagenta:
return "DarkMagenta";
case Color::DarkCyan:
return "DarkCyan";
case Color::LightGray:
return "LightGray";
case Color::DarkGray:
return "DarkGray";
case Color::Red:
return "Red";
case Color::Green:
return "Green";
case Color::Yellow:
return "Yellow";
case Color::Blue:
return "Blue";
case Color::Magenta:
return "Magenta";
case Color::Cyan:
return "Cyan";
case Color::White:
return "White";
default:
return "";
}
}
Color get_random_color(const std::vector<Color>& palette)
{
auto num = static_cast<int>(palette.size());
if (num == 0)
return Color::Default;
auto idx = rnd::rand_int(0, num - 1);
return palette[idx];
}
std::vector<Color> colors_hue_light
{
Color::Red,
Color::Yellow,
Color::Green,
Color::Cyan,
Color::Blue,
};
std::vector<Color> colors_hue_light_dark
{
Color::Red,
Color::Yellow,
Color::Green,
Color::Cyan,
Color::Blue,
Color::Magenta,
Color::DarkRed,
Color::DarkYellow,
Color::DarkGreen,
Color::DarkCyan,
Color::DarkBlue,
Color::DarkMagenta,
};
std::vector<Color> colors_bright
{
Color::White,
Color::LightGray,
Color::DarkGray,
Color::Cyan,
Color::Magenta,
Color::Yellow,
Color::Red,
Color::Green,
Color::Blue,
};
std::vector<Color> colors_dark
{
Color::LightGray,
Color::DarkGray,
Color::Black,
Color::DarkCyan,
Color::DarkMagenta,
Color::DarkYellow,
Color::DarkRed,
Color::DarkGreen,
Color::DarkBlue,
};
enum class ShadeType { Unchanged, Bright, Dark };
// #NOTE: Returns Color::Default if no matching color was found.
// If shade = ShadeType::Unchanged, then it will return the same color as the argument.
// If inputting a bright color and ShadeType is Bright, then you will get the same color.
// If inputting a dark color and ShadeType is Bright, then you will get the corresponding bright color.
// If inputting a bright color and ShadeType is Dark, then you will get the corresponding dark color.
// If inputting a dark color and ShadeType is Dark, then you will get the same color.
Color shade_color(Color color, ShadeType shade)
{
int idx = -1;
switch (shade)
{
case ShadeType::Unchanged:
return color;
case ShadeType::Bright:
idx = stlutils::find_idx(colors_dark, color);
if (0 <= idx)
return colors_bright[idx];
if (stlutils::contains(colors_bright, color))
return color;
break;
case ShadeType::Dark:
idx = stlutils::find_idx(colors_bright, color);
if (0 <= idx)
return colors_dark[idx];
if (stlutils::contains(colors_dark, color))
return color;
break;
}
return Color::Default;
}
int get_color_value_win(Color color)
{
switch (color)
{
case Color::DarkRed:
return 4;
case Color::DarkGreen:
return 2;
case Color::DarkYellow:
return 6;
case Color::DarkBlue:
return 1;
case Color::DarkMagenta:
return 5;
case Color::DarkCyan:
return 3;
case Color::LightGray:
return 7;
case Color::DarkGray:
return 8;
case Color::Red:
return 12;
case Color::Green:
return 10;
case Color::Yellow:
return 14;
case Color::Blue:
return 9;
case Color::Magenta:
return 13;
case Color::Cyan:
return 11;
case Color::White:
return 15;
case Color::Black:
default:
return 0;
}
}
Color get_color_win(int color_val)
{
switch (color_val)
{
case 0:
return Color::Black;
case 1:
return Color::DarkBlue;
case 2:
return Color::DarkGreen;
case 3:
return Color::DarkCyan;
case 4:
return Color::DarkRed;
case 5:
return Color::DarkMagenta;
case 6:
return Color::DarkYellow;
case 7:
return Color::LightGray;
case 8:
return Color::DarkGray;
case 9:
return Color::Blue;
case 10:
return Color::Green;
case 11:
return Color::Cyan;
case 12:
return Color::Red;
case 13:
return Color::Magenta;
case 14:
return Color::Yellow;
case 15:
return Color::White;
default:
return Color::Default;
}
}
}