TGUI  0.8.8
Color.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages 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 freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_COLOR_HPP
27 #define TGUI_COLOR_HPP
28 
29 #include <TGUI/Config.hpp>
30 #include <SFML/Graphics/Color.hpp>
31 #include <SFML/System/String.hpp>
32 #include <cstdint>
33 #include <string>
34 #include <map>
35 
37 
38 namespace tgui
39 {
48  class TGUI_API Color
49  {
50  public:
51 
55  static Color calcColorOpacity(const Color& color, float alpha)
56  {
57  return {color.getRed(), color.getGreen(), color.getBlue(), static_cast<std::uint8_t>(color.getAlpha() * alpha)};
58  }
59 
60 
61  public:
62 
68  Color() :
69  m_isSet{false}
70  {
71  }
72 
73 
79  Color(const sf::Color& color) :
80  m_isSet{true},
81  m_color{color}
82  {
83  }
84 
85 
94  Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha = 255) :
95  m_isSet{true},
96  m_color{red, green, blue, alpha}
97  {
98  }
99 
100 
108  Color(const sf::String& string);
109 
110 
118  Color(const std::string& string);
119 
120 
128  Color(const char* string);
129 
130 
136  bool isSet() const;
137 
138 
144  operator sf::Color() const;
145 
146 
152  std::uint8_t getRed() const;
153 
154 
160  std::uint8_t getGreen() const;
161 
162 
168  std::uint8_t getBlue() const;
169 
170 
176  std::uint8_t getAlpha() const;
177 
178 
182  bool operator==(const Color& right) const;
183 
184 
188  bool operator!=(const Color& right) const;
189 
190 
194  bool operator==(const sf::Color& right) const;
195 
196 
200  bool operator!=(const sf::Color& right) const;
201 
202 
204  public:
205 
206  static const Color Black;
207  static const Color White;
208  static const Color Red;
209  static const Color Green;
210  static const Color Blue;
211  static const Color Yellow;
212  static const Color Magenta;
213  static const Color Cyan;
214  static const Color Transparent;
215 
216  static const std::map<std::string, Color> colorMap;
217 
218 
220  private:
221 
222  bool m_isSet;
223  sf::Color m_color;
224  };
225 
227 }
228 
230 
231 #endif // TGUI_COLOR_HPP
232 
static const Color Magenta
Magenta predefined color.
Definition: Color.hpp:212
bool operator!=(const sf::Color &right) const
Compares the color with another one.
bool operator==(const sf::Color &right) const
Compares the color with another one.
std::uint8_t getBlue() const
Returns the blue component of the color.
static const Color Blue
Blue predefined color.
Definition: Color.hpp:210
Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha=255)
Creates the object from an the RGB or RGBA values.
Definition: Color.hpp:94
bool operator!=(const Color &right) const
Compares the color with another one.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37
Color(const sf::Color &color)
Creates the object from an sf::Color.
Definition: Color.hpp:79
static Color calcColorOpacity(const Color &color, float alpha)
Returns the color with its alpha channel multiplied with the alpha parameter.
Definition: Color.hpp:55
Wrapper for colors.
Definition: Color.hpp:49
std::uint8_t getAlpha() const
Returns the alpha component of the color.
static const Color Cyan
Cyan predefined color.
Definition: Color.hpp:213
Color(const std::string &string)
Creates the object from a string.
std::uint8_t getRed() const
Returns the red component of the color.
static const Color White
White predefined color.
Definition: Color.hpp:207
bool operator==(const Color &right) const
Compares the color with another one.
static const Color Green
Green predefined color.
Definition: Color.hpp:209
static const Color Yellow
Yellow predefined color.
Definition: Color.hpp:211
bool isSet() const
Checks if a color was set.
static const Color Transparent
Transparent (black) predefined color.
Definition: Color.hpp:214
Color()
Creates the object without a color.
Definition: Color.hpp:68
static const Color Red
Red predefined color.
Definition: Color.hpp:208
Color(const sf::String &string)
Creates the object from a string.
Color(const char *string)
Creates the object from a string.
static const Color Black
Black predefined color.
Definition: Color.hpp:206
std::uint8_t getGreen() const
Returns the green component of the color.