00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __NECOLOR_H
00028 #define __NECOLOR_H
00029
00030
00031 #include "base.h"
00032 #include "util.h"
00033
00034
00041 namespace NeoEngine
00042 {
00043
00044
00050 class NEOENGINE_API Color
00051 {
00052 public:
00053
00055 float r,g,b,a;
00056
00057
00061 Color() : r(0.0f), g(0.0f), b(0.0f), a(1.0f) {}
00062
00067 Color( unsigned int uiColor ) : r( float( uiColor & 0xFF ) * 0.0039215686f ), g( float( ( uiColor >> 8 ) & 0xFF ) * 0.0039215686f ), b( float( ( uiColor >> 16 ) & 0xFF ) * 0.0039215686f ), a( float( ( uiColor >> 24 ) & 0xFF ) * 0.0039215686f ) {}
00068
00076 Color( float fR, float fG, float fB, float fA = 1.0f ) : r(fR), g(fG), b(fB), a(fA) {}
00077
00085 inline void Set( float fR, float fG, float fB, float fA = 1.0f ) { r = fR; g = fG; b = fB; a = fA; }
00086
00091 inline void Set( unsigned int uiColor ) { r = float( uiColor & 0xFF ) * 0.0039215686f; g = float( ( uiColor >> 8 ) & 0xFF ) * 0.0039215686f; b = float( ( uiColor >> 16 ) & 0xFF ) * 0.0039215686f; a = float( ( uiColor >> 24 ) & 0xFF ) * 0.0039215686f; }
00092
00097 inline void Set( const Color &rkColor ) { fmemcpy( &r, &rkColor.r, sizeof( float ) * 4 ); }
00098
00102 inline operator float* () { return &r; }
00103
00107 inline operator const float* () const { return &r; }
00108
00112 inline float &operator [] ( int iComponent ) { return ((float*)&r)[ iComponent ]; }
00113
00117 inline const float &operator [] ( int iComponent ) const { return ((const float*)&r)[ iComponent ]; }
00118
00124 inline Color &operator = ( const Color &rkColor ) { fmemcpy( &r, &rkColor.r, sizeof( float ) * 4 ); return( *this ); }
00125
00131 inline bool operator == ( const Color &rkColor ) const { return( ( r == rkColor.r ) && ( g == rkColor.g ) && ( b == rkColor.b ) && ( a == rkColor.a ) ); }
00132
00138 inline bool operator != ( const Color &rkColor ) const { return( !( *this == rkColor ) ); }
00139
00140
00142 static const NE_STATIC Color BLACK;
00143
00145 static const NE_STATIC Color WHITE;
00146
00148 static const NE_STATIC Color RED;
00149
00151 static const NE_STATIC Color GREEN;
00152
00154 static const NE_STATIC Color BLUE;
00155
00156 #if 0
00157
00158 static NEOENGINE_API Color BLACK;
00159
00161 static NEOENGINE_API Color WHITE;
00162
00164 static NEOENGINE_API Color RED;
00165
00167 static NEOENGINE_API Color GREEN;
00168
00170 static NEOENGINE_API Color BLUE;
00171 #endif
00172 };
00173
00174
00181 class NEOENGINE_API Color32
00182 {
00183 private:
00184
00188 union Color32Union
00189 {
00190 unsigned int m_uiValue;
00191 unsigned char m_aucComponent[4];
00192 } m_uiColor;
00193
00194
00195 public:
00196
00198 static unsigned int s_uiShift[4];
00199
00201 static unsigned int s_uiComponent[4];
00202
00203
00207 Color32() { m_uiColor.m_uiValue = 0xFF << s_uiShift[3]; }
00208
00216 Color32( unsigned char ucR, unsigned char ucG, unsigned char ucB, unsigned char ucA = 0xFF ) { m_uiColor.m_uiValue = ( ucR << s_uiShift[0] ) | ( ucG << s_uiShift[1] ) | ( ucB << s_uiShift[2] ) | ( ucA << s_uiShift[3] ); }
00217
00222 Color32( unsigned char *pucComponents ) { m_uiColor.m_uiValue = ( pucComponents[0] << s_uiShift[0] ) | ( pucComponents[1] << s_uiShift[1] ) | ( pucComponents[2] << s_uiShift[2] ) | ( pucComponents[3] << s_uiShift[3] ); }
00223
00228 Color32( const Color &rkColor ) { m_uiColor.m_uiValue = ( ( int( rkColor.r * 255.0f ) & 0xFF ) << s_uiShift[0] ) | ( ( int( rkColor.g * 255.0f ) & 0xFF ) << s_uiShift[1] ) | ( ( int( rkColor.b * 255.0f ) & 0xFF ) << s_uiShift[2] ) | ( ( int( rkColor.a * 255.0f ) & 0xFF ) << s_uiShift[3] ); }
00229
00234 Color32( float *pfComponents ) { m_uiColor.m_uiValue = ( ( int( pfComponents[0] * 255.0f ) & 0xFF ) << s_uiShift[0] ) | ( ( int( pfComponents[1] * 255.0f ) & 0xFF ) << s_uiShift[1] ) | ( ( int( pfComponents[2] * 255.0f ) & 0xFF ) << s_uiShift[2] ) | ( ( int( pfComponents[3] * 255.0f ) & 0xFF ) << s_uiShift[3] ); }
00235
00243 Color32( float fR, float fG, float fB, float fA = 1.0f ) { m_uiColor.m_uiValue = ( ( int( fR * 255.0f ) & 0xFF ) << s_uiShift[0] ) | ( ( int( fG * 255.0f ) & 0xFF ) << s_uiShift[1] ) | ( ( int( fB * 255.0f ) & 0xFF ) << s_uiShift[2] ) | ( ( int( fA * 255.0f ) & 0xFF ) << s_uiShift[3] ); }
00244
00252 inline void Set( unsigned char ucR, unsigned char ucG, unsigned char ucB, unsigned char ucA = 0xFF ) { m_uiColor.m_uiValue = ( ucR << s_uiShift[0] ) | ( ucG << s_uiShift[1] ) | ( ucB << s_uiShift[2] ) | ( ucA << s_uiShift[3] ); }
00253
00258 inline void Set( unsigned char *pucComponents ) { m_uiColor.m_uiValue = ( pucComponents[0] << s_uiShift[0] ) | ( pucComponents[1] << s_uiShift[1] ) | ( pucComponents[2] << s_uiShift[2] ) | ( pucComponents[3] << s_uiShift[3] ); }
00259
00264 inline void Set( const Color &rkColor ) { m_uiColor.m_uiValue = ( ( int( rkColor.r * 255.0f ) & 0xFF ) | ( ( int( rkColor.g * 255.0f ) & 0xFF ) << 8 ) | ( ( int( rkColor.b * 255.0f ) & 0xFF ) << 16 ) | ( ( int( rkColor.a * 255.0f ) & 0xFF ) << 24 ) ); }
00265
00273 inline void Set( float fR, float fG, float fB, float fA = 1.0f ) { m_uiColor.m_uiValue = ( ( int( fR * 255.0f ) & 0xFF ) << s_uiShift[0] ) | ( ( int( fG * 255.0f ) & 0xFF ) << s_uiShift[1] ) | ( ( int( fB * 255.0f ) & 0xFF ) << s_uiShift[2] ) | ( ( int( fA * 255.0f ) & 0xFF ) << s_uiShift[3] ); }
00274
00278 operator const unsigned int& () const { return m_uiColor.m_uiValue; }
00279
00280
00284 operator unsigned char* () { return m_uiColor.m_aucComponent; }
00285
00289 unsigned char &operator [] ( int iComponent ) { return m_uiColor.m_aucComponent[ s_uiComponent[ iComponent ] ]; }
00290
00294 const unsigned char &operator [] ( int iComponent ) const { return m_uiColor.m_aucComponent[ s_uiComponent[ iComponent ] ]; }
00295
00301 Color32 &operator = ( const Color32 &rkColor ) { m_uiColor.m_uiValue = rkColor.m_uiColor.m_uiValue; return( *this ); }
00302
00308 Color32 &operator = ( const Color &rkColor ) { Set( rkColor.r, rkColor.g, rkColor.b, rkColor.a ); return( *this ); }
00309
00315 Color32 &operator = ( unsigned int uiColor ) { Set( (unsigned char)( uiColor & 0xFF ), (unsigned char)( ( uiColor >> 8 ) & 0xFF ), (unsigned char)( ( uiColor >> 16 ) & 0xFF ), (unsigned char)( ( uiColor >> 24 ) & 0xFF ) ); return( *this ); }
00316 };
00317
00318
00319 };
00320
00321
00322 #endif
00323