TGUI  0.8-beta
Sprite.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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_SPRITE_HPP
27 #define TGUI_SPRITE_HPP
28 
29 #include <TGUI/Texture.hpp>
30 #include <TGUI/Vector2f.hpp>
31 #include <TGUI/FloatRect.hpp>
32 #include <TGUI/Color.hpp>
33 #include <SFML/Graphics/Transformable.hpp>
34 #include <SFML/Graphics/RenderStates.hpp>
35 #include <SFML/Graphics/Vertex.hpp>
36 
38 
39 namespace tgui
40 {
42 
43  class TGUI_API Sprite : public sf::Transformable
44  {
45  public:
46 
51  enum class ScalingType
52  {
53  Normal,
54  Horizontal,
55  Vertical,
56  NineSlice
57  };
58 
59 
61  public:
62 
69  void setTexture(const Texture& texture);
70 
71 
78  const Texture& getTexture() const;
79 
80 
87  Texture& getTexture();
88 
89 
96  bool isSet() const;
97 
98 
105  void setSize(const Vector2f& size);
106 
107 
114  Vector2f getSize() const;
115 
116 
128  void setColor(const Color& color);
129 
130 
142  const Color& getColor() const;
143 
144 
153  virtual void setOpacity(float opacity);
154 
155 
162  float getOpacity() const;
163 
164 
173  void setVisibleRect(const FloatRect& visibleRect);
174 
175 
182  FloatRect getVisibleRect() const;
183 
184 
193  bool isTransparentPixel(Vector2f pos) const;
194 
195 
202  ScalingType getScalingType() const;
203 
204 
208  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
209 
210 
212  private:
213 
215  // Update the location of the vertices
217  void updateVertices();
218 
219 
221  private:
222 
223  Vector2f m_size;
224  Texture m_texture;
225  std::vector<sf::Vertex> m_vertices;
226 
227  FloatRect m_visibleRect;
228 
229  Color m_vertexColor = Color::White;
230  float m_opacity = 1;
231 
232  ScalingType m_scalingType = ScalingType::Normal;
233  };
234 
236 }
237 
239 
240 #endif // TGUI_SPRITE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:43
Wrapper for colors.
Definition: Color.hpp:47
Definition: Vector2f.hpp:37
Definition: Texture.hpp:40
static const Color White
White predefined color.
Definition: Color.hpp:196
Definition: FloatRect.hpp:36
ScalingType
The way the image should be scaled.
Definition: Sprite.hpp:51