From fea24befc56ea4acd8c33c8678ea0fea240ae181 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Fri, 28 Dec 2012 16:10:44 -0500 Subject: [PATCH] WinRT: scaled relative mouse mode values from the native screen size to SDL's window size --- src/video/windowsrt/SDL_WinRTApp.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/video/windowsrt/SDL_WinRTApp.cpp b/src/video/windowsrt/SDL_WinRTApp.cpp index a3cd3a663..0026f229a 100644 --- a/src/video/windowsrt/SDL_WinRTApp.cpp +++ b/src/video/windowsrt/SDL_WinRTApp.cpp @@ -173,6 +173,14 @@ void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args) } } +static inline int _lround(float arg) { + if (arg >= 0.0f) { + return (int)floor(arg + 0.5f); + } else { + return (int)ceil(arg - 0.5f); + } +} + void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args) { if (m_sdlWindowData && m_useRelativeMouseMode) { @@ -229,9 +237,16 @@ void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args) // are compared to the values from OnMouseMoved in order to detect // when this bug is active. A suitable transformation could then be made to // OnMouseMoved's values. For now, however, the system-reported values are sent - // without transformation. + // to SDL with minimal transformation: from native screen coordinates (in DIPs) + // to SDL window coordinates. // - SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 1, args->MouseDelta.X, args->MouseDelta.Y); + const Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y); + const Point mouseDeltaInSDLWindowCoords = TransformCursor(mouseDeltaInDIPs); + SDL_SendMouseMotion( + m_sdlWindowData->sdlWindow, + 1, + _lround(mouseDeltaInSDLWindowCoords.X), + _lround(mouseDeltaInSDLWindowCoords.Y)); } }