diff options
Diffstat (limited to 'backends/graphics/sdl')
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.cpp | 30 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 11 |
2 files changed, 39 insertions, 2 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index a13ca45477..aa6087beae 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -21,13 +21,16 @@ */ #include "backends/graphics/sdl/sdl-graphics.h" - #include "backends/platform/sdl/sdl-sys.h" #include "backends/events/sdl/sdl-events.h" #include "common/textconsole.h" SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window) - : _eventSource(source), _window(window) { + : _eventSource(source), _window(window) +#if SDL_VERSION_ATLEAST(2, 0, 0) + , _allowWindowSizeReset(false), _lastFlags(0) +#endif + { } SdlGraphicsManager::~SdlGraphicsManager() { @@ -73,3 +76,26 @@ bool SdlGraphicsManager::setState(const State &state) { } } +#if SDL_VERSION_ATLEAST(2, 0, 0) +bool SdlGraphicsManager::createOrUpdateWindow(const int width, const int height, const Uint32 flags) { + if (!_window) { + return false; + } + + // We only update the actual window when flags change (which usually means + // fullscreen mode is entered/exited) or when updates are forced so that we + // do not reset the window size whenever a game makes a call to change the + // size or pixel format of the internal game surface (since a user may have + // resized the game window) + if (!_window->getSDLWindow() || _lastFlags != flags || _allowWindowSizeReset) { + if (!_window->createOrUpdateWindow(width, height, flags)) { + return false; + } + + _lastFlags = flags; + _allowWindowSizeReset = false; + } + + return true; +} +#endif diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 7f8790a9b4..937beef9b4 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -123,6 +123,17 @@ public: SdlWindow *getWindow() const { return _window; } protected: +#if SDL_VERSION_ATLEAST(2, 0, 0) +public: + void unlockWindowSize() { _allowWindowSizeReset = true; } + +protected: + Uint32 _lastFlags; + bool _allowWindowSizeReset; + + bool createOrUpdateWindow(const int width, const int height, const Uint32 flags); +#endif + SdlEventSource *_eventSource; SdlWindow *_window; }; |