From 5137da295a55651fbf6beffaa717dc7552d0024e Mon Sep 17 00:00:00 2001 From: ruevs Date: Sun, 22 Nov 2020 19:58:46 +0200 Subject: [PATCH] Win32: Mouse wheel zooming always remains properly centered On scroll wheel events convert the mouse coordinates from screen to client area so that scroll wheel zooming remains centered irrespective of the window position. Fixes https://github.com/solvespace/solvespace/issues/806 --- src/platform/guiwin.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/platform/guiwin.cpp b/src/platform/guiwin.cpp index 43e7a59..cfa4b7e 100644 --- a/src/platform/guiwin.cpp +++ b/src/platform/guiwin.cpp @@ -907,8 +907,8 @@ public: // Make the mousewheel work according to which window the mouse is // over, not according to which window is active. POINT pt; - pt.x = LOWORD(lParam); - pt.y = HIWORD(lParam); + pt.x = GET_X_LPARAM(lParam); + pt.y = GET_Y_LPARAM(lParam); HWND hWindowUnderMouse; sscheck(hWindowUnderMouse = WindowFromPoint(pt)); if(hWindowUnderMouse && hWindowUnderMouse != h) { @@ -917,6 +917,13 @@ public: break; } + // Convert the mouse coordinates from screen to client area so that + // scroll wheel zooming remains centered irrespective of the window + // position. + ScreenToClient(hWindowUnderMouse, &pt); + event.x = pt.x / pixelRatio; + event.y = pt.y / pixelRatio; + event.type = MouseEvent::Type::SCROLL_VERT; event.scrollDelta = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? 1 : -1; break;