NW4F Sys
Loading...
Searching...
No Matches
ut_Color.h
Go to the documentation of this file.
1#ifndef NW_UT_COLOR_H_
2#define NW_UT_COLOR_H_
3
4#include <nw/math/math_Types.h>
5
6namespace nw { namespace ut {
7
8// TODO
9struct Color4u8
10{
11public:
13
15 : r(0)
16 , g(0)
17 , b(0)
18 , a(1)
19 {
20 }
21
22 Color4u8(u8 red, u8 green, u8 blue, u8 alpha)
23 : r(red)
24 , g(green)
25 , b(blue)
26 , a(alpha)
27 {
28 }
29
30public:
35};
36
38
40{
41public:
43
44 static const int ELEMENT_MIN = 0;
45 static const int ELEMENT_MAX = 1;
46 static const int ALPHA_MIN = ELEMENT_MIN;
47 static const int ALPHA_MAX = ELEMENT_MAX;
48 static const int ALPHA_OPACITY = ALPHA_MAX;
49 static const int ALPHA_TRANSPARENT = ALPHA_MIN;
50
52 : r(0.0f)
53 , g(0.0f)
54 , b(0.0f)
55 , a(1.0f)
56 {
57 }
58
59 explicit FloatColor(const nw::math::VEC4& vec)
60 : r(vec.x)
61 , g(vec.y)
62 , b(vec.z)
63 , a(vec.w)
64 {
65 }
66
67 FloatColor(const SelfType& color)
68 : r(color.r)
69 , g(color.g)
70 , b(color.b)
71 , a(color.a)
72 {
73 }
74
75 FloatColor(const SelfType& color, f32 alpha)
76 : r(color.r)
77 , g(color.g)
78 , b(color.b)
79 , a(alpha)
80 {
81 }
82
83 FloatColor(f32 red, f32 green, f32 blue, f32 alpha)
84 : r(red)
85 , g(green)
86 , b(blue)
87 , a(alpha)
88 {
89 }
90
91 FloatColor& operator=(const FloatColor& other) = default;
92
94 {
95 }
96
97 SelfType& operator =(const nw::math::VEC4& vec)
98 {
99 this->Set( vec.x, vec.y, vec.z, vec.w );
100 return *this;
101 }
102
103 operator f32*() { return &r; }
104 operator const f32*() const { return &r; }
105
106 const SelfType operator +(const SelfType& right) const
107 {
109 this->r + right.r,
110 this->g + right.g,
111 this->b + right.b,
112 this->a + right.a
113 );
114 return color;
115 }
116
117 const SelfType operator -(const SelfType& right) const
118 {
120 this->r - right.r,
121 this->g - right.g,
122 this->b - right.b,
123 this->a - right.a
124 );
125 return color;
126 }
127
128 const SelfType operator *(const SelfType& right) const
129 {
131 this->r * right.r,
132 this->g * right.g,
133 this->b * right.b,
134 this->a * right.a
135 );
136 return color;
137 }
138
139#pragma clang diagnostic push
140#pragma clang diagnostic ignored "-Wfloat-equal"
141 const SelfType operator /(const SelfType& right) const
142 {
144 (right.r != 0) ? (this->r / right.r) : ELEMENT_MAX,
145 (right.g != 0) ? (this->g / right.g) : ELEMENT_MAX,
146 (right.b != 0) ? (this->b / right.b) : ELEMENT_MAX,
147 (right.a != 0) ? (this->a / right.a) : ELEMENT_MAX
148 );
149 return color;
150 }
151#pragma clang diagnostic pop
152
154 {
155 *this = *this + rhs;
156 return *this;
157 }
158
160 {
161 *this = *this - rhs;
162 return *this;
163 }
164
166 {
167 *this = *this * rhs;
168 return *this;
169 }
170
172 {
173 *this = *this / rhs;
174 return *this;
175 }
176
178 {
179 this->r += right;
180 this->g += right;
181 this->b += right;
182 this->a += right;
183 return *this;
184 }
185
187 {
188 this->r -= right;
189 this->g -= right;
190 this->b -= right;
191 this->a -= right;
192 return *this;
193 }
194
196 {
197 this->r *= right;
198 this->g *= right;
199 this->b *= right;
200 this->a *= right;
201 return *this;
202 }
203
205 {
206 if (right != 0.0f)
207 {
208 this->r /= right;
209 this->g /= right;
210 this->b /= right;
211 this->a /= right;
212 }
213 else
214 {
215 this->r = ELEMENT_MAX;
216 this->g = ELEMENT_MAX;
217 this->b = ELEMENT_MAX;
218 this->a = ELEMENT_MAX;
219 }
220 return *this;
221 }
222
223#pragma clang diagnostic push
224#pragma clang diagnostic ignored "-Wfloat-equal"
225
226 bool operator ==(const SelfType& rhs) const
227 {
228 return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a);
229 }
230
231#pragma clang diagnostic pop
232
233 bool operator !=(const SelfType& rhs) const
234 {
235 return !(*this == rhs);
236 }
237
238 void Set(
239 f32 red,
240 f32 green,
241 f32 blue,
243 {
244 r = red;
245 g = green;
246 b = blue;
247 a = alpha;
248 }
249
251 f32 red,
252 f32 green,
253 f32 blue )
254 {
255 r = red;
256 g = green;
257 b = blue;
258 }
259
261 {
262 a = alpha;
263 }
264
265 void Set(const SelfType& color) { operator =(color); }
266
267 bool IsTransparent() { return a <= 0.0f; }
268
269 f32* ToArray() { return reinterpret_cast<f32*>( this ); }
270 const f32* ToArray() const { return reinterpret_cast<const f32*>( this ); }
271
272protected:
274 {
275 return *reinterpret_cast<nw::math::VEC4*>(this);
276 }
277
278 const nw::math::VEC4& ToVEC4() const
279 {
280 return *reinterpret_cast<const nw::math::VEC4*>(this);
281 }
282
283public:
288};
289
290} } // namespace nw::ut
291
292#endif // NW_UT_COLOR_H_
Definition math_Constant.cpp:5
Definition ut_CriticalSection.h:6
Color4u8 Color8
Definition ut_Color.h:37
Definition math_Constant.cpp:5
Definition math_Vector4.h:69
Definition ut_Color.h:10
Color4u8(u8 red, u8 green, u8 blue, u8 alpha)
Definition ut_Color.h:22
Color4u8 SelfType
Definition ut_Color.h:12
u8 b
Definition ut_Color.h:33
u8 r
Definition ut_Color.h:31
u8 a
Definition ut_Color.h:34
Color4u8()
Definition ut_Color.h:14
u8 g
Definition ut_Color.h:32
Definition ut_Color.h:40
static const int ALPHA_MIN
Definition ut_Color.h:46
f32 b
Definition ut_Color.h:286
FloatColor SelfType
Definition ut_Color.h:42
f32 a
Definition ut_Color.h:287
FloatColor(const SelfType &color, f32 alpha)
Definition ut_Color.h:75
static const int ALPHA_MAX
Definition ut_Color.h:47
FloatColor(const SelfType &color)
Definition ut_Color.h:67
FloatColor(f32 red, f32 green, f32 blue, f32 alpha)
Definition ut_Color.h:83
SelfType & operator=(const nw::math::VEC4 &vec)
Definition ut_Color.h:97
~FloatColor()
Definition ut_Color.h:93
static const int ALPHA_OPACITY
Definition ut_Color.h:48
FloatColor & operator=(const FloatColor &other)=default
static const int ELEMENT_MAX
Definition ut_Color.h:45
FloatColor()
Definition ut_Color.h:51
static const int ALPHA_TRANSPARENT
Definition ut_Color.h:49
static const int ELEMENT_MIN
Definition ut_Color.h:44
f32 g
Definition ut_Color.h:285
FloatColor(const nw::math::VEC4 &vec)
Definition ut_Color.h:59