TGUI 1.11
Loading...
Searching...
No Matches
Sprite.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 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#ifndef TGUI_SPRITE_HPP
26#define TGUI_SPRITE_HPP
27
28#include <TGUI/Texture.hpp>
29#include <TGUI/Vector2.hpp>
30#include <TGUI/Rect.hpp>
31#include <TGUI/Color.hpp>
32#include <TGUI/RenderStates.hpp>
33
34#include <vector>
35#include <memory>
36
38
39namespace tgui
40{
42
44 class TGUI_API Sprite
45 {
46 public:
47
58
60 public:
61
65 Sprite() = default;
66
72 Sprite(const Texture& texture);
73
77 Sprite(const Sprite&);
78
82 Sprite(Sprite&&) noexcept;
83
88
92 Sprite& operator=(const Sprite&);
93
97 Sprite& operator=(Sprite&&) noexcept;
98
104 void setTexture(const Texture& texture);
105
111 TGUI_NODISCARD const Texture& getTexture() const;
112
118 TGUI_NODISCARD bool isSet() const;
119
125 void setSize(Vector2f size);
126
132 TGUI_NODISCARD Vector2f getSize() const;
133
141 void setOpacity(float opacity);
142
148 TGUI_NODISCARD float getOpacity() const;
149
157 void setVisibleRect(const FloatRect& visibleRect);
158
164 TGUI_NODISCARD FloatRect getVisibleRect() const;
165
171 void setPosition(Vector2f position);
172
178 TGUI_NODISCARD Vector2f getPosition() const;
179
187 void setRotation(float angle);
188
194 TGUI_NODISCARD float getRotation() const;
195
203 TGUI_NODISCARD bool isTransparentPixel(Vector2f pos) const;
204
210 TGUI_NODISCARD ScalingType getScalingType() const;
211
216 TGUI_NODISCARD const std::shared_ptr<BackendTexture>& getSvgTexture() const
217 {
218 return m_svgTexture;
219 }
220
225 TGUI_NODISCARD const std::vector<Vertex>& getVertices() const
226 {
227 return m_vertices;
228 }
229
234 TGUI_NODISCARD const std::vector<unsigned int>& getIndices() const
235 {
236 return m_indices;
237 }
238
243 void updateVertices();
244
246 private:
247
248 Vector2f m_size;
249 Texture m_texture;
250 std::shared_ptr<BackendTexture> m_svgTexture;
251 std::vector<Vertex> m_vertices;
252 std::vector<unsigned int> m_indices;
253
254 FloatRect m_visibleRect;
255
256 Color m_vertexColor = Color::White;
257 float m_opacity = 1;
258 float m_rotation = 0;
259 Vector2f m_position;
260
261 ScalingType m_scalingType = ScalingType::Normal;
262 };
263
265}
266
268
269#endif // TGUI_SPRITE_HPP
Base class for texture implementations that depend on the backend.
Definition BackendTexture.hpp:41
FloatRect getVisibleRect() const
Returns the part of the sprite that is drawn.
float getRotation() const
Gets rotation of the sprite.
void setOpacity(float opacity)
Changes the opacity of the texture.
void setRotation(float angle)
Sets rotation of the sprite.
ScalingType
The way the image should be scaled.
Definition Sprite.hpp:52
@ Vertical
Image is split in Top, Middle and Bottom parts. Top and Bottom keep ratio, Middle gets stretched.
Definition Sprite.hpp:55
@ Normal
The image is not split and scaled normally.
Definition Sprite.hpp:53
@ Horizontal
Image is split in Left, Middle and Right parts. Left and Right keep ratio, Middle gets stretched.
Definition Sprite.hpp:54
@ NineSlice
Image is split in 9 parts. Corners keep size, sides are stretched in one direction,...
Definition Sprite.hpp:56
float getOpacity() const
Returns the opacity of the texture.
void setSize(Vector2f size)
Changes the size that the image will have when drawing.
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.
Sprite(Sprite &&) noexcept
Move constructor.
Vector2f getPosition() const
Gets the position of the sprite.
const Texture & getTexture() const
Returns the texture used by this sprite.
void setPosition(Vector2f position)
Sets the position of the sprite.
Sprite(const Texture &texture)
Constructor that immediately sets the texture.
void setTexture(const Texture &texture)
Changes the texture.
void setVisibleRect(const FloatRect &visibleRect)
Changes the part of the sprite that should be drawn.
Vector2f getSize() const
Returns the size that the image has when drawing.
bool isTransparentPixel(Vector2f pos) const
Checks if a certain pixel is transparent.
Sprite(const Sprite &)
Copy constructor.
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:52
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36