aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/graphics/surfacesdl/surfacesdl-graphics.cpp')
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.cpp59
1 files changed, 42 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();