TGUI  0.8.5
Sprite.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2019 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 <TGUI/Aurora/SmartPtr/CopiedPtr.hpp>
34 #include <SFML/Graphics/Transformable.hpp>
35 #include <SFML/Graphics/RenderStates.hpp>
36 #include <SFML/Graphics/Vertex.hpp>
37 
39 
40 namespace tgui
41 {
43 
45  class TGUI_API Sprite : public sf::Transformable
46  {
47  public:
48 
53  enum class ScalingType
54  {
55  Normal,
56  Horizontal,
57  Vertical,
58  NineSlice
59  };
60 
61 
63  public:
64 
65 
69  Sprite() = default;
70 
71 
77  Sprite(const Texture& texture);
78 
79 
86  void setTexture(const Texture& texture);
87 
88 
95  const Texture& getTexture() const;
96 
97 #ifndef TGUI_NEXT
98  Texture& getTexture();
105 #endif
106 
113  bool isSet() const;
114 
115 
122  void setSize(const Vector2f& size);
123 
124 
131  Vector2f getSize() const;
132 
133 #ifndef TGUI_REMOVE_DEPRECATED_CODE
134  TGUI_DEPRECATED("Color should be changed through the texture") void setColor(const Color& color);
146 
147 
159  TGUI_DEPRECATED("Color should be changed through the texture") const Color& getColor() const;
160 #endif
161 
170  virtual void setOpacity(float opacity);
171 
172 
179  float getOpacity() const;
180 
181 
190  void setVisibleRect(const FloatRect& visibleRect);
191 
192 
199  FloatRect getVisibleRect() const;
200 
201 
210  bool isTransparentPixel(Vector2f pos) const;
211 
212 
219  ScalingType getScalingType() const;
220 
221 
225  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
226 
227 
229  private:
230 
232  // Update the location of the vertices
234  void updateVertices();
235 
236 
238  private:
239 
240  Vector2f m_size;
241  Texture m_texture;
242  aurora::CopiedPtr<sf::Texture> m_svgTexture;
243  std::vector<sf::Vertex> m_vertices;
244 
245  FloatRect m_visibleRect;
246 
247  sf::Shader* m_shader = nullptr;
248  Color m_vertexColor = Color::White;
249  float m_opacity = 1;
250 
251  ScalingType m_scalingType = ScalingType::Normal;
252  };
253 
255 }
256 
258 
259 #endif // TGUI_SPRITE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:45
Wrapper for colors.
Definition: Color.hpp:48
Definition: Vector2f.hpp:37
Definition: Texture.hpp:41
static const Color White
White predefined color.
Definition: Color.hpp:207
Definition: FloatRect.hpp:36
ScalingType
The way the image should be scaled.
Definition: Sprite.hpp:53