WinRT: fixed incorrect cursor positions when using non-native screen resolutions
authorDavid Ludwig <dludwig@pobox.com>
Sun, 25 Nov 2012 23:27:12 -0500
changeset 8372e6c3e06ba940
parent 8371 0814a5de5b48
child 8373 46d45dfa5fc7
WinRT: fixed incorrect cursor positions when using non-native screen resolutions
src/video/windowsrt/SDL_WinRTApp.cpp
src/video/windowsrt/SDL_WinRTApp.h
     1.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Nov 25 19:13:45 2012 -0500
     1.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Nov 25 23:27:12 2012 -0500
     1.3 @@ -167,11 +167,25 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +// Applies necessary geometric transformations to raw cursor positions:
     1.8 +Point SDL_WinRTApp::TransformCursor(Point rawPosition)
     1.9 +{
    1.10 +    if ( ! m_sdlWindowData || ! m_sdlWindowData->sdlWindow ) {
    1.11 +        return rawPosition;
    1.12 +    }
    1.13 +    CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
    1.14 +    Point outputPosition;
    1.15 +    outputPosition.X = rawPosition.X * (((float32)m_sdlWindowData->sdlWindow->w) / nativeWindow->Bounds.Width);
    1.16 +    outputPosition.Y = rawPosition.Y * (((float32)m_sdlWindowData->sdlWindow->h) / nativeWindow->Bounds.Height);
    1.17 +    return outputPosition;
    1.18 +}
    1.19 +
    1.20  void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
    1.21  {
    1.22      if (m_sdlWindowData)
    1.23      {
    1.24 -        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)args->CurrentPoint->Position.X, (int)args->CurrentPoint->Position.Y);
    1.25 +        Point transformedPoint = TransformCursor(args->CurrentPoint->Position);
    1.26 +        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
    1.27      }
    1.28  }
    1.29  
     2.1 --- a/src/video/windowsrt/SDL_WinRTApp.h	Sun Nov 25 19:13:45 2012 -0500
     2.2 +++ b/src/video/windowsrt/SDL_WinRTApp.h	Sun Nov 25 23:27:12 2012 -0500
     2.3 @@ -28,6 +28,7 @@
     2.4      void SetSDLWindowData(const SDL_WindowData * windowData);
     2.5      void UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects);
     2.6      void ResizeMainTexture(int w, int h);
     2.7 +    Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
     2.8  
     2.9  protected:
    2.10  	// Event Handlers.