GameKit  0.0.1a
C++ gamedev tools
Color.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Color.hpp
5  *
6  * Description:
7  *
8  * Created: 27/09/2014 22:35:38
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_COLOR_HPP_
15 #define GK_COLOR_HPP_
16 
17 #include "gk/core/IntTypes.hpp"
18 
19 namespace gk {
20 
25 class Color {
26  public:
34  Color() = default;
35 
45  Color(u8 _r, u8 _g, u8 _b, u8 _a = 255);
46 
47  // Only used in Asylia
48  void invert() { r = 1 - r; g = 1 - g; b = 1 - b; }
49 
61  Color operator+(const Color &c) { return Color(r + c.r, g + c.g, b + c.b, a + c.a); }
62 
74  Color operator-(const Color &c) { return Color(r - c.r, g - c.g, b - c.b, a - c.a); }
75 
86  bool operator==(const Color &color) const {
87  return r == color.r && g == color.g && b == color.b && a == color.a;
88  }
89 
100  bool operator!=(const Color &color) const {
101  return !(*this == color);
102  }
103 
104  // Only used in Asylia
105  u8 r255() const { return r * 255; }
106  u8 g255() const { return g * 255; }
107  u8 b255() const { return b * 255; }
108  u8 a255() const { return a * 255; }
109 
110  // FIXME: Use u8 instead of float and normalize when sending to OpenGL
111  float r = 1.0f;
112  float g = 1.0f;
113  float b = 1.0f;
114  float a = 1.0f;
115 
116  static const Color Black;
117  static const Color White;
118  static const Color Red;
119  static const Color Green;
120  static const Color Blue;
121  static const Color Yellow;
122  static const Color Magenta;
123  static const Color Cyan;
124  static const Color Transparent;
125 };
126 
127 } // namespace gk
128 
129 #endif // GK_COLOR_HPP_
130 
static const Color Transparent
Transparent (black) predefined color.
Definition: Color.hpp:124
static const Color Green
Green predefined color.
Definition: Color.hpp:119
u8 r255() const
Definition: Color.hpp:105
Color()=default
Default constructor.
Color operator+(const Color &c)
Overload of the binary + operator.
Definition: Color.hpp:61
static const Color Yellow
Yellow predefined color.
Definition: Color.hpp:121
static const Color Cyan
Cyan predefined color.
Definition: Color.hpp:123
Utility class for manipulating RGBA colors.
Definition: Color.hpp:25
static const Color Magenta
Magenta predefined color.
Definition: Color.hpp:122
unsigned char u8
Definition: IntTypes.hpp:21
float g
Green component.
Definition: Color.hpp:112
float a
Alpha (opacity) component.
Definition: Color.hpp:114
static const Color White
White predefined color.
Definition: Color.hpp:117
u8 a255() const
Definition: Color.hpp:108
u8 g255() const
Definition: Color.hpp:106
float b
Blue component.
Definition: Color.hpp:113
float r
Red component.
Definition: Color.hpp:111
bool operator==(const Color &color) const
Overload of binary operator ==.
Definition: Color.hpp:86
static const Color Blue
Blue predefined color.
Definition: Color.hpp:120
static const Color Black
Black predefined color.
Definition: Color.hpp:116
Color operator-(const Color &c)
Overload of the binary - operator.
Definition: Color.hpp:74
bool operator!=(const Color &color) const
Overload of binary operator !=.
Definition: Color.hpp:100
void invert()
Definition: Color.hpp:48
static const Color Red
Red predefined color.
Definition: Color.hpp:118
u8 b255() const
Definition: Color.hpp:107