Initial integration, lots of broken stuff
[supertux.git] / src / unison / include / unison / video / Color.hpp
1 //          Copyright Timothy Goya 2007.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef UNISON_VIDEO_COLOR_HPP
7 #define UNISON_VIDEO_COLOR_HPP
8
9 //#include "SDL_stdinc.h"
10
11 namespace Unison
12 {
13    namespace Video
14    {
15       /// A RGBA color
16       class Color
17       {
18          public:
19             /// The red component (0x00 to 0xff)
20             unsigned char red;
21
22             /// The green component (0x00 to 0xff)
23             unsigned char green;
24
25             /// The blue component (0x00 to 0xff)
26             unsigned char blue;
27
28             /// The alpha component (0x00 to 0xff)
29             unsigned char alpha;
30
31             /// Default constructor (transparent black)
32             Color() :
33                red(),
34                green(),
35                blue(),
36                alpha()
37             {
38             }
39
40             /// Create a color from the given values
41             /// \param[in] red The red component (0x00 to 0xff)
42             /// \param[in] green The red component (0x00 to 0xff)
43             /// \param[in] blue The red component (0x00 to 0xff)
44             /// \param[in] alpha The red component (0x00 to 0xff)
45             Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 0xff) :
46                red(red),
47                green(green),
48                blue(blue),
49                alpha(alpha)
50             {
51             }
52
53             /// Equality operator
54             /// \param[in] rhs The color to test
55             /// \return Whether the colors are equal
56             bool operator == (const Color &rhs) const
57             {
58                return red == rhs.red && green == rhs.green && blue == rhs.blue && alpha == rhs.alpha;
59             }
60
61             /// Equality operator
62             /// \param[in] rhs The color to test
63             /// \return Whether the colors are not equal
64             bool operator != (const Color &rhs) const
65             {
66                return !(*this == rhs);
67             }
68
69             /// Less than operator
70             /// \param[in] rhs The color to test
71             /// \return Whether the color's grayscale value is less than the tested color
72             bool operator < (const Color &rhs) const
73             {
74                return grayscale() < rhs.grayscale();
75             }
76
77             /// Calculate the grayscale value of the color
78             /// \return The grayscale value (30% red, 59% green, 11% blue)
79             unsigned char grayscale() const
80             {
81                return (red * 30 + green * 59 + blue * 11) / 100;
82             }
83
84             /// Opaque black (red = 0x00, green = 0x00, blue = 0x00)
85             static const Color BLACK;
86
87             /// Opaque red (red = 0xff, green = 0x00, blue = 0x00)
88             static const Color RED;
89
90             /// Opaque green (red = 0x00, green = 0xff, blue = 0x00)
91             static const Color GREEN;
92
93             /// Opaque blue (red = 0x00, green = 0x00, blue = 0xff)
94             static const Color BLUE;
95
96             /// Opaque cyan (red = 0x00, green = 0xff, blue = 0xff)
97             static const Color CYAN;
98
99             /// Opaque magenta (red = 0xff, green = 0x00, blue = 0xff)
100             static const Color MAGENTA;
101
102             /// Opaque yellow (red = 0xff, green = 0xff, blue = 0x00)
103             static const Color YELLOW;
104
105             /// Opaque white (red = 0xff, green = 0xff, blue = 0xff)
106             static const Color WHITE;
107       };
108    }
109 }
110
111 #endif