CommonLibSSE (Parapets fork)
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 class NiColor
9 {
10 public:
11 enum : std::size_t
12 {
16
17 kTotal
18 };
19
20 constexpr NiColor() noexcept :
21 red(0.0),
22 green(0.0),
23 blue(0.0)
24 {}
25
26 constexpr NiColor(const NiColor& a_rhs) noexcept :
27 red(a_rhs.red),
28 green(a_rhs.green),
29 blue(a_rhs.blue)
30 {}
31
32 constexpr NiColor(NiColor&& a_rhs) noexcept :
33 red(std::move(a_rhs.red)),
34 green(std::move(a_rhs.green)),
35 blue(std::move(a_rhs.blue))
36 {}
37
38 constexpr NiColor(float a_red, float a_green, float a_blue) noexcept :
39 red(a_red),
40 green(a_green),
41 blue(a_blue)
42 {}
43
44 ~NiColor() noexcept = default;
45
46 constexpr NiColor& operator=(const NiColor& a_rhs) noexcept
47 {
48 if (this != std::addressof(a_rhs)) {
49 red = a_rhs.red;
50 green = a_rhs.green;
51 blue = a_rhs.blue;
52 }
53 return *this;
54 }
55
56 constexpr NiColor& operator=(NiColor&& a_rhs) noexcept
57 {
58 if (this != std::addressof(a_rhs)) {
59 red = std::move(a_rhs.red);
60 green = std::move(a_rhs.green);
61 blue = std::move(a_rhs.blue);
62 }
63 return *this;
64 }
65
66 constexpr NiColor& operator=(const NiColorA& a_rhs) noexcept;
67
68 [[nodiscard]] friend constexpr bool operator==(const NiColor& a_lhs, const NiColor& a_rhs) noexcept
69 {
70 for (std::size_t i = 0; i < kTotal; ++i) {
71 if (a_lhs[i] != a_rhs[i]) {
72 return false;
73 }
74 }
75 return true;
76 }
77
78 [[nodiscard]] friend constexpr bool operator!=(const NiColor& a_lhs, const NiColor& a_rhs) noexcept
79 {
80 return !(a_lhs == a_rhs);
81 }
82
83 [[nodiscard]] constexpr float& operator[](std::size_t a_idx) noexcept
84 {
85 assert(a_idx < kTotal);
86 return std::addressof(red)[a_idx];
87 }
88
89 [[nodiscard]] constexpr const float& operator[](std::size_t a_idx) const noexcept
90 {
91 assert(a_idx < kTotal);
92 return std::addressof(red)[a_idx];
93 }
94
95 [[nodiscard]] NiColor operator*(float a_value) const noexcept
96 {
97 NiColor tmp = *this;
98 for (std::size_t i = 0; i < kTotal; ++i) {
99 tmp[i] *= a_value;
100 }
101 return tmp;
102 }
103
104 NiColor& operator*=(float a_value) noexcept
105 {
106 for (std::size_t i = 0; i < kTotal; ++i) {
107 operator[](i) *= a_value;
108 }
109 return *this;
110 }
111
112 [[nodiscard]] NiColor operator/(float a_value) const noexcept
113 {
114 NiColor tmp = *this;
115 for (std::size_t i = 0; i < kTotal; ++i) {
116 tmp[i] /= a_value;
117 }
118 return tmp;
119 }
120
121 NiColor& operator/=(float a_value) noexcept
122 {
123 for (std::size_t i = 0; i < kTotal; ++i) {
124 operator[](i) /= a_value;
125 }
126 return *this;
127 }
128
129 // members
130 float red; // 0
131 float green; // 4
132 float blue; // 8
133 };
134 static_assert(sizeof(NiColor) == 0xC);
135
137 {
138 public:
139 enum : std::size_t
140 {
145
146 kTotal
147 };
148
149 constexpr NiColorA() noexcept :
150 red(0.0),
151 green(0.0),
152 blue(0.0),
153 alpha(0.0)
154 {}
155
156 constexpr NiColorA(const NiColorA& a_rhs) noexcept :
157 red(a_rhs.red),
158 green(a_rhs.green),
159 blue(a_rhs.blue),
160 alpha(a_rhs.alpha)
161 {}
162
163 constexpr NiColorA(NiColorA&& a_rhs) noexcept :
164 red(std::move(a_rhs.red)),
165 green(std::move(a_rhs.green)),
166 blue(std::move(a_rhs.blue)),
167 alpha(std::move(a_rhs.alpha))
168 {}
169
170 constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept :
171 red(a_red),
172 green(a_green),
173 blue(a_blue),
174 alpha(a_alpha)
175 {}
176
177 ~NiColorA() noexcept = default;
178
179 constexpr NiColorA& operator=(const NiColorA& a_rhs) noexcept
180 {
181 if (this != std::addressof(a_rhs)) {
182 red = a_rhs.red;
183 green = a_rhs.green;
184 blue = a_rhs.blue;
185 alpha = a_rhs.alpha;
186 }
187 return *this;
188 }
189
190 constexpr NiColorA& operator=(NiColorA&& a_rhs) noexcept
191 {
192 if (this != std::addressof(a_rhs)) {
193 red = std::move(a_rhs.red);
194 green = std::move(a_rhs.green);
195 blue = std::move(a_rhs.blue);
196 alpha = std::move(a_rhs.alpha);
197 }
198 return *this;
199 }
200
201 constexpr NiColorA& operator=(const NiColor& a_rhs) noexcept;
202
203 [[nodiscard]] friend constexpr bool operator==(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
204 {
205 for (std::size_t i = 0; i < kTotal; ++i) {
206 if (a_lhs[i] != a_rhs[i]) {
207 return false;
208 }
209 }
210 return true;
211 }
212
213 [[nodiscard]] friend constexpr bool operator!=(const NiColorA& a_lhs, const NiColorA& a_rhs) noexcept
214 {
215 return !(a_lhs == a_rhs);
216 }
217
218 [[nodiscard]] constexpr float& operator[](std::size_t a_idx) noexcept
219 {
220 assert(a_idx < kTotal);
221 return std::addressof(red)[a_idx];
222 }
223
224 [[nodiscard]] constexpr const float& operator[](std::size_t a_idx) const noexcept
225 {
226 assert(a_idx < kTotal);
227 return std::addressof(red)[a_idx];
228 }
229
230 [[nodiscard]] NiColorA operator*(float a_value) const noexcept
231 {
232 NiColorA tmp = *this;
233 for (std::size_t i = 0; i < kTotal; ++i) {
234 tmp[i] *= a_value;
235 }
236 return tmp;
237 }
238
239 NiColorA& operator*=(float a_value) noexcept
240 {
241 for (std::size_t i = 0; i < kTotal; ++i) {
242 operator[](i) *= a_value;
243 }
244 return *this;
245 }
246
247 [[nodiscard]] NiColorA operator/(float a_value) const noexcept
248 {
249 NiColorA tmp = *this;
250 for (std::size_t i = 0; i < kTotal; ++i) {
251 tmp[i] /= a_value;
252 }
253 return tmp;
254 }
255
256 NiColorA& operator/=(float a_value) noexcept
257 {
258 for (std::size_t i = 0; i < kTotal; ++i) {
259 operator[](i) /= a_value;
260 }
261 return *this;
262 }
263
264 // members
265 float red; // 00
266 float green; // 04
267 float blue; // 08
268 float alpha; // 0C
269 };
270 static_assert(sizeof(NiColorA) == 0x10);
271
272 constexpr NiColor& NiColor::operator=(const NiColorA& a_rhs) noexcept
273 {
274 red = a_rhs.red;
275 green = a_rhs.green;
276 blue = a_rhs.blue;
277 return *this;
278 }
279
280 constexpr NiColorA& NiColorA::operator=(const NiColor& a_rhs) noexcept
281 {
282 red = a_rhs.red;
283 green = a_rhs.green;
284 blue = a_rhs.blue;
285 alpha = 0.0;
286 return *this;
287 }
288}
Definition: NiColor.h:137
float alpha
Definition: NiColor.h:268
NiColorA & operator*=(float a_value) noexcept
Definition: NiColor.h:239
constexpr NiColorA & operator=(NiColorA &&a_rhs) noexcept
Definition: NiColor.h:190
~NiColorA() noexcept=default
constexpr NiColorA() noexcept
Definition: NiColor.h:149
friend constexpr bool operator==(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition: NiColor.h:203
constexpr float & operator[](std::size_t a_idx) noexcept
Definition: NiColor.h:218
friend constexpr bool operator!=(const NiColorA &a_lhs, const NiColorA &a_rhs) noexcept
Definition: NiColor.h:213
@ kTotal
Definition: NiColor.h:146
@ kRed
Definition: NiColor.h:141
@ kBlue
Definition: NiColor.h:143
@ kAlpha
Definition: NiColor.h:144
@ kGreen
Definition: NiColor.h:142
NiColorA & operator/=(float a_value) noexcept
Definition: NiColor.h:256
float blue
Definition: NiColor.h:267
constexpr NiColorA & operator=(const NiColorA &a_rhs) noexcept
Definition: NiColor.h:179
constexpr NiColorA(NiColorA &&a_rhs) noexcept
Definition: NiColor.h:163
float red
Definition: NiColor.h:265
constexpr NiColorA(const NiColorA &a_rhs) noexcept
Definition: NiColor.h:156
NiColorA operator/(float a_value) const noexcept
Definition: NiColor.h:247
constexpr NiColorA(float a_red, float a_green, float a_blue, float a_alpha) noexcept
Definition: NiColor.h:170
constexpr const float & operator[](std::size_t a_idx) const noexcept
Definition: NiColor.h:224
NiColorA operator*(float a_value) const noexcept
Definition: NiColor.h:230
float green
Definition: NiColor.h:266
Definition: NiColor.h:9
constexpr NiColor(NiColor &&a_rhs) noexcept
Definition: NiColor.h:32
float red
Definition: NiColor.h:130
friend constexpr bool operator==(const NiColor &a_lhs, const NiColor &a_rhs) noexcept
Definition: NiColor.h:68
NiColor & operator*=(float a_value) noexcept
Definition: NiColor.h:104
float green
Definition: NiColor.h:131
float blue
Definition: NiColor.h:132
~NiColor() noexcept=default
friend constexpr bool operator!=(const NiColor &a_lhs, const NiColor &a_rhs) noexcept
Definition: NiColor.h:78
constexpr const float & operator[](std::size_t a_idx) const noexcept
Definition: NiColor.h:89
constexpr float & operator[](std::size_t a_idx) noexcept
Definition: NiColor.h:83
NiColor operator/(float a_value) const noexcept
Definition: NiColor.h:112
constexpr NiColor(const NiColor &a_rhs) noexcept
Definition: NiColor.h:26
constexpr NiColor & operator=(const NiColor &a_rhs) noexcept
Definition: NiColor.h:46
@ kBlue
Definition: NiColor.h:15
@ kGreen
Definition: NiColor.h:14
@ kRed
Definition: NiColor.h:13
@ kTotal
Definition: NiColor.h:17
constexpr NiColor & operator=(NiColor &&a_rhs) noexcept
Definition: NiColor.h:56
NiColor & operator/=(float a_value) noexcept
Definition: NiColor.h:121
constexpr NiColor(float a_red, float a_green, float a_blue) noexcept
Definition: NiColor.h:38
NiColor operator*(float a_value) const noexcept
Definition: NiColor.h:95
constexpr NiColor() noexcept
Definition: NiColor.h:20
Definition: AbsorbEffect.h:6