diff --git a/CMakeLists.txt b/CMakeLists.txt index ba96dd160..b28ab3909 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,7 @@ set(ES_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer.h ${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.h ${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/Vector2.h ${CMAKE_CURRENT_SOURCE_DIR}/src/VolumeControl.h ${CMAKE_CURRENT_SOURCE_DIR}/src/Window.h ${CMAKE_CURRENT_SOURCE_DIR}/src/XMLReader.h @@ -171,7 +172,6 @@ set(ES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiGameList.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiImage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiInputConfig.cpp -# ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiList.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GuiTheme.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/pugiXML/pugixml.cpp diff --git a/src/Vector2.h b/src/Vector2.h new file mode 100644 index 000000000..925115eef --- /dev/null +++ b/src/Vector2.h @@ -0,0 +1,97 @@ +#ifndef _VECTOR2_H_ +#define _VECTOR2_H_ + +//Taken from the SFML Vector2 class: +//https://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.hpp +//https://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.inl + +template +class Vector2 +{ +public: + Vector2() : x(0), y(0) + { + } + + Vector2(T X, T Y) : x(X), y(Y) + { + } + + //convert between vector types + template + explicit Vector2(const Vector2& vector) : x(static_cast(vector.x)), y(static_cast(vector.y)) + { + } + + T x; + T y; +}; + + +template +Vector2 operator -(const Vector2& right) +{ + return Vector2(-right.x, -right.y); +} + +template +Vector2& operator +=(Vector2& left, const Vector2& right) +{ + left.x += right.x; + left.y += right.y; + + return left; +} + +template +Vector2& operator -=(Vector2& left, const Vector2& right) +{ + left.x -= right.x; + left.y -= right.y; + + return left; +} + +template +Vector2 operator +(const Vector2& left, const Vector2& right) +{ + return Vector2(left.x + right.x, left.y + right.y); +} + +template +Vector2 operator -(const Vector2& left, const Vector2& right) +{ + return Vector2(left.x - right.x, left.y - right.y); +} + +template +Vector2 operator *(const Vector2& left, T right) +{ + return Vector2(left.x * right, left.y * right); +} + +template +Vector2& operator *=(Vector2& left, T right) +{ + left.x *= right; + left.y *= right; + + return left; +} + +template +bool operator ==(const Vector2& left, const Vector2& right) +{ + return (left.x == right.x && left.y == right.y); +} + +template +bool operator !=(const Vector2& left, const Vector2& right) +{ + return (left.x != right.x) || (left.y != right.y); +} + +typedef Vector2 Vector2i; +typedef Vector2 Vector2f; + +#endif