Create function to resize window frame

This commit is contained in:
Michael Steenbeek 2022-11-06 10:29:40 +01:00 committed by GitHub
parent 22a2d11cfc
commit 27f3a3a796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 50 additions and 170 deletions

View File

@ -148,11 +148,7 @@ public:
void OnPrepareDraw() override void OnPrepareDraw() override
{ {
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrame();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
auto& list = widgets[WIDX_LIST]; auto& list = widgets[WIDX_LIST];
list.left = 6; list.left = 6;

View File

@ -147,13 +147,7 @@ public:
void OnPrepareDraw() override void OnPrepareDraw() override
{ {
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
widgets[WIDX_CONTENT_PANEL].right = width - 1;
widgets[WIDX_CONTENT_PANEL].bottom = height - 1;
widgets[WIDX_SCROLL].right = width - 3; widgets[WIDX_SCROLL].right = width - 3;
widgets[WIDX_SCROLL].bottom = height - 22; widgets[WIDX_SCROLL].bottom = height - 22;
widgets[WIDX_OPEN_URL].bottom = height - 5; widgets[WIDX_OPEN_URL].bottom = height - 5;

View File

@ -442,13 +442,7 @@ public:
widgets[WIDX_CLOSE].type = gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR ? WindowWidgetType::Empty widgets[WIDX_CLOSE].type = gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR ? WindowWidgetType::Empty
: WindowWidgetType::CloseBox; : WindowWidgetType::CloseBox;
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
widgets[WIDX_RESIZE].right = width - 1;
widgets[WIDX_RESIZE].bottom = height - 1;
int16_t scrollListHeight = (height - 88) / 2; int16_t scrollListHeight = (height - 88) / 2;

View File

@ -815,13 +815,7 @@ public:
void OnPrepareDraw() override void OnPrepareDraw() override
{ {
// Resize widgets // Resize widgets
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
widgets[WIDX_TAB_CONTENT_PANEL].right = width - 1;
widgets[WIDX_TAB_CONTENT_PANEL].bottom = height - 1;
widgets[WIDX_ADVANCED].left = width - 130; widgets[WIDX_ADVANCED].left = width - 130;
widgets[WIDX_ADVANCED].right = width - 9; widgets[WIDX_ADVANCED].right = width - 9;
widgets[WIDX_LIST].right = width - 309; widgets[WIDX_LIST].right = width - 309;

View File

@ -225,13 +225,7 @@ static void WindowEditorObjectiveOptionsSetPressedTab(rct_window* w)
static void WindowEditorObjectiveOptionsAnchorBorderWidgets(rct_window* w) static void WindowEditorObjectiveOptionsAnchorBorderWidgets(rct_window* w)
{ {
w->widgets[WIDX_BACKGROUND].right = w->width - 1; w->ResizeFrameWithPage();
w->widgets[WIDX_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_PAGE_BACKGROUND].right = w->width - 1;
w->widgets[WIDX_PAGE_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_TITLE].right = w->width - 2;
w->widgets[WIDX_CLOSE].left = w->width - 13;
w->widgets[WIDX_CLOSE].right = w->width - 3;
} }
static void WindowEditorObjectiveOptionsDrawTabImages(rct_window* w, rct_drawpixelinfo* dpi) static void WindowEditorObjectiveOptionsDrawTabImages(rct_window* w, rct_drawpixelinfo* dpi)

View File

@ -317,13 +317,7 @@ private:
void AnchorBorderWidgets() void AnchorBorderWidgets()
{ {
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_PAGE_BACKGROUND].right = width - 1;
widgets[WIDX_PAGE_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
} }
void DrawTabImages(rct_drawpixelinfo& dpi) void DrawTabImages(rct_drawpixelinfo& dpi)

View File

@ -440,13 +440,7 @@ private:
auto ft = Formatter::Common(); auto ft = Formatter::Common();
peep->FormatNameTo(ft); peep->FormatNameTo(ft);
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_PAGE_BACKGROUND].right = width - 1;
widgets[WIDX_PAGE_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
window_align_tabs(this, WIDX_TAB_1, WIDX_TAB_7); window_align_tabs(this, WIDX_TAB_1, WIDX_TAB_7);
} }

View File

@ -414,13 +414,7 @@ public:
if (_selectedTab == TabId::Individual && _selectedFilter) if (_selectedTab == TabId::Individual && _selectedFilter)
widgets[WIDX_MAP].type = WindowWidgetType::FlatBtn; widgets[WIDX_MAP].type = WindowWidgetType::FlatBtn;
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TAB_CONTENT_PANEL].right = width - 1;
widgets[WIDX_TAB_CONTENT_PANEL].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
widgets[WIDX_GUEST_LIST].right = width - 4; widgets[WIDX_GUEST_LIST].right = width - 4;
widgets[WIDX_GUEST_LIST].bottom = height - 15; widgets[WIDX_GUEST_LIST].bottom = height - 15;
widgets[WIDX_MAP].left = 273 - 350 + width; widgets[WIDX_MAP].left = 273 - 350 + width;

View File

@ -654,16 +654,7 @@ static void WindowLoadsaveComputeMaxDateWidth()
static void WindowLoadsaveInvalidate(rct_window* w) static void WindowLoadsaveInvalidate(rct_window* w)
{ {
window_loadsave_widgets[WIDX_TITLE].right = w->width - 2; w->ResizeFrameWithPage();
// close button has to move if it's on the right side
window_loadsave_widgets[WIDX_CLOSE].left = w->width - 13;
window_loadsave_widgets[WIDX_CLOSE].right = w->width - 3;
window_loadsave_widgets[WIDX_BACKGROUND].right = w->width - 1;
window_loadsave_widgets[WIDX_BACKGROUND].bottom = w->height - 1;
window_loadsave_widgets[WIDX_RESIZE].top = w->height - 1;
window_loadsave_widgets[WIDX_RESIZE].right = w->width - 1;
window_loadsave_widgets[WIDX_RESIZE].bottom = w->height - 1;
rct_widget* date_widget = &window_loadsave_widgets[WIDX_SORT_DATE]; rct_widget* date_widget = &window_loadsave_widgets[WIDX_SORT_DATE];
date_widget->right = w->width - 5; date_widget->right = w->width - 5;

View File

@ -752,13 +752,7 @@ public:
SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gMapSize.x != gMapSize.y); SetWidgetDisabled(WIDX_MAP_SIZE_LINK, gMapSize.x != gMapSize.y);
// Resize widgets to window size // Resize widgets to window size
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_RESIZE].right = width - 1;
widgets[WIDX_RESIZE].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 2 - 11;
widgets[WIDX_CLOSE].right = width - 2 - 11 + 10;
widgets[WIDX_MAP].right = width - 4; widgets[WIDX_MAP].right = width - 4;
if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode) if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode)

View File

@ -266,13 +266,7 @@ static void WindowMultiplayerSetPage(rct_window* w, int32_t page)
static void WindowMultiplayerAnchorBorderWidgets(rct_window* w) static void WindowMultiplayerAnchorBorderWidgets(rct_window* w)
{ {
w->widgets[WIDX_BACKGROUND].right = w->width - 1; w->ResizeFrameWithPage();
w->widgets[WIDX_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_TITLE].right = w->width - 2;
w->widgets[WIDX_CONTENT_PANEL].right = w->width - 1;
w->widgets[WIDX_CONTENT_PANEL].bottom = w->height - 1;
w->widgets[WIDX_CLOSE].left = w->width - 13;
w->widgets[WIDX_CLOSE].right = w->width - 3;
} }
static void WindowMultiplayerSetPressedTab(rct_window* w) static void WindowMultiplayerSetPressedTab(rct_window* w)

View File

@ -94,11 +94,7 @@ public:
void OnPrepareDraw() override void OnPrepareDraw() override
{ {
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrame();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 2 - 0x0B;
widgets[WIDX_CLOSE].right = width - 2 - 0x0B + 0x0A;
} }
void OnDraw(rct_drawpixelinfo& dpi) override void OnDraw(rct_drawpixelinfo& dpi) override

View File

@ -762,18 +762,12 @@ private:
Invalidate(); Invalidate();
// Resize widgets to new window size // Resize widgets to new window size
widgets[WIDX_BACKGROUND].right = newWidth - 1; width = newWidth;
widgets[WIDX_BACKGROUND].bottom = newHeight - 1; height = newHeight;
widgets[WIDX_PAGE_BACKGROUND].right = newWidth - 1; ResizeFrameWithPage();
widgets[WIDX_PAGE_BACKGROUND].bottom = newHeight - 1;
widgets[WIDX_TITLE].right = newWidth - 2;
widgets[WIDX_CLOSE].left = newWidth - 13;
widgets[WIDX_CLOSE].right = newWidth - 3;
widgets[WIDX_GROUP_BY_TRACK_TYPE].left = newWidth - 8 - GroupByTrackTypeWidth; widgets[WIDX_GROUP_BY_TRACK_TYPE].left = newWidth - 8 - GroupByTrackTypeWidth;
widgets[WIDX_GROUP_BY_TRACK_TYPE].right = newWidth - 8; widgets[WIDX_GROUP_BY_TRACK_TYPE].right = newWidth - 8;
width = newWidth;
height = newHeight;
Invalidate(); Invalidate();
} }

View File

@ -1202,13 +1202,7 @@ private:
void AnchorBorderWidgets() void AnchorBorderWidgets()
{ {
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_PAGE_BACKGROUND].right = width - 1;
widgets[WIDX_PAGE_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
} }
void SetPressedTab() void SetPressedTab()

View File

@ -379,13 +379,7 @@ void WindowPlayerOverviewInvalidate(rct_window* w)
WindowPlayerUpdateTitle(w); WindowPlayerUpdateTitle(w);
w->widgets[WIDX_BACKGROUND].right = w->width - 1; w->ResizeFrameWithPage();
w->widgets[WIDX_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_PAGE_BACKGROUND].right = w->width - 1;
w->widgets[WIDX_PAGE_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_TITLE].right = w->width - 2;
w->widgets[WIDX_CLOSE].left = w->width - 13;
w->widgets[WIDX_CLOSE].right = w->width - 3;
w->widgets[WIDX_LOCATE].right = w->width - 2; w->widgets[WIDX_LOCATE].right = w->width - 2;
w->widgets[WIDX_LOCATE].left = w->width - 25; w->widgets[WIDX_LOCATE].left = w->width - 25;
w->widgets[WIDX_KICK].right = w->width - 2; w->widgets[WIDX_KICK].right = w->width - 2;
@ -472,13 +466,7 @@ void WindowPlayerStatisticsInvalidate(rct_window* w)
WindowPlayerUpdateTitle(w); WindowPlayerUpdateTitle(w);
w->widgets[WIDX_BACKGROUND].right = w->width - 1; w->ResizeFrameWithPage();
w->widgets[WIDX_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_PAGE_BACKGROUND].right = w->width - 1;
w->widgets[WIDX_PAGE_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_TITLE].right = w->width - 2;
w->widgets[WIDX_CLOSE].left = w->width - 13;
w->widgets[WIDX_CLOSE].right = w->width - 3;
window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_2); window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_2);
} }

View File

@ -1468,13 +1468,7 @@ static void WindowRideSetPressedTab(rct_window* w)
static void WindowRideAnchorBorderWidgets(rct_window* w) static void WindowRideAnchorBorderWidgets(rct_window* w)
{ {
w->widgets[WIDX_BACKGROUND].right = w->width - 1; w->ResizeFrameWithPage();
w->widgets[WIDX_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_PAGE_BACKGROUND].right = w->width - 1;
w->widgets[WIDX_PAGE_BACKGROUND].bottom = w->height - 1;
w->widgets[WIDX_TITLE].right = w->width - 2;
w->widgets[WIDX_CLOSE].left = w->width - 13;
w->widgets[WIDX_CLOSE].right = w->width - 3;
} }
#pragma region Main #pragma region Main

View File

@ -450,15 +450,7 @@ public:
else else
pressed_widgets &= ~(1uLL << WIDX_QUICK_DEMOLISH); pressed_widgets &= ~(1uLL << WIDX_QUICK_DEMOLISH);
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_PAGE_BACKGROUND].right = width - 1;
widgets[WIDX_PAGE_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
// if close button is on the right then it must move
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
widgets[WIDX_LIST].right = width - 26; widgets[WIDX_LIST].right = width - 26;
widgets[WIDX_LIST].bottom = height - 15; widgets[WIDX_LIST].bottom = height - 15;

View File

@ -412,20 +412,11 @@ static void WindowScenarioselectInvalidate(rct_window* w)
w->pressed_widgets |= 1LL << (w->selected_tab + WIDX_TAB1); w->pressed_widgets |= 1LL << (w->selected_tab + WIDX_TAB1);
int32_t windowWidth = w->width; w->ResizeFrameWithPage();
window_scenarioselect_widgets[WIDX_BACKGROUND].right = windowWidth - 1;
window_scenarioselect_widgets[WIDX_TITLEBAR].right = windowWidth - 2;
window_scenarioselect_widgets[WIDX_CLOSE].left = windowWidth - 13;
window_scenarioselect_widgets[WIDX_CLOSE].right = windowWidth - 3;
window_scenarioselect_widgets[WIDX_TABCONTENT].right = windowWidth - 1;
window_scenarioselect_widgets[WIDX_SCENARIOLIST].right = windowWidth - 179;
int32_t windowHeight = w->height;
window_scenarioselect_widgets[WIDX_BACKGROUND].bottom = windowHeight - 1;
window_scenarioselect_widgets[WIDX_TABCONTENT].bottom = windowHeight - 1;
const int32_t bottomMargin = gConfigGeneral.DebuggingTools ? 17 : 5; const int32_t bottomMargin = gConfigGeneral.DebuggingTools ? 17 : 5;
window_scenarioselect_widgets[WIDX_SCENARIOLIST].bottom = windowHeight - bottomMargin; window_scenarioselect_widgets[WIDX_SCENARIOLIST].right = w->width - 179;
window_scenarioselect_widgets[WIDX_SCENARIOLIST].bottom = w->height - bottomMargin;
} }
static void WindowScenarioselectPaint(rct_window* w, rct_drawpixelinfo* dpi) static void WindowScenarioselectPaint(rct_window* w, rct_drawpixelinfo* dpi)

View File

@ -352,11 +352,7 @@ static OpenRCT2String WindowServerListTooltip(rct_window* const w, const WidgetI
static void WindowServerListInvalidate(rct_window* w) static void WindowServerListInvalidate(rct_window* w)
{ {
window_server_list_widgets[WIDX_BACKGROUND].right = w->width - 1; w->ResizeFrame();
window_server_list_widgets[WIDX_BACKGROUND].bottom = w->height - 1;
window_server_list_widgets[WIDX_TITLE].right = w->width - 2;
window_server_list_widgets[WIDX_CLOSE].left = w->width - 2 - 11;
window_server_list_widgets[WIDX_CLOSE].right = w->width - 2 - 11 + 10;
int32_t margin = 6; int32_t margin = 6;
int32_t buttonHeight = 13; int32_t buttonHeight = 13;

View File

@ -234,13 +234,7 @@ public:
void OnPrepareDraw() override void OnPrepareDraw() override
{ {
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].right = width - 3;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_TAB_CONTENT_PANEL].right = width - 1;
widgets[WIDX_TAB_CONTENT_PANEL].bottom = height - 1;
widgets[WIDX_SCROLL].right = width - 5; widgets[WIDX_SCROLL].right = width - 5;
widgets[WIDX_SCROLL].bottom = height - 19; widgets[WIDX_SCROLL].bottom = height - 19;
widgets[WIDX_RESET].top = height - 16; widgets[WIDX_RESET].top = height - 16;

View File

@ -339,16 +339,7 @@ private:
auto ft = Formatter::Common(); auto ft = Formatter::Common();
staff->FormatNameTo(ft); staff->FormatNameTo(ft);
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_RESIZE].right = width - 1;
widgets[WIDX_RESIZE].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
} }
void CommonPrepareDrawAfter() void CommonPrepareDrawAfter()

View File

@ -177,13 +177,7 @@ public:
{ {
rct_widget* viewportWidget = &window_viewport_widgets[WIDX_VIEWPORT]; rct_widget* viewportWidget = &window_viewport_widgets[WIDX_VIEWPORT];
widgets[WIDX_BACKGROUND].right = width - 1; ResizeFrameWithPage();
widgets[WIDX_BACKGROUND].bottom = height - 1;
widgets[WIDX_TITLE].right = width - 2;
widgets[WIDX_CLOSE].left = width - 13;
widgets[WIDX_CLOSE].right = width - 3;
widgets[WIDX_CONTENT_PANEL].right = width - 1;
widgets[WIDX_CONTENT_PANEL].bottom = height - 1;
widgets[WIDX_ZOOM_IN].left = width - 27; widgets[WIDX_ZOOM_IN].left = width - 27;
widgets[WIDX_ZOOM_IN].right = width - 2; widgets[WIDX_ZOOM_IN].right = width - 2;
widgets[WIDX_ZOOM_OUT].left = width - 27; widgets[WIDX_ZOOM_OUT].left = width - 27;

View File

@ -2238,3 +2238,23 @@ void WidgetScrollUpdateThumbs(rct_window& w, WidgetIndex widget_index)
} }
} }
} }
void rct_window::ResizeFrame()
{
// Frame
widgets[0].right = width - 1;
widgets[0].bottom = height - 1;
// Title
widgets[1].right = width - 2;
// Close button
widgets[2].left = width - 13;
widgets[2].right = width - 3;
}
void rct_window::ResizeFrameWithPage()
{
ResizeFrame();
// Page background
widgets[3].right = width - 1;
widgets[3].bottom = height - 1;
}

View File

@ -197,6 +197,9 @@ struct rct_window
virtual void OnUnknown5() virtual void OnUnknown5()
{ {
} }
void ResizeFrame();
void ResizeFrameWithPage();
}; };
#ifdef __WARN_SUGGEST_FINAL_METHODS__ #ifdef __WARN_SUGGEST_FINAL_METHODS__