diff options
author | Vincent Bénony | 2016-01-06 16:20:23 +0100 |
---|---|---|
committer | Vincent Bénony | 2016-01-06 16:20:23 +0100 |
commit | efdb5679ce6304dbc854afbbc511e633d7513338 (patch) | |
tree | e680a240e5f6018fc3a4cce53b50060caa22a929 /backends/graphics/surfacesdl | |
parent | 4687ff6d6d2863cc95c8137543ecf9c39bc01723 (diff) | |
parent | b72c02bad44749a1355acefdb198e36b2e772575 (diff) | |
download | scummvm-rg350-efdb5679ce6304dbc854afbbc511e633d7513338.tar.gz scummvm-rg350-efdb5679ce6304dbc854afbbc511e633d7513338.tar.bz2 scummvm-rg350-efdb5679ce6304dbc854afbbc511e633d7513338.zip |
IOS: Merge branch 'master' into ios-fix
Diffstat (limited to 'backends/graphics/surfacesdl')
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 59 | ||||
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.h | 13 |
2 files changed, 55 insertions, 17 deletions
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index b2da47110b..2b9d3aa100 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -2367,6 +2367,14 @@ void SurfaceSdlGraphicsManager::notifyVideoExpose() { _forceFull = true; } +#ifdef USE_SDL_RESIZABLE_WINDOW +void SurfaceSdlGraphicsManager::notifyResize(const uint width, const uint height) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + setWindowResolution(width, height); +#endif +} +#endif + void SurfaceSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) { #if SDL_VERSION_ATLEAST(2, 0, 0) // In SDL2 the actual output resolution might be different from what we @@ -2402,21 +2410,10 @@ void SurfaceSdlGraphicsManager::deinitializeRenderer() { _window->destroyWindow(); } -SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) { - deinitializeRenderer(); - - const bool isFullscreen = (flags & SDL_FULLSCREEN) != 0; - if (!_window->createWindow(width, height, isFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) { - return nullptr; - } +void SurfaceSdlGraphicsManager::setWindowResolution(int width, int height) { + _windowWidth = width; + _windowHeight = height; - _renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0); - if (!_renderer) { - deinitializeRenderer(); - return nullptr; - } - - SDL_GetWindowSize(_window->getSDLWindow(), &_windowWidth, &_windowHeight); // We expect full screen resolution as inputs coming from the event system. _eventSource->resetKeyboadEmulation(_windowWidth - 1, _windowHeight - 1); @@ -2425,7 +2422,7 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, // this case, we add black bars if necessary to assure the aspect ratio // is preserved. const frac_t outputAspect = intToFrac(_windowWidth) / _windowHeight; - const frac_t desiredAspect = intToFrac(width) / height; + const frac_t desiredAspect = intToFrac(_videoMode.hardwareWidth) / _videoMode.hardwareHeight; _viewport.w = _windowWidth; _viewport.h = _windowHeight; @@ -2433,15 +2430,43 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, // Adjust one dimension for mantaining the aspect ratio. if (abs(outputAspect - desiredAspect) >= (int)(FRAC_ONE / 1000)) { if (outputAspect < desiredAspect) { - _viewport.h = height * _windowWidth / width; + _viewport.h = _videoMode.hardwareHeight * _windowWidth / _videoMode.hardwareWidth; } else if (outputAspect > desiredAspect) { - _viewport.w = width * _windowHeight / height; + _viewport.w = _videoMode.hardwareWidth * _windowHeight / _videoMode.hardwareHeight; } } _viewport.x = (_windowWidth - _viewport.w) / 2; _viewport.y = (_windowHeight - _viewport.h) / 2; + // Force a full redraw because we changed the viewport. + _forceFull = true; +} + +SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) { + deinitializeRenderer(); + + uint32 createWindowFlags = 0; +#ifdef USE_SDL_RESIZABLE_WINDOW + createWindowFlags |= SDL_WINDOW_RESIZABLE; +#endif + if ((flags & SDL_FULLSCREEN) != 0) { + createWindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + } + + if (!_window->createWindow(width, height, createWindowFlags)) { + return nullptr; + } + + _renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0); + if (!_renderer) { + deinitializeRenderer(); + return nullptr; + } + + SDL_GetWindowSize(_window->getSDLWindow(), &_windowWidth, &_windowHeight); + setWindowResolution(_windowWidth, _windowHeight); + _screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height); if (!_screenTexture) { deinitializeRenderer(); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index ac9844c849..c4f7346525 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -39,6 +39,15 @@ #define USE_SDL_DEBUG_FOCUSRECT #endif +// We have (some) support for resizable windows when SDL2 is used. However +// the overlay still uses the resolution setup with SDL_SetVideoMode. This +// makes the GUI look subpar when the user resizes the window. In addition +// we do not adapt the scale factor right now. Thus, we disable this code +// path for now. +#if SDL_VERSION_ATLEAST(2, 0, 0) && 0 +#define USE_SDL_RESIZABLE_WINDOW +#endif + #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) // Uncomment this to enable the 'on screen display' code. #define USE_OSD 1 @@ -143,6 +152,9 @@ public: // SdlGraphicsManager interface virtual void notifyVideoExpose(); +#ifdef USE_SDL_RESIZABLE_WINDOW + virtual void notifyResize(const uint width, const uint height); +#endif virtual void transformMouseCoordinates(Common::Point &point); virtual void notifyMousePos(Common::Point mouse); @@ -174,6 +186,7 @@ protected: SDL_Rect _viewport; int _windowWidth, _windowHeight; void deinitializeRenderer(); + void setWindowResolution(int width, int height); SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags); void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects); |