diff --git a/SDLU/graphics/RenderWindow.cpp b/SDLU/graphics/RenderWindow.cpp index 9cd383a..a3ba8e3 100644 --- a/SDLU/graphics/RenderWindow.cpp +++ b/SDLU/graphics/RenderWindow.cpp @@ -171,4 +171,31 @@ namespace sdlu SDL_RenderPresent(m_pRenderer); } + + void RenderWindow::SetVisible(bool visible) + { + RETURN_IF_NULLPTR(m_pWindow); + if (visible) + SDL_ShowWindow(m_pWindow); + else + SDL_HideWindow(m_pWindow); + } + + void RenderWindow::SetVsync(bool vsync) + { + // SDL actually doesn't allow you to change the VSync + // flag of a Renderer after it's been created. This + // Changes it globally for all other windows + SDL_GL_SetSwapInterval(vsync); + } + + void RenderWindow::SetMouseCursorVisible(bool visible) + { + SDL_ShowCursor(visible); + } + + void RenderWindow::SetMouseCursorGrabbed(bool grabbed) + { + SDL_SetWindowGrab(m_pWindow, grabbed ? SDL_TRUE : SDL_FALSE); + } } \ No newline at end of file diff --git a/SDLU/graphics/RenderWindow.hpp b/SDLU/graphics/RenderWindow.hpp index 8d29897..ffe79ee 100644 --- a/SDLU/graphics/RenderWindow.hpp +++ b/SDLU/graphics/RenderWindow.hpp @@ -170,6 +170,34 @@ namespace sdlu */ void Display(); + /** + * @brief Set the windows visibility + * + * @param[in] visible The new visibility setting + */ + void SetVisible(bool visible); + + /** + * @brief (De)activates VSync !globally! + * + * @param[in] vsync Wether to enable or disable vsync + */ + void SetVsync(bool vsync); + + /** + * @brief Hides/Shows the mouse cursor inside the windos + * + * @param[in] visible The new visibility of the cursor + */ + void SetMouseCursorVisible(bool visible); + + /** + * @brief Traps the mouse cursor inside the window + * + * @param[in] grabbed Wether to (un)trap the cursor + */ + void SetMouseCursorGrabbed(bool grabbed); + protected: SDL_Window* m_pWindow; ///< A pointer to the window object SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object diff --git a/SDLU_Example/main.cpp b/SDLU_Example/main.cpp index 151c307..9551707 100644 --- a/SDLU_Example/main.cpp +++ b/SDLU_Example/main.cpp @@ -6,6 +6,7 @@ int main(int argc, char** argv) MyWindow window(800, 800, "Test"); SDL_SetWindowTitle(window.GetWindow(), "New Title"); + window.SetMouseCursorGrabbed(true); SDL_Event event; while (window.IsOpen())