Color.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_COLORS_HEADERS
30 #define NOMLIB_COLORS_HEADERS
31 
32 #include <algorithm>
33 
34 #include "nomlib/config.hpp"
35 
36 namespace nom {
37 
38 const std::string color_delimiter = ", ";
39 
43 class Color
44 {
45  public:
47  Color ( void );
48 
50  ~Color ( void );
51 
53  Color ( const Color& color );
54 
56  Color ( uint8 red, uint8 green, uint8 blue );
57 
59  Color ( uint8 red, uint8 green, uint8 blue, uint8 alpha );
60 
65  bool isNull ( void ) const;
66 
68  const Color& get ( void ) const;
69 
71  Color& operator = ( const Color& other );
72 
74  static const Color null;
75 
77  static const Color Black;
78  static const Color White;
79  static const Color Red;
80  static const Color Green;
81  static const Color Blue;
82  static const Color Yellow;
83  static const Color Magenta;
84  static const Color Cyan;
85 
87  static const Color LightGray;
88  static const Color Gray;
89 
91  static const Color NomPrimaryColorKey;
92 
95 
96  public:
97  uint8 red;
98  uint8 green;
99  uint8 blue;
100  uint8 alpha;
101 
103  uint8& r = red;
104 
106  uint8& g = green;
107 
109  uint8& b = blue;
110 
112  uint8& a = alpha;
113 };
114 
122 std::ostream& operator << ( std::ostream& os, const Color& color );
123 
124 bool operator == ( const Color& left, const Color& right );
125 bool operator != ( const Color& left, const Color& right );
126 
128 Color operator + ( const Color& left, const Color& right );
129 
131 Color operator ++ ( Color& left );
132 
134 Color operator - ( const Color& left, const Color& right );
135 
137 Color operator -- ( Color& left );
138 
140 Color operator * ( const Color& left, const Color& right);
141 
142 Color& operator += ( Color& left, const Color& right );
143 Color& operator -= ( Color& left, const Color& right );
144 Color& operator *= ( Color& left, const Color& right );
145 
146 
147 } // namespace nom
148 
149 #endif // NOMLIB_COLORS_HEADERS defined
uint8 & r
Reference alias for red instance variable.
Definition: Color.hpp:103
static const Color NomSecondaryColorKey
Light magenta color key.
Definition: Color.hpp:94
static const Color NomPrimaryColorKey
Sky blue color key.
Definition: Color.hpp:91
Color & operator=(const Color &other)
Copy assignment operator.
Definition: Color.cpp:89
static const Color Black
Predefined color constants for convenience sake.
Definition: Color.hpp:77
static const Color null
Convenience object that will always contain a value of -1.
Definition: Color.hpp:74
bool isNull(void) const
Definition: Color.cpp:74
uint8 & a
Reference alias for alpha instance variable.
Definition: Color.hpp:112
Color(void)
Default constructor; sets the color to their respective defaults.
Definition: Color.cpp:50
static const Color LightGray
Additional predefined color constants.
Definition: Color.hpp:87
uint8 & g
Reference alias for green instance variable.
Definition: Color.hpp:106
uint8 & b
Reference alias for blue instance variable.
Definition: Color.hpp:109
~Color(void)
Destructor.
Definition: Color.cpp:72
Utility class container for RGBA colors.
Definition: Color.hpp:43