29#ifndef NOMLIB_MATH_COLOR4_HPP
30#define NOMLIB_MATH_COLOR4_HPP
36#include "nomlib/config.hpp"
45#if defined( NOM_PLATFORM_WINDOWS )
53const std::string COLOR_DELIMITER =
", ";
85 r{ static_cast<T> ( rhs.
r ) },
86 g{ static_cast<T> ( rhs.
g ) },
87 b{ static_cast<T> ( rhs.
b ) },
88 a{ static_cast<T> ( rhs.
a ) }
99 r{ static_cast<float> ( rhs.
r ) },
100 g{ static_cast<float> ( rhs.
g ) },
101 b{ static_cast<float> ( rhs.
b ) },
102 a{ static_cast<float> ( rhs.
a ) }
118 Color4 ( T red, T green, T blue, T alpha ) :
143 NOM_EXPORT
static const Color4 Black;
144 NOM_EXPORT
static const Color4 White;
145 NOM_EXPORT
static const Color4 Red;
146 NOM_EXPORT
static const Color4 Green;
147 NOM_EXPORT
static const Color4 Blue;
148 NOM_EXPORT
static const Color4 Yellow;
149 NOM_EXPORT
static const Color4 Magenta;
150 NOM_EXPORT
static const Color4 Cyan;
154 NOM_EXPORT
static const Color4 Purple;
155 NOM_EXPORT
static const Color4 Orange;
156 NOM_EXPORT
static const Color4 LightGray;
157 NOM_EXPORT
static const Color4 Gray;
158 NOM_EXPORT
static const Color4 SkyBlue;
183 c.
r = abs( lhs.
r - rhs.
r );
184 c.
g = abs( lhs.
g - rhs.
g );
185 c.
b = abs( lhs.
b - rhs.
b );
201std::ostream& operator << ( std::ostream& os,
const Color4<T>& color )
204 <<
static_cast<sint
> ( color.r )
206 <<
static_cast<sint
> ( color.g )
208 <<
static_cast<sint
> ( color.b )
210 <<
static_cast<sint
> ( color.a );
222std::ostream& operator <<( std::ostream& os,
const Color4<float>& color )
225 <<
static_cast<float> ( color.r )
227 <<
static_cast<float> ( color.g )
229 <<
static_cast<float> ( color.b )
231 <<
static_cast<float> ( color.a );
241 return ( left.r == right.r ) &&
242 ( left.g == right.g ) &&
243 ( left.b == right.b ) &&
244 ( left.a == right.a );
252 return ! ( left == right );
260 return Color4<T> (
static_cast<T
> ( std::min ( left.r + right.r, 255 ) ),
261 static_cast<T
> ( std::min ( left.g + right.g, 255 ) ),
262 static_cast<T
> ( std::min ( left.b + right.b, 255 ) ),
263 static_cast<T
> ( std::min ( left.a + right.a, 255 ) )
272 std::min( ( lhs.r + rhs.r / 255 ), 1.0f ),
273 std::min( ( lhs.g + rhs.g / 255 ), 1.0f ),
274 std::min( ( lhs.b + rhs.b / 255 ), 1.0f ),
275 std::min( ( lhs.a + rhs.a / 255 ), 1.0f )
283 return Color4<T> (
static_cast<T
> ( left.r-- ),
284 static_cast<T
> ( left.g-- ),
285 static_cast<T
> ( left.b-- ),
286 static_cast<T
> ( left.a-- )
296 static_cast<T
> ( std::min( left.r - right.r, 255 ) ),
297 static_cast<T
> ( std::min( left.g - right.g, 255 ) ),
298 static_cast<T
> ( std::min( left.b - right.b, 255 ) ),
299 static_cast<T
> ( std::min( left.a - right.a, 255 ) )
308 std::min( ( lhs.r - rhs.r ) / 255, 1.0f ),
309 std::min( ( lhs.g - rhs.g ) / 255, 1.0f ),
310 std::min( ( lhs.b - rhs.b ) / 255, 1.0f ),
311 std::min( ( lhs.a - rhs.a ) / 255, 1.0f )
319 return Color4<T> (
static_cast<T
> ( left.r-- ),
320 static_cast<T
> ( left.g-- ),
321 static_cast<T
> ( left.b-- ),
322 static_cast<T
> ( left.a-- )
332 static_cast<T
> ( left.r * right.r / 255 ),
333 static_cast<T
> ( left.g * right.g / 255 ),
334 static_cast<T
> ( left.b * right.b / 255 ),
335 static_cast<T
> ( left.a * right.a / 255 )
343 return left = left + right;
350 return left = left - right;
357 return left = left * right;
368 return (lhs.r < rhs.r) && (lhs.r < rhs.r) &&
369 (lhs.g < rhs.g) && (lhs.g < rhs.g) &&
370 (lhs.b < rhs.b) && (lhs.b < rhs.b) &&
371 (lhs.a < rhs.a) && (lhs.a < rhs.a);
382 return (rhs.r < lhs.r) && (rhs.r < lhs.r) &&
383 (rhs.g < lhs.g) && (rhs.g < lhs.g) &&
384 (rhs.b < lhs.b) && (rhs.b < lhs.b) &&
385 (rhs.a < lhs.a) && (rhs.a < lhs.a);
396 return (lhs.r <= rhs.r) && (lhs.r <= rhs.r) &&
397 (lhs.g <= rhs.g) && (lhs.g <= rhs.g) &&
398 (lhs.b <= rhs.b) && (lhs.b <= rhs.b) &&
399 (lhs.a <= rhs.a) && (lhs.a <= rhs.a);
410 return (rhs.r <= lhs.r) && (rhs.r <= lhs.r) &&
411 (rhs.g <= lhs.g) && (rhs.g <= lhs.g) &&
412 (rhs.b <= lhs.b) && (rhs.b <= lhs.b) &&
413 (rhs.a <= lhs.a) && (rhs.a <= lhs.a);
470typedef std::vector<Color4i> Color4iColors;
473typedef std::vector<Color4f> Color4fColors;
476typedef std::vector<Color4u> Color4uColors;
488template <> NOM_EXPORT
const Color4i Color4i::Black;
489template <> NOM_EXPORT
const Color4i Color4i::White;
490template <> NOM_EXPORT
const Color4i Color4i::Red;
491template <> NOM_EXPORT
const Color4i Color4i::Green;
492template <> NOM_EXPORT
const Color4i Color4i::Blue;
493template <> NOM_EXPORT
const Color4i Color4i::Yellow;
494template <> NOM_EXPORT
const Color4i Color4i::Magenta;
495template <> NOM_EXPORT
const Color4i Color4i::Cyan;
497template <> NOM_EXPORT
const Color4i Color4i::Purple;
498template <> NOM_EXPORT
const Color4i Color4i::Orange;
499template <> NOM_EXPORT
const Color4i Color4i::LightGray;
500template <> NOM_EXPORT
const Color4i Color4i::Gray;
501template <> NOM_EXPORT
const Color4i Color4i::SkyBlue;
504template <> NOM_EXPORT
const Color4f Color4f::Black;
505template <> NOM_EXPORT
const Color4f Color4f::White;
506template <> NOM_EXPORT
const Color4f Color4f::Red;
507template <> NOM_EXPORT
const Color4f Color4f::Green;
508template <> NOM_EXPORT
const Color4f Color4f::Blue;
509template <> NOM_EXPORT
const Color4f Color4f::Yellow;
510template <> NOM_EXPORT
const Color4f Color4f::Magenta;
511template <> NOM_EXPORT
const Color4f Color4f::Cyan;
514make_color_from_hex_string(
const std::string& hex_encoding);
517make_color_from_string(
const std::string& color);
static NOM_EXPORT const Color4 null
Color4(void)
Default constructor; initialize values to Color<T>::null.
static NOM_EXPORT const Color4 Silver
static NOM_EXPORT const int16 ALPHA_TRANSPARENT
Color4(T red, T green, T blue, T alpha)
Constructor variant for setting a color using RGBA values.
static NOM_EXPORT const int16 ALPHA_OPAQUE
static NOM_EXPORT const Color4 Transparent
Color4(const Color4< float > &rhs)
Copy constructor.
Color4(T r, T g, T b)
Constructor variant for setting a color using RGB values.
Color4(const Color4< U > &rhs)
Copy constructor.