From a57f81e0b3a69c27122e5f96f5061c3f9bc155a2 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 16 May 2020 20:23:28 +0200 Subject: [PATCH] Added Size/Position Getters/Setters --- SDLU/graphics/RenderWindow.cpp | 34 +++++++++++++++++++++++++ SDLU/graphics/RenderWindow.hpp | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/SDLU/graphics/RenderWindow.cpp b/SDLU/graphics/RenderWindow.cpp index 3616706..0c0c3f8 100644 --- a/SDLU/graphics/RenderWindow.cpp +++ b/SDLU/graphics/RenderWindow.cpp @@ -69,4 +69,38 @@ namespace sdlu while (!PollEvent(event)) continue; return true; } + + Vector2i RenderWindow::GetPosition() + { + int x = 0, y = 0; + SDL_GetWindowPosition(m_pWindow, &x, &y); + return Vector2i(x, y); + } + + void RenderWindow::SetPosition(Vector2i position) + { + SDL_SetWindowPosition(m_pWindow, position.x, position.y); + } + + void RenderWindow::SetPosition(int x, int y) + { + SDL_SetWindowPosition(m_pWindow, x, y); + } + + Vector2u RenderWindow::GetSize() + { + unsigned int x = 0, y = 0; + SDL_GetWindowSize(m_pWindow, x, y); + return Vector2u(x, y); + } + + void RenderWindow::SetSize(Vector2u size) + { + SDL_SetWindowSize(m_pWindow, size.x, size.y); + } + + void RenderWindow::SetSize(unsigned int width, unsigned int height) + { + SDL_SetWindowSize(m_pWindow, width, height); + } } \ No newline at end of file diff --git a/SDLU/graphics/RenderWindow.hpp b/SDLU/graphics/RenderWindow.hpp index 8c02f17..b66d851 100644 --- a/SDLU/graphics/RenderWindow.hpp +++ b/SDLU/graphics/RenderWindow.hpp @@ -80,6 +80,52 @@ namespace sdlu */ bool WaitEvent(SDL_Event* event); + + /** + * @brief Returns the current position of the window + * + * @return A vector with the current position relative to the top left corner of the display + */ + Vector2i GetPosition(); + + /** + * @brief Sets a new window position + * + * @param[in] position A vector with the new position + */ + void SetPosition(Vector2i position); + + /** + * @brief Sets a new window position + * + * @param[in] x The new x position + * @param[in] y The new y position + */ + void SetPosition(int x, int y); + + + /** + * @brief Gets the current window size + * + * @return A vector with the windows size + */ + Vector2u GetSize(); + + /** + * @brief Sets a new window size + * + * @param[in] size A vector with the new size + */ + void SetSize(Vector2u size); + + /** + * @brief Sets a new window size + * + * @param[in] width The new width of the window + * @param[in] height The new height of the window + */ + void SetSize(unsigned int width, unsigned int height); + protected: SDL_Window* m_pWindow; ///< A pointer to the window object SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object