diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index e6dfd8e9f9..4e650679a9 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -612,16 +612,17 @@ static void input_scroll_begin(rct_window* w, rct_widgetindex widgetIndex, Scree gTooltipCursorX = screenCoords.x; gTooltipCursorY = screenCoords.y; - int32_t eax, ebx, scroll_area, scroll_id; + int32_t scroll_area, scroll_id; + ScreenCoordsXY scrollCoords; scroll_id = 0; // safety - widget_scroll_get_part(w, widget, screenCoords.x, screenCoords.y, &eax, &ebx, &scroll_area, &scroll_id); + widget_scroll_get_part(w, widget, screenCoords, scrollCoords, &scroll_area, &scroll_id); _currentScrollArea = scroll_area; _currentScrollIndex = scroll_id; window_event_unknown_15_call(w, scroll_id, scroll_area); if (scroll_area == SCROLL_PART_VIEW) { - window_event_scroll_mousedown_call(w, scroll_id, ScreenCoordsXY(eax, ebx)); + window_event_scroll_mousedown_call(w, scroll_id, scrollCoords); return; } @@ -675,7 +676,6 @@ static void input_scroll_continue(rct_window* w, rct_widgetindex widgetIndex, Sc { rct_widget* widget; int32_t scroll_part, scroll_id; - int32_t x2, y2; assert(w != nullptr); @@ -687,7 +687,8 @@ static void input_scroll_continue(rct_window* w, rct_widgetindex widgetIndex, Sc return; } - widget_scroll_get_part(w, widget, screenCoords.x, screenCoords.y, &x2, &y2, &scroll_part, &scroll_id); + ScreenCoordsXY newScreenCoords; + widget_scroll_get_part(w, widget, screenCoords, newScreenCoords, &scroll_part, &scroll_id); if (_currentScrollArea == SCROLL_PART_HSCROLLBAR_THUMB) { @@ -705,9 +706,6 @@ static void input_scroll_continue(rct_window* w, rct_widgetindex widgetIndex, Sc return; } - screenCoords.x = x2; - screenCoords.y = y2; - if (scroll_part != _currentScrollArea) { invalidate_scroll(); @@ -717,7 +715,7 @@ static void input_scroll_continue(rct_window* w, rct_widgetindex widgetIndex, Sc switch (scroll_part) { case SCROLL_PART_VIEW: - window_event_scroll_mousedrag_call(w, scroll_id, screenCoords); + window_event_scroll_mousedrag_call(w, scroll_id, newScreenCoords); break; case SCROLL_PART_HSCROLLBAR_LEFT: input_scroll_part_update_hleft(w, widgetIndex, scroll_id); @@ -928,14 +926,15 @@ static void input_widget_over(ScreenCoordsXY screenCoords, rct_window* w, rct_wi if (w != nullptr && widgetIndex != -1 && widget->type == WWT_SCROLL) { - int32_t eax, ebx, scroll_part, edx; - widget_scroll_get_part(w, widget, screenCoords.x, screenCoords.y, &eax, &ebx, &scroll_part, &edx); + int32_t scroll_part, scrollId; + ScreenCoordsXY newScreenCoords; + widget_scroll_get_part(w, widget, screenCoords, newScreenCoords, &scroll_part, &scrollId); if (scroll_part != SCROLL_PART_VIEW) window_tooltip_close(); else { - window_event_scroll_mouseover_call(w, edx, ScreenCoordsXY(eax, ebx)); + window_event_scroll_mouseover_call(w, scrollId, newScreenCoords); input_update_tooltip(w, widgetIndex, screenCoords); } } @@ -1154,10 +1153,9 @@ void process_mouse_over(ScreenCoordsXY screenCoords) case WWT_SCROLL: { int32_t output_scroll_area, scroll_id; - int32_t scroll_x, scroll_y; + ScreenCoordsXY scrollCoords; widget_scroll_get_part( - window, &window->widgets[widgetId], screenCoords.x, screenCoords.y, &scroll_x, &scroll_y, - &output_scroll_area, &scroll_id); + window, &window->widgets[widgetId], screenCoords, scrollCoords, &output_scroll_area, &scroll_id); cursorId = scroll_id; if (output_scroll_area != SCROLL_PART_VIEW) { @@ -1165,7 +1163,7 @@ void process_mouse_over(ScreenCoordsXY screenCoords) break; } // Same as default but with scroll_x/y - cursorId = window_event_cursor_call(window, widgetId, ScreenCoordsXY(scroll_x, scroll_y)); + cursorId = window_event_cursor_call(window, widgetId, scrollCoords); if (cursorId == -1) cursorId = CURSOR_ARROW; break; diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 48a291ab54..f1821fd06e 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -869,8 +869,8 @@ bool widget_is_active_tool(rct_window* w, rct_widgetindex widgetIndex) * edi: widget */ void widget_scroll_get_part( - rct_window* w, rct_widget* widget, int32_t x, int32_t y, int32_t* output_x, int32_t* output_y, int32_t* output_scroll_area, - int32_t* scroll_id) + rct_window* w, rct_widget* widget, 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++) @@ -881,7 +881,7 @@ void widget_scroll_get_part( } } - if ((w->scrolls[*scroll_id].flags & HSCROLLBAR_VISIBLE) && y >= (w->y + widget->bottom - 11)) + if ((w->scrolls[*scroll_id].flags & HSCROLLBAR_VISIBLE) && screenCoords.y >= (w->y + widget->bottom - 11)) { // horizontal scrollbar int32_t rightOffset = 0; @@ -892,23 +892,23 @@ void widget_scroll_get_part( rightOffset = 11; } - if (x <= iteratorLeft) + if (screenCoords.x <= iteratorLeft) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_LEFT; } - else if (x >= iteratorRight + rightOffset) + else if (screenCoords.x >= iteratorRight + rightOffset) { *output_scroll_area = SCROLL_PART_NONE; } - else if (x >= iteratorRight + rightOffset - 10) + else if (screenCoords.x >= iteratorRight + rightOffset - 10) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT; } - else if (x < (widget->left + w->x + w->scrolls[*scroll_id].h_thumb_left)) + else if (screenCoords.x < (widget->left + w->x + w->scrolls[*scroll_id].h_thumb_left)) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_LEFT_TROUGH; } - else if (x > (widget->left + w->x + w->scrolls[*scroll_id].h_thumb_right)) + else if (screenCoords.x > (widget->left + w->x + w->scrolls[*scroll_id].h_thumb_right)) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT_TROUGH; } @@ -917,7 +917,7 @@ void widget_scroll_get_part( *output_scroll_area = SCROLL_PART_HSCROLLBAR_THUMB; } } - else if ((w->scrolls[*scroll_id].flags & VSCROLLBAR_VISIBLE) && (x >= w->x + widget->right - 11)) + else if ((w->scrolls[*scroll_id].flags & VSCROLLBAR_VISIBLE) && (screenCoords.x >= w->x + widget->right - 11)) { // vertical scrollbar int32_t bottomOffset = 0; @@ -928,23 +928,23 @@ void widget_scroll_get_part( bottomOffset = 11; } - if (y <= iteratorTop) + if (screenCoords.y <= iteratorTop) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_TOP; } - else if (y >= (iteratorBottom - bottomOffset)) + else if (screenCoords.y >= (iteratorBottom - bottomOffset)) { *output_scroll_area = SCROLL_PART_NONE; } - else if (y >= (iteratorBottom - bottomOffset - 10)) + else if (screenCoords.y >= (iteratorBottom - bottomOffset - 10)) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM; } - else if (y < (widget->top + w->y + w->scrolls[*scroll_id].v_thumb_top)) + else if (screenCoords.y < (widget->top + w->y + w->scrolls[*scroll_id].v_thumb_top)) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_TOP_TROUGH; } - else if (y > (widget->top + w->y + w->scrolls[*scroll_id].v_thumb_bottom)) + else if (screenCoords.y > (widget->top + w->y + w->scrolls[*scroll_id].v_thumb_bottom)) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM_TROUGH; } @@ -957,18 +957,18 @@ void widget_scroll_get_part( { // view *output_scroll_area = SCROLL_PART_VIEW; - *output_x = x - widget->left; - *output_y = y - widget->top; - *output_x -= w->x; - *output_y -= w->y; - if (*output_x <= 0 || *output_y <= 0) + retScreenCoords.x = screenCoords.x - widget->left; + retScreenCoords.y = screenCoords.y - widget->top; + retScreenCoords.x -= w->x; + retScreenCoords.y -= w->y; + if (retScreenCoords.x <= 0 || retScreenCoords.y <= 0) { *output_scroll_area = SCROLL_PART_NONE; } else { - *output_x += w->scrolls[*scroll_id].h_left - 1; - *output_y += w->scrolls[*scroll_id].v_top - 1; + retScreenCoords.x += w->scrolls[*scroll_id].h_left - 1; + retScreenCoords.y += w->scrolls[*scroll_id].v_top - 1; } } } diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 08fea90f05..92e9bf4d16 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -271,13 +271,14 @@ static ResearchItem* get_research_item_at(int32_t x, int32_t y, int32_t* outScro if (widgetIndex == WIDX_PRE_RESEARCHED_SCROLL || widgetIndex == WIDX_RESEARCH_ORDER_SCROLL) { gPressedWidget.widget_index = widgetIndex; - int32_t outX, outY, outScrollArea; - widget_scroll_get_part(w, widget, x, y, &outX, &outY, &outScrollArea, outScrollId); + int32_t outScrollArea; + ScreenCoordsXY outScrollCoords; + widget_scroll_get_part(w, widget, ScreenCoordsXY(x, y), outScrollCoords, &outScrollArea, outScrollId); if (outScrollArea == SCROLL_PART_VIEW) { *outScrollId = *outScrollId == 0 ? 0 : 1; - int32_t scrollY = y - (w->y + widget->top) + w->scrolls[*outScrollId].v_top + 5; + int32_t scrollY = outScrollCoords.y + 6; return window_editor_inventions_list_get_item_from_scroll_y_include_seps(*outScrollId, scrollY); } } diff --git a/src/openrct2/interface/Widget.h b/src/openrct2/interface/Widget.h index e4b04956a7..2cc91a5a9a 100644 --- a/src/openrct2/interface/Widget.h +++ b/src/openrct2/interface/Widget.h @@ -67,8 +67,8 @@ bool widget_is_pressed(rct_window* w, rct_widgetindex widgetIndex); bool widget_is_highlighted(rct_window* w, rct_widgetindex widgetIndex); bool widget_is_active_tool(rct_window* w, rct_widgetindex widgetIndex); void widget_scroll_get_part( - rct_window* w, rct_widget* widget, int32_t x, int32_t y, int32_t* output_x, int32_t* output_y, int32_t* output_scroll_area, - int32_t* scroll_id); + rct_window* w, rct_widget* widget, ScreenCoordsXY screenCoords, ScreenCoordsXY& retScreenCoords, + int32_t* output_scroll_area, int32_t* scroll_id); void widget_set_enabled(rct_window* w, rct_widgetindex widgetIndex, bool enabled); void widget_set_checkbox_value(rct_window* w, rct_widgetindex widgetIndex, int32_t value);