CommonLibSSE NG
Loading...
Searching...
No Matches
Color.h
Go to the documentation of this file.
1#pragma once
2
3namespace RE
4{
5 class NiColor;
6
7 struct Color
8 {
9 public:
10 enum : std::size_t
11 {
16
17 kTotal
18 };
19
20 constexpr Color() noexcept :
21 red(0),
22 green(0),
23 blue(0),
24 alpha(0)
25 {}
26
27 constexpr Color(const Color& a_rhs) noexcept :
28 red(a_rhs.red),
29 green(a_rhs.green),
30 blue(a_rhs.blue),
31 alpha(a_rhs.alpha)
32 {}
33
34 constexpr Color(Color&& 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 alpha(std::move(a_rhs.alpha))
39 {}
40
41 constexpr Color(std::uint8_t a_red, std::uint8_t a_green, std::uint8_t a_blue, std::uint8_t a_alpha) noexcept :
42 red(a_red),
43 green(a_green),
44 blue(a_blue),
45 alpha(a_alpha)
46 {}
47
48 constexpr Color(std::uint32_t a_hexValue) noexcept :
49 red((a_hexValue >> 16) & 0xFF),
50 green((a_hexValue >> 8) & 0xFF),
51 blue((a_hexValue)&0xFF),
52 alpha(0)
53 {}
54
55 Color(const NiColor& a_rhs);
56 ~Color() noexcept = default;
57
58 constexpr Color& operator=(const Color& a_rhs) noexcept
59 {
60 if (this != std::addressof(a_rhs)) {
61 red = a_rhs.red;
62 green = a_rhs.green;
63 blue = a_rhs.blue;
64 alpha = a_rhs.alpha;
65 }
66 return *this;
67 }
68
69 constexpr Color& operator=(Color&& a_rhs) noexcept
70 {
71 if (this != std::addressof(a_rhs)) {
72 red = std::move(a_rhs.red);
73 green = std::move(a_rhs.green);
74 blue = std::move(a_rhs.blue);
75 alpha = std::move(a_rhs.alpha);
76 }
77 return *this;
78 }
79
80 [[nodiscard]] friend constexpr bool operator==(const Color& a_lhs, const Color& a_rhs) noexcept
81 {
82 for (std::size_t i = 0; i < kTotal; ++i) {
83 if (a_lhs[i] != a_rhs[i]) {
84 return false;
85 }
86 }
87 return true;
88 }
89
90 [[nodiscard]] friend constexpr bool operator!=(const Color& a_lhs, const Color& a_rhs) noexcept
91 {
92 return !(a_lhs == a_rhs);
93 }
94
95 [[nodiscard]] constexpr std::uint8_t& operator[](std::size_t a_idx) noexcept
96 {
97 assert(a_idx < kTotal);
98 return std::addressof(red)[a_idx];
99 }
100
101 [[nodiscard]] constexpr const std::uint8_t& operator[](std::size_t a_idx) const noexcept
102 {
103 assert(a_idx < kTotal);
104 return std::addressof(red)[a_idx];
105 }
106
107 [[nodiscard]] Color operator+(const Color& a_rhs) const noexcept
108 {
109 Color tmp = *this;
110 for (std::size_t i = 0; i < kTotal; ++i) {
111 tmp[i] += a_rhs[i];
112 }
113 return tmp;
114 }
115
116 Color& operator+=(const Color& a_rhs) noexcept
117 {
118 for (std::size_t i = 0; i < kTotal; ++i) {
119 operator[](i) += a_rhs[i];
120 }
121 return *this;
122 }
123
124 [[nodiscard]] Color operator-(const Color& a_rhs) const noexcept
125 {
126 Color tmp = *this;
127 for (std::size_t i = 0; i < kTotal; ++i) {
128 tmp[i] -= a_rhs[i];
129 }
130 return tmp;
131 }
132
133 Color& operator-=(const Color& a_rhs) noexcept
134 {
135 for (std::size_t i = 0; i < kTotal; ++i) {
136 operator[](i) -= a_rhs[i];
137 }
138 return *this;
139 }
140
141 friend Color operator-(std::uint8_t a_lhs, const Color& a_rhs)
142 {
143 return Color(
144 a_lhs - a_rhs.red,
145 a_lhs - a_rhs.green,
146 a_lhs - a_rhs.blue,
147 a_lhs - a_rhs.alpha);
148 }
149
150 [[nodiscard]] Color operator*(const Color& a_rhs) const noexcept
151 {
152 Color tmp = *this;
153 for (std::size_t i = 0; i < kTotal; ++i) {
154 tmp[i] *= a_rhs[i];
155 }
156 return tmp;
157 }
158
159 Color& operator*=(const Color& a_rhs) noexcept
160 {
161 for (std::size_t i = 0; i < kTotal; ++i) {
162 operator[](i) *= a_rhs[i];
163 }
164 return *this;
165 }
166
167 friend Color operator*(std::uint8_t a_lhs, const Color& a_rhs)
168 {
169 return Color(
170 a_lhs * a_rhs.red,
171 a_lhs * a_rhs.green,
172 a_lhs * a_rhs.blue,
173 a_lhs * a_rhs.alpha);
174 }
175
176 [[nodiscard]] Color operator/(const Color& a_rhs) const noexcept
177 {
178 Color tmp = *this;
179 for (std::size_t i = 0; i < kTotal; ++i) {
180 tmp[i] /= a_rhs[i];
181 }
182 return tmp;
183 }
184
185 Color& operator/=(const Color& a_rhs) noexcept
186 {
187 for (std::size_t i = 0; i < kTotal; ++i) {
188 operator[](i) /= a_rhs[i];
189 }
190 return *this;
191 }
192
193 friend Color operator/(std::uint8_t a_lhs, const Color& a_rhs)
194 {
195 return Color(
196 a_lhs / a_rhs.red,
197 a_lhs / a_rhs.green,
198 a_lhs / a_rhs.blue,
199 a_lhs / a_rhs.alpha);
200 }
201
202 [[nodiscard]] Color operator+(std::uint8_t a_value) const noexcept
203 {
204 Color tmp = *this;
205 for (std::size_t i = 0; i < kTotal; ++i) {
206 tmp[i] += a_value;
207 }
208 return tmp;
209 }
210
211 Color& operator+=(std::uint8_t 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]] Color operator-(std::uint8_t a_value) const noexcept
220 {
221 Color tmp = *this;
222 for (std::size_t i = 0; i < kTotal; ++i) {
223 tmp[i] -= a_value;
224 }
225 return tmp;
226 }
227
228 Color& operator-=(std::uint8_t 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]] Color operator*(std::uint8_t a_value) const noexcept
237 {
238 Color tmp = *this;
239 for (std::size_t i = 0; i < kTotal; ++i) {
240 tmp[i] *= a_value;
241 }
242 return tmp;
243 }
244
245 Color& operator*=(std::uint8_t 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]] Color operator/(std::uint8_t a_value) const noexcept
254 {
255 Color tmp = *this;
256 for (std::size_t i = 0; i < kTotal; ++i) {
257 tmp[i] /= a_value;
258 }
259 return tmp;
260 }
261
262 Color& operator/=(std::uint8_t 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 std::uint32_t ToInt() const;
271 std::string ToHex() const;
272
273 // members
274 std::uint8_t red; // 0
275 std::uint8_t green; // 1
276 std::uint8_t blue; // 2
277 std::uint8_t alpha; // 3
278 };
279 static_assert(sizeof(Color) == 0x4);
280}
Definition NiColor.h:11
Definition AbsorbEffect.h:6
Definition Color.h:8
std::uint8_t blue
Definition Color.h:276
std::uint8_t red
Definition Color.h:274
Color operator*(const Color &a_rhs) const noexcept
Definition Color.h:150
constexpr Color(std::uint32_t a_hexValue) noexcept
Definition Color.h:48
Color operator/(std::uint8_t a_value) const noexcept
Definition Color.h:253
Color operator*(std::uint8_t a_value) const noexcept
Definition Color.h:236
constexpr Color(std::uint8_t a_red, std::uint8_t a_green, std::uint8_t a_blue, std::uint8_t a_alpha) noexcept
Definition Color.h:41
constexpr Color(Color &&a_rhs) noexcept
Definition Color.h:34
friend Color operator-(std::uint8_t a_lhs, const Color &a_rhs)
Definition Color.h:141
@ kBlue
Definition Color.h:14
@ kTotal
Definition Color.h:17
@ kRed
Definition Color.h:12
@ kGreen
Definition Color.h:13
@ kAlpha
Definition Color.h:15
Color & operator*=(const Color &a_rhs) noexcept
Definition Color.h:159
constexpr std::uint8_t & operator[](std::size_t a_idx) noexcept
Definition Color.h:95
constexpr Color & operator=(Color &&a_rhs) noexcept
Definition Color.h:69
Color & operator*=(std::uint8_t a_value) noexcept
Definition Color.h:245
std::uint8_t green
Definition Color.h:275
std::string ToHex() const
constexpr const std::uint8_t & operator[](std::size_t a_idx) const noexcept
Definition Color.h:101
friend Color operator*(std::uint8_t a_lhs, const Color &a_rhs)
Definition Color.h:167
Color operator-(const Color &a_rhs) const noexcept
Definition Color.h:124
constexpr Color(const Color &a_rhs) noexcept
Definition Color.h:27
Color(const NiColor &a_rhs)
~Color() noexcept=default
Color & operator-=(std::uint8_t a_value) noexcept
Definition Color.h:228
Color & operator/=(const Color &a_rhs) noexcept
Definition Color.h:185
Color operator+(const Color &a_rhs) const noexcept
Definition Color.h:107
Color operator-(std::uint8_t a_value) const noexcept
Definition Color.h:219
Color & operator+=(std::uint8_t a_value) noexcept
Definition Color.h:211
std::uint32_t ToInt() const
Color operator+(std::uint8_t a_value) const noexcept
Definition Color.h:202
Color operator/(const Color &a_rhs) const noexcept
Definition Color.h:176
constexpr Color() noexcept
Definition Color.h:20
Color & operator/=(std::uint8_t a_value) noexcept
Definition Color.h:262
friend constexpr bool operator!=(const Color &a_lhs, const Color &a_rhs) noexcept
Definition Color.h:90
Color & operator+=(const Color &a_rhs) noexcept
Definition Color.h:116
Color & operator-=(const Color &a_rhs) noexcept
Definition Color.h:133
std::uint8_t alpha
Definition Color.h:277
friend Color operator/(std::uint8_t a_lhs, const Color &a_rhs)
Definition Color.h:193
friend constexpr bool operator==(const Color &a_lhs, const Color &a_rhs) noexcept
Definition Color.h:80