From 06579b45d2ed41fb6714986328a18accc373fb9a Mon Sep 17 00:00:00 2001 From: mix Date: Wed, 27 Aug 2025 08:57:39 +0100 Subject: [PATCH] Calculate zoom to cursor based on mouse coordinates --- distribution/changelog.txt | 1 + src/openrct2/interface/Window.cpp | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 0886c28936..9795e4b203 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -9,6 +9,7 @@ - Change: [#23351] Diagonal sloped Go-Kart track can no longer be built without cheats if the karts do not have sprites for them. - Change: [#24606] Increase Misc Entity limit from 1600 to 3200. - Change: [#24974] Raise the Go-Karts maximum support height to allow 2 large sloped turns to be built on flat ground. +- Fix: [#12831] Zooming to cursor on land edges sometimes causes the camera to move to the wrong position. - Fix: [#16988] AppImage version does not show changelog. - Fix: [#18048] Play music from all ride's stations. - Fix: [#19137] Non-inverted left corkscrew supports are incorrect at one angle (original bug). diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 08be8c8628..0341e15da2 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -490,15 +490,7 @@ static constexpr float kWindowScrollLocations[][2] = { if (v->zoom == zoomLevel) return; - // Zooming to cursor? Remember where we're pointing at the moment. - int32_t saved_map_x = 0; - int32_t saved_map_y = 0; - int32_t offset_x = 0; - int32_t offset_y = 0; - if (Config::Get().general.ZoomToCursor && atCursor) - { - WindowViewportGetMapCoordsByCursor(w, &saved_map_x, &saved_map_y, &offset_x, &offset_y); - } + const ZoomLevel previousZoomLevel = v->zoom; // Zoom in while (v->zoom > zoomLevel) @@ -516,10 +508,21 @@ static constexpr float kWindowScrollLocations[][2] = { w.savedViewPos.y -= v->ViewHeight() / 4; } - // Zooming to cursor? Centre around the tile we were hovering over just now. if (Config::Get().general.ZoomToCursor && atCursor) { - WindowViewportCentreTileAroundCursor(w, saved_map_x, saved_map_y, offset_x, offset_y); + const auto mouseCoords = ContextGetCursorPositionScaled() - v->pos; + const int32_t diffX = (mouseCoords.x - (zoomLevel.ApplyInversedTo(v->ViewWidth()) / 2)); + const int32_t diffY = (mouseCoords.y - (zoomLevel.ApplyInversedTo(v->ViewHeight()) / 2)); + if (previousZoomLevel > zoomLevel) + { + w.savedViewPos.x += zoomLevel.ApplyTo(diffX); + w.savedViewPos.y += zoomLevel.ApplyTo(diffY); + } + else + { + w.savedViewPos.x -= previousZoomLevel.ApplyTo(diffX); + w.savedViewPos.y -= previousZoomLevel.ApplyTo(diffY); + } } // HACK: Prevents the redraw from failing when there is