From f3bc4abd1703d0e79855dfc51ee61a10c6317985 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Thu, 20 Jul 2017 14:12:33 +0300 Subject: [PATCH] Implement SDL_SetWindowResizable() Fixes #83 --- CHANGES.md | 4 ++++ SDL2pp/Window.cc | 5 +++++ SDL2pp/Window.hh | 12 ++++++++++++ tests/live_window.cc | 23 +++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c40ce38..20a695b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## 0.16.0 - unreleased +### Added +* New SDL 2.0.5 ```Window``` method: ```Window::SetResizable()``` + ## 0.15.0 - 2017-07-10 ### Added * ```Color``` class wrapping around ```SDL_Color``` diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index ff98ce3..de8d803 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -259,6 +259,11 @@ float Window::GetOpacity() const { return opacity; } + +Window& Window::SetResizable(bool resizable) { + SDL_SetWindowResizable(window_, resizable ? SDL_TRUE : SDL_FALSE); + return *this; +} #endif } diff --git a/SDL2pp/Window.hh b/SDL2pp/Window.hh index ea7ff2d..768b969 100644 --- a/SDL2pp/Window.hh +++ b/SDL2pp/Window.hh @@ -558,6 +558,18 @@ public: /// //////////////////////////////////////////////////////////// float GetOpacity() const; + + //////////////////////////////////////////////////////////// + /// \brief Set user-resizable state of a window + /// + /// \param[in] resizable True to allow resizing, false to disallow + /// + /// \returns Reference to self + /// + /// \see http://wiki.libsdl.org/SDL_SetWindowResizable + /// + //////////////////////////////////////////////////////////// + Window& SetResizable(bool resizable = true); #endif }; diff --git a/tests/live_window.cc b/tests/live_window.cc index 26df603..9009837 100644 --- a/tests/live_window.cc +++ b/tests/live_window.cc @@ -212,6 +212,29 @@ BEGIN_TEST(int, char*[]) EventSleep(1000); } } + + { + // Resizable + Uint32 flags = window.GetFlags(); + + if (flags & SDL_WINDOW_RESIZABLE) { + window.SetResizable(false); + EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_RESIZABLE)); + EventSleep(1000); + + window.SetResizable(true); + EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_RESIZABLE); + EventSleep(1000); + } else { + window.SetResizable(true); + EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_RESIZABLE); + EventSleep(1000); + + window.SetResizable(false); + EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_RESIZABLE)); + EventSleep(1000); + } + } #endif END_TEST()