Gamedev Framework (gf)  0.1.0
A C++11 framework for 2D games
Color.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_COLOR_H
22 #define GF_COLOR_H
23 
24 #include "Portability.h"
25 #include "Vector.h"
26 
27 namespace gf {
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 inline namespace v1 {
30 #endif
31 
32  /**
33  * @ingroup graphics
34  * @brief Predefined colors
35  *
36  * This class does not contain anything but predefined colors. All the
37  * primary, secondary and [tertiary colors](https://en.wikipedia.org/wiki/Tertiary_color)
38  * are defined by their usual names.
39  *
40  * If you want to define a color, you should use gf::Color4f.
41  *
42  * @sa gf::Color4f
43  */
44  struct GF_API Color {
45  /**
46  * @brief Deleted constructor
47  */
48  Color() = delete;
49 
50  /**
51  * @brief Black predefined color
52  */
53  static constexpr Color4f Black{0.0f, 0.0f, 0.0f, 1.0f};
54 
55  /**
56  * @brief White predefined color
57  */
58  static constexpr Color4f White{1.0f, 1.0f, 1.0f, 1.0f};
59 
60  /**
61  * @brief Red predefined color
62  */
63  static constexpr Color4f Red{1.0f, 0.0f, 0.0f, 1.0f};
64 
65  /**
66  * @brief Green predefined color
67  */
68  static constexpr Color4f Green{0.0f, 1.0f, 0.0f, 1.0f};
69 
70  /**
71  * @brief Blue predefined color
72  */
73  static constexpr Color4f Blue{0.0f, 0.0f, 1.0f, 1.0f};
74 
75  /**
76  * @brief Cyan predefined color
77  */
78  static constexpr Color4f Cyan{0.0f, 1.0f, 1.0f, 1.0f};
79 
80  /**
81  * @brief Magenta predefined color
82  */
83  static constexpr Color4f Magenta{1.0f, 0.0f, 1.0f, 1.0f};
84 
85  /**
86  * @brief Yellow predefined color
87  */
88  static constexpr Color4f Yellow{1.0f, 1.0f, 0.0f, 1.0f};
89 
90  /**
91  * @brief Transparent (black) predefined color
92  */
93  static constexpr Color4f Transparent{0.0f, 0.0f, 0.0f, 0.0f};
94 
95  /**
96  * @brief Grey predefined color
97  */
98  static constexpr Color4f Grey(float value = 0.5f) {
99  return { value, value, value, 1.0f };
100  }
101 
102  /**
103  * @brief Orange predefined color
104  */
105  static constexpr Color4f Orange{1.0f, 0.5f, 0.0f, 1.0f};
106 
107  /**
108  * @brief Rose predefined color
109  */
110  static constexpr Color4f Rose{1.0f, 0.0f, 0.5f, 1.0f};
111 
112  /**
113  * @brief Chartreuse predefined color
114  */
115  static constexpr Color4f Chartreuse{0.5f, 1.0f, 0.0f, 1.0f};
116 
117  /**
118  * @brief Spring (green) predefined color
119  */
120  static constexpr Color4f Spring{0.0f, 1.0f, 0.5f, 1.0f};
121 
122  /**
123  * @brief Violet predefined color
124  */
125  static constexpr Color4f Violet{0.5f, 0.0f, 1.0f, 1.0f};
126 
127  /**
128  * @brief Azure predefined color
129  */
130  static constexpr Color4f Azure{0.0f, 0.5f, 1.0f, 1.0f};
131 
132 
133  /**
134  * @brief Compute a lighter color
135  *
136  * This function takes a color and gives a lighter color based on a
137  * percentage. If this percentage is 0, the same color is returned. If this
138  * percentage is 1, the white color is returned.
139  *
140  * @param color The color
141  * @param percent The percentage, must be in @f$ [0, 1] @f$
142  */
143  static Color4f lighter(Color4f color, float percent = 0.5f);
144 
145  /**
146  * @brief Compute a darker color
147  *
148  * This function takes a color and gives a darker color based on a
149  * percentage. If this percentage is 0, the same color is returned. If this
150  * percentage is 1, the black color is returned.
151  *
152  * @param color The color
153  * @param percent The percentage, must be in @f$ [0, 1] @f$
154  */
155  static Color4f darker(Color4f color, float percent = 0.5f);
156 
157  };
158 
159 
160 #ifndef DOXYGEN_SHOULD_SKIP_THIS
161 }
162 #endif
163 }
164 
165 #endif // GF_COLOR_H
static constexpr Color4f Azure
Azure predefined color.
Definition: Color.h:130
Color()=delete
Deleted constructor.
static constexpr Color4f Transparent
Transparent (black) predefined color.
Definition: Color.h:93
static constexpr Color4f Magenta
Magenta predefined color.
Definition: Color.h:83
static Color4f lighter(Color4f color, float percent=0.5f)
Compute a lighter color.
static constexpr Color4f Chartreuse
Chartreuse predefined color.
Definition: Color.h:115
static constexpr Color4f White
White predefined color.
Definition: Color.h:58
static constexpr Color4f Violet
Violet predefined color.
Definition: Color.h:125
static constexpr Color4f Cyan
Cyan predefined color.
Definition: Color.h:78
static constexpr Color4f Red
Red predefined color.
Definition: Color.h:63
static constexpr Color4f Yellow
Yellow predefined color.
Definition: Color.h:88
static constexpr Color4f Grey(float value=0.5f)
Grey predefined color.
Definition: Color.h:98
constexpr Vector(T x, T y, T z, T w)
Constructor that takes 4 components.
Definition: Vector.h:652
Definition: Action.h:34
Predefined colors.
Definition: Color.h:44
static constexpr Color4f Rose
Rose predefined color.
Definition: Color.h:110
static constexpr Color4f Green
Green predefined color.
Definition: Color.h:68
static constexpr Color4f Black
Black predefined color.
Definition: Color.h:53
static constexpr Color4f Spring
Spring (green) predefined color.
Definition: Color.h:120
Vector< float, 4 > Color4f
A float color vector with 4 components.
Definition: Vector.h:855
static constexpr Color4f Blue
Blue predefined color.
Definition: Color.h:73
static Color4f darker(Color4f color, float percent=0.5f)
Compute a darker color.
#define GF_API
Definition: Portability.h:35
static constexpr Color4f Orange
Orange predefined color.
Definition: Color.h:105