00001 #include "gui_color.hpp" 00002 #include <utils.hpp> 00003 #include <iostream> 00004 00005 namespace gui 00006 { 00007 const color color::EMPTY(0.0f, 0.0f, 0.0f, 0.0f); 00008 const color color::WHITE(1.0f, 1.0f, 1.0f); 00009 const color color::BLACK(0.0f, 0.0f, 0.0f); 00010 const color color::RED (1.0f, 0.0f, 0.0f); 00011 const color color::GREEN(0.0f, 1.0f, 0.0f); 00012 const color color::BLUE (0.0f, 0.0f, 1.0f); 00013 const color color::GREY (0.5f, 0.5f, 0.5f); 00014 00015 color::color() 00016 { 00017 } 00018 00019 color::color(chanel nr, chanel ng, chanel nb, chanel na) : 00020 r(nr), g(ng), b(nb), a(na) 00021 { 00022 } 00023 00024 bool color::operator == (const color& c) const 00025 { 00026 return (r == c.r && g == c.g && b == c.b && a == c.a); 00027 } 00028 00029 bool color::operator != (const color& c) const 00030 { 00031 return (r != c.r || g != c.g || b != c.b || a != c.a); 00032 } 00033 00034 void color::operator += (const color& c) 00035 { 00036 r += c.r; g += c.g; b += c.b; a += c.a; 00037 } 00038 00039 void color::operator -= (const color& c) 00040 { 00041 r -= c.r; g -= c.g; b -= c.b; a -= c.a; 00042 } 00043 00044 void color::operator *= (const color& c) 00045 { 00046 r *= c.r; g *= c.g; b *= c.b; a *= c.a; 00047 } 00048 00049 void color::operator *= (float f) 00050 { 00051 r *= f; g *= f; b *= f; a *= f; 00052 } 00053 00054 color operator + (const color& c1, const color& c2) 00055 { 00056 return color(c1.r+c2.r, c1.g+c2.g, c1.b+c2.b, c1.a+c2.a); 00057 } 00058 00059 color operator - (const color& c1, const color& c2) 00060 { 00061 return color(c1.r-c2.r, c1.g-c2.g, c1.b-c2.b, c1.a-c2.a); 00062 } 00063 00064 color operator * (const color& c1, const color& c2) 00065 { 00066 return color(c1.r*c2.r, c1.g*c2.g, c1.b*c2.b, c1.a*c2.a); 00067 } 00068 00069 color operator * (const color& c1, float f) 00070 { 00071 return color(c1.r*f, c1.g*f, c1.b*f, c1.a); 00072 } 00073 00074 color operator * (float f, const color& c2) 00075 { 00076 return color(f*c2.r, f*c2.g, f*c2.b, c2.a); 00077 } 00078 00079 std::ostream& operator << (std::ostream& mStream, const color& mColor) 00080 { 00081 return mStream << (uint)255*mColor.r << ", " << (uint)255*mColor.g << ", " 00082 << (uint)255*mColor.b << ", " << (uint)255*mColor.a; 00083 } 00084 }