TGUI  0.8.4
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 <SFML/Graphics/Transformable.hpp>
34 #include <SFML/Graphics/RenderStates.hpp>
35 #include <SFML/Graphics/Vertex.hpp>
36 
38 
39 namespace tgui
40 {
42 
44  class TGUI_API Sprite : public sf::Transformable
45  {
46  public:
47 
52  enum class ScalingType
53  {
54  Normal,
55  Horizontal,
56  Vertical,
57  NineSlice
58  };
59 
60 
62  public:
63 
70  void setTexture(const Texture& texture);
71 
72 
79  const Texture& getTexture() const;
80 
81 #ifndef TGUI_NEXT
82  Texture& getTexture();
89 #endif
90 
97  bool isSet() const;
98 
99 
106  void setSize(const Vector2f& size);
107 
108 
115  Vector2f getSize() const;
116 
117 #ifndef TGUI_REMOVE_DEPRECATED_CODE
118  TGUI_DEPRECATED("Color should be changed through the texture") void setColor(const Color& color);
130 
131 
143  TGUI_DEPRECATED("Color should be changed through the texture") const Color& getColor() const;
144 #endif
145 
154  virtual void setOpacity(float opacity);
155 
156 
163  float getOpacity() const;
164 
165 
174  void setVisibleRect(const FloatRect& visibleRect);
175 
176 
183  FloatRect getVisibleRect() const;
184 
185 
194  bool isTransparentPixel(Vector2f pos) const;
195 
196 
203  ScalingType getScalingType() const;
204 
205 
209  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
210 
211 
213  private:
214 
216  // Update the location of the vertices
218  void updateVertices();
219 
220 
222  private:
223 
224  Vector2f m_size;
225  Texture m_texture;
226  std::vector<sf::Vertex> m_vertices;
227 
228  FloatRect m_visibleRect;
229 
230  sf::Shader* m_shader = nullptr;
231  Color m_vertexColor = Color::White;
232  float m_opacity = 1;
233 
234  ScalingType m_scalingType = ScalingType::Normal;
235  };
236 
238 }
239 
241 
242 #endif // TGUI_SPRITE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:44
Wrapper for colors.
Definition: Color.hpp:47
Definition: Vector2f.hpp:37
Definition: Texture.hpp:41
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:52