diff --git a/CHANGES.md b/CHANGES.md index 729e43c..8049f9f 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.14.0 - unreleased +### Added +* ```Window::GetOpacity()``` and ```Window()::SetOpacity()``` wrappers for functions appeared in SDL 2.0.5 + ## 0.13.0 - 2016-11-08 ### Fixed * Fixed SDL 2.0.4 specific ```AudioDevice``` methods: ```AudioDevice::QueueAudio()```, ```AudioDevice::GetQueuedAudioSize()``` diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index 234f91a..ae2b4bd 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -242,4 +242,20 @@ Window& Window::SetBordered(bool bordered) { return *this; } +#if SDL_VERSION_ATLEAST(2, 0, 5) +Window& Window::SetOpacity(float opacity) { + if (SDL_SetWindowOpacity(window_, opacity)) + throw SDL2pp::Exception("SDL_SetWindowOpacity"); + return *this; +} + +float Window::GetOpacity() const { + float opacity; + if (SDL_GetWindowOpacity(window_, &opacity) == -1) + throw SDL2pp::Exception("SDL_GetWindowOpacity"); + + return opacity; +} +#endif + } diff --git a/SDL2pp/Window.hh b/SDL2pp/Window.hh index e2bf4e1..5c76256 100644 --- a/SDL2pp/Window.hh +++ b/SDL2pp/Window.hh @@ -24,6 +24,7 @@ #include +#include #include #include @@ -534,6 +535,30 @@ public: /// //////////////////////////////////////////////////////////// Window& SetBordered(bool bordered = true); + +#if SDL_VERSION_ATLEAST(2, 0, 5) + //////////////////////////////////////////////////////////// + /// \brief Set the opacity for a window + /// + /// \param[in] opacity The opacity value (0.0f - transparent, 1.0f - opaque) + /// + /// \returns Reference to self + /// + /// \see http://wiki.libsdl.org/SDL_SetWindowOpacity + /// + //////////////////////////////////////////////////////////// + Window& SetOpacity(float opacity = 1.0f); + + //////////////////////////////////////////////////////////// + /// \brief Get the opacity of a window + /// + /// \returns Opacity value (0.0f - transparent, 1.0f - opaque) + /// + /// \see http://wiki.libsdl.org/SDL_GetWindowOpacity + /// + //////////////////////////////////////////////////////////// + float GetOpacity() const; +#endif }; } diff --git a/tests/live_window.cc b/tests/live_window.cc index cdd8216..03985db 100644 --- a/tests/live_window.cc +++ b/tests/live_window.cc @@ -191,4 +191,27 @@ BEGIN_TEST(int, char*[]) EventSleep(1000); } +#if SDL_VERSION_ATLEAST(2, 0, 5) + { + // Opacity + bool has_opacity = true; + try { + window.SetOpacity(0.5f); + } catch (...) { + has_opacity = false; + std::cerr << "Setting window opacity is not supported on this platform" << std::endl; + } + + if (has_opacity) { + EXPECT_TRUE(window.GetOpacity() > 0.49f); + EXPECT_TRUE(window.GetOpacity() < 0.51f); + EventSleep(1000); + + window.SetOpacity(); + EXPECT_TRUE(window.GetOpacity() > 0.99f); + EventSleep(1000); + } + } +#endif + END_TEST()