25#ifndef TGUI_VECTOR2_HPP
26#define TGUI_VECTOR2_HPP
28#include <TGUI/Config.hpp>
29#include <TGUI/String.hpp>
31#if TGUI_HAS_WINDOW_BACKEND_SFML
32 #include <SFML/System/Vector2.hpp>
37TGUI_MODULE_EXPORT
namespace tgui
65 x{static_cast<T>(vec.
x)},
66 y{static_cast<T>(vec.
y)}
70#if TGUI_HAS_WINDOW_BACKEND_SFML
74 constexpr Vector2(
const sf::Vector2<T>& vec) :
96 TGUI_PRINT_WARNING(
"Failed to parse Vector2. String was empty.");
101 if (((str.front() ==
'(') && (str.back() ==
')')) || ((str.front() ==
'{') && (str.back() ==
'}')))
102 str = str.substr(1, str.length() - 2);
111 auto commaPos = str.find(
',');
112 if (commaPos == String::npos)
114 TGUI_PRINT_WARNING(
"Failed to parse Vector2 '" + str +
"'. Expected numbers separated with a comma.");
118 x =
static_cast<T
>(str.substr(0, commaPos).trim().toFloat());
119 y =
static_cast<T
>(str.substr(commaPos + 1).trim().toFloat());
122#if TGUI_HAS_WINDOW_BACKEND_SFML
126 TGUI_NODISCARD
operator sf::Vector2<T>()
const
128 return sf::Vector2<T>{
x,
y};
144 template <
typename T>
147 return {-right.
x, -right.
y};
153 template <
typename T>
164 template <
typename T>
175 template <
typename T>
178 return {left.
x + right.
x, left.
y + right.
y};
184 template <
typename T>
187 return {left.
x - right.
x, left.
y - right.
y};
193 template <
typename T>
196 return {
static_cast<T
>(
static_cast<float>(left.
x) * right),
static_cast<T
>(
static_cast<float>(left.
y) * right)};
202 template <
typename T>
205 return {
static_cast<T
>(left *
static_cast<float>(right.
x)),
static_cast<T
>(left *
static_cast<float>(right.
y))};
211 template <
typename T>
214 return left = left * right;
220 template <
typename T>
223 return {
static_cast<T
>(
static_cast<float>(left.
x) / right),
static_cast<T
>(
static_cast<float>(left.
y) / right)};
229 template <
typename T>
232 return left = left / right;
238 template <
typename T>
241 return (left.
x == right.
x) && (left.
y == right.
y);
247 template <
typename T>
250 return !(left == right);
255 using Vector2f = Vector2<float>;
256 using Vector2u = Vector2<unsigned int>;
257 using Vector2i = Vector2<int>;
Wrapper class to store strings.
Definition String.hpp:96
Definition Vector2.hpp:41
constexpr Vector2(T xValue, T yValue)
Constructor to create from X and Y values.
Definition Vector2.hpp:52
constexpr Vector2()=default
Default constructor.
constexpr Vector2(const sf::Vector2< T > &vec)
Copy constructor to create from an sf::Vector2.
Definition Vector2.hpp:74
T y
Y coordinate of the vector.
Definition Vector2.hpp:136
Vector2(String str)
Constructor to create from a string.
Definition Vector2.hpp:92
constexpr Vector2(const Vector2< U > &vec)
Constructs the vector from an another Vector2 with a different type.
Definition Vector2.hpp:64
Vector2(const char *str)
Constructor to create from a string.
Definition Vector2.hpp:84
T x
X coordinate of the vector.
Definition Vector2.hpp:135
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38