00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_COLOR_HH
00020 #define OST_COLOR_HH
00021
00022
00023
00024
00025
00026 #include <iosfwd>
00027
00028 #include <boost/operators.hpp>
00029
00030 #include <ost/gfx/module_config.hh>
00031
00032 namespace ost { namespace gfx {
00033
00035 class DLLEXPORT_OST_GFX Color :
00036 private boost::additive<Color>,
00037 private boost::additive<Color, float>,
00038 private boost::multiplicative<Color, float>{
00039 public:
00040 Color() {
00041 rgba[0]=1.0;
00042 rgba[1]=1.0;
00043 rgba[2]=1.0;
00044 rgba[3]=1.0;
00045 }
00046
00047 Color(float r, float g, float b, float a=1.0) {
00048 rgba[0]=r;
00049 rgba[1]=g;
00050 rgba[2]=b;
00051 rgba[3]=a;
00052 }
00053
00054 enum COLOR_NAME {
00055 WHITE=0xffffff,
00056 LIGHT_GREY=0xaaaaff,
00057 GREY=0x999999ff,
00058 DARK_GREY=0x333333ff,
00059 BLACK=0x000000,
00060 RED=0xff0000,
00061 GREEN=0x00ff00,
00062 BLUE=0x0000ff,
00063 CYAN=0x00ffff,
00064 MAGENTA=0xff00ff,
00065 YELLOW=0xffff00
00066 };
00067
00068 Color(int hex_code);
00069
00070 float& Red() {return rgba[0];}
00071 const float& Red() const {return rgba[0];}
00072 float& Green() {return rgba[1];}
00073 const float& Green() const {return rgba[1];}
00074 float& Blue() {return rgba[2];}
00075 const float& Blue() const {return rgba[2];}
00076 float& Alpha() {return rgba[3];}
00077 const float& Alpha() const {return rgba[3];}
00078
00079 static Color FromRGB(unsigned char r, unsigned char g,
00080 unsigned char b, unsigned char a = 0xff) {
00081 static float f=1.0/255.0;
00082 return Color(f*static_cast<float>(r),f*static_cast<float>(g),
00083 f*static_cast<float>(b),f*static_cast<float>(a));
00084 }
00085
00086
00087
00088 operator float* () {return rgba;}
00089 operator const float* () const {return rgba;}
00090
00091 Color& operator*=(float rhs);
00092 Color& operator+=(float rhs);
00093
00094 Color& operator+=(const Color& rhs);
00095 Color& operator-=(const Color& rhs);
00096 Color& operator-=(float rhs);
00097 Color& operator/=(float rhs);
00098 private:
00099 float rgba[4];
00100 };
00101
00102 DLLEXPORT_OST_GFX std::ostream& operator<<(std::ostream&, const Color& c);
00103
00104 }}
00105
00106 #endif
00107