From 2159fd282bcce723dd075c6e014974cde48c5dd2 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Fri, 18 Oct 2019 12:44:26 -0300 Subject: [PATCH] Use ScreenCoordsXY for Window functions (#10083) --- src/openrct2-ui/input/MouseInput.cpp | 6 +++--- src/openrct2-ui/windows/Tooltip.cpp | 25 +++++++++++++------------ src/openrct2-ui/windows/Window.h | 6 +++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index df05d25aad..e2f3f9b9bb 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -285,7 +285,7 @@ static void game_handle_input_mouse(int32_t x, int32_t y, int32_t state) switch (_inputState) { case INPUT_STATE_RESET: - window_tooltip_reset(x, y); + window_tooltip_reset(ScreenCoordsXY(x, y)); // fall-through case INPUT_STATE_NORMAL: switch (state) @@ -1428,7 +1428,7 @@ void input_state_widget_pressed( STR_COLOUR_LIGHT_PINK_TIP, }; - window_tooltip_show(colourTooltips[dropdown_index], x, y); + window_tooltip_show(colourTooltips[dropdown_index], ScreenCoordsXY(x, y)); } if (dropdown_index < DROPDOWN_ITEMS_MAX_SIZE && dropdown_is_disabled(dropdown_index)) @@ -1461,7 +1461,7 @@ static void input_update_tooltip(rct_window* w, rct_widgetindex widgetIndex, int if (_tooltipNotShownTicks > 50) { gTooltipTimeout = 0; - window_tooltip_open(w, widgetIndex, x, y); + window_tooltip_open(w, widgetIndex, ScreenCoordsXY(x, y)); } } } diff --git a/src/openrct2-ui/windows/Tooltip.cpp b/src/openrct2-ui/windows/Tooltip.cpp index fa5c25e7d5..3a5cd67281 100644 --- a/src/openrct2-ui/windows/Tooltip.cpp +++ b/src/openrct2-ui/windows/Tooltip.cpp @@ -63,17 +63,17 @@ static rct_window_event_list window_tooltip_events = { static utf8 _tooltipText[sizeof(gCommonStringFormatBuffer)]; static int16_t _tooltipNumLines; -void window_tooltip_reset(int32_t x, int32_t y) +void window_tooltip_reset(ScreenCoordsXY screenCoords) { - gTooltipCursorX = x; - gTooltipCursorY = y; + gTooltipCursorX = screenCoords.x; + gTooltipCursorY = screenCoords.y; gTooltipTimeout = 0; gTooltipWidget.window_classification = 255; input_set_state(INPUT_STATE_NORMAL); input_set_flag(INPUT_FLAG_4, false); } -void window_tooltip_show(rct_string_id id, int32_t x, int32_t y) +void window_tooltip_show(rct_string_id id, ScreenCoordsXY screenCoords) { rct_window* w; int32_t width, height; @@ -107,20 +107,21 @@ void window_tooltip_show(rct_string_id id, int32_t x, int32_t y) int32_t screenWidth = context_get_width(); int32_t screenHeight = context_get_height(); - x = std::clamp(x - (width / 2), 0, screenWidth - width); + screenCoords.x = std::clamp(screenCoords.x - (width / 2), 0, screenWidth - width); // TODO The cursor size will be relative to the window DPI. // The amount to offset the y should be adjusted. int32_t max_y = screenHeight - height; - y += 26; // Normally, we'd display the tooltip 26 lower - if (y > max_y) + screenCoords.y += 26; // Normally, we'd display the tooltip 26 lower + if (screenCoords.y > max_y) // If y is too large, the tooltip could be forced below the cursor if we'd just clamped y, // so we'll subtract a bit more - y -= height + 40; - y = std::clamp(y, 22, max_y); + screenCoords.y -= height + 40; + screenCoords.y = std::clamp(screenCoords.y, 22, max_y); - w = window_create(x, y, width, height, &window_tooltip_events, WC_TOOLTIP, WF_TRANSPARENT | WF_STICK_TO_FRONT); + w = window_create( + screenCoords.x, screenCoords.y, width, height, &window_tooltip_events, WC_TOOLTIP, WF_TRANSPARENT | WF_STICK_TO_FRONT); w->widgets = window_tooltip_widgets; reset_tooltip_not_shown(); @@ -130,7 +131,7 @@ void window_tooltip_show(rct_string_id id, int32_t x, int32_t y) * * rct2: 0x006EA10D */ -void window_tooltip_open(rct_window* widgetWindow, rct_widgetindex widgetIndex, int32_t x, int32_t y) +void window_tooltip_open(rct_window* widgetWindow, rct_widgetindex widgetIndex, ScreenCoordsXY screenCords) { rct_widget* widget; @@ -149,7 +150,7 @@ void window_tooltip_open(rct_window* widgetWindow, rct_widgetindex widgetIndex, if (window_event_tooltip_call(widgetWindow, widgetIndex) == STR_NONE) return; - window_tooltip_show(widget->tooltip, x, y); + window_tooltip_show(widget->tooltip, screenCords); } /** diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index 26f543f269..bd7e2a815a 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -164,7 +164,7 @@ void window_tile_inspector_clear_clipboard(); rct_window* window_editor_object_selection_open(); -void window_tooltip_reset(int32_t x, int32_t y); -void window_tooltip_show(rct_string_id id, int32_t x, int32_t y); -void window_tooltip_open(rct_window* widgetWindow, rct_widgetindex widgetIndex, int32_t x, int32_t y); +void window_tooltip_reset(ScreenCoordsXY screenCoords); +void window_tooltip_show(rct_string_id id, ScreenCoordsXY screenCoords); +void window_tooltip_open(rct_window* widgetWindow, rct_widgetindex widgetIndex, ScreenCoordsXY screenCoords); void window_tooltip_close();