00001
00002
00003
00004
00005
00006
00007
00009
00016 #ifndef __COLOR_HEADER__
00017 #define __COLOR_HEADER__
00018
00019 #include "defs.h"
00020 #include "utils.h"
00021
00022 namespace hoa_video {
00023
00030 class Color {
00031 public:
00036 static Color clear;
00037 static Color white;
00038 static Color gray;
00039 static Color black;
00040 static Color red;
00041 static Color orange;
00042 static Color yellow;
00043 static Color green;
00044 static Color aqua;
00045 static Color blue;
00046 static Color violet;
00047 static Color brown;
00048
00049
00050 Color()
00051 { _colors[0] = 0.0f; _colors[1] = 0.0f; _colors[2] = 0.0f; _colors[3] = 1.0f; }
00052
00053 Color(float r, float g, float b, float a)
00054 { _colors[0] = r; _colors[1] = g; _colors[2] = b; _colors[3] = a; }
00055
00057
00058 bool operator == (const Color &c) const
00059 { return _colors[0] == c._colors[0] && _colors[1] == c._colors[1] && _colors[2] == c._colors[2] && _colors[3] == c._colors[3]; }
00060
00061 bool operator != (const Color &c) const
00062 { return _colors[0] != c._colors[0] || _colors[1] != c._colors[1] || _colors[2] != c._colors[2] || _colors[3] != c._colors[3]; }
00063
00064 Color operator + (const Color &c) const
00065 {
00066 Color col = Color(_colors[0] + c._colors[0], _colors[1] + c._colors[1], _colors[2] + c._colors[2], _colors[3] + c._colors[3]);
00067 if (col[0] > 1.0f) col[0] = 1.0f; else if (col[0] < 0.0f) col[0] = 0.0f;
00068 if (col[1] > 1.0f) col[1] = 1.0f; else if (col[1] < 0.0f) col[1] = 0.0f;
00069 if (col[2] > 1.0f) col[2] = 1.0f; else if (col[2] < 0.0f) col[2] = 0.0f;
00070 if (col[3] > 1.0f) col[3] = 1.0f; else if (col[3] < 0.0f) col[3] = 0.0f;
00071 return col;
00072 }
00073
00074 Color operator *= (const Color &c)
00075 { return Color(_colors[0] * c._colors[0], _colors[1] * c._colors[1], _colors[2] * c._colors[2], _colors[3] * c._colors[3]); }
00076
00077 Color operator * (const Color &c) const
00078 { return Color(_colors[0] * c._colors[0], _colors[1] * c._colors[1], _colors[2] * c._colors[2], _colors[3] * c._colors[3]); }
00079
00080 Color operator * (float f) const
00081 { return Color(_colors[0] * f, _colors[1] * f, _colors[2] * f, _colors[3]); }
00082
00086 float &operator[](int32 i)
00087 { return _colors[i]; }
00088
00092 const float &operator[](int32 i) const
00093 { return _colors[i]; }
00095
00097
00098 const float* GetColors() const
00099 { return _colors; }
00100
00101 float GetRed() const
00102 { return _colors[0]; }
00103
00104 float GetGreen() const
00105 { return _colors[1]; }
00106
00107 float GetBlue() const
00108 { return _colors[2]; }
00109
00110 float GetAlpha() const
00111 { return _colors[3]; }
00112
00113 void SetRed(float r)
00114 { _colors[0] = r; if (_colors[0] > 1.0f) _colors[0] = 1.0f; else if (_colors[0] < 0.0f) _colors[0] = 0.0f; }
00115
00116 void SetGreen(float g)
00117 { _colors[1] = g; if (_colors[1] > 1.0f) _colors[1] = 1.0f; else if (_colors[1] < 0.0f) _colors[1] = 0.0f; }
00118
00119 void SetBlue(float b)
00120 { _colors[2] = b; if (_colors[2] > 1.0f) _colors[2] = 1.0f; else if (_colors[2] < 0.0f) _colors[2] = 0.0f; }
00121
00122 void SetAlpha(float a)
00123 { _colors[3] = a; if (_colors[3] > 1.0f) _colors[3] = 1.0f; else if (_colors[3] < 0.0f) _colors[3] = 0.0f; }
00125
00126 private:
00131 float _colors[4];
00132 };
00133
00134 }
00135
00136 #endif // __COLOR_HEADER__