mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 10:55:57 -04:00
Implement Get/SetOpacity for Window (new in SDL 2.0.5)
This commit is contained in:
parent
39eea2b892
commit
49e3c6a6a9
@ -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()```
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <SDL2/SDL_version.h>
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user