00001 #ifndef COLOR_H
00002 #define COLOR_H
00003
00004 #include "AbstractEditable.h"
00005
00006
00007
00009 class VColor : public VAbstractEditable
00010 {
00011 protected:
00012 int r, g, b;
00013
00014 bool m_bOpaque;
00015
00016 public:
00017
00018 VColor(COLORREF c)
00019 {
00020 r = GetRValue(c);
00021 g = GetGValue(c);
00022 b = GetBValue(c);
00023
00024 m_bOpaque = true;
00025 }
00026 VColor(int red, int green, int blue)
00027 {
00028 r = red;
00029 g = green;
00030 b = blue;
00031
00032 m_bOpaque = true;
00033 }
00034 VColor()
00035 {
00036 r = 0;
00037 g = 0;
00038 b = 0;
00039
00040 m_bOpaque = true;
00041 }
00042 operator COLORREF()
00043 {
00044 if (r > 255)
00045 r = 255;
00046 if (g > 255)
00047 g = 255;
00048 if (b > 255)
00049 b = 255;
00050 if (r < 0)
00051 r = 0;
00052 if (g < 0)
00053 g = 0;
00054 if (b < 0)
00055 b = 0;
00056
00057 return RGB(r,g,b);
00058 }
00059
00060
00061 int GetRed() const { return r; }
00062 int GetGreen() const { return g; }
00063 int GetBlue() const { return b; }
00064
00065 bool IsOpaque() const {
00066 return m_bOpaque;
00067 }
00068
00069 void SetOpaque(bool bOpaque)
00070 {
00071 m_bOpaque = bOpaque;
00072 }
00073
00074 void SetRed(int value)
00075 {
00076 r = value;
00077 }
00078 void SetGreen(int value)
00079 {
00080 g = value;
00081 }
00082 void SetBlue(int value)
00083 {
00084 b = value;
00085 }
00086
00088
00089 VColor operator-() const {
00090 VColor newcolor(RGB(0, 0, 0));
00091 return (newcolor - *this);
00092 }
00093
00094 VColor operator+(VColor addme) const {
00095 VColor newcolor( r + addme.GetRed(), g + addme.GetGreen(), b + addme.GetBlue());
00096 return newcolor;
00097 }
00098
00099 VColor operator-(VColor addme) const {
00100 VColor newcolor( r - addme.GetRed(), g - addme.GetGreen(), b - addme.GetBlue());
00101 return newcolor;
00102 }
00103
00104 VColor operator*(VColor addme) const {
00105 VColor newcolor( r * addme.GetRed(), g * addme.GetGreen(), b * addme.GetBlue());
00106 return newcolor;
00107 }
00108
00109 VColor operator/(VColor addme) const {
00110 int newr = addme.GetRed(), newg = addme.GetGreen(), newb = addme.GetBlue();
00111 if (newr == 0)
00112 newr = 1;
00113 if (newg == 0)
00114 newg = 1;
00115 if (newb == 0)
00116 newb = 1;
00117
00118
00119 VColor newcolor( r / newr, g / newg, b / newb);
00120 return newcolor;
00121 }
00122
00123
00124 VColor operator*(int ratio) const {
00125 VColor newcolor(r * ratio, g * ratio, b * ratio);
00126 return newcolor;
00127 }
00128
00129 VColor operator/(int ratio) const {
00130 VColor newcolor(r / ratio, g / ratio, b / ratio);
00131 return newcolor;
00132 }
00133
00134
00135
00136 bool operator>(int test) const {
00137 return (r > test && g > test && b > test);
00138 }
00139 bool operator==(int test) const {
00140 return (r == test && g == test && b == test);
00141 }
00142 bool operator<(int test) const{
00143 return (r < test && g < test && b < test);
00144 }
00146
00148 VAbstractEditor* CreateEditor() ;
00149
00150 };
00151
00152
00153 #endif