From c679793f946dd5246f7b2366be59d396ce4115d8 Mon Sep 17 00:00:00 2001 From: M4x1m3 Date: Sat, 2 Nov 2019 16:55:15 +0100 Subject: [PATCH] [ion/simulator] Keep original aspect ratio in screen only mode. --- ion/src/simulator/shared/main_sdl.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ion/src/simulator/shared/main_sdl.cpp b/ion/src/simulator/shared/main_sdl.cpp index 0c9ce6315..0add2d50c 100644 --- a/ion/src/simulator/shared/main_sdl.cpp +++ b/ion/src/simulator/shared/main_sdl.cpp @@ -132,10 +132,18 @@ void relayout() { SDL_RenderSetLogicalSize(sRenderer, windowWidth, windowHeight); if (argument_screen_only) { - sScreenRect.x = 0; - sScreenRect.y = 0; - sScreenRect.w = windowWidth; - sScreenRect.h = windowHeight; + // Keep original aspect ration in screen_only mode. + float scale = (float)(Ion::Display::Width) / (float)(Ion::Display::Height); + if ((float)(windowHeight) * scale > float(windowWidth)) { + sScreenRect.w = windowWidth; + sScreenRect.h = (int)((float)(windowWidth) / scale); + } else { + sScreenRect.w = (int)((float)(windowHeight) * scale); + sScreenRect.h = windowHeight; + } + + sScreenRect.x = (windowWidth - sScreenRect.w) / 2; + sScreenRect.y = (windowHeight - sScreenRect.h) / 2; } else { Layout::recompute(windowWidth, windowHeight); SDL_Rect backgroundRect;