26#ifndef TGUI_VECTOR2_HPP
27#define TGUI_VECTOR2_HPP
29#include <TGUI/Config.hpp>
30#include <TGUI/String.hpp>
32#if TGUI_HAS_BACKEND_SFML
33 #include <SFML/System/Vector2.hpp>
57 TGUI_CONSTEXPR
Vector2(T xValue, T yValue) :
71 x{static_cast<T>(vec.
x)},
72 y{static_cast<T>(vec.
y)}
76#if TGUI_HAS_BACKEND_SFML
80 TGUI_CONSTEXPR
Vector2(
const sf::Vector2<T>& vec) :
102 TGUI_PRINT_WARNING(
"Failed to parse Vector2. String was empty.");
107 if (((str.front() ==
'(') && (str.back() ==
')')) || ((str.front() ==
'{') && (str.back() ==
'}')))
108 str = str.substr(1, str.length() - 2);
117 auto commaPos = str.find(
',');
118 if (commaPos == String::npos)
120 TGUI_PRINT_WARNING(
"Failed to parse Vector2 '" + str +
"'. Expected numbers separated with a comma.");
124 x =
static_cast<T
>(str.substr(0, commaPos).
trim().
toFloat());
125 y =
static_cast<T
>(str.substr(commaPos + 1).
trim().
toFloat());
128#if TGUI_HAS_BACKEND_SFML
132 operator sf::Vector2<T>()
const
134 return sf::Vector2<T>{
x,
y};
151 template <
typename T>
154 return {-right.
x, -right.
y};
160 template <
typename T>
171 template <
typename T>
182 template <
typename T>
185 return {left.
x + right.
x, left.
y + right.
y};
191 template <
typename T>
194 return {left.
x - right.
x, left.
y - right.
y};
200 template <
typename T>
203 return {left.
x * right, left.
y * right};
209 template <
typename T>
212 return {left * right.
x, left * right.
y};
218 template <
typename T>
229 template <
typename T>
232 return {left.
x / right, left.
y / right};
238 template <
typename T>
249 template <
typename T>
252 return (left.
x == right.
x) && (left.
y == right.
y);
258 template <
typename T>
261 return !(left == right);
266 using Vector2f = Vector2<float>;
267 using Vector2u = Vector2<unsigned int>;
268 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
T y
Y coordinate of the vector.
Definition Vector2.hpp:142
TGUI_CONSTEXPR Vector2(T xValue, T yValue)
Constructor to create from X and Y values.
Definition Vector2.hpp:57
Vector2(String str)
Constructor to create from a string.
Definition Vector2.hpp:98
TGUI_CONSTEXPR Vector2(const sf::Vector2< T > &vec)
Copy constructor to create from an sf::Vector2.
Definition Vector2.hpp:80
TGUI_CONSTEXPR Vector2()
Default constructor.
Definition Vector2.hpp:48
Vector2(const char *str)
Constructor to create from a string.
Definition Vector2.hpp:90
T x
X coordinate of the vector.
Definition Vector2.hpp:141
TGUI_CONSTEXPR Vector2(const Vector2< U > &vec)
Constructs the vector from an another Vector2 with a different type.
Definition Vector2.hpp:70
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36