TGUI  0.8.9
Sprite.hpp
1
2//
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/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
40namespace 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
105#endif
106
113 bool isSet() const;
114
115
122 void setSize(const Vector2f& size);
123
124
132
133#ifndef TGUI_REMOVE_DEPRECATED_CODE
145 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
200
201
211
212
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
Wrapper for colors.
Definition: Color.hpp:49
static const Color White
White predefined color.
Definition: Color.hpp:207
Definition: FloatRect.hpp:37
Definition: Sprite.hpp:46
FloatRect getVisibleRect() const
Returns the part of the sprite that is drawn.
ScalingType
The way the image should be scaled.
Definition: Sprite.hpp:54
float getOpacity() const
Returns the opacity of the texture.
Sprite()=default
Default constructor.
ScalingType getScalingType() const
Returns the way in which the image is being scaled.
bool isSet() const
Returns whether a texture was set.
void setSize(const Vector2f &size)
Changes the size that the image will have when drawing.
const Texture & getTexture() const
Returns the texture used by this sprite.
Sprite(const Texture &texture)
Constructor that immediately sets the texture.
void setTexture(const Texture &texture)
Changes the texture.
Texture & getTexture()
Returns a reference to the texture used by this sprite.
void setVisibleRect(const FloatRect &visibleRect)
Changes the part of the sprite that should be drawn.
void draw(sf::RenderTarget &target, sf::RenderStates states) const
Draws the sprite.
Vector2f getSize() const
Returns the size that the image has when drawing.
bool isTransparentPixel(Vector2f pos) const
Checks if a certain pixel is transparent.
virtual void setOpacity(float opacity)
Changes the opacity of the texture.
Definition: Texture.hpp:42
Definition: Vector2f.hpp:39
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37