2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_VIDEO_COLOR_HPP
18 #define HEADER_SUPERTUX_VIDEO_COLOR_HPP
23 #include "util/log.hpp"
35 Color(float red, float green, float blue, float alpha = 1.0) :
46 Color(const std::vector<float>& vals) :
52 assert(vals.size() >= 3);
65 bool operator==(const Color& other) const
67 return red == other.red && green == other.green && blue == other.blue
68 && alpha == other.alpha;
71 void check_color_ranges()
73 if(red < 0 || red > 1.0 || green < 0 || green > 1.0
74 || blue < 0 || blue > 1.0
75 || alpha < 0 || alpha > 1.0)
76 log_warning << "color value out of range: " << red << ", " << green << ", " << blue << ", " << alpha << std::endl;
79 float greyscale() const
81 return red * 0.30 + green * 0.59 + blue * 0.11;
84 bool operator < (const Color& other) const
86 return greyscale() < other.greyscale();
89 float red, green, blue, alpha;
91 static const Color BLACK;
92 static const Color RED;
93 static const Color GREEN;
94 static const Color BLUE;
95 static const Color CYAN;
96 static const Color MAGENTA;
97 static const Color YELLOW;
98 static const Color WHITE;