mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-21 14:53:02 +01:00
Move title height helper functions to WindowBase and fix FlexUI plugins
This commit is contained in:
@@ -840,7 +840,7 @@ public:
|
|||||||
std::unique_ptr<WindowBase>&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height,
|
std::unique_ptr<WindowBase>&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height,
|
||||||
uint32_t flags) override
|
uint32_t flags) override
|
||||||
{
|
{
|
||||||
height += getTitleHeightDiff();
|
height += wp->getTitleBarDiffTarget();
|
||||||
|
|
||||||
if (flags & WF_AUTO_POSITION)
|
if (flags & WF_AUTO_POSITION)
|
||||||
{
|
{
|
||||||
@@ -854,7 +854,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
height -= getTitleHeightDiff();
|
height -= wp->getTitleBarDiffTarget();
|
||||||
|
|
||||||
// Check if there are any window slots left
|
// 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.
|
// include kWindowLimitReserved for items such as the main viewport and toolbars to not appear to be counted.
|
||||||
|
|||||||
@@ -984,8 +984,18 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
if (Config::Get().interface.EnlargedUi)
|
if (Config::Get().interface.EnlargedUi)
|
||||||
{
|
{
|
||||||
w.min_height += getTitleHeightDiff();
|
// Not sure why plugin windows have to be treated differently,
|
||||||
w.max_height += getTitleHeightDiff();
|
// 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
|
// Clamp width and height to minimum and maximum
|
||||||
|
|||||||
@@ -439,6 +439,16 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
void OnResize() override
|
void OnResize() override
|
||||||
{
|
{
|
||||||
|
if (width < min_width)
|
||||||
|
{
|
||||||
|
Invalidate();
|
||||||
|
width = min_width;
|
||||||
|
}
|
||||||
|
if (height < min_height)
|
||||||
|
{
|
||||||
|
Invalidate();
|
||||||
|
height = min_height;
|
||||||
|
}
|
||||||
UpdateViewport();
|
UpdateViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,6 +757,9 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
void ChangeTab(size_t tabIndex)
|
void ChangeTab(size_t tabIndex)
|
||||||
{
|
{
|
||||||
|
if (page == static_cast<int16_t>(tabIndex) && !widgets.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
page = static_cast<int16_t>(tabIndex);
|
page = static_cast<int16_t>(tabIndex);
|
||||||
frame_no = 0;
|
frame_no = 0;
|
||||||
RefreshWidgets();
|
RefreshWidgets();
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ namespace OpenRCT2::Scripting
|
|||||||
auto widget = GetWidget();
|
auto widget = GetWidget();
|
||||||
if (widget != nullptr)
|
if (widget != nullptr)
|
||||||
{
|
{
|
||||||
return widget->top - getTitleHeightDiff();
|
auto w = GetWindow();
|
||||||
|
return widget->top - w->getTitleBarDiffNormal();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -176,7 +177,8 @@ namespace OpenRCT2::Scripting
|
|||||||
auto widget = GetWidget();
|
auto widget = GetWidget();
|
||||||
if (widget != nullptr)
|
if (widget != nullptr)
|
||||||
{
|
{
|
||||||
value += getTitleHeightDiff();
|
auto w = GetWindow();
|
||||||
|
value += w->getTitleBarDiffNormal();
|
||||||
auto delta = value - widget->top;
|
auto delta = value - widget->top;
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|||||||
@@ -97,8 +97,14 @@ namespace OpenRCT2::Scripting
|
|||||||
auto w = GetWindow();
|
auto w = GetWindow();
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
w->width = value;
|
if (WindowCanResize(*w))
|
||||||
WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, w->max_height });
|
{
|
||||||
|
WindowResizeByDelta(*w, value - w->width, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WindowSetResize(*w, { value, w->min_height }, { value, w->max_height });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int32_t height_get() const
|
int32_t height_get() const
|
||||||
@@ -106,7 +112,7 @@ namespace OpenRCT2::Scripting
|
|||||||
auto w = GetWindow();
|
auto w = GetWindow();
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
return w->height - getTitleHeightDiff();
|
return w->height - w->getTitleBarDiffNormal();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -115,8 +121,15 @@ namespace OpenRCT2::Scripting
|
|||||||
auto w = GetWindow();
|
auto w = GetWindow();
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
w->height = value + getTitleHeightDiff();
|
value += w->getTitleBarDiffNormal();
|
||||||
WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, w->max_height });
|
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
|
int32_t minWidth_get() const
|
||||||
@@ -158,7 +171,7 @@ namespace OpenRCT2::Scripting
|
|||||||
auto w = GetWindow();
|
auto w = GetWindow();
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
return w->min_height;
|
return w->min_height - w->getTitleBarDiffNormal();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -167,6 +180,7 @@ namespace OpenRCT2::Scripting
|
|||||||
auto w = GetWindow();
|
auto w = GetWindow();
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
|
value += w->getTitleBarDiffNormal();
|
||||||
WindowSetResize(*w, { w->min_width, value }, { w->max_width, w->max_height });
|
WindowSetResize(*w, { w->min_width, value }, { w->max_width, w->max_height });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +189,7 @@ namespace OpenRCT2::Scripting
|
|||||||
auto w = GetWindow();
|
auto w = GetWindow();
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
return w->max_height;
|
return w->max_height - w->getTitleBarDiffNormal();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -184,6 +198,7 @@ namespace OpenRCT2::Scripting
|
|||||||
auto w = GetWindow();
|
auto w = GetWindow();
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
|
value += w->getTitleBarDiffNormal();
|
||||||
WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, value });
|
WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
// We need to compensate for the enlarged title bar for windows that do not
|
// We need to compensate for the enlarged title bar for windows that do not
|
||||||
// constrain the window height between tabs (e.g. chart tabs)
|
// constrain the window height between tabs (e.g. chart tabs)
|
||||||
height -= getTitleHeightDiff();
|
height -= getTitleBarDiffNormal();
|
||||||
|
|
||||||
WindowSetResize(*this, { WW_OTHER_TABS, kHeightOtherTabs }, kMaxWindowSize);
|
WindowSetResize(*this, { WW_OTHER_TABS, kHeightOtherTabs }, kMaxWindowSize);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -570,7 +570,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
auto& config = Config::Get().general;
|
auto& config = Config::Get().general;
|
||||||
config.FileBrowserWidth = width;
|
config.FileBrowserWidth = width;
|
||||||
config.FileBrowserHeight = height - getTitleHeightDiff();
|
config.FileBrowserHeight = height - getTitleBarDiffNormal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUpdate() override
|
void OnUpdate() override
|
||||||
|
|||||||
@@ -1197,7 +1197,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
{
|
{
|
||||||
// We need to compensate for the enlarged title bar for windows that do not
|
// We need to compensate for the enlarged title bar for windows that do not
|
||||||
// constrain the window height between tabs (e.g. chart tabs)
|
// constrain the window height between tabs (e.g. chart tabs)
|
||||||
height -= getTitleHeightDiff();
|
height -= getTitleBarDiffNormal();
|
||||||
}
|
}
|
||||||
|
|
||||||
OnResize();
|
OnResize();
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
constexpr int32_t WINDOW_SCENERY_MIN_HEIGHT = 195 - kTitleHeightNormal;
|
constexpr int32_t WINDOW_SCENERY_MIN_HEIGHT = 195 - kTitleHeightNormal;
|
||||||
constexpr int32_t SCENERY_BUTTON_WIDTH = 66;
|
constexpr int32_t SCENERY_BUTTON_WIDTH = 66;
|
||||||
constexpr int32_t SCENERY_BUTTON_HEIGHT = 80;
|
constexpr int32_t SCENERY_BUTTON_HEIGHT = 80;
|
||||||
constexpr int32_t InitTabPosX = 3;
|
constexpr int32_t kTabMargin = 3;
|
||||||
constexpr int32_t InitTabPosY = 17;
|
|
||||||
constexpr int32_t TabWidth = 31;
|
constexpr int32_t TabWidth = 31;
|
||||||
constexpr int32_t TabHeight = 28;
|
constexpr int32_t TabHeight = 28;
|
||||||
constexpr int32_t ReservedTabCount = 2;
|
constexpr int32_t ReservedTabCount = 2;
|
||||||
@@ -637,7 +636,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
void OnPrepareDraw() override
|
void OnPrepareDraw() override
|
||||||
{
|
{
|
||||||
_actualMinHeight = WINDOW_SCENERY_MIN_HEIGHT + getTitleBarHeight();
|
_actualMinHeight = WINDOW_SCENERY_MIN_HEIGHT + getTitleBarTargetHeight();
|
||||||
|
|
||||||
// Set the window title
|
// Set the window title
|
||||||
StringId titleStringId = STR_MISCELLANEOUS;
|
StringId titleStringId = STR_MISCELLANEOUS;
|
||||||
@@ -784,7 +783,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
const auto lastTabWidget = &widgets[WIDX_SCENERY_TAB_1 + lastTabIndex];
|
const auto lastTabWidget = &widgets[WIDX_SCENERY_TAB_1 + lastTabIndex];
|
||||||
windowWidth = std::max<int32_t>(windowWidth, lastTabWidget->right + 3);
|
windowWidth = std::max<int32_t>(windowWidth, lastTabWidget->right + 3);
|
||||||
|
|
||||||
auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + 3;
|
auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin;
|
||||||
if (GetSceneryTabInfoForMisc() != nullptr)
|
if (GetSceneryTabInfoForMisc() != nullptr)
|
||||||
{
|
{
|
||||||
auto miscTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 2];
|
auto miscTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 2];
|
||||||
@@ -1376,7 +1375,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
|
|
||||||
// Add tabs
|
// Add tabs
|
||||||
int32_t tabsInThisRow = 0;
|
int32_t tabsInThisRow = 0;
|
||||||
ScreenCoordsXY pos = { InitTabPosX, InitTabPosY + getTitleHeightDiff() };
|
ScreenCoordsXY pos = { kTabMargin, widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin };
|
||||||
for (const auto& tabInfo : _tabEntries)
|
for (const auto& tabInfo : _tabEntries)
|
||||||
{
|
{
|
||||||
auto widget = MakeTab(pos, STR_STRING_DEFINED_TOOLTIP);
|
auto widget = MakeTab(pos, STR_STRING_DEFINED_TOOLTIP);
|
||||||
@@ -1408,7 +1407,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
tabsInThisRow++;
|
tabsInThisRow++;
|
||||||
if (tabsInThisRow >= maxTabsInThisRow)
|
if (tabsInThisRow >= maxTabsInThisRow)
|
||||||
{
|
{
|
||||||
pos.x = InitTabPosX;
|
pos.x = kTabMargin;
|
||||||
pos.y += TabHeight;
|
pos.y += TabHeight;
|
||||||
tabsInThisRow = 0;
|
tabsInThisRow = 0;
|
||||||
_actualMinHeight += TabHeight;
|
_actualMinHeight += TabHeight;
|
||||||
|
|||||||
@@ -301,15 +301,14 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
Close();
|
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.
|
// String length needs to add 12 either side of box +13 for cursor when max length.
|
||||||
int32_t numLines{};
|
int32_t numLines{};
|
||||||
GfxWrapString(text, WW - (24 + 13), FontStyle::Medium, nullptr, &numLines);
|
GfxWrapString(text, WW - (24 + 13), FontStyle::Medium, nullptr, &numLines);
|
||||||
|
|
||||||
const auto textHeight = numLines * 10;
|
const auto textHeight = numLines * 10;
|
||||||
const auto addedTitleHeight = getTitleBarHeight() - kTitleHeightNormal;
|
return WH + textHeight + getTitleBarDiffNormal();
|
||||||
return WH + textHeight + addedTitleHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -371,8 +370,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
auto* windowMgr = GetWindowManager();
|
auto* windowMgr = GetWindowManager();
|
||||||
windowMgr->CloseByClass(WindowClass::Textinput);
|
windowMgr->CloseByClass(WindowClass::Textinput);
|
||||||
|
|
||||||
auto height = TextInputWindow::CalculateWindowHeight(existing_text);
|
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, WH + 10, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
|
||||||
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
|
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
w->SetParentWindow(call_w, call_widget);
|
w->SetParentWindow(call_w, call_widget);
|
||||||
@@ -386,8 +384,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
std::function<void(std::string_view)> callback, std::function<void()> cancelCallback)
|
std::function<void(std::string_view)> callback, std::function<void()> cancelCallback)
|
||||||
{
|
{
|
||||||
auto* windowMgr = GetWindowManager();
|
auto* windowMgr = GetWindowManager();
|
||||||
auto height = TextInputWindow::CalculateWindowHeight(initialValue);
|
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, WH + 10, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
|
||||||
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
|
|
||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
w->SetTitle(title, description);
|
w->SetTitle(title, description);
|
||||||
|
|||||||
@@ -975,19 +975,6 @@ static constexpr float kWindowScrollLocations[][2] = {
|
|||||||
return w->viewport;
|
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
|
// TODO: declared in WindowManager.h; move when refactors continue
|
||||||
Ui::IWindowManager* Ui::GetWindowManager()
|
Ui::IWindowManager* Ui::GetWindowManager()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -348,7 +348,4 @@ namespace OpenRCT2
|
|||||||
|
|
||||||
void WindowFollowSprite(WindowBase& w, EntityId spriteIndex);
|
void WindowFollowSprite(WindowBase& w, EntityId spriteIndex);
|
||||||
void WindowUnfollowSprite(WindowBase& w);
|
void WindowUnfollowSprite(WindowBase& w);
|
||||||
|
|
||||||
int16_t getTitleBarHeight();
|
|
||||||
int16_t getTitleHeightDiff();
|
|
||||||
} // namespace OpenRCT2
|
} // namespace OpenRCT2
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace OpenRCT2
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Figure out if we need to push the other widgets down to accommodate a resized title/caption
|
// 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 currentHeight = titleWidget.height();
|
||||||
auto heightDifference = preferredHeight - currentHeight;
|
auto heightDifference = preferredHeight - currentHeight;
|
||||||
|
|
||||||
@@ -133,4 +133,27 @@ namespace OpenRCT2
|
|||||||
if (viewport != nullptr)
|
if (viewport != nullptr)
|
||||||
viewport->pos.y += heightDifference;
|
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
|
} // namespace OpenRCT2
|
||||||
|
|||||||
@@ -115,6 +115,11 @@ namespace OpenRCT2
|
|||||||
void SetWidgets(const std::span<const Widget> newWidgets);
|
void SetWidgets(const std::span<const Widget> newWidgets);
|
||||||
void ResizeFrame();
|
void ResizeFrame();
|
||||||
|
|
||||||
|
int16_t getTitleBarTargetHeight() const;
|
||||||
|
int16_t getTitleBarCurrentHeight() const;
|
||||||
|
int16_t getTitleBarDiffTarget() const;
|
||||||
|
int16_t getTitleBarDiffNormal() const;
|
||||||
|
|
||||||
WindowBase() = default;
|
WindowBase() = default;
|
||||||
WindowBase(WindowBase&) = delete;
|
WindowBase(WindowBase&) = delete;
|
||||||
virtual ~WindowBase() = default;
|
virtual ~WindowBase() = default;
|
||||||
|
|||||||
Reference in New Issue
Block a user