TGUI  1.2.0
Loading...
Searching...
No Matches
Sprite.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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/Vector2.hpp>
31#include <TGUI/Rect.hpp>
32#include <TGUI/Color.hpp>
33#include <TGUI/RenderStates.hpp>
34
35#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
36 #include <vector>
37 #include <memory>
38#endif
39
41
42TGUI_MODULE_EXPORT namespace tgui
43{
45
47 class TGUI_API Sprite
48 {
49 public:
50
55 enum class ScalingType
56 {
57 Normal,
58 Horizontal,
59 Vertical,
60 NineSlice
61 };
62
63
65 public:
66
67
71 Sprite() = default;
72
78 Sprite(const Texture& texture);
79
83 Sprite(const Sprite&);
84
88 Sprite(Sprite&&) noexcept;
89
94
98 Sprite& operator=(const Sprite&);
99
103 Sprite& operator=(Sprite&&) noexcept;
104
105
112 void setTexture(const Texture& texture);
113
114
121 TGUI_NODISCARD const Texture& getTexture() const;
122
123
130 TGUI_NODISCARD bool isSet() const;
131
132
139 void setSize(const Vector2f& size);
140
141
148 TGUI_NODISCARD Vector2f getSize() const;
149
150
159 void setOpacity(float opacity);
160
161
168 TGUI_NODISCARD float getOpacity() const;
169
170
179 void setVisibleRect(const FloatRect& visibleRect);
180
181
188 TGUI_NODISCARD FloatRect getVisibleRect() const;
189
190
196 void setPosition(Vector2f position);
197
198
204 TGUI_NODISCARD Vector2f getPosition() const;
205
206
214 void setRotation(float angle);
215
216
222 TGUI_NODISCARD float getRotation() const;
223
224
233 TGUI_NODISCARD bool isTransparentPixel(Vector2f pos) const;
234
235
242 TGUI_NODISCARD ScalingType getScalingType() const;
243
244
249 TGUI_NODISCARD const std::shared_ptr<BackendTexture>& getSvgTexture() const
250 {
251 return m_svgTexture;
252 }
253
254
259 TGUI_NODISCARD const std::vector<Vertex>& getVertices() const
260 {
261 return m_vertices;
262 }
263
264
269 TGUI_NODISCARD const std::vector<unsigned int>& getIndices() const
270 {
271 return m_indices;
272 }
273
274
279 void updateVertices();
280
281
283 private:
284
285 Vector2f m_size;
286 Texture m_texture;
287 std::shared_ptr<BackendTexture> m_svgTexture;
288 std::vector<Vertex> m_vertices;
289 std::vector<unsigned int> m_indices;
290
291 FloatRect m_visibleRect;
292
293 Color m_vertexColor = Color::White;
294 float m_opacity = 1;
295 float m_rotation = 0;
296 Vector2f m_position;
297
298 ScalingType m_scalingType = ScalingType::Normal;
299 };
300
302}
303
305
306#endif // TGUI_SPRITE_HPP
Base class for texture implementations that depend on the backend.
Definition BackendTexture.hpp:44
Definition Sprite.hpp:48
ScalingType
The way the image should be scaled.
Definition Sprite.hpp:56
Sprite()=default
Default constructor.
Sprite(Sprite &&) noexcept
Move constructor.
Sprite(const Texture &texture)
Constructor that immediately sets the texture.
Sprite(const Sprite &)
Copy constructor.
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:57
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39