TGUI 1.13
Loading...
Searching...
No Matches
Transform.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_TRANSFORM_HPP
26#define TGUI_TRANSFORM_HPP
27
29
30#include <TGUI/Config.hpp>
31
32#include <TGUI/Rect.hpp>
33
34#include <array>
35
37
38namespace tgui
39{
42 // Based on sf::Transform from SFML
44 class TGUI_API Transform
45 {
46 public:
53
67 Transform(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22);
68
74 Transform(const std::array<float, 16>& matrix);
75
88 [[nodiscard]] const std::array<float, 16>& getMatrix() const;
89
97 [[nodiscard]] Transform getInverse() const;
98
106 [[nodiscard]] Vector2f transformPoint(const Vector2f& point) const
107 {
108 return {(m_matrix[0] * point.x) + (m_matrix[4] * point.y) + m_matrix[12],
109 (m_matrix[1] * point.x) + (m_matrix[5] * point.y) + m_matrix[13]};
110 }
111
121 [[nodiscard]] FloatRect transformRect(const FloatRect& rectangle) const;
122
134
142 Transform& translate(const Vector2f& offset);
143
155 Transform& rotate(float angle, const Vector2f& center = {0, 0});
156
168 Transform& scale(const Vector2f& factors, const Vector2f& center = {0, 0});
169
177 [[nodiscard]] Transform operator*(const Transform& right) const;
178 Transform& operator*=(const Transform& right);
179 [[nodiscard]] Vector2f operator*(const Vector2f& right) const;
180
187 TGUI_DEPRECATED("Use roundPosition(Vector2f) instead") void roundPosition(float pixelScaleX, float pixelScaleY);
188
194 void roundPosition(Vector2f pixelScale);
195
196 private:
197 std::array<float, 16> m_matrix;
198 };
199} // namespace tgui
200
201#endif // TGUI_TRANSFORM_HPP
FloatRect transformRect(const FloatRect &rectangle) const
Transform a rectangle.
Transform(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
Construct a transform from a 3x3 matrix.
Transform & translate(const Vector2f &offset)
Combine the current transform with a translation.
void roundPosition(float pixelScaleX, float pixelScaleY)
Rounds the position stored in the transform to the nearest pixel.
const std::array< float, 16 > & getMatrix() const
Return the transform as a 4x4 matrix.
Transform & combine(const Transform &other)
Combine the current transform with another one.
Transform()
Default constructor.
Vector2f transformPoint(const Vector2f &point) const
Transform a 2D point.
Definition Transform.hpp:106
Transform getInverse() const
Return the inverse of the transform.
Transform & scale(const Vector2f &factors, const Vector2f &center={0, 0})
Combine the current transform with a scaling.
Transform & rotate(float angle, const Vector2f &center={0, 0})
Combine the current transform with a rotation.
Transform(const std::array< float, 16 > &matrix)
Constructs a transform from a 4x4 matrix.
Transform operator*(const Transform &right) const
Overload of binary operator * to combine two transforms.
T y
Y coordinate of the vector.
Definition Vector2.hpp:136
T x
X coordinate of the vector.
Definition Vector2.hpp:135
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37