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>
38TGUI_MODULE_EXPORT
namespace tgui
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 TGUI_NODISCARD
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 {
static_cast<T
>(
static_cast<float>(left.
x) * right),
static_cast<T
>(
static_cast<float>(left.
y) * right)};
206 template <
typename T>
209 return {
static_cast<T
>(left *
static_cast<float>(right.
x)),
static_cast<T
>(left *
static_cast<float>(right.
y))};
215 template <
typename T>
218 return left = left * right;
224 template <
typename T>
227 return {
static_cast<T
>(
static_cast<float>(left.
x) / right),
static_cast<T
>(
static_cast<float>(left.
y) / right)};
233 template <
typename T>
236 return left = left / right;
242 template <
typename T>
245 return (left.
x == right.
x) && (left.
y == right.
y);
251 template <
typename T>
254 return !(left == right);
259 using Vector2f = Vector2<float>;
260 using Vector2u = Vector2<unsigned int>;
261 using Vector2i = Vector2<int>;
Wrapper class to store strings.
Definition String.hpp:101
TGUI_NODISCARD String trim() const
Returns a string with the whitespace at the start and end of this string removed.
TGUI_NODISCARD float toFloat(float defaultValue=0) const
Converts the string to a float.
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:39