Removed trailing whitespace from all *.?pp files
[supertux.git] / src / video / color.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #ifndef HEADER_SUPERTUX_VIDEO_COLOR_HPP
18 #define HEADER_SUPERTUX_VIDEO_COLOR_HPP
19
20 #include <assert.h>
21 #include <vector>
22
23 #include "util/log.hpp"
24
25 class Color
26 {
27 public:
28   Color() :
29     red(0),
30     green(0),
31     blue(0),
32     alpha(1.0f)
33   {}
34
35   Color(float red_, float green_, float blue_, float alpha_ = 1.0) :
36     red(red_),
37     green(green_),
38     blue(blue_),
39     alpha(alpha_)
40   {
41     assert(0 <= red   && red <= 1.0);
42     assert(0 <= green && green <= 1.0);
43     assert(0 <= blue  && blue <= 1.0);
44   }
45
46   Color(const std::vector<float>& vals) :
47     red(),
48     green(),
49     blue(),
50     alpha()
51   {
52     assert(vals.size() >= 3);
53     red   = vals[0];
54     green = vals[1];
55     blue  = vals[2];
56     if(vals.size() > 3)
57       alpha = vals[3];
58     else
59       alpha = 1.0;
60     assert(0 <= red   && red <= 1.0);
61     assert(0 <= green && green <= 1.0);
62     assert(0 <= blue  && blue <= 1.0);
63   }
64
65   bool operator==(const Color& other) const
66   {
67     return red == other.red && green == other.green && blue == other.blue
68       && alpha == other.alpha;
69   }
70
71   float greyscale() const
72   {
73     return red * 0.30 + green * 0.59 + blue * 0.11;
74   }
75
76   bool operator < (const Color& other) const
77   {
78     return greyscale() < other.greyscale();
79   }
80
81   float red, green, blue, alpha;
82
83   static const Color BLACK;
84   static const Color RED;
85   static const Color GREEN;
86   static const Color BLUE;
87   static const Color CYAN;
88   static const Color MAGENTA;
89   static const Color YELLOW;
90   static const Color WHITE;
91 };
92
93 #endif
94
95 /* EOF */