From b017ea41597117b45c2fa2a43bf869a56b127bc6 Mon Sep 17 00:00:00 2001 From: Daniel Karandikar Date: Sat, 3 Jul 2021 13:38:39 +0100 Subject: [PATCH] Fix [#12262]: Windows can appear off screen in some cases (#14881) Fix: [#12262] Windows can appear off screen with small screens or high scaling. --- contributors.md | 1 + distribution/changelog.txt | 1 + src/openrct2-ui/interface/Window.cpp | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/contributors.md b/contributors.md index c6a637b285..94aa5b8ea4 100644 --- a/contributors.md +++ b/contributors.md @@ -170,6 +170,7 @@ The following people are not part of the development team, but have been contrib * Ryan D. (rctdude2) * (zrowny) * Emre Aydin (aemreaydin) +* Daniel Karandikar (DKarandikar) ## Toolchain * (Balletie) - macOS diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 7625a95a1c..92b963d00e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -13,6 +13,7 @@ - Change: [#14751] “No construction above tree height” limitation now allows placing high trees. - Change: [#14841] Redesign the About window, including new button to copy the current version info. - Fix: [#11829] Visual glitches and crashes when using RCT1 assets from mismatched or corrupt CSG1.DAT and CSG1i.DAT files. +- Fix: [#12262] Windows can appear off screen with small screens or high scaling. - Fix: [#13581] Opening the Options menu causes a noticeable drop in FPS. - Fix: [#13894] Block brakes do not animate. - Fix: [#13986] OpenGL: Track preview window, flip/rotate button do not update the thumbnail. diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index 70cca8f993..bf11d1c644 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -86,14 +86,21 @@ static bool WindowFitsOnScreen(const ScreenCoordsXY& loc, int32_t width, int32_t return WindowFitsBetweenOthers(loc, width, height); } -static ScreenCoordsXY ClampWindowToScreen(const ScreenCoordsXY& pos, const int32_t screenWidth, const int32_t width) +static ScreenCoordsXY ClampWindowToScreen( + const ScreenCoordsXY& pos, const int32_t screenWidth, const int32_t screenHeight, const int32_t width, const int32_t height) { auto screenPos = pos; - if (screenPos.x < 0) + if (width > screenWidth || screenPos.x < 0) screenPos.x = 0; - if (screenPos.x + width > screenWidth) + else if (screenPos.x + width > screenWidth) screenPos.x = screenWidth - width; + auto toolbarAllowance = (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) ? 0 : (TOP_TOOLBAR_HEIGHT + 1); + if (height - toolbarAllowance > screenHeight || screenPos.y < toolbarAllowance) + screenPos.y = toolbarAllowance; + else if (screenPos.y + height - toolbarAllowance > screenHeight) + screenPos.y = screenHeight + toolbarAllowance - height; + return screenPos; } @@ -115,7 +122,7 @@ static ScreenCoordsXY GetAutoPositionForNewWindow(int32_t width, int32_t height) { if (WindowFitsWithinSpace(cornerPos, width, height)) { - return ClampWindowToScreen(cornerPos, screenWidth, width); + return ClampWindowToScreen(cornerPos, screenWidth, screenHeight, width, height); } } @@ -139,7 +146,7 @@ static ScreenCoordsXY GetAutoPositionForNewWindow(int32_t width, int32_t height) auto screenPos = w->windowPos + offset; if (WindowFitsWithinSpace(screenPos, width, height)) { - return ClampWindowToScreen(screenPos, screenWidth, width); + return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); } } } @@ -164,7 +171,7 @@ static ScreenCoordsXY GetAutoPositionForNewWindow(int32_t width, int32_t height) auto screenPos = w->windowPos + offset; if (WindowFitsOnScreen(screenPos, width, height)) { - return ClampWindowToScreen(screenPos, screenWidth, width); + return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); } } } @@ -180,7 +187,7 @@ static ScreenCoordsXY GetAutoPositionForNewWindow(int32_t width, int32_t height) } } - return ClampWindowToScreen(screenPos, screenWidth, width); + return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); } static ScreenCoordsXY GetCentrePositionForNewWindow(int32_t width, int32_t height)