From 9fa355cb8c37eecb02ceb9218903302dfb37f66c Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 18 Nov 2019 19:13:32 -0300 Subject: [PATCH] Make window_event_list use Coords for moved and cursor (#10258) --- .../windows/EditorInventionsList.cpp | 29 ++++++++++--------- src/openrct2-ui/windows/GameBottomToolbar.cpp | 4 +-- src/openrct2-ui/windows/TitleMenu.cpp | 4 +-- src/openrct2/interface/Window.cpp | 4 +-- src/openrct2/interface/Window.h | 4 +-- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 25afd461ba..2f111fc092 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -75,13 +75,13 @@ static void window_editor_inventions_list_update(rct_window *w); static void window_editor_inventions_list_scrollgetheight(rct_window *w, int32_t scrollIndex, int32_t *width, int32_t *height); static void window_editor_inventions_list_scrollmousedown(rct_window *w, int32_t scrollIndex, ScreenCoordsXY screenCoords); static void window_editor_inventions_list_scrollmouseover(rct_window *w, int32_t scrollIndex, ScreenCoordsXY screenCoords); -static void window_editor_inventions_list_cursor(rct_window *w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t *cursorId); +static void window_editor_inventions_list_cursor(rct_window *w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t *cursorId); static void window_editor_inventions_list_invalidate(rct_window *w); static void window_editor_inventions_list_paint(rct_window *w, rct_drawpixelinfo *dpi); static void window_editor_inventions_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int32_t scrollIndex); -static void window_editor_inventions_list_drag_cursor(rct_window *w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t *cursorId); -static void window_editor_inventions_list_drag_moved(rct_window* w, int32_t x, int32_t y); +static void window_editor_inventions_list_drag_cursor(rct_window *w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t *cursorId); +static void window_editor_inventions_list_drag_moved(rct_window* w, ScreenCoordsXY screenCoords); static void window_editor_inventions_list_drag_paint(rct_window *w, rct_drawpixelinfo *dpi); static rct_string_id window_editor_inventions_list_prepare_name(const ResearchItem * researchItem, bool withGap); @@ -261,19 +261,20 @@ static ResearchItem* window_editor_inventions_list_get_item_from_scroll_y_includ return nullptr; } -static ResearchItem* get_research_item_at(int32_t x, int32_t y, int32_t* outScrollId) +static ResearchItem* get_research_item_at(ScreenCoordsXY screenCoords, int32_t* outScrollId) { rct_window* w = window_find_by_class(WC_EDITOR_INVENTION_LIST); - if (w != nullptr && w->x <= x && w->y < y && w->x + w->width > x && w->y + w->height > y) + if (w != nullptr && w->x <= screenCoords.x && w->y < screenCoords.y && w->x + w->width > screenCoords.x + && w->y + w->height > screenCoords.y) { - rct_widgetindex widgetIndex = window_find_widget_from_point(w, ScreenCoordsXY(x, y)); + rct_widgetindex widgetIndex = window_find_widget_from_point(w, screenCoords); rct_widget* widget = &w->widgets[widgetIndex]; if (widgetIndex == WIDX_PRE_RESEARCHED_SCROLL || widgetIndex == WIDX_RESEARCH_ORDER_SCROLL) { gPressedWidget.widget_index = widgetIndex; int32_t outScrollArea; ScreenCoordsXY outScrollCoords; - widget_scroll_get_part(w, widget, ScreenCoordsXY(x, y), outScrollCoords, &outScrollArea, outScrollId); + widget_scroll_get_part(w, widget, screenCoords, outScrollCoords, &outScrollArea, outScrollId); if (outScrollArea == SCROLL_PART_VIEW) { *outScrollId = *outScrollId == 0 ? 0 : 1; @@ -464,7 +465,7 @@ static void window_editor_inventions_list_scrollmouseover(rct_window* w, int32_t * rct2: 0x00685291 */ static void window_editor_inventions_list_cursor( - rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t* cursorId) + rct_window* w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t* cursorId) { ResearchItem* researchItem; int32_t scrollIndex; @@ -482,7 +483,7 @@ static void window_editor_inventions_list_cursor( } // Use the open hand as cursor for items that can be picked up - researchItem = window_editor_inventions_list_get_item_from_scroll_y(scrollIndex, y); + researchItem = window_editor_inventions_list_get_item_from_scroll_y(scrollIndex, screenCoords.y); if (researchItem != nullptr && !research_item_is_always_researched(researchItem)) { *cursorId = CURSOR_HAND_OPEN; @@ -765,13 +766,13 @@ static void window_editor_inventions_list_drag_open(ResearchItem* researchItem) * rct2: 0x0068549C */ static void window_editor_inventions_list_drag_cursor( - rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t* cursorId) + rct_window* w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t* cursorId) { rct_window* inventionListWindow = window_find_by_class(WC_EDITOR_INVENTION_LIST); if (inventionListWindow != nullptr) { int32_t scrollId; - ResearchItem* researchItem = get_research_item_at(x, y, &scrollId); + ResearchItem* researchItem = get_research_item_at(screenCoords, &scrollId); if (researchItem != inventionListWindow->research_item) { inventionListWindow->Invalidate(); @@ -785,7 +786,7 @@ static void window_editor_inventions_list_drag_cursor( * * rct2: 0x00685412 */ -static void window_editor_inventions_list_drag_moved(rct_window* w, int32_t x, int32_t y) +static void window_editor_inventions_list_drag_moved(rct_window* w, ScreenCoordsXY screenCoords) { ResearchItem* researchItem; @@ -793,8 +794,8 @@ static void window_editor_inventions_list_drag_moved(rct_window* w, int32_t x, i // Skip always researched items, so that the dragged item gets placed underneath them do { - researchItem = get_research_item_at(x, y, &scrollId); - y += LIST_ROW_HEIGHT; + researchItem = get_research_item_at(screenCoords, &scrollId); + screenCoords.y += LIST_ROW_HEIGHT; } while (researchItem != nullptr && research_item_is_always_researched(researchItem)); if (scrollId != -1) diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 285efc300a..bfa64f9c5e 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -72,7 +72,7 @@ static void window_game_bottom_toolbar_tooltip(rct_window* w, rct_widgetindex wi static void window_game_bottom_toolbar_invalidate(rct_window *w); static void window_game_bottom_toolbar_paint(rct_window *w, rct_drawpixelinfo *dpi); static void window_game_bottom_toolbar_update(rct_window* w); -static void window_game_bottom_toolbar_cursor(rct_window *w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t *cursorId); +static void window_game_bottom_toolbar_cursor(rct_window *w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t *cursorId); static void window_game_bottom_toolbar_unknown05(rct_window *w); static void window_game_bottom_toolbar_draw_left_panel(rct_drawpixelinfo *dpi, rct_window *w); @@ -712,7 +712,7 @@ static void window_game_bottom_toolbar_update(rct_window* w) * rct2: 0x0066C644 */ static void window_game_bottom_toolbar_cursor( - rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t* cursorId) + rct_window* w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t* cursorId) { switch (widgetIndex) { diff --git a/src/openrct2-ui/windows/TitleMenu.cpp b/src/openrct2-ui/windows/TitleMenu.cpp index 9a5bbc31dc..2914fa50f4 100644 --- a/src/openrct2-ui/windows/TitleMenu.cpp +++ b/src/openrct2-ui/windows/TitleMenu.cpp @@ -41,7 +41,7 @@ static rct_widget window_title_menu_widgets[] = { static void window_title_menu_mouseup(rct_window *w, rct_widgetindex widgetIndex); static void window_title_menu_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget); static void window_title_menu_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex); -static void window_title_menu_cursor(rct_window *w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t *cursorId); +static void window_title_menu_cursor(rct_window *w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t *cursorId); static void window_title_menu_paint(rct_window *w, rct_drawpixelinfo *dpi); static rct_window_event_list window_title_menu_events = { @@ -217,7 +217,7 @@ static void window_title_menu_dropdown(rct_window* w, rct_widgetindex widgetInde } } -static void window_title_menu_cursor(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y, int32_t* cursorId) +static void window_title_menu_cursor(rct_window* w, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords, int32_t* cursorId) { gTooltipTimeout = 2000; } diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 5678335e47..4ad02c5ee2 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -1526,14 +1526,14 @@ int32_t window_event_cursor_call(rct_window* w, rct_widgetindex widgetIndex, Scr { int32_t cursorId = CURSOR_ARROW; if (w->event_handlers->cursor != nullptr) - w->event_handlers->cursor(w, widgetIndex, screenCoords.x, screenCoords.y, &cursorId); + w->event_handlers->cursor(w, widgetIndex, screenCoords, &cursorId); return cursorId; } void window_event_moved_call(rct_window* w, ScreenCoordsXY screenCoords) { if (w->event_handlers->moved != nullptr) - w->event_handlers->moved(w, screenCoords.x, screenCoords.y); + w->event_handlers->moved(w, screenCoords); } void window_event_invalidate_call(rct_window* w) diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 4f81b8bb11..63a986e309 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -194,8 +194,8 @@ struct rct_window_event_list void (*viewport_rotate)(struct rct_window*); void (*unknown_15)(struct rct_window*, int32_t, int32_t); void (*tooltip)(struct rct_window*, rct_widgetindex, rct_string_id*); - void (*cursor)(struct rct_window*, rct_widgetindex, int32_t, int32_t, int32_t*); - void (*moved)(struct rct_window*, int32_t, int32_t); + void (*cursor)(struct rct_window*, rct_widgetindex, ScreenCoordsXY, int32_t*); + void (*moved)(struct rct_window*, ScreenCoordsXY); void (*invalidate)(struct rct_window*); void (*paint)(struct rct_window*, rct_drawpixelinfo*); void (*scroll_paint)(struct rct_window*, rct_drawpixelinfo*, int32_t);