From 87bb2f10dd66be9faf85f829d8c6367820caf99f Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:55:33 +0100 Subject: [PATCH] Introduce WindowBase::canBeResized --- src/openrct2-ui/input/MouseInput.cpp | 5 +---- src/openrct2-ui/interface/Widget.cpp | 10 ++-------- src/openrct2-ui/scripting/CustomWindow.cpp | 3 +-- src/openrct2/interface/Window_internal.h | 5 +++++ 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index fea008c3b6..638b839c41 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -1177,10 +1177,7 @@ namespace OpenRCT2 case WindowWidgetType::Frame: case WindowWidgetType::Resize: - if (!(window->flags & WF_RESIZABLE)) - break; - - if (window->min_width == window->max_width && window->min_height == window->max_height) + if (!window->canBeResized()) break; if (screenCoords.x < window->windowPos.x + window->width - 0x13) diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 3b80ae036c..217800f3f3 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -145,10 +145,7 @@ namespace OpenRCT2::Ui // Draw the frame GfxFillRectInset(dpi, { leftTop, { r, b } }, colour, press); - // Check if the window can be resized - if (!(w.flags & WF_RESIZABLE)) - return; - if (w.min_width == w.max_width && w.min_height == w.max_height) + if (!w.canBeResized()) return; // Draw the resize sprite at the bottom right corner @@ -175,10 +172,7 @@ namespace OpenRCT2::Ui // Draw the panel GfxFillRectInset(dpi, { leftTop, { r, b } }, colour, 0); - // Check if the window can be resized - if (!(w.flags & WF_RESIZABLE)) - return; - if (w.min_width == w.max_width && w.min_height == w.max_height) + if (!w.canBeResized()) return; // Draw the resize sprite at the bottom right corner diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 4993eb7df9..574c9e9e0d 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -492,9 +492,8 @@ namespace OpenRCT2::Ui::Windows // Having the content panel visible for transparent windows makes the borders darker than they should be // For now just hide it if there are no tabs and the window is not resizable - auto canResize = (flags & WF_RESIZABLE) != 0 && (min_width != max_width || min_height != max_height); auto numTabs = _info.Desc.Tabs.size(); - if (canResize || numTabs != 0) + if (canBeResized() || numTabs != 0) { widgets[WIDX_CONTENT_PANEL].flags &= ~WIDGET_FLAGS::IS_HIDDEN; } diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index a5aade3cc9..587dbc9c3e 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -119,6 +119,11 @@ namespace OpenRCT2 WindowBase& operator=(const WindowBase&) = delete; + constexpr bool canBeResized() const + { + return (flags & WF_RESIZABLE) && (min_width != max_width || min_height != max_height); + } + // Events virtual void OnOpen() {