TGUI  1.4.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#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#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
35 #include <vector>
36 #include <memory>
37#endif
38
40
41TGUI_MODULE_EXPORT namespace tgui
42{
44
46 class TGUI_API Sprite
47 {
48 public:
49
53 enum class ScalingType
54 {
55 Normal,
57 Vertical,
58 NineSlice
59 };
60
62 public:
63
67 Sprite() = default;
68
74 Sprite(const Texture& texture);
75
79 Sprite(const Sprite&);
80
84 Sprite(Sprite&&) noexcept;
85
90
94 Sprite& operator=(const Sprite&);
95
99 Sprite& operator=(Sprite&&) noexcept;
100
106 void setTexture(const Texture& texture);
107
113 TGUI_NODISCARD const Texture& getTexture() const;
114
120 TGUI_NODISCARD bool isSet() const;
121
127 void setSize(const Vector2f& size);
128
134 TGUI_NODISCARD Vector2f getSize() const;
135
143 void setOpacity(float opacity);
144
150 TGUI_NODISCARD float getOpacity() const;
151
159 void setVisibleRect(const FloatRect& visibleRect);
160
166 TGUI_NODISCARD FloatRect getVisibleRect() const;
167
173 void setPosition(Vector2f position);
174
180 TGUI_NODISCARD Vector2f getPosition() const;
181
189 void setRotation(float angle);
190
196 TGUI_NODISCARD float getRotation() const;
197
205 TGUI_NODISCARD bool isTransparentPixel(Vector2f pos) const;
206
212 TGUI_NODISCARD ScalingType getScalingType() const;
213
218 TGUI_NODISCARD const std::shared_ptr<BackendTexture>& getSvgTexture() const
219 {
220 return m_svgTexture;
221 }
222
227 TGUI_NODISCARD const std::vector<Vertex>& getVertices() const
228 {
229 return m_vertices;
230 }
231
236 TGUI_NODISCARD const std::vector<unsigned int>& getIndices() const
237 {
238 return m_indices;
239 }
240
245 void updateVertices();
246
248 private:
249
250 Vector2f m_size;
251 Texture m_texture;
252 std::shared_ptr<BackendTexture> m_svgTexture;
253 std::vector<Vertex> m_vertices;
254 std::vector<unsigned int> m_indices;
255
256 FloatRect m_visibleRect;
257
258 Color m_vertexColor = Color::White;
259 float m_opacity = 1;
260 float m_rotation = 0;
261 Vector2f m_position;
262
263 ScalingType m_scalingType = ScalingType::Normal;
264 };
265
267}
268
270
271#endif // TGUI_SPRITE_HPP
Base class for texture implementations that depend on the backend.
Definition BackendTexture.hpp:43
Definition Sprite.hpp:47
ScalingType
The way the image should be scaled.
Definition Sprite.hpp:54
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:38
@ Vertical
Vertical orientation.
@ Horizontal
Horizontal orientation.