CommonLibVR
Loading...
Searching...
No Matches
NiColor.h
Go to the documentation of this file.
1#pragma once
2
3namespace RE
4{
5 class NiColor;
6 class NiColorA;
7
8 struct Color;
9
10 class NiColor
11 {
12 public:
13 enum : std::size_t
14 {
18
19 kTotal
20 };
21
22 constexpr NiColor() noexcept :
23 red(0.0),
24 green(0.0),
25 blue(0.0)
26 {}
27
28 constexpr NiColor(const NiColor& a_rhs) noexcept :
29 red(a_rhs.red),
30 green(a_rhs.green),
31 blue(a_rhs.blue)
32 {}
33
34 constexpr NiColor(NiColor&& a_rhs) noexcept :
35 red(std::move(a_rhs.red)),
36 green(std::move(a_rhs.green)),
37 blue(std::move(a_rhs.blue))
38 {}
39
40 constexpr NiColor(float a_red, float a_green, float a_blue) noexcept :
41 red(a_red),
42 green(a_green),
43 blue(a_blue)
44 {}
45
46 constexpr NiColor(std::uint32_t a_hexValue) noexcept :
47 red(((a_hexValue >> 16) & 0xFF) / 255.0f),
48 green(((a_hexValue >> 8) & 0xFF) / 255.0f),
49 blue(((a_hexValue)&0xFF) / 255.0f)
50 {
51 }
52
53 NiColor(const Color& a_rhs);
54 ~NiColor() noexcept = default;
55
56 constexpr NiColor& operator=(const NiColor& a_rhs) noexcept
57 {
58 if (this != std::addressof(a_rhs)) {
59 red = a_rhs.red;
60 green = a_rhs.green;
61 blue = a_rhs.blue;
62 }
63 return *this;
64 }
65
66 constexpr NiColor& operator=(NiColor&& a_rhs) noexcept
67 {
68 if (this != std::addressof(a_rhs)) {
69 red = std::move(a_rhs.red);
70 green = std::move(a_rhs.green);
71 blue = std::move(a_rhs.blue);
72 }
73 return *this;
74 }
75
76 constexpr NiColor& operator=(const NiColorA& a_rhs) noexcept;
77
78 [[nodiscard]] friend constexpr bool operator==(const NiColor& a_lhs, const NiColor& a_rhs) noexcept
79 {
80 for (std::size_t i = 0; i < kTotal; ++i) {
81 if (a_lhs[i] != a_rhs[i]) {
82 return false;
83 }
84 }
85 return true;
86 }
87
88 [[nodiscard]] friend constexpr bool operator!=(const NiColor& a_lhs, const NiColor& a_rhs) noexcept
89 {
90 return !(a_lhs == a_rhs);
91 }
92
93 [[nodiscard]] constexpr float& operator[](std::size_t a_idx) noexcept
94 {
95 assert(a_idx < kTotal);
96 return std::addressof(red)[a_idx];
97 }
98
99 [[nodiscard]] constexpr const float& operator[](std::size_t a_idx) const noexcept
100 {
101 assert(a_idx < kTotal);
102 return std::addressof(red)[a_idx];
103 }
104
105 [[nodiscard]] NiColor operator+(const NiColor& a_rhs) const noexcept
106 {
107 NiColor tmp = *this;
108 for (std::size_t i = 0; i < kTotal; ++i) {
109 tmp[i] += a_rhs[i];
110 }
111 return tmp;
112 }
113
114 NiColor& operator+=(const NiColor& a_rhs) noexcept
115 {
116 for (std::size_t i = 0; i < kTotal; ++i) {
117 operator[](i) += a_rhs[i];
118 }
119 return *this;
120 }
121
122 [[nodiscard]] NiColor operator-(const NiColor& a_rhs) const noexcept
123 {
124 NiColor tmp = *this;
125 for (std::size_t i = 0; i < kTotal; ++i) {
126 tmp[i] -= a_rhs[i];
127 }
128 return tmp;
129 }
130
131 NiColor& operator-=(const NiColor& a_rhs) noexcept
132 {
133 for (std::size_t i = 0; i < kTotal; ++i) {
134 operator[](i) -= a_rhs[i];
135 }
136 return *this;
137 }
138
140 {
141 return NiColor(-red, -green, -blue);
142 }
143
144 friend NiColor operator-(float a_lhs, const NiColor& a_rhs)
145 {
146 return NiColor(
147 a_lhs - a_rhs.red,
148 a_lhs - a_rhs.green,
149 a_lhs - a_rhs.blue);
150 }
151
152 [[nodiscard]] NiColor operator*(const NiColor& a_rhs) const noexcept
153 {
154 NiColor tmp = *this;
155 for (std::size_t i = 0; i < kTotal; ++i) {
156 tmp[i] *= a_rhs[i];
157 }
158 return tmp;
159 }
160
161 NiColor& operator*=(const NiColor& a_rhs) noexcept
162 {
163 for (std::size_t i = 0; i < kTotal; ++i) {
164 operator[](i) *= a_rhs[i];
165 }
166 return *this;
167 }
168
169 friend NiColor operator*(float a_lhs, const NiColor& a_rhs)
170 {
171 return NiColor(
172 a_lhs * a_rhs.red,
173 a_lhs * a_rhs.green,
174 a_lhs * a_rhs.blue);
175 }
176
177 [[nodiscard]] NiColor operator/(const NiColor& a_rhs) const noexcept
178 {
179 NiColor tmp = *this;
180 for (std::size_t i = 0; i < kTotal; ++i) {
181 tmp[i] /= a_rhs[i];
182 }
183 return tmp;
184 }
185
186 NiColor& operator/=(const NiColor& a_rhs) noexcept
187 {
188 for (std::size_t i = 0; i < kTotal; ++i) {
189 operator[](i) /= a_rhs[i];
190 }
191 return *this;
192 }
193
194 friend NiColor operator/(float a_lhs, const NiColor& a_rhs)
195 {
196 return NiColor(
197 a_lhs / a_rhs.red,
198 a_lhs / a_rhs.green,
199 a_lhs / a_rhs.blue);
200 }
201
202 [[nodiscard]] NiColor operator+(float a_value) const noexcept
203 {
204 NiColor tmp = *this;
205 for (std::size_t i = 0; i < kTotal; ++i) {
206 tmp[i] += a_value;
207 }
208 return tmp;
209 }
210
211 NiColor& operator+=(float a_value) noexcept
212 {
213 for (std::size_t i = 0; i < kTotal; ++i) {
214 operator[](i) += a_value;
215 }
216 return *this;
217 }
218
219 [[nodiscard]] NiColor operator-(float a_value) const noexcept
220 {
221 NiColor tmp = *this;
222 for (std::size_t i = 0; i < kTotal; ++i) {
223 tmp[i] -= a_value;
224 }
225 return tmp;
226 }
227
228 NiColor& operator-=(float a_value) noexcept
229 {
230 for (std::size_t i = 0; i < kTotal; ++i) {
231 operator[](i) -= a_value;
232 }
233 return *this;
234 }
235
236 [[nodiscard]] NiColor operator*(float a_value) const noexcept
237 {
238 NiColor tmp = *this;
239 for (std::size_t i = 0; i < kTotal; ++i) {
240 tmp[i] *= a_value;
241 }
242 return tmp;
243 }
244
245 NiColor& operator*=(float a_value) noexcept
246 {
247 for (std::size_t i = 0; i < kTotal; ++i) {
248 operator[](i) *= a_value;
249 }
250 return *this;
251 }
252
253 [[nodiscard]] NiColor operator/(float a_value) const noexcept
254 {
255 NiColor tmp = *this;
256 for (std::size_t i = 0; i < kTotal; ++i) {
257 tmp[i] /= a_value;
258 }
259 return tmp;
260 }
261
262 NiColor& operator/=(float a_value) noexcept
263 {
264 for (std::size_t i = 0; i < kTotal; ++i) {
265 operator[](i) /= a_value;
266 }
267 return *this;
268 }
269
270 [[nodiscard]] std::uint32_t ToInt() const;
271 [[nodiscard]] std::string ToHex() const;
272
273 // members
274 float red; // 0
275 float green; // 4
276 float blue; // 8
277 private:
279 };
280 static_assert(sizeof(NiColor) == 0xC);
281
283 {
284 public:
285 enum : std::size_t
286 {
291
292 kTotal
293 };
294
295 constexpr NiColorA() noexcept :
296 red(0.0),
297 green(0.0),
298 blue(0.0),
299 alpha(0.0)
300 {}
301
302 constexpr NiColorA(const NiColorA& a_rhs) noexcept :
303 red(a_rhs.red),
304 green(a_rhs.green),
305 blue(a_rhs.blue),
306 alpha(a_rhs.alpha)
307 {}
308
309 constexpr NiColorA(NiColorA&& a_rhs) noexcept :
310 red(std::move(a_rhs.red)),
311 green(std::move(a_rhs.green)),
312 blue(std::move(a_rhs.blue)),
313 alpha(std::move(a_rhs.alpha))
314 {}
315
316 constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept :
317 red(a_red),
318 green(a_green),
319 blue(a_blue),
320 alpha(a_alpha)
321 {}
322
323 NiColorA(const Color& a_rhs);
324 ~NiColorA() noexcept = default;
325
326 constexpr NiColorA& operator=(const NiColorA& a_rhs) noexcept
327 {
328 if (this != std::addressof(a_rhs)) {
329 red = a_rhs.red;
330 green = a_rhs.green;
331 blue = a_rhs.blue;
332 alpha = a_rhs.alpha;
333 }
334 return *this;
335 }
336
337 constexpr NiColorA& operator=(NiColorA&& a_rhs) noexcept
338 {
339 if (this != std::addressof(a_rhs)) {
340 red = std::move(a_rhs.red);
341 green = std::move(a_rhs.green);
342 blue = std::move(a_rhs.blue);
343 alpha = std::move(a_rhs.alpha);
344 }
345 return *this;
346 }
347
348 constexpr NiColorA& operator=(const NiColor& a_rhs) noexcept;
349
350 [[nodiscard]] friend constexpr bool operator==(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
351 {
352 for (std::size_t i = 0; i < kTotal; ++i) {
353 if (a_lhs[i] != a_rhs[i]) {
354 return false;
355 }
356 }
357 return true;
358 }
359
360 [[nodiscard]] friend constexpr bool operator!=(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
361 {
362 return !(a_lhs == a_rhs);
363 }
364
365 [[nodiscard]] constexpr float& operator[](std::size_t a_idx) noexcept
366 {
367 assert(a_idx < kTotal);
368 return std::addressof(red)[a_idx];
369 }
370
371 [[nodiscard]] constexpr const float& operator[](std::size_t a_idx) const noexcept
372 {
373 assert(a_idx < kTotal);
374 return std::addressof(red)[a_idx];
375 }
376
377 [[nodiscard]] NiColorA operator*(float a_value) const noexcept
378 {
379 NiColorA tmp = *this;
380 for (std::size_t i = 0; i < kTotal; ++i) {
381 tmp[i] *= a_value;
382 }
383 return tmp;
384 }
385
386 NiColorA& operator*=(float a_value) noexcept
387 {
388 for (std::size_t i = 0; i < kTotal; ++i) {
389 operator[](i) *= a_value;
390 }
391 return *this;
392 }
393
394 [[nodiscard]] NiColorA operator/(float a_value) const noexcept
395 {
396 NiColorA tmp = *this;
397 for (std::size_t i = 0; i < kTotal; ++i) {
398 tmp[i] /= a_value;
399 }
400 return tmp;
401 }
402
403 NiColorA& operator/=(float a_value) noexcept
404 {
405 for (std::size_t i = 0; i < kTotal; ++i) {
406 operator[](i) /= a_value;
407 }
408 return *this;
409 }
410
411 // members
412 float red; // 00
413 float green; // 04
414 float blue; // 08
415 float alpha; // 0C
416 private:
418 };
419 static_assert(sizeof(NiColorA) == 0x10);
420
421 constexpr NiColor& NiColor::operator=(const NiColorA& a_rhs) noexcept
422 {
423 red = a_rhs.red;
424 green = a_rhs.green;
425 blue = a_rhs.blue;
426 return *this;
427 }
428
429 constexpr NiColorA& NiColorA::operator=(const NiColor& a_rhs) noexcept
430 {
431 red = a_rhs.red;
432 green = a_rhs.green;
433 blue = a_rhs.blue;
434 alpha = 0.0;
435 return *this;
436 }
437}
#define KEEP_FOR_RE()
Definition PCH.h:517
Definition NiColor.h:283
float alpha
Definition NiColor.h:415
NiColorA & operator*=(float a_value) noexcept
Definition NiColor.h:386
constexpr NiColorA & operator=(NiColorA &&a_rhs) noexcept
Definition NiColor.h:337
~NiColorA() noexcept=default
constexpr NiColorA() noexcept
Definition NiColor.h:295
@ kTotal
Definition NiColor.h:292
@ kRed
Definition NiColor.h:287
@ kBlue
Definition NiColor.h:289
@ kAlpha
Definition NiColor.h:290
@ kGreen
Definition NiColor.h:288
friend constexpr bool operator==(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition NiColor.h:350
constexpr float & operator[](std::size_t a_idx) noexcept
Definition NiColor.h:365
friend constexpr bool operator!=(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition NiColor.h:360
NiColorA & operator/=(float a_value) noexcept
Definition NiColor.h:403
float blue
Definition NiColor.h:414
constexpr NiColorA & operator=(const NiColorA &a_rhs) noexcept
Definition NiColor.h:326
constexpr NiColorA(NiColorA &&a_rhs) noexcept
Definition NiColor.h:309
float red
Definition NiColor.h:412
constexpr NiColorA(const NiColorA &a_rhs) noexcept
Definition NiColor.h:302
NiColorA operator/(float a_value) const noexcept
Definition NiColor.h:394
constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept
Definition NiColor.h:316
constexpr const float & operator[](std::size_t a_idx) const noexcept
Definition NiColor.h:371
NiColorA(const Color &a_rhs)
NiColorA operator*(float a_value) const noexcept
Definition NiColor.h:377
float green
Definition NiColor.h:413
Definition NiColor.h:11
std::string ToHex() const
constexpr NiColor(NiColor &&a_rhs) noexcept
Definition NiColor.h:34
NiColor & operator+=(const NiColor &a_rhs) noexcept
Definition NiColor.h:114
std::uint32_t ToInt() const
float red
Definition NiColor.h:274
NiColor & operator+=(float a_value) noexcept
Definition NiColor.h:211
friend constexpr bool operator==(const NiColor &a_lhs, const NiColor &a_rhs) noexcept
Definition NiColor.h:78
NiColor & operator*=(float a_value) noexcept
Definition NiColor.h:245
NiColor & operator/=(const NiColor &a_rhs) noexcept
Definition NiColor.h:186
float green
Definition NiColor.h:275
float blue
Definition NiColor.h:276
~NiColor() noexcept=default
friend constexpr bool operator!=(const NiColor &a_lhs, const NiColor &a_rhs) noexcept
Definition NiColor.h:88
NiColor & operator*=(const NiColor &a_rhs) noexcept
Definition NiColor.h:161
friend NiColor operator-(float a_lhs, const NiColor &a_rhs)
Definition NiColor.h:144
constexpr const float & operator[](std::size_t a_idx) const noexcept
Definition NiColor.h:99
NiColor operator-(float a_value) const noexcept
Definition NiColor.h:219
constexpr float & operator[](std::size_t a_idx) noexcept
Definition NiColor.h:93
NiColor operator/(const NiColor &a_rhs) const noexcept
Definition NiColor.h:177
NiColor operator-()
Definition NiColor.h:139
NiColor operator/(float a_value) const noexcept
Definition NiColor.h:253
constexpr NiColor(const NiColor &a_rhs) noexcept
Definition NiColor.h:28
NiColor & operator-=(const NiColor &a_rhs) noexcept
Definition NiColor.h:131
constexpr NiColor & operator=(const NiColor &a_rhs) noexcept
Definition NiColor.h:56
friend NiColor operator/(float a_lhs, const NiColor &a_rhs)
Definition NiColor.h:194
NiColor operator-(const NiColor &a_rhs) const noexcept
Definition NiColor.h:122
NiColor operator+(float a_value) const noexcept
Definition NiColor.h:202
NiColor(const Color &a_rhs)
NiColor operator*(const NiColor &a_rhs) const noexcept
Definition NiColor.h:152
constexpr NiColor & operator=(NiColor &&a_rhs) noexcept
Definition NiColor.h:66
NiColor & operator/=(float a_value) noexcept
Definition NiColor.h:262
constexpr NiColor(std::uint32_t a_hexValue) noexcept
Definition NiColor.h:46
friend NiColor operator*(float a_lhs, const NiColor &a_rhs)
Definition NiColor.h:169
NiColor & operator-=(float a_value) noexcept
Definition NiColor.h:228
@ kBlue
Definition NiColor.h:17
@ kGreen
Definition NiColor.h:16
@ kRed
Definition NiColor.h:15
@ kTotal
Definition NiColor.h:19
constexpr NiColor(float a_red, float a_green, float a_blue) noexcept
Definition NiColor.h:40
NiColor operator+(const NiColor &a_rhs) const noexcept
Definition NiColor.h:105
NiColor operator*(float a_value) const noexcept
Definition NiColor.h:236
constexpr NiColor() noexcept
Definition NiColor.h:22
Definition AbsorbEffect.h:6
Definition Color.h:8