diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 09674f8b80..1a58214527 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -840,7 +840,7 @@ public: std::unique_ptr&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, uint32_t flags) override { - height += getTitleHeightDiff(); + height += wp->getTitleBarDiffTarget(); if (flags & WF_AUTO_POSITION) { @@ -854,7 +854,7 @@ public: } } - height -= getTitleHeightDiff(); + height -= wp->getTitleBarDiffTarget(); // Check if there are any window slots left // include kWindowLimitReserved for items such as the main viewport and toolbars to not appear to be counted. diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index a6c0b77e3c..d7bf0720b8 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -984,8 +984,18 @@ namespace OpenRCT2::Ui::Windows if (Config::Get().interface.EnlargedUi) { - w.min_height += getTitleHeightDiff(); - w.max_height += getTitleHeightDiff(); + // Not sure why plugin windows have to be treated differently, + // but they currently show a deviation if we don't. + if (w.classification == WindowClass::Custom) + { + w.min_height += w.getTitleBarDiffTarget(); + w.max_height += w.getTitleBarDiffTarget(); + } + else + { + w.min_height += w.getTitleBarDiffNormal(); + w.max_height += w.getTitleBarDiffNormal(); + } } // Clamp width and height to minimum and maximum diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index b5f856147b..a2645f5218 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -439,6 +439,16 @@ namespace OpenRCT2::Ui::Windows void OnResize() override { + if (width < min_width) + { + Invalidate(); + width = min_width; + } + if (height < min_height) + { + Invalidate(); + height = min_height; + } UpdateViewport(); } @@ -747,6 +757,9 @@ namespace OpenRCT2::Ui::Windows void ChangeTab(size_t tabIndex) { + if (page == static_cast(tabIndex) && !widgets.empty()) + return; + page = static_cast(tabIndex); frame_no = 0; RefreshWidgets(); diff --git a/src/openrct2-ui/scripting/ScWidget.hpp b/src/openrct2-ui/scripting/ScWidget.hpp index 01dd8d9672..6e71873ab8 100644 --- a/src/openrct2-ui/scripting/ScWidget.hpp +++ b/src/openrct2-ui/scripting/ScWidget.hpp @@ -167,7 +167,8 @@ namespace OpenRCT2::Scripting auto widget = GetWidget(); if (widget != nullptr) { - return widget->top - getTitleHeightDiff(); + auto w = GetWindow(); + return widget->top - w->getTitleBarDiffNormal(); } return 0; } @@ -176,7 +177,8 @@ namespace OpenRCT2::Scripting auto widget = GetWidget(); if (widget != nullptr) { - value += getTitleHeightDiff(); + auto w = GetWindow(); + value += w->getTitleBarDiffNormal(); auto delta = value - widget->top; Invalidate(); diff --git a/src/openrct2-ui/scripting/ScWindow.hpp b/src/openrct2-ui/scripting/ScWindow.hpp index c416bd8d2c..f1d28d04b1 100644 --- a/src/openrct2-ui/scripting/ScWindow.hpp +++ b/src/openrct2-ui/scripting/ScWindow.hpp @@ -97,8 +97,14 @@ namespace OpenRCT2::Scripting auto w = GetWindow(); if (w != nullptr) { - w->width = value; - WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, w->max_height }); + if (WindowCanResize(*w)) + { + WindowResizeByDelta(*w, value - w->width, 0); + } + else + { + WindowSetResize(*w, { value, w->min_height }, { value, w->max_height }); + } } } int32_t height_get() const @@ -106,7 +112,7 @@ namespace OpenRCT2::Scripting auto w = GetWindow(); if (w != nullptr) { - return w->height - getTitleHeightDiff(); + return w->height - w->getTitleBarDiffNormal(); } return 0; } @@ -115,8 +121,15 @@ namespace OpenRCT2::Scripting auto w = GetWindow(); if (w != nullptr) { - w->height = value + getTitleHeightDiff(); - WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, w->max_height }); + value += w->getTitleBarDiffNormal(); + if (WindowCanResize(*w)) + { + WindowResizeByDelta(*w, 0, value - w->height); + } + else + { + WindowSetResize(*w, { w->min_width, value }, { w->max_width, value }); + } } } int32_t minWidth_get() const @@ -158,7 +171,7 @@ namespace OpenRCT2::Scripting auto w = GetWindow(); if (w != nullptr) { - return w->min_height; + return w->min_height - w->getTitleBarDiffNormal(); } return 0; } @@ -167,6 +180,7 @@ namespace OpenRCT2::Scripting auto w = GetWindow(); if (w != nullptr) { + value += w->getTitleBarDiffNormal(); WindowSetResize(*w, { w->min_width, value }, { w->max_width, w->max_height }); } } @@ -175,7 +189,7 @@ namespace OpenRCT2::Scripting auto w = GetWindow(); if (w != nullptr) { - return w->max_height; + return w->max_height - w->getTitleBarDiffNormal(); } return 0; } @@ -184,6 +198,7 @@ namespace OpenRCT2::Scripting auto w = GetWindow(); if (w != nullptr) { + value += w->getTitleBarDiffNormal(); WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, value }); } } diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 002e6a7984..384e682d58 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -508,7 +508,7 @@ namespace OpenRCT2::Ui::Windows // We need to compensate for the enlarged title bar for windows that do not // constrain the window height between tabs (e.g. chart tabs) - height -= getTitleHeightDiff(); + height -= getTitleBarDiffNormal(); WindowSetResize(*this, { WW_OTHER_TABS, kHeightOtherTabs }, kMaxWindowSize); } diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index fd4a16a09e..51fd337400 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -570,7 +570,7 @@ namespace OpenRCT2::Ui::Windows auto& config = Config::Get().general; config.FileBrowserWidth = width; - config.FileBrowserHeight = height - getTitleHeightDiff(); + config.FileBrowserHeight = height - getTitleBarDiffNormal(); } void OnUpdate() override diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index b4f493277f..2e8320aaf2 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -1197,7 +1197,7 @@ namespace OpenRCT2::Ui::Windows { // We need to compensate for the enlarged title bar for windows that do not // constrain the window height between tabs (e.g. chart tabs) - height -= getTitleHeightDiff(); + height -= getTitleBarDiffNormal(); } OnResize(); diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 59d5e74a5a..43102a21af 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -71,8 +71,7 @@ namespace OpenRCT2::Ui::Windows constexpr int32_t WINDOW_SCENERY_MIN_HEIGHT = 195 - kTitleHeightNormal; constexpr int32_t SCENERY_BUTTON_WIDTH = 66; constexpr int32_t SCENERY_BUTTON_HEIGHT = 80; - constexpr int32_t InitTabPosX = 3; - constexpr int32_t InitTabPosY = 17; + constexpr int32_t kTabMargin = 3; constexpr int32_t TabWidth = 31; constexpr int32_t TabHeight = 28; constexpr int32_t ReservedTabCount = 2; @@ -637,7 +636,7 @@ namespace OpenRCT2::Ui::Windows void OnPrepareDraw() override { - _actualMinHeight = WINDOW_SCENERY_MIN_HEIGHT + getTitleBarHeight(); + _actualMinHeight = WINDOW_SCENERY_MIN_HEIGHT + getTitleBarTargetHeight(); // Set the window title StringId titleStringId = STR_MISCELLANEOUS; @@ -784,7 +783,7 @@ namespace OpenRCT2::Ui::Windows const auto lastTabWidget = &widgets[WIDX_SCENERY_TAB_1 + lastTabIndex]; windowWidth = std::max(windowWidth, lastTabWidget->right + 3); - auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + 3; + auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin; if (GetSceneryTabInfoForMisc() != nullptr) { auto miscTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 2]; @@ -1376,7 +1375,7 @@ namespace OpenRCT2::Ui::Windows // Add tabs int32_t tabsInThisRow = 0; - ScreenCoordsXY pos = { InitTabPosX, InitTabPosY + getTitleHeightDiff() }; + ScreenCoordsXY pos = { kTabMargin, widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin }; for (const auto& tabInfo : _tabEntries) { auto widget = MakeTab(pos, STR_STRING_DEFINED_TOOLTIP); @@ -1408,7 +1407,7 @@ namespace OpenRCT2::Ui::Windows tabsInThisRow++; if (tabsInThisRow >= maxTabsInThisRow) { - pos.x = InitTabPosX; + pos.x = kTabMargin; pos.y += TabHeight; tabsInThisRow = 0; _actualMinHeight += TabHeight; diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 24d9197889..a1b8917444 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -301,15 +301,14 @@ namespace OpenRCT2::Ui::Windows Close(); } - static int32_t CalculateWindowHeight(std::string_view text) + int32_t CalculateWindowHeight(std::string_view text) { // String length needs to add 12 either side of box +13 for cursor when max length. int32_t numLines{}; GfxWrapString(text, WW - (24 + 13), FontStyle::Medium, nullptr, &numLines); const auto textHeight = numLines * 10; - const auto addedTitleHeight = getTitleBarHeight() - kTitleHeightNormal; - return WH + textHeight + addedTitleHeight; + return WH + textHeight + getTitleBarDiffNormal(); } private: @@ -371,8 +370,7 @@ namespace OpenRCT2::Ui::Windows auto* windowMgr = GetWindowManager(); windowMgr->CloseByClass(WindowClass::Textinput); - auto height = TextInputWindow::CalculateWindowHeight(existing_text); - auto w = windowMgr->Create(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); + auto w = windowMgr->Create(WindowClass::Textinput, WW, WH + 10, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); if (w != nullptr) { w->SetParentWindow(call_w, call_widget); @@ -386,8 +384,7 @@ namespace OpenRCT2::Ui::Windows std::function callback, std::function cancelCallback) { auto* windowMgr = GetWindowManager(); - auto height = TextInputWindow::CalculateWindowHeight(initialValue); - auto w = windowMgr->Create(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); + auto w = windowMgr->Create(WindowClass::Textinput, WW, WH + 10, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); if (w != nullptr) { w->SetTitle(title, description); diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index e81d6ed363..aaadad021a 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -975,19 +975,6 @@ static constexpr float kWindowScrollLocations[][2] = { return w->viewport; } - int16_t getTitleBarHeight() - { - return Config::Get().interface.EnlargedUi ? kTitleHeightLarge : kTitleHeightNormal; - } - - int16_t getTitleHeightDiff() - { - if (Config::Get().interface.EnlargedUi) - return kTitleHeightLarge - kTitleHeightNormal; - else - return 0; - } - // TODO: declared in WindowManager.h; move when refactors continue Ui::IWindowManager* Ui::GetWindowManager() { diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 63f98e3a3d..fae2c72762 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -348,7 +348,4 @@ namespace OpenRCT2 void WindowFollowSprite(WindowBase& w, EntityId spriteIndex); void WindowUnfollowSprite(WindowBase& w); - - int16_t getTitleBarHeight(); - int16_t getTitleHeightDiff(); } // namespace OpenRCT2 diff --git a/src/openrct2/interface/WindowBase.cpp b/src/openrct2/interface/WindowBase.cpp index 99b9c9591d..87e1439775 100644 --- a/src/openrct2/interface/WindowBase.cpp +++ b/src/openrct2/interface/WindowBase.cpp @@ -99,7 +99,7 @@ namespace OpenRCT2 } // Figure out if we need to push the other widgets down to accommodate a resized title/caption - auto preferredHeight = getTitleBarHeight(); + auto preferredHeight = getTitleBarTargetHeight(); auto currentHeight = titleWidget.height(); auto heightDifference = preferredHeight - currentHeight; @@ -133,4 +133,27 @@ namespace OpenRCT2 if (viewport != nullptr) viewport->pos.y += heightDifference; } + + int16_t WindowBase::getTitleBarTargetHeight() const + { + return Config::Get().interface.EnlargedUi ? kTitleHeightLarge : kTitleHeightNormal; + } + + int16_t WindowBase::getTitleBarCurrentHeight() const + { + if (!(flags & WF_NO_TITLE_BAR) && widgets.size() > 2) + return widgets[1].height(); + else + return 0; + } + + int16_t WindowBase::getTitleBarDiffTarget() const + { + return getTitleBarTargetHeight() - getTitleBarCurrentHeight(); + } + + int16_t WindowBase::getTitleBarDiffNormal() const + { + return getTitleBarCurrentHeight() - kTitleHeightNormal; + } } // namespace OpenRCT2 diff --git a/src/openrct2/interface/WindowBase.h b/src/openrct2/interface/WindowBase.h index 05555b9e73..02dd52acd4 100644 --- a/src/openrct2/interface/WindowBase.h +++ b/src/openrct2/interface/WindowBase.h @@ -115,6 +115,11 @@ namespace OpenRCT2 void SetWidgets(const std::span newWidgets); void ResizeFrame(); + int16_t getTitleBarTargetHeight() const; + int16_t getTitleBarCurrentHeight() const; + int16_t getTitleBarDiffTarget() const; + int16_t getTitleBarDiffNormal() const; + WindowBase() = default; WindowBase(WindowBase&) = delete; virtual ~WindowBase() = default;