From 502a15512b947ee5375826225db1713a97d6a23c Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Tue, 17 Dec 2019 23:21:12 -0300 Subject: [PATCH 1/2] Save mouse differential coords using ScreenCoordsXY --- src/openrct2-ui/input/MouseInput.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 272552450d..e090685e9a 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -484,13 +484,11 @@ static void input_window_resize_continue(rct_window* w, ScreenCoordsXY screenCoo { if (screenCoords.y < (int32_t)context_get_height() - 2) { - int32_t dx, dy, targetWidth, targetHeight; - dx = screenCoords.x - gInputDragLast.x; - dy = screenCoords.y - gInputDragLast.y; - targetWidth = _originalWindowWidth + dx; - targetHeight = _originalWindowHeight + dy; + auto differentialCoords = ScreenCoordsXY{ screenCoords.x - gInputDragLast.x, screenCoords.y - gInputDragLast.y }; + int32_t targetWidth = _originalWindowWidth + differentialCoords.x - w->width; + int32_t targetHeight = _originalWindowHeight + differentialCoords.y - w->height; - window_resize(w, targetWidth - w->width, targetHeight - w->height); + window_resize(w, targetWidth, targetHeight); } } @@ -522,15 +520,13 @@ static void input_viewport_drag_begin(rct_window* w) static void input_viewport_drag_continue() { - int32_t dx, dy; rct_window* w; rct_viewport* viewport; auto newDragCoords = context_get_cursor_position(); const CursorState* cursorState = context_get_cursor_state(); - dx = newDragCoords.x - gInputDragLast.x; - dy = newDragCoords.y - gInputDragLast.y; + auto differentialCoords = ScreenCoordsXY{ newDragCoords.x - gInputDragLast.x, newDragCoords.y - gInputDragLast.y }; w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number); // #3294: Window can be closed during a drag session, so just finish @@ -548,7 +544,7 @@ static void input_viewport_drag_continue() context_show_cursor(); _inputState = INPUT_STATE_RESET; } - else if (dx != 0 || dy != 0) + else if (differentialCoords.x != 0 || differentialCoords.y != 0) { if (!(w->flags & WF_NO_SCROLLING)) { @@ -558,17 +554,17 @@ static void input_viewport_drag_continue() // As the user moved the mouse, don't interpret it as right click in any case. _ticksSinceDragStart = 1000; - dx *= 1 << (viewport->zoom + 1); - dy *= 1 << (viewport->zoom + 1); + differentialCoords.x *= 1 << (viewport->zoom + 1); + differentialCoords.y *= 1 << (viewport->zoom + 1); if (gConfigGeneral.invert_viewport_drag) { - w->saved_view_x -= dx; - w->saved_view_y -= dy; + w->saved_view_x -= differentialCoords.x; + w->saved_view_y -= differentialCoords.y; } else { - w->saved_view_x += dx; - w->saved_view_y += dy; + w->saved_view_x += differentialCoords.x; + w->saved_view_y += differentialCoords.y; } } } From a5065e95c61b3d7f20fb70c0bab2525856e429f9 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 18 Dec 2019 23:57:57 -0300 Subject: [PATCH 2/2] Simplify MouseInput differential coords calculation --- src/openrct2-ui/input/MouseInput.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index e090685e9a..41af5765cb 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -484,7 +484,7 @@ static void input_window_resize_continue(rct_window* w, ScreenCoordsXY screenCoo { if (screenCoords.y < (int32_t)context_get_height() - 2) { - auto differentialCoords = ScreenCoordsXY{ screenCoords.x - gInputDragLast.x, screenCoords.y - gInputDragLast.y }; + auto differentialCoords = screenCoords - gInputDragLast; int32_t targetWidth = _originalWindowWidth + differentialCoords.x - w->width; int32_t targetHeight = _originalWindowHeight + differentialCoords.y - w->height; @@ -526,7 +526,7 @@ static void input_viewport_drag_continue() auto newDragCoords = context_get_cursor_position(); const CursorState* cursorState = context_get_cursor_state(); - auto differentialCoords = ScreenCoordsXY{ newDragCoords.x - gInputDragLast.x, newDragCoords.y - gInputDragLast.y }; + auto differentialCoords = newDragCoords - gInputDragLast; w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number); // #3294: Window can be closed during a drag session, so just finish