TGUI  0.8-dev
Sprite.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_SPRITE_HPP
27 #define TGUI_SPRITE_HPP
28 
29 #include <TGUI/Texture.hpp>
30 #include <SFML/Graphics/Transformable.hpp>
31 #include <SFML/Graphics/RenderStates.hpp>
32 #include <SFML/Graphics/Vertex.hpp>
33 
35 
36 namespace tgui
37 {
39 
40  class TGUI_API Sprite : public sf::Transformable
41  {
42  public:
43 
48  enum class ScalingType
49  {
50  Normal,
51  Horizontal,
52  Vertical,
53  NineSlice
54  };
55 
56 
58  public:
59 
66  void setTexture(const Texture& texture);
67 
68 
75  const Texture& getTexture() const;
76 
77 
84  Texture& getTexture();
85 
86 
93  bool isSet() const;
94 
95 
102  void setSize(const sf::Vector2f& size);
103 
104 
111  sf::Vector2f getSize() const;
112 
113 
125  void setColor(const sf::Color& color);
126 
127 
139  const sf::Color& getColor() const;
140 
141 
150  virtual void setOpacity(float opacity);
151 
152 
159  float getOpacity() const;
160 
161 
170  void setVisibleRect(const sf::FloatRect& visibleRect);
171 
172 
179  sf::FloatRect getVisibleRect() const;
180 
181 
190  bool isTransparentPixel(sf::Vector2f pos) const;
191 
192 
199  ScalingType getScalingType() const;
200 
201 
205  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
206 
207 
209  private:
210 
212  // Update the location of the vertices
214  void updateVertices();
215 
216 
218  private:
219 
220  sf::Vector2f m_size;
221  Texture m_texture;
222  std::vector<sf::Vertex> m_vertices;
223 
224  sf::FloatRect m_visibleRect;
225 
226  sf::Color m_vertexColor = sf::Color::White;
227  float m_opacity = 1;
228 
229  ScalingType m_scalingType = ScalingType::Normal;
230  };
231 
233 }
234 
236 
237 #endif // TGUI_SPRITE_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:40
Definition: Texture.hpp:39
ScalingType
The way the image should be scaled.
Definition: Sprite.hpp:48