TGUI  0.9-dev
Sprite.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_SPRITE_HPP
27 #define TGUI_SPRITE_HPP
28 
29 #include <TGUI/Texture.hpp>
30 #include <TGUI/Vector2.hpp>
31 #include <TGUI/Rect.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 
104  bool isSet() const;
105 
106 
113  void setSize(const Vector2f& size);
114 
115 
122  Vector2f getSize() const;
123 
124 
133  virtual void setOpacity(float opacity);
134 
135 
142  float getOpacity() const;
143 
144 
153  void setVisibleRect(const FloatRect& visibleRect);
154 
155 
162  FloatRect getVisibleRect() const;
163 
164 
173  bool isTransparentPixel(Vector2f pos) const;
174 
175 
182  ScalingType getScalingType() const;
183 
184 
188  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
189 
190 
192  private:
193 
195  // Update the location of the vertices
197  void updateVertices();
198 
199 
201  private:
202 
203  Vector2f m_size;
204  Texture m_texture;
205  aurora::CopiedPtr<sf::Texture> m_svgTexture;
206  std::vector<sf::Vertex> m_vertices;
207 
208  FloatRect m_visibleRect;
209 
210  sf::Shader* m_shader = nullptr;
211  Color m_vertexColor = Color::White;
212  float m_opacity = 1;
213 
214  ScalingType m_scalingType = ScalingType::Normal;
215  };
216 
218 }
219 
221 
222 #endif // TGUI_SPRITE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:35
Wrapper for colors.
Definition: Color.hpp:47
static const Color White
White predefined color.
Definition: Color.hpp:222
Definition: Sprite.hpp:45
Definition: Texture.hpp:42
ScalingType
The way the image should be scaled.
Definition: Sprite.hpp:53