TGUI  0.8-dev
Color.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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 <string>
32 
34 
35 namespace tgui
36 {
46  class TGUI_API Color
47  {
48  public:
49 
54  static sf::Color calcColorOpacity(const sf::Color& color, float alpha)
55  {
56  return {color.r, color.g, color.b, static_cast<sf::Uint8>(color.a * alpha)};
57  }
58 
59 
60  public:
61 
68  Color() :
69  m_isSet{false}
70  {
71  }
72 
73 
80  Color(const sf::Color& color) :
81  m_isSet{true},
82  m_color{color}
83  {
84  }
85 
86 
96  Color(sf::Uint8 red, sf::Uint8 green, sf::Uint8 blue, sf::Uint8 alpha = 255) :
97  m_isSet{true},
98  m_color{red, green, blue, alpha}
99  {
100  }
101 
102 
111  Color(const std::string& string);
112 
113 
122  Color(const char* string);
123 
124 
131  bool isSet() const;
132 
133 
140  operator sf::Color() const;
141 
142 
149  sf::Uint8 getRed() const;
150 
151 
158  sf::Uint8 getGreen() const;
159 
160 
167  sf::Uint8 getBlue() const;
168 
169 
176  sf::Uint8 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  private:
205 
206  bool m_isSet;
207  sf::Color m_color;
208  };
209 
211 }
212 
214 
215 #endif // TGUI_COLOR_HPP
216 
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Wrapper for colors.
Definition: Color.hpp:46
Color()
Creates the object without a color.
Definition: Color.hpp:68
Color(const sf::Color &color)
Creates the object from an sf::Color.
Definition: Color.hpp:80
Color(sf::Uint8 red, sf::Uint8 green, sf::Uint8 blue, sf::Uint8 alpha=255)
Creates the object from an the RGB or RGBA values.
Definition: Color.hpp:96
static sf::Color calcColorOpacity(const sf::Color &color, float alpha)
Returns the color with its alpha channel multiplied with the alpha parameter.
Definition: Color.hpp:54