From 235b8f4ac37d0c6936ab178d6d1ca16d38c4d191 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 19 May 2020 15:24:47 +0200 Subject: [PATCH] Added mouse position setters --- SDLU/graphics/RenderWindow.cpp | 4 ++-- SDLU/graphics/RenderWindow.hpp | 4 ++-- SDLU/structures/Mouse.cpp | 10 ++++++++++ SDLU/structures/Mouse.hpp | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/SDLU/graphics/RenderWindow.cpp b/SDLU/graphics/RenderWindow.cpp index a41dc67..bed4869 100644 --- a/SDLU/graphics/RenderWindow.cpp +++ b/SDLU/graphics/RenderWindow.cpp @@ -151,12 +151,12 @@ namespace sdlu SDL_SetWindowTitle(m_pWindow, title.c_str()); } - SDL_Window* const RenderWindow::GetWindow() + SDL_Window* const RenderWindow::GetWindow() const { return m_pWindow; } - SDL_Renderer* const RenderWindow::GetRenderer() + SDL_Renderer* const RenderWindow::GetRenderer() const { return m_pRenderer; } diff --git a/SDLU/graphics/RenderWindow.hpp b/SDLU/graphics/RenderWindow.hpp index 301db47..b2189d9 100644 --- a/SDLU/graphics/RenderWindow.hpp +++ b/SDLU/graphics/RenderWindow.hpp @@ -154,14 +154,14 @@ namespace sdlu * * @return A constant pointer to SDL_Window */ - SDL_Window* const GetWindow(); + SDL_Window* const GetWindow() const; /** * @brief Returns a constant pointer to the SDL_Renderer * * @return A constant pointer to SDL_Renderer */ - SDL_Renderer* const GetRenderer(); + SDL_Renderer* const GetRenderer() const; /** * @brief Clears the display diff --git a/SDLU/structures/Mouse.cpp b/SDLU/structures/Mouse.cpp index 87efd1c..1443d94 100644 --- a/SDLU/structures/Mouse.cpp +++ b/SDLU/structures/Mouse.cpp @@ -25,4 +25,14 @@ namespace sdlu { return GetPosition() - relativeTo.GetPosition(); } + + void Mouse::SetPosition(const Vector2i& position) + { + SDL_WarpMouseGlobal(position.x, position.y); + } + + void Mouse::SetPosition(const Vector2i& position, const RenderWindow& relativeTo) + { + SDL_WarpMouseInWindow(relativeTo.GetWindow(), position.x, position.y); + } } \ No newline at end of file diff --git a/SDLU/structures/Mouse.hpp b/SDLU/structures/Mouse.hpp index 6f536f2..adc2290 100644 --- a/SDLU/structures/Mouse.hpp +++ b/SDLU/structures/Mouse.hpp @@ -58,5 +58,20 @@ namespace sdlu * @return The position of the mouse relative to the top left of the passed window object */ static Vector2i GetPosition(const RenderWindow& relativeTo); + + /** + * @brief Sets the absolute position of the mouse + * + * @param[in] position A 2D vector of the new position + */ + static void SetPosition(const Vector2i& position); + + /** + * @brief Sets current relative position of the mouse + * + * @param[in] position A 2D vector of the new position + * @param[in] relativeTo The window the mouse position should be relative to + */ + static void SetPosition(const Vector2i& position, const RenderWindow& relativeTo); }; } \ No newline at end of file