CommonLibSSE (powerof3)
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 
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  };
278  static_assert(sizeof(NiColor) == 0xC);
279 
280  class NiColorA
281  {
282  public:
283  enum : std::size_t
284  {
289 
290  kTotal
291  };
292 
293  constexpr NiColorA() noexcept :
294  red(0.0),
295  green(0.0),
296  blue(0.0),
297  alpha(0.0)
298  {}
299 
300  constexpr NiColorA(const NiColorA& a_rhs) noexcept :
301  red(a_rhs.red),
302  green(a_rhs.green),
303  blue(a_rhs.blue),
304  alpha(a_rhs.alpha)
305  {}
306 
307  constexpr NiColorA(NiColorA&& a_rhs) noexcept :
308  red(std::move(a_rhs.red)),
309  green(std::move(a_rhs.green)),
310  blue(std::move(a_rhs.blue)),
311  alpha(std::move(a_rhs.alpha))
312  {}
313 
314  constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept :
315  red(a_red),
316  green(a_green),
317  blue(a_blue),
318  alpha(a_alpha)
319  {}
320 
321  NiColorA(const Color& a_rhs);
322  ~NiColorA() noexcept = default;
323 
324  constexpr NiColorA& operator=(const NiColorA& a_rhs) noexcept
325  {
326  if (this != std::addressof(a_rhs)) {
327  red = a_rhs.red;
328  green = a_rhs.green;
329  blue = a_rhs.blue;
330  alpha = a_rhs.alpha;
331  }
332  return *this;
333  }
334 
335  constexpr NiColorA& operator=(NiColorA&& a_rhs) noexcept
336  {
337  if (this != std::addressof(a_rhs)) {
338  red = std::move(a_rhs.red);
339  green = std::move(a_rhs.green);
340  blue = std::move(a_rhs.blue);
341  alpha = std::move(a_rhs.alpha);
342  }
343  return *this;
344  }
345 
346  constexpr NiColorA& operator=(const NiColor& a_rhs) noexcept;
347 
348  [[nodiscard]] friend constexpr bool operator==(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
349  {
350  for (std::size_t i = 0; i < kTotal; ++i) {
351  if (a_lhs[i] != a_rhs[i]) {
352  return false;
353  }
354  }
355  return true;
356  }
357 
358  [[nodiscard]] friend constexpr bool operator!=(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
359  {
360  return !(a_lhs == a_rhs);
361  }
362 
363  [[nodiscard]] constexpr float& operator[](std::size_t a_idx) noexcept
364  {
365  assert(a_idx < kTotal);
366  return std::addressof(red)[a_idx];
367  }
368 
369  [[nodiscard]] constexpr const float& operator[](std::size_t a_idx) const noexcept
370  {
371  assert(a_idx < kTotal);
372  return std::addressof(red)[a_idx];
373  }
374 
375  [[nodiscard]] NiColorA operator*(float a_value) const noexcept
376  {
377  NiColorA tmp = *this;
378  for (std::size_t i = 0; i < kTotal; ++i) {
379  tmp[i] *= a_value;
380  }
381  return tmp;
382  }
383 
384  NiColorA& operator*=(float a_value) noexcept
385  {
386  for (std::size_t i = 0; i < kTotal; ++i) {
387  operator[](i) *= a_value;
388  }
389  return *this;
390  }
391 
392  [[nodiscard]] NiColorA operator/(float a_value) const noexcept
393  {
394  NiColorA tmp = *this;
395  for (std::size_t i = 0; i < kTotal; ++i) {
396  tmp[i] /= a_value;
397  }
398  return tmp;
399  }
400 
401  NiColorA& operator/=(float a_value) noexcept
402  {
403  for (std::size_t i = 0; i < kTotal; ++i) {
404  operator[](i) /= a_value;
405  }
406  return *this;
407  }
408 
409  // members
410  float red; // 00
411  float green; // 04
412  float blue; // 08
413  float alpha; // 0C
414  };
415  static_assert(sizeof(NiColorA) == 0x10);
416 
417  constexpr NiColor& NiColor::operator=(const NiColorA& a_rhs) noexcept
418  {
419  red = a_rhs.red;
420  green = a_rhs.green;
421  blue = a_rhs.blue;
422  return *this;
423  }
424 
425  constexpr NiColorA& NiColorA::operator=(const NiColor& a_rhs) noexcept
426  {
427  red = a_rhs.red;
428  green = a_rhs.green;
429  blue = a_rhs.blue;
430  alpha = 0.0;
431  return *this;
432  }
433 }
Definition: NiColor.h:281
float alpha
Definition: NiColor.h:413
constexpr friend bool operator!=(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition: NiColor.h:358
~NiColorA() noexcept=default
constexpr NiColorA() noexcept
Definition: NiColor.h:293
constexpr friend bool operator==(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition: NiColor.h:348
@ kTotal
Definition: NiColor.h:290
@ kRed
Definition: NiColor.h:285
@ kBlue
Definition: NiColor.h:287
@ kAlpha
Definition: NiColor.h:288
@ kGreen
Definition: NiColor.h:286
constexpr NiColorA & operator=(const NiColorA &a_rhs) noexcept
Definition: NiColor.h:324
NiColorA & operator/=(float a_value) noexcept
Definition: NiColor.h:401
constexpr NiColorA & operator=(NiColorA &&a_rhs) noexcept
Definition: NiColor.h:335
float blue
Definition: NiColor.h:412
constexpr NiColorA(NiColorA &&a_rhs) noexcept
Definition: NiColor.h:307
float red
Definition: NiColor.h:410
constexpr const float & operator[](std::size_t a_idx) const noexcept
Definition: NiColor.h:369
NiColorA & operator*=(float a_value) noexcept
Definition: NiColor.h:384
constexpr NiColorA(const NiColorA &a_rhs) noexcept
Definition: NiColor.h:300
constexpr float & operator[](std::size_t a_idx) noexcept
Definition: NiColor.h:363
NiColorA operator/(float a_value) const noexcept
Definition: NiColor.h:392
constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept
Definition: NiColor.h:314
NiColorA(const Color &a_rhs)
NiColorA operator*(float a_value) const noexcept
Definition: NiColor.h:375
float green
Definition: NiColor.h:411
Definition: NiColor.h:11
std::string ToHex() const
NiColor & operator+=(float a_value) noexcept
Definition: NiColor.h:211
constexpr NiColor(NiColor &&a_rhs) noexcept
Definition: NiColor.h:34
std::uint32_t ToInt() const
NiColor & operator*=(float a_value) noexcept
Definition: NiColor.h:245
float red
Definition: NiColor.h:274
constexpr NiColor & operator=(NiColor &&a_rhs) noexcept
Definition: NiColor.h:66
NiColor & operator-=(float a_value) noexcept
Definition: NiColor.h:228
NiColor & operator+=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:114
float green
Definition: NiColor.h:275
float blue
Definition: NiColor.h:276
~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:144
NiColor & operator-=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:131
NiColor operator-(float a_value) const noexcept
Definition: NiColor.h:219
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: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
friend NiColor operator/(float a_lhs, const NiColor &a_rhs)
Definition: NiColor.h:194
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:202
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:262
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:152
NiColor & operator/=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:186
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
@ kBlue
Definition: NiColor.h:17
@ kGreen
Definition: NiColor.h:16
@ kRed
Definition: NiColor.h:15
@ kTotal
Definition: NiColor.h:19
NiColor & operator*=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:161
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
string(const CharT(&)[N]) -> string< CharT, N - 1 >
Definition: Color.h:8