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)
6 #ifndef UNISON_VIDEO_COLOR_HPP
7 #define UNISON_VIDEO_COLOR_HPP
9 //#include "SDL_stdinc.h"
19 /// The red component (0x00 to 0xff)
22 /// The green component (0x00 to 0xff)
25 /// The blue component (0x00 to 0xff)
28 /// The alpha component (0x00 to 0xff)
31 /// Default constructor (transparent black)
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) :
54 /// \param[in] rhs The color to test
55 /// \return Whether the colors are equal
56 bool operator == (const Color &rhs) const
58 return red == rhs.red && green == rhs.green && blue == rhs.blue && alpha == rhs.alpha;
62 /// \param[in] rhs The color to test
63 /// \return Whether the colors are not equal
64 bool operator != (const Color &rhs) const
66 return !(*this == rhs);
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
74 return grayscale() < rhs.grayscale();
77 /// Calculate the grayscale value of the color
78 /// \return The grayscale value (30% red, 59% green, 11% blue)
79 unsigned char grayscale() const
81 return (red * 30 + green * 59 + blue * 11) / 100;
84 /// Opaque black (red = 0x00, green = 0x00, blue = 0x00)
85 static const Color BLACK;
87 /// Opaque red (red = 0xff, green = 0x00, blue = 0x00)
88 static const Color RED;
90 /// Opaque green (red = 0x00, green = 0xff, blue = 0x00)
91 static const Color GREEN;
93 /// Opaque blue (red = 0x00, green = 0x00, blue = 0xff)
94 static const Color BLUE;
96 /// Opaque cyan (red = 0x00, green = 0xff, blue = 0xff)
97 static const Color CYAN;
99 /// Opaque magenta (red = 0xff, green = 0x00, blue = 0xff)
100 static const Color MAGENTA;
102 /// Opaque yellow (red = 0xff, green = 0xff, blue = 0x00)
103 static const Color YELLOW;
105 /// Opaque white (red = 0xff, green = 0xff, blue = 0xff)
106 static const Color WHITE;