00001 #ifndef __INSTANTIO_COLORRGBA_H
00002 #define __INSTANTIO_COLORRGBA_H
00003
00004 #ifdef _MSC_VER
00005 # pragma once
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "InstantIODef.h"
00027 #include "TypeName.h"
00028 #ifdef _MSC_VER
00029 # pragma warning (push)
00030 # pragma warning (disable: 4351)
00031 #endif
00032
00033
00034 namespace InstantIO
00035 {
00036
00037
00056 class INSTANTIO_DLLMAPPING ColorRGBA
00057 {
00058 public:
00059
00064 inline ColorRGBA(): color_()
00065 { color_[0] = color_[1] = color_[2] = 0.f; color_[3] = 1.f; }
00066
00075 inline ColorRGBA(float r, float g, float b, float a): color_()
00076 { color_[0] = r; color_[1] = g; color_[2] = b; color_[3] = a; }
00077
00088 inline ColorRGBA(const float *color): color_()
00089 { color_[0] = color[0]; color_[1] = color[1]; color_[2] = color[2]; color_[3] = color[3]; }
00090
00096 inline ColorRGBA(const ColorRGBA &color): color_()
00097 { color_[0] = color.color_[0]; color_[1] = color.color_[1]; color_[2] = color.color_[2]; color_[3] = color.color_[3]; }
00098
00105 inline const ColorRGBA &operator=(const ColorRGBA &color)
00106 {
00107 color_[0] = color.color_[0]; color_[1] = color.color_[1]; color_[2] = color.color_[2]; color_[3] = color.color_[3];
00108 return color;
00109 }
00110
00121 inline const float *operator =(const float *color)
00122 {
00123 color_[0] = color[0]; color_[1] = color[1]; color_[2] = color[2]; color_[3] = color[3];
00124 return color;
00125 }
00126
00131 inline void setR(float r) { color_[0] = r; }
00132
00137 inline float getR() const { return color_[0]; }
00138
00143 inline void setG(float g) { color_[1] = g; }
00144
00149 inline float getG() const { return color_[1]; }
00150
00155 inline void setB(float b) { color_[2] = b; }
00156
00161 inline float getB() const { return color_[2]; }
00166 inline void setA(float a) { color_[3] = a; }
00167
00172 inline float getA() const { return color_[3]; }
00173
00181 inline void set(float r, float g, float b, float a)
00182 { color_[0] = r; color_[1] = g; color_[2] = b; color_[3] = a; }
00183
00192 inline void set(const float *color)
00193 { color_[0] = color[0]; color_[1] = color[1]; color_[2] = color[2]; color_[3] = color[3]; }
00194
00199 void set(const ColorRGBA &color)
00200 {
00201 color_[0] = color.color_[0];
00202 color_[1] = color.color_[1];
00203 color_[2] = color.color_[2];
00204 color_[2] = color.color_[3];
00205 }
00206
00213 inline void get(float &r, float &g, float &b, float &a) const
00214 { r = color_[0]; g = color_[1]; b = color_[2]; a = color_[3]; }
00215
00225 inline void get(float *color) const
00226 { color[0] = color_[0]; color[1] = color_[1]; color[2] = color_[2]; color[3] = color_[3]; }
00227
00233 inline void get(ColorRGBA &color) const
00234 { color.color_[0] = color_[0]; color.color_[1] = color_[1]; color.color_[2] = color_[2]; color.color_[3] = color_[3]; }
00235
00243 inline const float *get() const { return color_; }
00244
00252 inline float *get() { return color_; }
00253
00259 inline float operator[](int i) const { return color_[i]; }
00260
00266 inline float &operator[](int i) { return color_[i]; }
00267
00272 inline operator float *() { return &color_[0]; }
00273
00278 inline operator const float *() const { return &color_[0]; }
00279
00287 friend inline bool operator==(const ColorRGBA &a, const ColorRGBA &b)
00288 {
00289 return (a.color_[0] == b.color_[0]) && (a.color_[1] == b.color_[1]) && (a.color_[2] == b.color_[2])&& (a.color_[3] == b.color_[3]);
00290 }
00291
00299 friend inline bool operator!=(const ColorRGBA &a, const ColorRGBA &b)
00300 {
00301 return (a.color_[0] != b.color_[0]) || (a.color_[1] != b.color_[1]) || (a.color_[2] != b.color_[2])|| (a.color_[3] != b.color_[3]);
00302 }
00303
00304 private:
00305
00307 float color_[4];
00308 };
00309
00310
00317 template <>
00318 class INSTANTIO_DLLMAPPING TypeName<ColorRGBA>
00319 {
00320 public:
00321
00326 static const char *getName();
00327
00328 private:
00329
00331 TypeName();
00332
00334 TypeName(const TypeName &);
00335
00337 const TypeName &operator=(const TypeName &);
00338 };
00339
00340
00341 }
00342
00343
00344 #ifdef _MSC_VER
00345 # pragma warning (pop)
00346 #endif
00347
00348 #endif // __INSTANTIO_COLORRGBA_H