26#ifndef TGUI_VECTOR2_HPP
27#define TGUI_VECTOR2_HPP
29#include <TGUI/Config.hpp>
30#include <TGUI/String.hpp>
32#if TGUI_HAS_WINDOW_BACKEND_SFML
33 #include <SFML/System/Vector2.hpp>
68 x{static_cast<T>(vec.
x)},
69 y{static_cast<T>(vec.
y)}
73#if TGUI_HAS_WINDOW_BACKEND_SFML
77 constexpr Vector2(
const sf::Vector2<T>& vec) :
99 TGUI_PRINT_WARNING(
"Failed to parse Vector2. String was empty.");
104 if (((str.front() ==
'(') && (str.back() ==
')')) || ((str.front() ==
'{') && (str.back() ==
'}')))
105 str = str.substr(1, str.length() - 2);
114 auto commaPos = str.find(
',');
115 if (commaPos == String::npos)
117 TGUI_PRINT_WARNING(
"Failed to parse Vector2 '" + str +
"'. Expected numbers separated with a comma.");
121 x =
static_cast<T
>(str.substr(0, commaPos).
trim().
toFloat());
122 y =
static_cast<T
>(str.substr(commaPos + 1).
trim().
toFloat());
125#if TGUI_HAS_WINDOW_BACKEND_SFML
129 operator sf::Vector2<T>()
const
131 return sf::Vector2<T>{
x,
y};
148 template <
typename T>
151 return {-right.
x, -right.
y};
157 template <
typename T>
168 template <
typename T>
179 template <
typename T>
182 return {left.
x + right.
x, left.
y + right.
y};
188 template <
typename T>
191 return {left.
x - right.
x, left.
y - right.
y};
197 template <
typename T>
200 return {left.
x * right, left.
y * right};
206 template <
typename T>
209 return {left * right.
x, left * right.
y};
215 template <
typename T>
226 template <
typename T>
229 return {left.
x / right, left.
y / right};
235 template <
typename T>
246 template <
typename T>
249 return (left.
x == right.
x) && (left.
y == right.
y);
255 template <
typename T>
258 return !(left == right);
263 using Vector2f = Vector2<float>;
264 using Vector2u = Vector2<unsigned int>;
265 using Vector2i = Vector2<int>;
Wrapper class to store strings.
Definition: String.hpp:79
float toFloat(float defaultValue=0) const
Converts the string to a float.
String trim() const
Returns a string with the whitespace at the start and end of this string removed.
Definition: Vector2.hpp:42
constexpr Vector2(T xValue, T yValue)
Constructor to create from X and Y values.
Definition: Vector2.hpp:54
constexpr Vector2()=default
Default constructor.
constexpr Vector2(const sf::Vector2< T > &vec)
Copy constructor to create from an sf::Vector2.
Definition: Vector2.hpp:77
T y
Y coordinate of the vector.
Definition: Vector2.hpp:139
Vector2(String str)
Constructor to create from a string.
Definition: Vector2.hpp:95
constexpr Vector2(const Vector2< U > &vec)
Constructs the vector from an another Vector2 with a different type.
Definition: Vector2.hpp:67
Vector2(const char *str)
Constructor to create from a string.
Definition: Vector2.hpp:87
T x
X coordinate of the vector.
Definition: Vector2.hpp:138
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36