diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 44a78dd9d1..5220802ee5 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -76,23 +76,23 @@ void InputStateWidgetPressed( const ScreenCoordsXY& screenCoords, MouseState state, rct_widgetindex widgetIndex, rct_window* w, rct_widget* widget); void SetCursor(CursorID cursor_id); static void InputWindowPositionContinue( - rct_window* w, const ScreenCoordsXY& lastScreenCoords, const ScreenCoordsXY& newScreenCoords); -static void InputWindowPositionEnd(rct_window* w, const ScreenCoordsXY& screenCoords); -static void InputWindowResizeBegin(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); -static void InputWindowResizeContinue(rct_window* w, const ScreenCoordsXY& screenCoords); + rct_window& w, const ScreenCoordsXY& lastScreenCoords, const ScreenCoordsXY& newScreenCoords); +static void InputWindowPositionEnd(rct_window& w, const ScreenCoordsXY& screenCoords); +static void InputWindowResizeBegin(rct_window& w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); +static void InputWindowResizeContinue(rct_window& w, const ScreenCoordsXY& screenCoords); static void InputWindowResizeEnd(); -static void InputViewportDragBegin(rct_window* w); +static void InputViewportDragBegin(rct_window& w); static void InputViewportDragContinue(); static void InputViewportDragEnd(); -static void InputScrollBegin(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); -static void InputScrollContinue(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); +static void InputScrollBegin(rct_window& w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); +static void InputScrollContinue(rct_window& w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); static void InputScrollEnd(); -static void InputScrollPartUpdateHThumb(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t scroll_id); -static void InputScrollPartUpdateHLeft(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id); -static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id); -static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetIndex, int32_t y, int32_t scroll_id); -static void InputScrollPartUpdateVTop(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id); -static void InputScrollPartUpdateVBottom(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id); +static void InputScrollPartUpdateHThumb(rct_window& w, rct_widgetindex widgetIndex, int32_t x, int32_t scroll_id); +static void InputScrollPartUpdateHLeft(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id); +static void InputScrollPartUpdateHRight(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id); +static void InputScrollPartUpdateVThumb(rct_window& w, rct_widgetindex widgetIndex, int32_t y, int32_t scroll_id); +static void InputScrollPartUpdateVTop(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id); +static void InputScrollPartUpdateVBottom(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id); static void InputUpdateTooltip(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords); #pragma region Mouse input @@ -307,7 +307,7 @@ static void GameHandleInputMouse(const ScreenCoordsXY& screenCoords, MouseState case WindowWidgetType::Viewport: if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_MANAGER | SCREEN_FLAGS_TITLE_DEMO))) { - InputViewportDragBegin(w); + InputViewportDragBegin(*w); } break; case WindowWidgetType::Scroll: @@ -335,10 +335,10 @@ static void GameHandleInputMouse(const ScreenCoordsXY& screenCoords, MouseState } else { - InputWindowPositionContinue(w, gInputDragLast, screenCoords); + InputWindowPositionContinue(*w, gInputDragLast, screenCoords); if (state == MouseState::LeftRelease) { - InputWindowPositionEnd(w, screenCoords); + InputWindowPositionEnd(*w, screenCoords); } } break; @@ -421,7 +421,7 @@ static void GameHandleInputMouse(const ScreenCoordsXY& screenCoords, MouseState switch (state) { case MouseState::Released: - InputScrollContinue(w, widgetIndex, screenCoords); + InputScrollContinue(*w, widgetIndex, screenCoords); break; case MouseState::LeftRelease: InputScrollEnd(); @@ -447,7 +447,7 @@ static void GameHandleInputMouse(const ScreenCoordsXY& screenCoords, MouseState } if (state == MouseState::Released || state == MouseState::LeftRelease) { - InputWindowResizeContinue(w, screenCoords); + InputWindowResizeContinue(*w, screenCoords); } } break; @@ -469,42 +469,42 @@ void InputWindowPositionBegin(rct_window* w, rct_widgetindex widgetIndex, const } static void InputWindowPositionContinue( - rct_window* w, const ScreenCoordsXY& lastScreenCoords, const ScreenCoordsXY& newScreenCoords) + rct_window& w, const ScreenCoordsXY& lastScreenCoords, const ScreenCoordsXY& newScreenCoords) { int32_t snapProximity; - snapProximity = (w->flags & WF_NO_SNAPPING) ? 0 : gConfigGeneral.window_snap_proximity; - window_move_and_snap(*w, newScreenCoords - lastScreenCoords, snapProximity); + snapProximity = (w.flags & WF_NO_SNAPPING) ? 0 : gConfigGeneral.window_snap_proximity; + window_move_and_snap(w, newScreenCoords - lastScreenCoords, snapProximity); } -static void InputWindowPositionEnd(rct_window* w, const ScreenCoordsXY& screenCoords) +static void InputWindowPositionEnd(rct_window& w, const ScreenCoordsXY& screenCoords) { _inputState = InputState::Normal; gTooltipTimeout = 0; gTooltipWidget = _dragWidget; - window_event_moved_call(w, screenCoords); + window_event_moved_call(&w, screenCoords); } -static void InputWindowResizeBegin(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) +static void InputWindowResizeBegin(rct_window& w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) { _inputState = InputState::Resizing; gInputDragLast = screenCoords; - _dragWidget.window_classification = w->classification; - _dragWidget.window_number = w->number; + _dragWidget.window_classification = w.classification; + _dragWidget.window_number = w.number; _dragWidget.widget_index = widgetIndex; - _originalWindowWidth = w->width; - _originalWindowHeight = w->height; + _originalWindowWidth = w.width; + _originalWindowHeight = w.height; } -static void InputWindowResizeContinue(rct_window* w, const ScreenCoordsXY& screenCoords) +static void InputWindowResizeContinue(rct_window& w, const ScreenCoordsXY& screenCoords) { if (screenCoords.y < static_cast(context_get_height()) - 2) { auto differentialCoords = screenCoords - gInputDragLast; - int32_t targetWidth = _originalWindowWidth + differentialCoords.x - w->width; - int32_t targetHeight = _originalWindowHeight + differentialCoords.y - w->height; + int32_t targetWidth = _originalWindowWidth + differentialCoords.x - w.width; + int32_t targetHeight = _originalWindowHeight + differentialCoords.y - w.height; - window_resize(*w, targetWidth, targetHeight); + window_resize(w, targetWidth, targetHeight); } } @@ -519,18 +519,18 @@ static void InputWindowResizeEnd() #pragma region Viewport dragging -static void InputViewportDragBegin(rct_window* w) +static void InputViewportDragBegin(rct_window& w) { - w->flags &= ~WF_SCROLLING_TO_LOCATION; + w.flags &= ~WF_SCROLLING_TO_LOCATION; _inputState = InputState::ViewportRight; - _dragWidget.window_classification = w->classification; - _dragWidget.window_number = w->number; + _dragWidget.window_classification = w.classification; + _dragWidget.window_number = w.number; _ticksSinceDragStart = 0; auto cursorPosition = context_get_cursor_position(); gInputDragLast = cursorPosition; context_hide_cursor(); - window_unfollow_sprite(w); + window_unfollow_sprite(&w); // gInputFlags |= INPUT_FLAG_5; } @@ -603,32 +603,32 @@ static void InputViewportDragEnd() #pragma region Scroll bars -static void InputScrollBegin(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) +static void InputScrollBegin(rct_window& w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) { - const auto& widget = w->widgets[widgetIndex]; + const auto& widget = w.widgets[widgetIndex]; _inputState = InputState::ScrollLeft; - gPressedWidget.window_classification = w->classification; - gPressedWidget.window_number = w->number; + gPressedWidget.window_classification = w.classification; + gPressedWidget.window_number = w.number; gPressedWidget.widget_index = widgetIndex; gTooltipCursor = screenCoords; 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; - window_event_unknown_15_call(w, scroll_id, scroll_area); + window_event_unknown_15_call(&w, scroll_id, scroll_area); if (scroll_area == SCROLL_PART_VIEW) { - window_event_scroll_mousedown_call(w, scroll_id, scrollCoords); + window_event_scroll_mousedown_call(&w, scroll_id, scrollCoords); return; } - const auto& widg = w->widgets[widgetIndex]; - auto& scroll = w->scrolls[scroll_id]; + const auto& widg = w.widgets[widgetIndex]; + auto& scroll = w.scrolls[scroll_id]; int32_t widget_width = widg.width() - 1; if (scroll.flags & VSCROLLBAR_VISIBLE) @@ -669,18 +669,16 @@ static void InputScrollBegin(rct_window* w, rct_widgetindex widgetIndex, const S default: break; } - WidgetScrollUpdateThumbs(*w, widgetIndex); - window_invalidate_by_number(widgetIndex, w->classification); + WidgetScrollUpdateThumbs(w, widgetIndex); + window_invalidate_by_number(widgetIndex, w.classification); } -static void InputScrollContinue(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) +static void InputScrollContinue(rct_window& w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) { int32_t scroll_part, scroll_id; - assert(w != nullptr); - - const auto& widget = w->widgets[widgetIndex]; - if (w->classification != gPressedWidget.window_classification || w->number != gPressedWidget.window_number + const auto& widget = w.widgets[widgetIndex]; + if (w.classification != gPressedWidget.window_classification || w.number != gPressedWidget.window_number || widgetIndex != gPressedWidget.widget_index) { InvalidateScroll(); @@ -688,7 +686,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) { @@ -715,7 +713,7 @@ static void InputScrollContinue(rct_window* w, rct_widgetindex widgetIndex, cons switch (scroll_part) { case SCROLL_PART_VIEW: - window_event_scroll_mousedrag_call(w, scroll_id, newScreenCoords); + window_event_scroll_mousedrag_call(&w, scroll_id, newScreenCoords); break; case SCROLL_PART_HSCROLLBAR_LEFT: InputScrollPartUpdateHLeft(w, widgetIndex, scroll_id); @@ -742,12 +740,12 @@ static void InputScrollEnd() * * rct2: 0x006E98F2 */ -static void InputScrollPartUpdateHThumb(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t scroll_id) +static void InputScrollPartUpdateHThumb(rct_window& w, rct_widgetindex widgetIndex, int32_t x, int32_t scroll_id) { - const auto& widget = w->widgets[widgetIndex]; - auto& scroll = w->scrolls[scroll_id]; + const auto& widget = w.widgets[widgetIndex]; + auto& scroll = w.scrolls[scroll_id]; - if (window_find_by_number(w->classification, w->number) != nullptr) + if (window_find_by_number(w.classification, w.number) != nullptr) { int32_t newLeft; newLeft = scroll.h_right; @@ -772,8 +770,8 @@ static void InputScrollPartUpdateHThumb(rct_window* w, rct_widgetindex widgetInd if (newLeft > x) newLeft = x; scroll.h_left = newLeft; - WidgetScrollUpdateThumbs(*w, widgetIndex); - widget_invalidate_by_number(w->classification, w->number, widgetIndex); + WidgetScrollUpdateThumbs(w, widgetIndex); + widget_invalidate_by_number(w.classification, w.number, widgetIndex); } } @@ -781,13 +779,12 @@ static void InputScrollPartUpdateHThumb(rct_window* w, rct_widgetindex widgetInd * * rct2: 0x006E99A9 */ -static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetIndex, int32_t y, int32_t scroll_id) +static void InputScrollPartUpdateVThumb(rct_window& w, rct_widgetindex widgetIndex, int32_t y, int32_t scroll_id) { - assert(w != nullptr); - const auto& widget = w->widgets[widgetIndex]; - auto& scroll = w->scrolls[scroll_id]; + const auto& widget = w.widgets[widgetIndex]; + auto& scroll = w.scrolls[scroll_id]; - if (window_find_by_number(w->classification, w->number) != nullptr) + if (window_find_by_number(w.classification, w.number) != nullptr) { int32_t newTop; newTop = scroll.v_bottom; @@ -812,8 +809,8 @@ static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetInd if (newTop > y) newTop = y; scroll.v_top = newTop; - WidgetScrollUpdateThumbs(*w, widgetIndex); - widget_invalidate_by_number(w->classification, w->number, widgetIndex); + WidgetScrollUpdateThumbs(w, widgetIndex); + widget_invalidate_by_number(w.classification, w.number, widgetIndex); } } @@ -821,17 +818,16 @@ static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetInd * * rct2: 0x006E9A60 */ -static void InputScrollPartUpdateHLeft(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id) +static void InputScrollPartUpdateHLeft(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id) { - assert(w != nullptr); - if (window_find_by_number(w->classification, w->number) != nullptr) + if (window_find_by_number(w.classification, w.number) != nullptr) { - auto& scroll = w->scrolls[scroll_id]; + auto& scroll = w.scrolls[scroll_id]; scroll.flags |= HSCROLLBAR_LEFT_PRESSED; if (scroll.h_left >= 3) scroll.h_left -= 3; - WidgetScrollUpdateThumbs(*w, widgetIndex); - widget_invalidate_by_number(w->classification, w->number, widgetIndex); + WidgetScrollUpdateThumbs(w, widgetIndex); + widget_invalidate_by_number(w.classification, w.number, widgetIndex); } } @@ -839,13 +835,12 @@ static void InputScrollPartUpdateHLeft(rct_window* w, rct_widgetindex widgetInde * * rct2: 0x006E9ABF */ -static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id) +static void InputScrollPartUpdateHRight(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id) { - assert(w != nullptr); - const auto& widget = w->widgets[widgetIndex]; - if (window_find_by_number(w->classification, w->number) != nullptr) + const auto& widget = w.widgets[widgetIndex]; + if (window_find_by_number(w.classification, w.number) != nullptr) { - auto& scroll = w->scrolls[scroll_id]; + auto& scroll = w.scrolls[scroll_id]; scroll.flags |= HSCROLLBAR_RIGHT_PRESSED; scroll.h_left += 3; int32_t newLeft = widget.width() - 1; @@ -857,8 +852,8 @@ static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetInd newLeft = 0; if (scroll.h_left > newLeft) scroll.h_left = newLeft; - WidgetScrollUpdateThumbs(*w, widgetIndex); - widget_invalidate_by_number(w->classification, w->number, widgetIndex); + WidgetScrollUpdateThumbs(w, widgetIndex); + widget_invalidate_by_number(w.classification, w.number, widgetIndex); } } @@ -866,17 +861,16 @@ static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetInd * * rct2: 0x006E9C37 */ -static void InputScrollPartUpdateVTop(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id) +static void InputScrollPartUpdateVTop(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id) { - assert(w != nullptr); - if (window_find_by_number(w->classification, w->number) != nullptr) + if (window_find_by_number(w.classification, w.number) != nullptr) { - auto& scroll = w->scrolls[scroll_id]; + auto& scroll = w.scrolls[scroll_id]; scroll.flags |= VSCROLLBAR_UP_PRESSED; if (scroll.v_top >= 3) scroll.v_top -= 3; - WidgetScrollUpdateThumbs(*w, widgetIndex); - widget_invalidate_by_number(w->classification, w->number, widgetIndex); + WidgetScrollUpdateThumbs(w, widgetIndex); + widget_invalidate_by_number(w.classification, w.number, widgetIndex); } } @@ -884,13 +878,12 @@ static void InputScrollPartUpdateVTop(rct_window* w, rct_widgetindex widgetIndex * * rct2: 0x006E9C96 */ -static void InputScrollPartUpdateVBottom(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id) +static void InputScrollPartUpdateVBottom(rct_window& w, rct_widgetindex widgetIndex, int32_t scroll_id) { - assert(w != nullptr); - const auto& widget = w->widgets[widgetIndex]; - if (window_find_by_number(w->classification, w->number) != nullptr) + const auto& widget = w.widgets[widgetIndex]; + if (window_find_by_number(w.classification, w.number) != nullptr) { - auto& scroll = w->scrolls[scroll_id]; + auto& scroll = w.scrolls[scroll_id]; scroll.flags |= VSCROLLBAR_DOWN_PRESSED; scroll.v_top += 3; int32_t newTop = widget.height() - 1; @@ -902,8 +895,8 @@ static void InputScrollPartUpdateVBottom(rct_window* w, rct_widgetindex widgetIn newTop = 0; if (scroll.v_top > newTop) scroll.v_top = newTop; - WidgetScrollUpdateThumbs(*w, widgetIndex); - widget_invalidate_by_number(w->classification, w->number, widgetIndex); + WidgetScrollUpdateThumbs(w, widgetIndex); + widget_invalidate_by_number(w.classification, w.number, widgetIndex); } } @@ -1037,7 +1030,7 @@ static void InputWidgetLeft(const ScreenCoordsXY& screenCoords, rct_window* w, r case WindowWidgetType::Resize: if (window_can_resize(*w) && (screenCoords.x >= w->windowPos.x + w->width - 19 && screenCoords.y >= w->windowPos.y + w->height - 19)) - InputWindowResizeBegin(w, widgetIndex, screenCoords); + InputWindowResizeBegin(*w, widgetIndex, screenCoords); break; case WindowWidgetType::Viewport: _inputState = InputState::ViewportLeft; @@ -1058,7 +1051,7 @@ static void InputWidgetLeft(const ScreenCoordsXY& screenCoords, rct_window* w, r InputWindowPositionBegin(w, widgetIndex, screenCoords); break; case WindowWidgetType::Scroll: - InputScrollBegin(w, widgetIndex, screenCoords); + InputScrollBegin(*w, widgetIndex, screenCoords); break; default: if (!WidgetIsDisabled(*w, widgetIndex))