From 523bb8136e5754a9852dae118cacdf8f32f823fb Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sat, 30 Jul 2022 22:40:33 +0200 Subject: [PATCH] Refactor window functions to take references 3 --- src/openrct2-ui/input/MouseInput.cpp | 24 +- src/openrct2-ui/interface/Widget.cpp | 310 +++++++++--------- src/openrct2-ui/interface/Window.cpp | 8 +- src/openrct2-ui/scripting/CustomWindow.cpp | 2 +- .../windows/EditorInventionsList.cpp | 2 +- src/openrct2-ui/windows/Finances.cpp | 2 +- src/openrct2-ui/windows/Land.cpp | 4 +- src/openrct2-ui/windows/Map.cpp | 2 +- src/openrct2-ui/windows/NewRide.cpp | 2 +- src/openrct2-ui/windows/News.cpp | 2 +- src/openrct2-ui/windows/Options.cpp | 2 +- src/openrct2-ui/windows/Ride.cpp | 2 +- src/openrct2-ui/windows/Scenery.cpp | 4 +- src/openrct2-ui/windows/ViewClipping.cpp | 2 +- src/openrct2/interface/Widget.h | 6 +- src/openrct2/interface/Window.cpp | 8 +- 16 files changed, 191 insertions(+), 191 deletions(-) diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 013d2f852a..46071b3d8e 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -218,7 +218,7 @@ static void InputScrollDragContinue(const ScreenCoordsXY& screenCoords, rct_wind scroll.v_top = std::min(std::max(0, scroll.v_top + differentialCoords.y), size); } - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); window_invalidate_by_number(w->classification, w->number); ScreenCoordsXY fixedCursorPosition = { static_cast(std::ceil(gInputDragLast.x * gConfigGeneral.window_scale)), @@ -616,7 +616,7 @@ static void InputScrollBegin(rct_window* w, rct_widgetindex widgetIndex, const S int32_t scroll_area, scroll_id; ScreenCoordsXY scrollCoords; scroll_id = 0; // safety - WidgetScrollGetPart(w, &widget, screenCoords, scrollCoords, &scroll_area, &scroll_id); + WidgetScrollGetPart(*w, &widget, screenCoords, scrollCoords, &scroll_area, &scroll_id); _currentScrollArea = scroll_area; _currentScrollIndex = scroll_id; @@ -669,7 +669,7 @@ static void InputScrollBegin(rct_window* w, rct_widgetindex widgetIndex, const S default: break; } - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); window_invalidate_by_number(widgetIndex, w->classification); } @@ -688,7 +688,7 @@ static void InputScrollContinue(rct_window* w, rct_widgetindex widgetIndex, cons } ScreenCoordsXY newScreenCoords; - WidgetScrollGetPart(w, &widget, screenCoords, newScreenCoords, &scroll_part, &scroll_id); + WidgetScrollGetPart(*w, &widget, screenCoords, newScreenCoords, &scroll_part, &scroll_id); if (_currentScrollArea == SCROLL_PART_HSCROLLBAR_THUMB) { @@ -772,7 +772,7 @@ static void InputScrollPartUpdateHThumb(rct_window* w, rct_widgetindex widgetInd if (newLeft > x) newLeft = x; scroll.h_left = newLeft; - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); widget_invalidate_by_number(w->classification, w->number, widgetIndex); } } @@ -812,7 +812,7 @@ static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetInd if (newTop > y) newTop = y; scroll.v_top = newTop; - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); widget_invalidate_by_number(w->classification, w->number, widgetIndex); } } @@ -830,7 +830,7 @@ static void InputScrollPartUpdateHLeft(rct_window* w, rct_widgetindex widgetInde scroll.flags |= HSCROLLBAR_LEFT_PRESSED; if (scroll.h_left >= 3) scroll.h_left -= 3; - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); widget_invalidate_by_number(w->classification, w->number, widgetIndex); } } @@ -857,7 +857,7 @@ static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetInd newLeft = 0; if (scroll.h_left > newLeft) scroll.h_left = newLeft; - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); widget_invalidate_by_number(w->classification, w->number, widgetIndex); } } @@ -875,7 +875,7 @@ static void InputScrollPartUpdateVTop(rct_window* w, rct_widgetindex widgetIndex scroll.flags |= VSCROLLBAR_UP_PRESSED; if (scroll.v_top >= 3) scroll.v_top -= 3; - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); widget_invalidate_by_number(w->classification, w->number, widgetIndex); } } @@ -902,7 +902,7 @@ static void InputScrollPartUpdateVBottom(rct_window* w, rct_widgetindex widgetIn newTop = 0; if (scroll.v_top > newTop) scroll.v_top = newTop; - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); widget_invalidate_by_number(w->classification, w->number, widgetIndex); } } @@ -934,7 +934,7 @@ static void InputWidgetOver(const ScreenCoordsXY& screenCoords, rct_window* w, r { int32_t scroll_part, scrollId; ScreenCoordsXY newScreenCoords; - WidgetScrollGetPart(w, widget, screenCoords, newScreenCoords, &scroll_part, &scrollId); + WidgetScrollGetPart(*w, widget, screenCoords, newScreenCoords, &scroll_part, &scrollId); if (scroll_part != SCROLL_PART_VIEW) WindowTooltipClose(); @@ -1138,7 +1138,7 @@ void ProcessMouseOver(const ScreenCoordsXY& screenCoords) int32_t output_scroll_area, scroll_id; ScreenCoordsXY scrollCoords; WidgetScrollGetPart( - window, &window->widgets[widgetId], screenCoords, scrollCoords, &output_scroll_area, &scroll_id); + *window, &window->widgets[widgetId], screenCoords, scrollCoords, &output_scroll_area, &scroll_id); if (output_scroll_area != SCROLL_PART_VIEW) { cursorId = CursorID::Arrow; diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index bac7fbe86d..924d86d205 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -21,34 +21,34 @@ #include #include -static void WidgetFrameDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetResizeDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetButtonDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetTabDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetFlatButtonDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetTextButton(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetTextCentred(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetText(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetTextInset(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetCaptionDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetCheckboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetCloseboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); -static void WidgetScrollDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); +static void WidgetFrameDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetResizeDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetButtonDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetTabDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetFlatButtonDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetTextButton(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetTextCentred(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetText(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetTextInset(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetCaptionDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetCheckboxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetCloseboxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); +static void WidgetScrollDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); static void WidgetHScrollbarDraw( rct_drawpixelinfo* dpi, const rct_scroll& scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour); static void WidgetVScrollbarDraw( rct_drawpixelinfo* dpi, const rct_scroll& scroll, int32_t l, int32_t t, int32_t r, int32_t b, int32_t colour); -static void WidgetDrawImage(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); +static void WidgetDrawImage(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); /** * * rct2: 0x006EB2A8 */ -void WidgetDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +void WidgetDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { - const auto* widget = GetWidgetByIndex(*w, widgetIndex); + const auto* widget = GetWidgetByIndex(w, widgetIndex); if (widget == nullptr) { log_error("Tried drawing an out-of-bounds widget index!"); @@ -116,33 +116,33 @@ void WidgetDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetInd * * rct2: 0x006EB6CE */ -static void WidgetFrameDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetFrameDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - auto leftTop = w->windowPos + ScreenCoordsXY{ widget.left, widget.top }; - int32_t r = w->windowPos.x + widget.right; - int32_t b = w->windowPos.y + widget.bottom; + auto leftTop = w.windowPos + ScreenCoordsXY{ widget.left, widget.top }; + int32_t r = w.windowPos.x + widget.right; + int32_t b = w.windowPos.y + widget.bottom; // - uint8_t press = ((w->flags & WF_10) ? INSET_RECT_FLAG_FILL_MID_LIGHT : 0); + uint8_t press = ((w.flags & WF_10) ? INSET_RECT_FLAG_FILL_MID_LIGHT : 0); // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; // Draw the frame gfx_fill_rect_inset(dpi, { leftTop, { r, b } }, colour, press); // Check if the window can be resized - if (!(w->flags & WF_RESIZABLE)) + if (!(w.flags & WF_RESIZABLE)) return; - if (w->min_width == w->max_width && w->min_height == w->max_height) + if (w.min_width == w.max_width && w.min_height == w.max_height) return; // Draw the resize sprite at the bottom right corner - leftTop = w->windowPos + ScreenCoordsXY{ widget.right - 18, widget.bottom - 18 }; + leftTop = w.windowPos + ScreenCoordsXY{ widget.right - 18, widget.bottom - 18 }; gfx_draw_sprite(dpi, ImageId(SPR_RESIZE, colour & 0x7F), leftTop); } @@ -150,30 +150,30 @@ static void WidgetFrameDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetind * * rct2: 0x006EB765 */ -static void WidgetResizeDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetResizeDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - auto leftTop = w->windowPos + ScreenCoordsXY{ widget.left, widget.top }; - int32_t r = w->windowPos.x + widget.right; - int32_t b = w->windowPos.y + widget.bottom; + auto leftTop = w.windowPos + ScreenCoordsXY{ widget.left, widget.top }; + int32_t r = w.windowPos.x + widget.right; + int32_t b = w.windowPos.y + widget.bottom; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; // Draw the panel gfx_fill_rect_inset(dpi, { leftTop, { r, b } }, colour, 0); // Check if the window can be resized - if (!(w->flags & WF_RESIZABLE)) + if (!(w.flags & WF_RESIZABLE)) return; - if (w->min_width == w->max_width && w->min_height == w->max_height) + if (w.min_width == w.max_width && w.min_height == w.max_height) return; // Draw the resize sprite at the bottom right corner - leftTop = w->windowPos + ScreenCoordsXY{ widget.right - 18, widget.bottom - 18 }; + leftTop = w.windowPos + ScreenCoordsXY{ widget.right - 18, widget.bottom - 18 }; gfx_draw_sprite(dpi, ImageId(SPR_RESIZE, colour & 0x7F), leftTop); } @@ -181,20 +181,20 @@ static void WidgetResizeDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetin * * rct2: 0x006EB8E5 */ -static void WidgetButtonDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetButtonDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - ScreenRect rect{ w->windowPos + ScreenCoordsXY{ widget.left, widget.top }, - w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; + ScreenRect rect{ w.windowPos + ScreenCoordsXY{ widget.left, widget.top }, + w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; // Check if the button is pressed down - uint8_t press = WidgetIsPressed(*w, widgetIndex) || WidgetIsActiveTool(*w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0; + uint8_t press = WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; if (static_cast(widget.image) == -2) { @@ -213,17 +213,17 @@ static void WidgetButtonDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetin * * rct2: 0x006EB806 */ -static void WidgetTabDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetTabDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - auto& widget = w->widgets[widgetIndex]; + auto& widget = w.widgets[widgetIndex]; if (widget.type != WindowWidgetType::Tab && static_cast(widget.image) == -1) return; if (widget.type == WindowWidgetType::Tab) { - if (WidgetIsDisabled(*w, widgetIndex)) + if (WidgetIsDisabled(w, widgetIndex)) return; if (widget.image == static_cast(SPR_NONE)) @@ -234,7 +234,7 @@ static void WidgetTabDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex } // Draw widgets that aren't explicitly disabled. - if (!WidgetIsDisabled(*w, widgetIndex)) + if (!WidgetIsDisabled(w, widgetIndex)) { WidgetDrawImage(dpi, w, widgetIndex); return; @@ -247,10 +247,10 @@ static void WidgetTabDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex } // Resolve the absolute ltrb - auto leftTop = w->windowPos + ScreenCoordsXY{ widget.left, widget.top }; + auto leftTop = w.windowPos + ScreenCoordsXY{ widget.left, widget.top }; // Get the colour and disabled image - auto colour = w->colours[widget.colour] & 0x7F; + auto colour = w.colours[widget.colour] & 0x7F; auto image = ImageId::FromUInt32(widget.image + 2).WithPrimary(colour); // Draw disabled image @@ -261,26 +261,26 @@ static void WidgetTabDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex * * rct2: 0x006EB861 */ -static void WidgetFlatButtonDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetFlatButtonDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { - if (!WidgetIsDisabled(*w, widgetIndex) && WidgetIsHighlighted(*w, widgetIndex)) + if (!WidgetIsDisabled(w, widgetIndex) && WidgetIsHighlighted(w, widgetIndex)) { WidgetButtonDraw(dpi, w, widgetIndex); return; } // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - ScreenRect rect{ w->windowPos + ScreenCoordsXY{ widget.left, widget.top }, - w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; + ScreenRect rect{ w.windowPos + ScreenCoordsXY{ widget.left, widget.top }, + w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; // Check if the button is pressed down - if (WidgetIsPressed(*w, widgetIndex) || WidgetIsActiveTool(*w, widgetIndex)) + if (WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex)) { if (static_cast(widget.image) == -2) { @@ -301,20 +301,20 @@ static void WidgetFlatButtonDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg * * rct2: 0x006EBBEB */ -static void WidgetTextButton(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetTextButton(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - ScreenRect rect{ w->windowPos + ScreenCoordsXY{ widget.left, widget.top }, - w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; + ScreenRect rect{ w.windowPos + ScreenCoordsXY{ widget.left, widget.top }, + w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; // Border - uint8_t press = WidgetIsPressed(*w, widgetIndex) || WidgetIsActiveTool(*w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0; + uint8_t press = WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0; gfx_fill_rect_inset(dpi, rect, colour, press); // Button caption @@ -332,23 +332,23 @@ static void WidgetTextButton(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetin * * rct2: 0x006EBC41 */ -static void WidgetTextCentred(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetTextCentred(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; if (widget.text == STR_NONE) return; // Get the colour - colour_t colour = w->colours[widget.colour]; + colour_t colour = w.colours[widget.colour]; colour &= ~(COLOUR_FLAG_TRANSLUCENT); - if (WidgetIsDisabled(*w, widgetIndex)) + if (WidgetIsDisabled(w, widgetIndex)) colour |= COLOUR_FLAG_INSET; // Resolve the absolute ltrb - auto topLeft = w->windowPos + ScreenCoordsXY{ widget.left, 0 }; - int32_t r = w->windowPos.x + widget.right; + auto topLeft = w.windowPos + ScreenCoordsXY{ widget.left, 0 }; + int32_t r = w.windowPos.x + widget.right; if (widget.type == WindowWidgetType::Button || widget.type == WindowWidgetType::TableHeader) topLeft.y += widget.textTop(); @@ -378,31 +378,31 @@ static void WidgetTextCentred(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti * * rct2: 0x006EBD52 */ -static void WidgetText(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetText(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; if (widget.text == STR_NONE || widget.text == STR_VIEWPORT) return; // Get the colour - uint8_t colour = w->colours[widget.colour]; - if (WidgetIsDisabled(*w, widgetIndex)) + uint8_t colour = w.colours[widget.colour]; + if (WidgetIsDisabled(w, widgetIndex)) colour |= COLOUR_FLAG_INSET; // Resolve the absolute ltrb - int32_t l = w->windowPos.x + widget.left; - int32_t r = w->windowPos.x + widget.right; + int32_t l = w.windowPos.x + widget.left; + int32_t r = w.windowPos.x + widget.right; int32_t t; if (widget.type == WindowWidgetType::Button || widget.type == WindowWidgetType::DropdownMenu || widget.type == WindowWidgetType::Spinner || widget.type == WindowWidgetType::TableHeader) { - t = w->windowPos.y + widget.textTop(); + t = w.windowPos.y + widget.textTop(); } else - t = w->windowPos.y + widget.top; + t = w.windowPos.y + widget.top; auto stringId = widget.text; auto ft = Formatter::Common(); @@ -427,17 +427,17 @@ static void WidgetText(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex wi * * rct2: 0x006EBD1F */ -static void WidgetTextInset(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetTextInset(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - ScreenRect rect{ w->windowPos + ScreenCoordsXY{ widget.left, widget.top }, - w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; + ScreenRect rect{ w.windowPos + ScreenCoordsXY{ widget.left, widget.top }, + w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; gfx_fill_rect_inset(dpi, rect, colour, INSET_RECT_F_60); WidgetText(dpi, w, widgetIndex); @@ -467,22 +467,22 @@ static std::pair WidgetGetStringidAndArgs(const rct_widget * * rct2: 0x006EB535 */ -static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - auto l = w->windowPos.x + widget.left + 5; - auto t = w->windowPos.y + widget.top; + auto l = w.windowPos.x + widget.left + 5; + auto t = w.windowPos.y + widget.top; auto textRight = l; // Text auto [stringId, formatArgs] = WidgetGetStringidAndArgs(widget); if (stringId != STR_NONE) { - uint8_t colour = w->colours[widget.colour] & 0x7F; - if (WidgetIsDisabled(*w, widgetIndex)) + uint8_t colour = w.colours[widget.colour] & 0x7F; + if (WidgetIsDisabled(w, widgetIndex)) colour |= COLOUR_FLAG_INSET; utf8 buffer[512] = { 0 }; @@ -495,13 +495,13 @@ static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widget // Border // Resolve the absolute ltrb - l = w->windowPos.x + widget.left; - t = w->windowPos.y + widget.top + 4; - const auto r = w->windowPos.x + widget.right; - const auto b = w->windowPos.y + widget.bottom; + l = w.windowPos.x + widget.left; + t = w.windowPos.y + widget.top + 4; + const auto r = w.windowPos.x + widget.right; + const auto b = w.windowPos.y + widget.bottom; // Get the colour - uint8_t colour = w->colours[widget.colour] & 0x7F; + uint8_t colour = w.colours[widget.colour] & 0x7F; // Border left of text gfx_fill_rect(dpi, { { l, t }, { l + 4, t } }, ColourMapA[colour].mid_dark); @@ -528,20 +528,20 @@ static void WidgetGroupboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widget * * rct2: 0x006EB2F9 */ -static void WidgetCaptionDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetCaptionDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto* widget = &w->widgets[widgetIndex]; + const auto* widget = &w.widgets[widgetIndex]; // Resolve the absolute ltrb - auto topLeft = w->windowPos + ScreenCoordsXY{ widget->left, widget->top }; - auto bottomRight = w->windowPos + ScreenCoordsXY{ widget->right, widget->bottom }; + auto topLeft = w.windowPos + ScreenCoordsXY{ widget->left, widget->top }; + auto bottomRight = w.windowPos + ScreenCoordsXY{ widget->right, widget->bottom }; // Get the colour - uint8_t colour = w->colours[widget->colour]; + uint8_t colour = w.colours[widget->colour]; uint8_t press = INSET_RECT_F_60; - if (w->flags & WF_10) + if (w.flags & WF_10) press |= INSET_RECT_FLAG_FILL_MID_LIGHT; gfx_fill_rect_inset(dpi, { topLeft, bottomRight }, colour, press); @@ -559,7 +559,7 @@ static void WidgetCaptionDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti if (widget->text == STR_NONE) return; - topLeft = w->windowPos + ScreenCoordsXY{ widget->left + 2, widget->top + 1 }; + topLeft = w.windowPos + ScreenCoordsXY{ widget->left + 2, widget->top + 1 }; int32_t width = widget->width() - 4; if ((widget + 1)->type == WindowWidgetType::CloseBox) { @@ -576,24 +576,24 @@ static void WidgetCaptionDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti * * rct2: 0x006EBB85 */ -static void WidgetCloseboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetCloseboxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - auto topLeft = w->windowPos + ScreenCoordsXY{ widget.left, widget.top }; - auto bottomRight = w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom }; + auto topLeft = w.windowPos + ScreenCoordsXY{ widget.left, widget.top }; + auto bottomRight = w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom }; // Check if the button is pressed down uint8_t press = 0; - if (w->flags & WF_10) + if (w.flags & WF_10) press |= INSET_RECT_FLAG_FILL_MID_LIGHT; - if (WidgetIsPressed(*w, widgetIndex) || WidgetIsActiveTool(*w, widgetIndex)) + if (WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex)) press |= INSET_RECT_FLAG_BORDER_INSET; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; // Draw the button gfx_fill_rect_inset(dpi, { topLeft, bottomRight }, colour, press); @@ -601,9 +601,9 @@ static void WidgetCloseboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widget if (widget.text == STR_NONE) return; - topLeft = w->windowPos + ScreenCoordsXY{ widget.midX() - 1, std::max(widget.top, widget.midY() - 5) }; + topLeft = w.windowPos + ScreenCoordsXY{ widget.midX() - 1, std::max(widget.top, widget.midY() - 5) }; - if (WidgetIsDisabled(*w, widgetIndex)) + if (WidgetIsDisabled(w, widgetIndex)) colour |= COLOUR_FLAG_INSET; DrawTextEllipsised(dpi, topLeft, widget.width() - 2, widget.text, Formatter::Common(), { colour, TextAlignment::CENTRE }); @@ -613,29 +613,29 @@ static void WidgetCloseboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widget * * rct2: 0x006EBAD9 */ -static void WidgetCheckboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetCheckboxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltb - ScreenCoordsXY topLeft = w->windowPos + ScreenCoordsXY{ widget.left, widget.top }; - ScreenCoordsXY bottomRight = w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom }; + ScreenCoordsXY topLeft = w.windowPos + ScreenCoordsXY{ widget.left, widget.top }; + ScreenCoordsXY bottomRight = w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom }; ScreenCoordsXY midLeft = { topLeft.x, (topLeft.y + bottomRight.y) / 2 }; // Get the colour - colour_t colour = w->colours[widget.colour]; + colour_t colour = w.colours[widget.colour]; // checkbox gfx_fill_rect_inset(dpi, { midLeft - ScreenCoordsXY{ 0, 5 }, midLeft + ScreenCoordsXY{ 9, 4 } }, colour, INSET_RECT_F_60); - if (WidgetIsDisabled(*w, widgetIndex)) + if (WidgetIsDisabled(w, widgetIndex)) { colour |= COLOUR_FLAG_INSET; } // fill it when checkbox is pressed - if (WidgetIsPressed(*w, widgetIndex)) + if (WidgetIsPressed(w, widgetIndex)) { gfx_draw_string( dpi, { midLeft - ScreenCoordsXY{ 0, 5 } }, static_cast(CheckBoxMarkString), @@ -654,19 +654,19 @@ static void WidgetCheckboxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widget * * rct2: 0x006EBD96 */ -static void WidgetScrollDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetScrollDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - int32_t scrollIndex = window_get_scroll_data_index(w, widgetIndex); - const auto& widget = w->widgets[widgetIndex]; - const auto& scroll = w->scrolls[scrollIndex]; + int32_t scrollIndex = window_get_scroll_data_index(&w, widgetIndex); + const auto& widget = w.widgets[widgetIndex]; + const auto& scroll = w.scrolls[scrollIndex]; // Resolve the absolute ltrb - ScreenCoordsXY topLeft = w->windowPos + ScreenCoordsXY{ widget.left, widget.top }; - ScreenCoordsXY bottomRight = w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom }; + ScreenCoordsXY topLeft = w.windowPos + ScreenCoordsXY{ widget.left, widget.top }; + ScreenCoordsXY bottomRight = w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom }; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; // Draw the border gfx_fill_rect_inset(dpi, { topLeft, bottomRight }, colour, INSET_RECT_F_60); @@ -719,7 +719,7 @@ static void WidgetScrollDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetin // Draw the scroll contents if (scroll_dpi.width > 0 && scroll_dpi.height > 0) - window_event_scroll_paint_call(w, &scroll_dpi, scrollIndex); + window_event_scroll_paint_call(&w, &scroll_dpi, scrollIndex); } static void WidgetHScrollbarDraw( @@ -796,10 +796,10 @@ static void WidgetVScrollbarDraw( * * rct2: 0x006EB951 */ -static void WidgetDrawImage(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetDrawImage(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Get the image int32_t image = widget.image; @@ -807,25 +807,25 @@ static void WidgetDrawImage(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetind return; // Resolve the absolute ltrb - auto screenCoords = w->windowPos + ScreenCoordsXY{ widget.left, widget.top }; + auto screenCoords = w.windowPos + ScreenCoordsXY{ widget.left, widget.top }; // Get the colour - uint8_t colour = NOT_TRANSLUCENT(w->colours[widget.colour]); + uint8_t colour = NOT_TRANSLUCENT(w.colours[widget.colour]); if (widget.type == WindowWidgetType::ColourBtn || widget.type == WindowWidgetType::TrnBtn || widget.type == WindowWidgetType::Tab) - if (WidgetIsPressed(*w, widgetIndex) || WidgetIsActiveTool(*w, widgetIndex)) + if (WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex)) image++; - if (WidgetIsDisabled(*w, widgetIndex)) + if (WidgetIsDisabled(w, widgetIndex)) { // Draw greyed out (light border bottom right shadow) - colour = w->colours[widget.colour]; + colour = w.colours[widget.colour]; colour = ColourMapA[NOT_TRANSLUCENT(colour)].lighter; gfx_draw_sprite_solid(dpi, image, screenCoords + ScreenCoordsXY{ 1, 1 }, colour); // Draw greyed out (dark) - colour = w->colours[widget.colour]; + colour = w.colours[widget.colour]; colour = ColourMapA[NOT_TRANSLUCENT(colour)].mid_light; gfx_draw_sprite_solid(dpi, image, screenCoords, colour); } @@ -932,11 +932,11 @@ bool WidgetIsActiveTool(const rct_window& w, rct_widgetindex widgetIndex) * edi: widget */ void WidgetScrollGetPart( - rct_window* w, const rct_widget* widget, const ScreenCoordsXY& screenCoords, ScreenCoordsXY& retScreenCoords, + rct_window& w, const rct_widget* widget, const ScreenCoordsXY& screenCoords, ScreenCoordsXY& retScreenCoords, int32_t* output_scroll_area, int32_t* scroll_id) { *scroll_id = 0; - for (rct_widget* iterator = w->widgets; iterator != widget; iterator++) + for (rct_widget* iterator = w.widgets; iterator != widget; iterator++) { if (iterator->type == WindowWidgetType::Scroll) { @@ -944,13 +944,13 @@ void WidgetScrollGetPart( } } - const auto& scroll = w->scrolls[*scroll_id]; - if ((scroll.flags & HSCROLLBAR_VISIBLE) && screenCoords.y >= (w->windowPos.y + widget->bottom - (SCROLLBAR_WIDTH + 1))) + const auto& scroll = w.scrolls[*scroll_id]; + if ((scroll.flags & HSCROLLBAR_VISIBLE) && screenCoords.y >= (w.windowPos.y + widget->bottom - (SCROLLBAR_WIDTH + 1))) { // horizontal scrollbar int32_t rightOffset = 0; - int32_t iteratorLeft = widget->left + w->windowPos.x + SCROLLBAR_WIDTH; - int32_t iteratorRight = widget->right + w->windowPos.x - SCROLLBAR_WIDTH; + int32_t iteratorLeft = widget->left + w.windowPos.x + SCROLLBAR_WIDTH; + int32_t iteratorRight = widget->right + w.windowPos.x - SCROLLBAR_WIDTH; if (!(scroll.flags & VSCROLLBAR_VISIBLE)) { rightOffset = SCROLLBAR_WIDTH + 1; @@ -968,11 +968,11 @@ void WidgetScrollGetPart( { *output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT; } - else if (screenCoords.x < (widget->left + w->windowPos.x + scroll.h_thumb_left)) + else if (screenCoords.x < (widget->left + w.windowPos.x + scroll.h_thumb_left)) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_LEFT_TROUGH; } - else if (screenCoords.x > (widget->left + w->windowPos.x + scroll.h_thumb_right)) + else if (screenCoords.x > (widget->left + w.windowPos.x + scroll.h_thumb_right)) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT_TROUGH; } @@ -981,12 +981,12 @@ void WidgetScrollGetPart( *output_scroll_area = SCROLL_PART_HSCROLLBAR_THUMB; } } - else if ((scroll.flags & VSCROLLBAR_VISIBLE) && (screenCoords.x >= w->windowPos.x + widget->right - (SCROLLBAR_WIDTH + 1))) + else if ((scroll.flags & VSCROLLBAR_VISIBLE) && (screenCoords.x >= w.windowPos.x + widget->right - (SCROLLBAR_WIDTH + 1))) { // vertical scrollbar int32_t bottomOffset = 0; - int32_t iteratorTop = widget->top + w->windowPos.y + SCROLLBAR_WIDTH; - int32_t iteratorBottom = widget->bottom + w->windowPos.y; + int32_t iteratorTop = widget->top + w.windowPos.y + SCROLLBAR_WIDTH; + int32_t iteratorBottom = widget->bottom + w.windowPos.y; if (scroll.flags & HSCROLLBAR_VISIBLE) { bottomOffset = (SCROLLBAR_WIDTH + 1); @@ -1004,11 +1004,11 @@ void WidgetScrollGetPart( { *output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM; } - else if (screenCoords.y < (widget->top + w->windowPos.y + scroll.v_thumb_top)) + else if (screenCoords.y < (widget->top + w.windowPos.y + scroll.v_thumb_top)) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_TOP_TROUGH; } - else if (screenCoords.y > (widget->top + w->windowPos.y + scroll.v_thumb_bottom)) + else if (screenCoords.y > (widget->top + w.windowPos.y + scroll.v_thumb_bottom)) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM_TROUGH; } @@ -1023,7 +1023,7 @@ void WidgetScrollGetPart( *output_scroll_area = SCROLL_PART_VIEW; retScreenCoords.x = screenCoords.x - widget->left; retScreenCoords.y = screenCoords.y - widget->top; - retScreenCoords -= w->windowPos; + retScreenCoords -= w.windowPos; if (retScreenCoords.x <= 0 || retScreenCoords.y <= 0) { *output_scroll_area = SCROLL_PART_NONE; @@ -1118,29 +1118,29 @@ void WidgetSetCheckboxValue(rct_window& w, rct_widgetindex widgetIndex, bool val WidgetSetPressed(w, widgetIndex, value); } -static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex) +static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex) { int32_t no_lines = 0; char wrapped_string[TEXT_INPUT_SIZE]; // Get the widget - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; // Resolve the absolute ltrb - ScreenCoordsXY topLeft{ w->windowPos + ScreenCoordsXY{ widget.left, widget.top } }; - ScreenCoordsXY bottomRight{ w->windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; + ScreenCoordsXY topLeft{ w.windowPos + ScreenCoordsXY{ widget.left, widget.top } }; + ScreenCoordsXY bottomRight{ w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } }; // Get the colour - uint8_t colour = w->colours[widget.colour]; + uint8_t colour = w.colours[widget.colour]; - bool active = w->classification == gCurrentTextBox.window.classification && w->number == gCurrentTextBox.window.number + bool active = w.classification == gCurrentTextBox.window.classification && w.number == gCurrentTextBox.window.number && widgetIndex == gCurrentTextBox.widget_index; // gfx_fill_rect_inset(dpi, l, t, r, b, colour, 0x20 | (!active ? 0x40 : 0x00)); gfx_fill_rect_inset(dpi, { topLeft, bottomRight }, colour, INSET_RECT_F_60); // Figure out where the text should be positioned vertically. - topLeft.y = w->windowPos.y + widget.textTop(); + topLeft.y = w.windowPos.y + widget.textTop(); if (!active || gTextInput == nullptr) { @@ -1149,7 +1149,7 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti safe_strcpy(wrapped_string, widget.string, 512); gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5, FontSpriteBase::MEDIUM, &no_lines); gfx_draw_string_no_formatting( - dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w->colours[1], FontSpriteBase::MEDIUM }); + dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w.colours[1], FontSpriteBase::MEDIUM }); } return; } @@ -1160,7 +1160,7 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti // +13 for cursor when max length. gfx_wrap_string(wrapped_string, bottomRight.x - topLeft.x - 5 - 6, FontSpriteBase::MEDIUM, &no_lines); - gfx_draw_string_no_formatting(dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w->colours[1], FontSpriteBase::MEDIUM }); + gfx_draw_string_no_formatting(dpi, { topLeft.x + 2, topLeft.y }, wrapped_string, { w.colours[1], FontSpriteBase::MEDIUM }); size_t string_length = get_string_size(wrapped_string) - 1; @@ -1181,7 +1181,7 @@ static void WidgetTextBoxDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti if (gTextBoxFrameNo <= 15) { - colour = ColourMapA[w->colours[1]].mid_light; + colour = ColourMapA[w.colours[1]].mid_light; auto y = topLeft.y + (widget.height() - 1); gfx_fill_rect(dpi, { { cur_x, y }, { cur_x + width, y } }, colour + 5); } diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index 6b0435142d..ed3d0d6bd8 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -379,7 +379,7 @@ static void WindowScrollWheelInput(rct_window& w, int32_t scrollIndex, int32_t w scroll.h_left = std::min(std::max(0, scroll.h_left + wheel), size); } - WidgetScrollUpdateThumbs(&w, widgetIndex); + WidgetScrollUpdateThumbs(w, widgetIndex); widget_invalidate(&w, widgetIndex); } @@ -607,7 +607,7 @@ void WindowInitScrollWidgets(rct_window& w) if (widget->content & SCROLL_VERTICAL) scroll.flags |= VSCROLLBAR_VISIBLE; - WidgetScrollUpdateThumbs(&w, widget_index); + WidgetScrollUpdateThumbs(w, widget_index); widget_index++; scroll_index++; @@ -640,7 +640,7 @@ void WindowDrawWidgets(rct_window& w, rct_drawpixelinfo* dpi) if (w.windowPos.y + widget->top < dpi->y + dpi->height && w.windowPos.y + widget->bottom >= dpi->y) { if (w.IsLegacy()) - WidgetDraw(dpi, &w, widgetIndex); + WidgetDraw(dpi, w, widgetIndex); else w.OnDrawWidget(widgetIndex, *dpi); } @@ -704,7 +704,7 @@ void Window::OnDraw(rct_drawpixelinfo& dpi) void Window::OnDrawWidget(rct_widgetindex widgetIndex, rct_drawpixelinfo& dpi) { - WidgetDraw(&dpi, this, widgetIndex); + WidgetDraw(&dpi, *this, widgetIndex); } void Window::InitScrollWidgets() diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index deb59cc71d..4ff74f25e6 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -469,7 +469,7 @@ namespace OpenRCT2::Ui::Windows { if (widget->type == WindowWidgetType::Scroll) { - WidgetScrollUpdateThumbs(this, widgetIndex); + WidgetScrollUpdateThumbs(*this, widgetIndex); } widgetIndex++; } diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 829c375add..ff55fb5096 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -491,7 +491,7 @@ public: int32_t outScrollArea{}; ScreenCoordsXY outScrollCoords{}; int32_t outScrollId{}; - WidgetScrollGetPart(this, &widget, screenCoords, outScrollCoords, &outScrollArea, &outScrollId); + WidgetScrollGetPart(*this, &widget, screenCoords, outScrollCoords, &outScrollArea, &outScrollId); if (outScrollArea == SCROLL_PART_VIEW) { const auto isInvented = outScrollId == 0; diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index d29855a42f..8a1f008328 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -983,7 +983,7 @@ public: const auto& widget = this->widgets[widgetIndex]; scrolls[scrollId].h_left = std::max(0, scrolls[scrollId].h_right - (widget.width() - 2)); - WidgetScrollUpdateThumbs(this, widgetIndex); + WidgetScrollUpdateThumbs(*this, widgetIndex); } void DrawTabImage(rct_drawpixelinfo& dpi, int32_t tabPage, int32_t spriteIndex) diff --git a/src/openrct2-ui/windows/Land.cpp b/src/openrct2-ui/windows/Land.cpp index 2341460a92..da9bd4792f 100644 --- a/src/openrct2-ui/windows/Land.cpp +++ b/src/openrct2-ui/windows/Land.cpp @@ -253,8 +253,8 @@ public: screenCoords = { windowPos.x + previewWidget->left, windowPos.y + previewWidget->top }; auto sprite = ImageId(gLandToolSize % 2 == 0 ? SPR_G2_MOUNTAIN_TOOL_EVEN : SPR_G2_MOUNTAIN_TOOL_ODD); gfx_draw_sprite(&dpi, sprite, screenCoords); - WidgetDraw(&dpi, this, WIDX_DECREMENT); - WidgetDraw(&dpi, this, WIDX_INCREMENT); + WidgetDraw(&dpi, *this, WIDX_DECREMENT); + WidgetDraw(&dpi, *this, WIDX_INCREMENT); } screenCoords = { windowPos.x + previewWidget->midX(), windowPos.y + previewWidget->bottom + 5 }; diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 47309110a3..4255c2dcac 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -962,7 +962,7 @@ private: scrolls[0].h_left = cx; scrolls[0].v_top = dx; - WidgetScrollUpdateThumbs(this, WIDX_MAP); + WidgetScrollUpdateThumbs(*this, WIDX_MAP); } void IncreaseMapSize() diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index 3d148f9879..4e42a05427 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -434,7 +434,7 @@ static void WindowNewRideRestoreScrollPositionForCurrentTab(rct_window* w) currentTabScroll = std::min(currentTabScroll, std::max(0, scrollHeight - listWidgetHeight)); w->scrolls[0].v_top = currentTabScroll; - WidgetScrollUpdateThumbs(w, WIDX_RIDE_LIST); + WidgetScrollUpdateThumbs(*w, WIDX_RIDE_LIST); } /** diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index f7e49ed1eb..7159c9fd6a 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -64,7 +64,7 @@ public: rct_widget* widget = &widgets[WIDX_SCROLL]; window_get_scroll_size(this, 0, &w, &h); scrolls[0].v_top = std::max(0, h - (widget->height() - 1)); - WidgetScrollUpdateThumbs(this, WIDX_SCROLL); + WidgetScrollUpdateThumbs(*this, WIDX_SCROLL); } void OnMouseUp(rct_widgetindex widgetIndex) override diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index d39f80551f..37ea1cc848 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -2137,7 +2137,7 @@ private: int32_t widgetSize = scroll.h_right - (widget.width() - 1); scroll.h_left = ceil(volume / 100.0f * widgetSize); - WidgetScrollUpdateThumbs(this, widgetIndex); + WidgetScrollUpdateThumbs(*this, widgetIndex); } static bool IsRCT1TitleMusicAvailable() diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index e4077143e5..adddad0851 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -5971,7 +5971,7 @@ static void WindowRideGraphsUpdate(rct_window* w) } w->scrolls[0].h_left = std::clamp(x, 0, w->scrolls[0].h_right - (widget->width() - 2)); - WidgetScrollUpdateThumbs(w, WIDX_GRAPH); + WidgetScrollUpdateThumbs(*w, WIDX_GRAPH); } /** diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 57aa5cb98d..14feb33706 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -322,7 +322,7 @@ public: ScreenCoordsXY scrollPos = {}; int32_t scrollArea = 0; int32_t scrollId = 0; - WidgetScrollGetPart(this, &widgets[WIDX_SCENERY_LIST], state->position, scrollPos, &scrollArea, &scrollId); + WidgetScrollGetPart(*this, &widgets[WIDX_SCENERY_LIST], state->position, scrollPos, &scrollArea, &scrollId); if (scrollArea == SCROLL_PART_VIEW) { const ScenerySelection scenery = GetSceneryIdByCursorPos(scrollPos); @@ -902,7 +902,7 @@ private: scrolls[SceneryContentScrollIndex].v_top = ContentRowsHeight(rowSelected); scrolls[SceneryContentScrollIndex].v_top = std::min(maxTop, scrolls[SceneryContentScrollIndex].v_top); - WidgetScrollUpdateThumbs(this, WIDX_SCENERY_LIST); + WidgetScrollUpdateThumbs(*this, WIDX_SCENERY_LIST); } SceneryItem ContentCountRowsWithSelectedItem(const size_t tabIndex) diff --git a/src/openrct2-ui/windows/ViewClipping.cpp b/src/openrct2-ui/windows/ViewClipping.cpp index a4cede52c3..9feed37ccf 100644 --- a/src/openrct2-ui/windows/ViewClipping.cpp +++ b/src/openrct2-ui/windows/ViewClipping.cpp @@ -254,7 +254,7 @@ public: void OnPrepareDraw() override { - WidgetScrollUpdateThumbs(this, WIDX_CLIP_HEIGHT_SLIDER); + WidgetScrollUpdateThumbs(*this, WIDX_CLIP_HEIGHT_SLIDER); rct_window* mainWindow = window_get_main(); if (mainWindow != nullptr) diff --git a/src/openrct2/interface/Widget.h b/src/openrct2/interface/Widget.h index dffaf3f3dc..fa2f8ba252 100644 --- a/src/openrct2/interface/Widget.h +++ b/src/openrct2/interface/Widget.h @@ -144,8 +144,8 @@ constexpr rct_widget MakeDropdownButtonWidget( return MakeWidget({ xPos, yPos }, { width, height }, WindowWidgetType::Button, colour, STR_DROPDOWN_GLYPH, tooltip); } -void WidgetScrollUpdateThumbs(rct_window* w, rct_widgetindex widget_index); -void WidgetDraw(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex widgetIndex); +void WidgetScrollUpdateThumbs(rct_window& w, rct_widgetindex widget_index); +void WidgetDraw(rct_drawpixelinfo* dpi, rct_window& w, rct_widgetindex widgetIndex); bool WidgetIsDisabled(const rct_window& w, rct_widgetindex widgetIndex); bool WidgetIsHoldable(const rct_window& w, rct_widgetindex widgetIndex); @@ -154,7 +154,7 @@ bool WidgetIsPressed(const rct_window& w, rct_widgetindex widgetIndex); bool WidgetIsHighlighted(const rct_window& w, rct_widgetindex widgetIndex); bool WidgetIsActiveTool(const rct_window& w, rct_widgetindex widgetIndex); void WidgetScrollGetPart( - rct_window* w, const rct_widget* widget, const ScreenCoordsXY& screenCoords, ScreenCoordsXY& retScreenCoords, + rct_window& w, const rct_widget* widget, const ScreenCoordsXY& screenCoords, ScreenCoordsXY& retScreenCoords, int32_t* output_scroll_area, int32_t* scroll_id); void WidgetSetEnabled(rct_window& w, rct_widgetindex widgetIndex, bool enabled); diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 22051053ba..254f721070 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -626,7 +626,7 @@ void window_update_scroll_widgets(rct_window* w) if (scrollPositionChanged) { - WidgetScrollUpdateThumbs(w, widgetIndex); + WidgetScrollUpdateThumbs(*w, widgetIndex); w->Invalidate(); } scrollIndex++; @@ -2195,10 +2195,10 @@ rct_windowclass window_get_classification(rct_window* window) * * rct2: 0x006EAF26 */ -void WidgetScrollUpdateThumbs(rct_window* w, rct_widgetindex widget_index) +void WidgetScrollUpdateThumbs(rct_window& w, rct_widgetindex widget_index) { - const auto& widget = w->widgets[widget_index]; - auto& scroll = w->scrolls[window_get_scroll_data_index(w, widget_index)]; + const auto& widget = w.widgets[widget_index]; + auto& scroll = w.scrolls[window_get_scroll_data_index(&w, widget_index)]; if (scroll.flags & HSCROLLBAR_VISIBLE) {