fix cr/lfs and remove trailing whitespaces...
[supertux.git] / src / video / color.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef __COLOR_HPP__
21 #define __COLOR_HPP__
22
23 #include <vector>
24 #include "log.hpp"
25
26 class Color
27 {
28 public:
29   Color()
30     : red(0), green(0), blue(0), alpha(1.0)
31   { }
32   Color(float red, float green, float blue, float alpha = 1.0)
33     : red(red), green(green), blue(blue), alpha(alpha)
34   {
35 #ifdef DEBUG
36     check_color_ranges();
37 #endif
38   }
39   Color(const std::vector<float>& vals)
40   {
41     red = vals[0];
42     green = vals[1];
43     blue = vals[2];
44     if(vals.size() > 3)
45       alpha = vals[3];
46     else
47       alpha = 1.0;
48 #ifdef DEBUG
49     check_color_ranges();
50 #endif
51   }
52
53   void check_color_ranges()
54   {
55     if(red < 0 || red > 1.0 || green < 0 || green > 1.0
56             || blue < 0 || blue > 1.0
57             || alpha < 0 || alpha > 1.0)
58       log_warning << "color value out of range: " << red << ", " << green << ", " << blue << ", " << alpha << std::endl;
59   }
60
61   float red, green, blue, alpha;
62 };
63
64 #endif