TGUI 1.13
Loading...
Searching...
No Matches
Sprite.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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/Color.hpp>
29#include <TGUI/Rect.hpp>
30#include <TGUI/RenderStates.hpp>
31#include <TGUI/Texture.hpp>
32#include <TGUI/Vector2.hpp>
33
34#include <memory>
35#include <vector>
36
38
39namespace tgui
40{
42
44 class TGUI_API Sprite
45 {
46 public:
50 enum class ScalingType
51 {
52 Normal,
55 NineSlice
56 };
57
59
60 public:
64 Sprite() = default;
65
71 Sprite(const Texture& texture);
72
76 Sprite(const Sprite&);
77
81 Sprite(Sprite&&) noexcept;
82
87
91 Sprite& operator=(const Sprite&);
92
96 Sprite& operator=(Sprite&&) noexcept;
97
103 void setTexture(const Texture& texture);
104
110 [[nodiscard]] const Texture& getTexture() const;
111
117 [[nodiscard]] bool isSet() const;
118
124 void setSize(Vector2f size);
125
131 [[nodiscard]] Vector2f getSize() const;
132
140 void setOpacity(float opacity);
141
147 [[nodiscard]] float getOpacity() const;
148
156 void setVisibleRect(const FloatRect& visibleRect);
157
163 [[nodiscard]] FloatRect getVisibleRect() const;
164
170 void setPosition(Vector2f position);
171
177 [[nodiscard]] Vector2f getPosition() const;
178
186 void setRotation(float angle);
187
193 [[nodiscard]] float getRotation() const;
194
202 [[nodiscard]] bool isTransparentPixel(Vector2f pos) const;
203
209 [[nodiscard]] ScalingType getScalingType() const;
210
215 [[nodiscard]] const std::shared_ptr<BackendTexture>& getSvgTexture() const
216 {
217 return m_svgTexture;
218 }
219
224 [[nodiscard]] const std::vector<Vertex>& getVertices() const
225 {
226 return m_vertices;
227 }
228
233 [[nodiscard]] const std::vector<unsigned int>& getIndices() const
234 {
235 return m_indices;
236 }
237
242 void updateVertices();
243
245
246 private:
247 Vector2f m_size;
248 Texture m_texture;
249 std::shared_ptr<BackendTexture> m_svgTexture;
250 std::vector<Vertex> m_vertices;
251 std::vector<unsigned int> m_indices;
252
253 FloatRect m_visibleRect;
254
255 Color m_vertexColor = Color::White;
256 float m_opacity = 1;
257 float m_rotation = 0;
258 Vector2f m_position;
259
260 ScalingType m_scalingType = ScalingType::Normal;
261 };
262} // namespace tgui
263
264#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:51
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:53
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
@ Vertical
Vertical orientation.
Definition Layout.hpp:51
@ Horizontal
Horizontal orientation.
Definition Layout.hpp:52