Go to the documentation of this file.00001 #ifndef LIBGEODECOMP_MISC_COLOR_H
00002 #define LIBGEODECOMP_MISC_COLOR_H
00003
00004 #include <sstream>
00005
00006 namespace LibGeoDecomp {
00007
00008 class Color
00009 {
00010 public:
00011 static const Color BLACK;
00012 static const Color WHITE ;
00013
00014 static const Color RED;
00015 static const Color GREEN;
00016 static const Color BLUE;
00017
00018 static const Color CYAN;
00019 static const Color MAGENTA;
00020 static const Color YELLOW;
00021
00022 unsigned rgb;
00023
00024 inline Color() { *this = Color(0, 0, 0); }
00025
00026 inline Color(
00027 const unsigned char& r,
00028 const unsigned char& g,
00029 const unsigned char& b)
00030 {
00031 rgb = 255;
00032 rgb <<= 8;
00033 rgb += r;
00034 rgb <<= 8;
00035 rgb += g;
00036 rgb <<= 8;
00037 rgb += b;
00038 }
00039
00040 unsigned char red() const
00041 {
00042 return (rgb >> 16) % 256;
00043 }
00044
00045 unsigned char green() const
00046 {
00047 return (rgb >> 8) % 256;
00048 }
00049
00050 unsigned char blue() const
00051 {
00052 return (rgb >> 0) % 256;
00053 }
00054
00055 bool operator==(const Color& com) const
00056 {
00057 return rgb == com.rgb;;
00058 }
00059
00060 bool operator!=(const Color& com) const
00061 {
00062 return !(*this == com);
00063 }
00064
00065 std::string toString() const
00066 {
00067 std::ostringstream tmp;
00068 tmp << "Color(" << (int)red() << ", " << (int)green() << ", " << (int)blue() << ")";
00069 return tmp.str();
00070 }
00071 };
00072
00073 template<typename _CharT, typename _Traits>
00074 std::basic_ostream<_CharT, _Traits>&
00075 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
00076 const Color& color)
00077 {
00078 __os << color.toString();
00079 return __os;
00080 }
00081
00082 }
00083
00084 #endif