WinRT: scaled relative mouse mode values from the native screen size to SDL's window size
authorDavid Ludwig <dludwig@pobox.com>
Fri, 28 Dec 2012 16:10:44 -0500
changeset 83791237c440712b
parent 8378 357a8e1166e5
child 8380 b2c3f59e5127
WinRT: scaled relative mouse mode values from the native screen size to SDL's window size
src/video/windowsrt/SDL_WinRTApp.cpp
     1.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Fri Dec 28 13:24:36 2012 -0500
     1.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Fri Dec 28 16:10:44 2012 -0500
     1.3 @@ -173,6 +173,14 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +static inline int _lround(float arg) {
     1.8 +    if (arg >= 0.0f) {
     1.9 +        return (int)floor(arg + 0.5f);
    1.10 +    } else {
    1.11 +        return (int)ceil(arg - 0.5f);
    1.12 +    }
    1.13 +}
    1.14 +
    1.15  void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
    1.16  {
    1.17      if (m_sdlWindowData && m_useRelativeMouseMode) {
    1.18 @@ -229,9 +237,16 @@
    1.19          // are compared to the values from OnMouseMoved in order to detect
    1.20          // when this bug is active.  A suitable transformation could then be made to
    1.21          // OnMouseMoved's values.  For now, however, the system-reported values are sent
    1.22 -        // without transformation.
    1.23 +        // to SDL with minimal transformation: from native screen coordinates (in DIPs)
    1.24 +        // to SDL window coordinates.
    1.25          //
    1.26 -        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 1, args->MouseDelta.X, args->MouseDelta.Y);
    1.27 +        const Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
    1.28 +        const Point mouseDeltaInSDLWindowCoords = TransformCursor(mouseDeltaInDIPs);
    1.29 +        SDL_SendMouseMotion(
    1.30 +            m_sdlWindowData->sdlWindow,
    1.31 +            1,
    1.32 +            _lround(mouseDeltaInSDLWindowCoords.X),
    1.33 +            _lround(mouseDeltaInSDLWindowCoords.Y));
    1.34      }
    1.35  }
    1.36