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
9{
10public:
12
13 static const int ELEMENT_MIN = 0;
14 static const int ELEMENT_MAX = 1;
15 static const int ALPHA_MIN = ELEMENT_MIN;
16 static const int ALPHA_MAX = ELEMENT_MAX;
17 static const int ALPHA_OPACITY = ALPHA_MAX;
18 static const int ALPHA_TRANSPARENT = ALPHA_MIN;
19
21 : r(0.0f)
22 , g(0.0f)
23 , b(0.0f)
24 , a(1.0f)
25 {
26 }
27
28 explicit FloatColor(const nw::math::VEC4& vec)
29 : r(vec.x)
30 , g(vec.y)
31 , b(vec.z)
32 , a(vec.w)
33 {
34 }
35
36 FloatColor(const SelfType& color)
37 : r(color.r)
38 , g(color.g)
39 , b(color.b)
40 , a(color.a)
41 {
42 }
43
44 FloatColor(const SelfType& color, f32 alpha)
45 : r(color.r)
46 , g(color.g)
47 , b(color.b)
48 , a(alpha)
49 {
50 }
51
52 FloatColor(f32 red, f32 green, f32 blue, f32 alpha)
53 : r(red)
54 , g(green)
55 , b(blue)
56 , a(alpha)
57 {
58 }
59
60 FloatColor& operator=(const FloatColor& other) = default;
61
63 {
64 }
65
66 SelfType& operator =(const nw::math::VEC4& vec)
67 {
68 this->Set( vec.x, vec.y, vec.z, vec.w );
69 return *this;
70 }
71
72 operator f32*() { return &r; }
73 operator const f32*() const { return &r; }
74
75 const SelfType operator +(const SelfType& right) const
76 {
78 this->r + right.r,
79 this->g + right.g,
80 this->b + right.b,
81 this->a + right.a
82 );
83 return color;
84 }
85
86 const SelfType operator -(const SelfType& right) const
87 {
89 this->r - right.r,
90 this->g - right.g,
91 this->b - right.b,
92 this->a - right.a
93 );
94 return color;
95 }
96
97 const SelfType operator *(const SelfType& right) const
98 {
100 this->r * right.r,
101 this->g * right.g,
102 this->b * right.b,
103 this->a * right.a
104 );
105 return color;
106 }
107
108#pragma clang diagnostic push
109#pragma clang diagnostic ignored "-Wfloat-equal"
110 const SelfType operator /(const SelfType& right) const
111 {
113 (right.r != 0) ? (this->r / right.r) : ELEMENT_MAX,
114 (right.g != 0) ? (this->g / right.g) : ELEMENT_MAX,
115 (right.b != 0) ? (this->b / right.b) : ELEMENT_MAX,
116 (right.a != 0) ? (this->a / right.a) : ELEMENT_MAX
117 );
118 return color;
119 }
120#pragma clang diagnostic pop
121
123 {
124 *this = *this + rhs;
125 return *this;
126 }
127
129 {
130 *this = *this - rhs;
131 return *this;
132 }
133
135 {
136 *this = *this * rhs;
137 return *this;
138 }
139
141 {
142 *this = *this / rhs;
143 return *this;
144 }
145
147 {
148 this->r += right;
149 this->g += right;
150 this->b += right;
151 this->a += right;
152 return *this;
153 }
154
156 {
157 this->r -= right;
158 this->g -= right;
159 this->b -= right;
160 this->a -= right;
161 return *this;
162 }
163
165 {
166 this->r *= right;
167 this->g *= right;
168 this->b *= right;
169 this->a *= right;
170 return *this;
171 }
172
174 {
175 if (right != 0.0f)
176 {
177 this->r /= right;
178 this->g /= right;
179 this->b /= right;
180 this->a /= right;
181 }
182 else
183 {
184 this->r = ELEMENT_MAX;
185 this->g = ELEMENT_MAX;
186 this->b = ELEMENT_MAX;
187 this->a = ELEMENT_MAX;
188 }
189 return *this;
190 }
191
192#pragma clang diagnostic push
193#pragma clang diagnostic ignored "-Wfloat-equal"
194
195 bool operator ==(const SelfType& rhs) const
196 {
197 return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a);
198 }
199
200#pragma clang diagnostic pop
201
202 bool operator !=(const SelfType& rhs) const
203 {
204 return !(*this == rhs);
205 }
206
207 void Set(
208 f32 red,
209 f32 green,
210 f32 blue,
212 {
213 r = red;
214 g = green;
215 b = blue;
216 a = alpha;
217 }
218
220 f32 red,
221 f32 green,
222 f32 blue )
223 {
224 r = red;
225 g = green;
226 b = blue;
227 }
228
230 {
231 a = alpha;
232 }
233
234 void Set(const SelfType& color) { operator =(color); }
235
236 bool IsTransparent() { return a <= 0.0f; }
237
238 f32* ToArray() { return reinterpret_cast<f32*>( this ); }
239 const f32* ToArray() const { return reinterpret_cast<const f32*>( this ); }
240
241protected:
243 {
244 return *reinterpret_cast<nw::math::VEC4*>(this);
245 }
246
247 const nw::math::VEC4& ToVEC4() const
248 {
249 return *reinterpret_cast<const nw::math::VEC4*>(this);
250 }
251
252public:
257};
258
259} } // namespace nw::ut
260
261#endif // NW_UT_COLOR_H_
Definition math_Constant.cpp:5
Definition ut_CriticalSection.h:6
Definition math_Constant.cpp:5
Definition math_Vector4.h:69
Definition ut_Color.h:9
static const int ALPHA_MIN
Definition ut_Color.h:15
f32 b
Definition ut_Color.h:255
FloatColor SelfType
Definition ut_Color.h:11
f32 a
Definition ut_Color.h:256
FloatColor(const SelfType &color, f32 alpha)
Definition ut_Color.h:44
static const int ALPHA_MAX
Definition ut_Color.h:16
FloatColor(const SelfType &color)
Definition ut_Color.h:36
FloatColor(f32 red, f32 green, f32 blue, f32 alpha)
Definition ut_Color.h:52
SelfType & operator=(const nw::math::VEC4 &vec)
Definition ut_Color.h:66
~FloatColor()
Definition ut_Color.h:62
static const int ALPHA_OPACITY
Definition ut_Color.h:17
FloatColor & operator=(const FloatColor &other)=default
static const int ELEMENT_MAX
Definition ut_Color.h:14
FloatColor()
Definition ut_Color.h:20
static const int ALPHA_TRANSPARENT
Definition ut_Color.h:18
static const int ELEMENT_MIN
Definition ut_Color.h:13
f32 g
Definition ut_Color.h:254
FloatColor(const nw::math::VEC4 &vec)
Definition ut_Color.h:28