00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_VIDEO_COLOR_HPP
00018 #define HEADER_SUPERTUX_VIDEO_COLOR_HPP
00019
00020 #include <assert.h>
00021 #include <vector>
00022
00023 #include "util/log.hpp"
00024
00025 class Color
00026 {
00027 public:
00028 Color() :
00029 red(0),
00030 green(0),
00031 blue(0),
00032 alpha(1.0f)
00033 {}
00034
00035 Color(float red_, float green_, float blue_, float alpha_ = 1.0) :
00036 red(red_),
00037 green(green_),
00038 blue(blue_),
00039 alpha(alpha_)
00040 {
00041 assert(0 <= red && red <= 1.0);
00042 assert(0 <= green && green <= 1.0);
00043 assert(0 <= blue && blue <= 1.0);
00044 }
00045
00046 Color(const std::vector<float>& vals) :
00047 red(),
00048 green(),
00049 blue(),
00050 alpha()
00051 {
00052 assert(vals.size() >= 3);
00053 red = vals[0];
00054 green = vals[1];
00055 blue = vals[2];
00056 if(vals.size() > 3)
00057 alpha = vals[3];
00058 else
00059 alpha = 1.0;
00060 assert(0 <= red && red <= 1.0);
00061 assert(0 <= green && green <= 1.0);
00062 assert(0 <= blue && blue <= 1.0);
00063 }
00064
00065 bool operator==(const Color& other) const
00066 {
00067 return red == other.red && green == other.green && blue == other.blue
00068 && alpha == other.alpha;
00069 }
00070
00071 float greyscale() const
00072 {
00073 return red * 0.30 + green * 0.59 + blue * 0.11;
00074 }
00075
00076 bool operator < (const Color& other) const
00077 {
00078 return greyscale() < other.greyscale();
00079 }
00080
00081 float red, green, blue, alpha;
00082
00083 static const Color BLACK;
00084 static const Color RED;
00085 static const Color GREEN;
00086 static const Color BLUE;
00087 static const Color CYAN;
00088 static const Color MAGENTA;
00089 static const Color YELLOW;
00090 static const Color WHITE;
00091 };
00092
00093 #endif
00094
00095