CommonLibSSE NG
NiColor.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace 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 
139  friend NiColor operator-(float a_lhs, const NiColor& a_rhs)
140  {
141  return NiColor(
142  a_lhs - a_rhs.red,
143  a_lhs - a_rhs.green,
144  a_lhs - a_rhs.blue);
145  }
146 
147  [[nodiscard]] NiColor operator*(const NiColor& a_rhs) const noexcept
148  {
149  NiColor tmp = *this;
150  for (std::size_t i = 0; i < kTotal; ++i) {
151  tmp[i] *= a_rhs[i];
152  }
153  return tmp;
154  }
155 
156  NiColor& operator*=(const NiColor& a_rhs) noexcept
157  {
158  for (std::size_t i = 0; i < kTotal; ++i) {
159  operator[](i) *= a_rhs[i];
160  }
161  return *this;
162  }
163 
164  friend NiColor operator*(float a_lhs, const NiColor& a_rhs)
165  {
166  return NiColor(
167  a_lhs * a_rhs.red,
168  a_lhs * a_rhs.green,
169  a_lhs * a_rhs.blue);
170  }
171 
172  [[nodiscard]] NiColor operator/(const NiColor& a_rhs) const noexcept
173  {
174  NiColor tmp = *this;
175  for (std::size_t i = 0; i < kTotal; ++i) {
176  tmp[i] /= a_rhs[i];
177  }
178  return tmp;
179  }
180 
181  NiColor& operator/=(const NiColor& a_rhs) noexcept
182  {
183  for (std::size_t i = 0; i < kTotal; ++i) {
184  operator[](i) /= a_rhs[i];
185  }
186  return *this;
187  }
188 
189  friend NiColor operator/(float a_lhs, const NiColor& a_rhs)
190  {
191  return NiColor(
192  a_lhs / a_rhs.red,
193  a_lhs / a_rhs.green,
194  a_lhs / a_rhs.blue);
195  }
196 
197  [[nodiscard]] NiColor operator+(float a_value) const noexcept
198  {
199  NiColor tmp = *this;
200  for (std::size_t i = 0; i < kTotal; ++i) {
201  tmp[i] += a_value;
202  }
203  return tmp;
204  }
205 
206  NiColor& operator+=(float a_value) noexcept
207  {
208  for (std::size_t i = 0; i < kTotal; ++i) {
209  operator[](i) += a_value;
210  }
211  return *this;
212  }
213 
214  [[nodiscard]] NiColor operator-(float a_value) const noexcept
215  {
216  NiColor tmp = *this;
217  for (std::size_t i = 0; i < kTotal; ++i) {
218  tmp[i] -= a_value;
219  }
220  return tmp;
221  }
222 
223  NiColor& operator-=(float a_value) noexcept
224  {
225  for (std::size_t i = 0; i < kTotal; ++i) {
226  operator[](i) -= a_value;
227  }
228  return *this;
229  }
230 
231  [[nodiscard]] NiColor operator*(float a_value) const noexcept
232  {
233  NiColor tmp = *this;
234  for (std::size_t i = 0; i < kTotal; ++i) {
235  tmp[i] *= a_value;
236  }
237  return tmp;
238  }
239 
240  NiColor& operator*=(float a_value) noexcept
241  {
242  for (std::size_t i = 0; i < kTotal; ++i) {
243  operator[](i) *= a_value;
244  }
245  return *this;
246  }
247 
248  [[nodiscard]] NiColor operator/(float a_value) const noexcept
249  {
250  NiColor tmp = *this;
251  for (std::size_t i = 0; i < kTotal; ++i) {
252  tmp[i] /= a_value;
253  }
254  return tmp;
255  }
256 
257  NiColor& operator/=(float a_value) noexcept
258  {
259  for (std::size_t i = 0; i < kTotal; ++i) {
260  operator[](i) /= a_value;
261  }
262  return *this;
263  }
264 
265  [[nodiscard]] std::uint32_t ToInt() const;
266  [[nodiscard]] std::string ToHex() const;
267 
268  // members
269  float red; // 0
270  float green; // 4
271  float blue; // 8
272  };
273  static_assert(sizeof(NiColor) == 0xC);
274 
275  class NiColorA
276  {
277  public:
278  enum : std::size_t
279  {
284 
285  kTotal
286  };
287 
288  constexpr NiColorA() noexcept :
289  red(0.0),
290  green(0.0),
291  blue(0.0),
292  alpha(0.0)
293  {}
294 
295  constexpr NiColorA(const NiColorA& a_rhs) noexcept :
296  red(a_rhs.red),
297  green(a_rhs.green),
298  blue(a_rhs.blue),
299  alpha(a_rhs.alpha)
300  {}
301 
302  constexpr NiColorA(NiColorA&& a_rhs) noexcept :
303  red(std::move(a_rhs.red)),
304  green(std::move(a_rhs.green)),
305  blue(std::move(a_rhs.blue)),
306  alpha(std::move(a_rhs.alpha))
307  {}
308 
309  constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept :
310  red(a_red),
311  green(a_green),
312  blue(a_blue),
313  alpha(a_alpha)
314  {}
315 
316  NiColorA(const Color& a_rhs);
317  ~NiColorA() noexcept = default;
318 
319  constexpr NiColorA& operator=(const NiColorA& a_rhs) noexcept
320  {
321  if (this != std::addressof(a_rhs)) {
322  red = a_rhs.red;
323  green = a_rhs.green;
324  blue = a_rhs.blue;
325  alpha = a_rhs.alpha;
326  }
327  return *this;
328  }
329 
330  constexpr NiColorA& operator=(NiColorA&& a_rhs) noexcept
331  {
332  if (this != std::addressof(a_rhs)) {
333  red = std::move(a_rhs.red);
334  green = std::move(a_rhs.green);
335  blue = std::move(a_rhs.blue);
336  alpha = std::move(a_rhs.alpha);
337  }
338  return *this;
339  }
340 
341  constexpr NiColorA& operator=(const NiColor& a_rhs) noexcept;
342 
343  [[nodiscard]] friend constexpr bool operator==(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
344  {
345  for (std::size_t i = 0; i < kTotal; ++i) {
346  if (a_lhs[i] != a_rhs[i]) {
347  return false;
348  }
349  }
350  return true;
351  }
352 
353  [[nodiscard]] friend constexpr bool operator!=(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
354  {
355  return !(a_lhs == a_rhs);
356  }
357 
358  [[nodiscard]] constexpr float& operator[](std::size_t a_idx) noexcept
359  {
360  assert(a_idx < kTotal);
361  return std::addressof(red)[a_idx];
362  }
363 
364  [[nodiscard]] constexpr const float& operator[](std::size_t a_idx) const noexcept
365  {
366  assert(a_idx < kTotal);
367  return std::addressof(red)[a_idx];
368  }
369 
370  [[nodiscard]] NiColorA operator*(float a_value) const noexcept
371  {
372  NiColorA tmp = *this;
373  for (std::size_t i = 0; i < kTotal; ++i) {
374  tmp[i] *= a_value;
375  }
376  return tmp;
377  }
378 
379  NiColorA& operator*=(float a_value) noexcept
380  {
381  for (std::size_t i = 0; i < kTotal; ++i) {
382  operator[](i) *= a_value;
383  }
384  return *this;
385  }
386 
387  [[nodiscard]] NiColorA operator/(float a_value) const noexcept
388  {
389  NiColorA tmp = *this;
390  for (std::size_t i = 0; i < kTotal; ++i) {
391  tmp[i] /= a_value;
392  }
393  return tmp;
394  }
395 
396  NiColorA& operator/=(float a_value) noexcept
397  {
398  for (std::size_t i = 0; i < kTotal; ++i) {
399  operator[](i) /= a_value;
400  }
401  return *this;
402  }
403 
404  // members
405  float red; // 00
406  float green; // 04
407  float blue; // 08
408  float alpha; // 0C
409  };
410  static_assert(sizeof(NiColorA) == 0x10);
411 
412  constexpr NiColor& NiColor::operator=(const NiColorA& a_rhs) noexcept
413  {
414  red = a_rhs.red;
415  green = a_rhs.green;
416  blue = a_rhs.blue;
417  return *this;
418  }
419 
420  constexpr NiColorA& NiColorA::operator=(const NiColor& a_rhs) noexcept
421  {
422  red = a_rhs.red;
423  green = a_rhs.green;
424  blue = a_rhs.blue;
425  alpha = 0.0;
426  return *this;
427  }
428 }
Definition: NiColor.h:276
float alpha
Definition: NiColor.h:408
constexpr friend bool operator!=(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition: NiColor.h:353
~NiColorA() noexcept=default
constexpr NiColorA() noexcept
Definition: NiColor.h:288
constexpr friend bool operator==(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition: NiColor.h:343
constexpr NiColorA & operator=(const NiColorA &a_rhs) noexcept
Definition: NiColor.h:319
NiColorA & operator/=(float a_value) noexcept
Definition: NiColor.h:396
constexpr NiColorA & operator=(NiColorA &&a_rhs) noexcept
Definition: NiColor.h:330
float blue
Definition: NiColor.h:407
constexpr NiColorA(NiColorA &&a_rhs) noexcept
Definition: NiColor.h:302
float red
Definition: NiColor.h:405
constexpr const float & operator[](std::size_t a_idx) const noexcept
Definition: NiColor.h:364
NiColorA & operator*=(float a_value) noexcept
Definition: NiColor.h:379
constexpr NiColorA(const NiColorA &a_rhs) noexcept
Definition: NiColor.h:295
constexpr float & operator[](std::size_t a_idx) noexcept
Definition: NiColor.h:358
NiColorA operator/(float a_value) const noexcept
Definition: NiColor.h:387
constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept
Definition: NiColor.h:309
NiColorA(const Color &a_rhs)
@ kTotal
Definition: NiColor.h:285
@ kRed
Definition: NiColor.h:280
@ kBlue
Definition: NiColor.h:282
@ kAlpha
Definition: NiColor.h:283
@ kGreen
Definition: NiColor.h:281
NiColorA operator*(float a_value) const noexcept
Definition: NiColor.h:370
float green
Definition: NiColor.h:406
Definition: NiColor.h:11
std::string ToHex() const
NiColor & operator+=(float a_value) noexcept
Definition: NiColor.h:206
constexpr NiColor(NiColor &&a_rhs) noexcept
Definition: NiColor.h:34
std::uint32_t ToInt() const
NiColor & operator*=(float a_value) noexcept
Definition: NiColor.h:240
float red
Definition: NiColor.h:269
constexpr NiColor & operator=(NiColor &&a_rhs) noexcept
Definition: NiColor.h:66
NiColor & operator-=(float a_value) noexcept
Definition: NiColor.h:223
NiColor & operator+=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:114
float green
Definition: NiColor.h:270
@ kBlue
Definition: NiColor.h:17
@ kGreen
Definition: NiColor.h:16
@ kRed
Definition: NiColor.h:15
@ kTotal
Definition: NiColor.h:19
float blue
Definition: NiColor.h:271
~NiColor() noexcept=default
constexpr const float & operator[](std::size_t a_idx) const noexcept
Definition: NiColor.h:99
friend NiColor operator-(float a_lhs, const NiColor &a_rhs)
Definition: NiColor.h:139
NiColor & operator-=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:131
NiColor operator-(float a_value) const noexcept
Definition: NiColor.h:214
constexpr friend bool operator==(const NiColor &a_lhs, const NiColor &a_rhs) noexcept
Definition: NiColor.h:78
NiColor operator/(const NiColor &a_rhs) const noexcept
Definition: NiColor.h:172
NiColor operator/(float a_value) const noexcept
Definition: NiColor.h:248
constexpr NiColor(const NiColor &a_rhs) noexcept
Definition: NiColor.h:28
friend NiColor operator/(float a_lhs, const NiColor &a_rhs)
Definition: NiColor.h:189
constexpr float & operator[](std::size_t a_idx) noexcept
Definition: NiColor.h:93
NiColor operator-(const NiColor &a_rhs) const noexcept
Definition: NiColor.h:122
NiColor operator+(float a_value) const noexcept
Definition: NiColor.h:197
NiColor(const Color &a_rhs)
constexpr NiColor & operator=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:56
NiColor & operator/=(float a_value) noexcept
Definition: NiColor.h:257
constexpr friend bool operator!=(const NiColor &a_lhs, const NiColor &a_rhs) noexcept
Definition: NiColor.h:88
NiColor operator*(const NiColor &a_rhs) const noexcept
Definition: NiColor.h:147
NiColor & operator/=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:181
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:164
NiColor & operator*=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:156
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:231
constexpr NiColor() noexcept
Definition: NiColor.h:22
Definition: AbsorbEffect.h:6
string(const CharT(&)[N]) -> string< CharT, N - 1 >
Definition: Color.h:8