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 8372 e6c3e06ba940
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
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Nov 25 19:13:45 2012 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Nov 25 23:27:12 2012 -0500
@@ -167,11 +167,25 @@
     }
 }
 
+// Applies necessary geometric transformations to raw cursor positions:
+Point SDL_WinRTApp::TransformCursor(Point rawPosition)
+{
+    if ( ! m_sdlWindowData || ! m_sdlWindowData->sdlWindow ) {
+        return rawPosition;
+    }
+    CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
+    Point outputPosition;
+    outputPosition.X = rawPosition.X * (((float32)m_sdlWindowData->sdlWindow->w) / nativeWindow->Bounds.Width);
+    outputPosition.Y = rawPosition.Y * (((float32)m_sdlWindowData->sdlWindow->h) / nativeWindow->Bounds.Height);
+    return outputPosition;
+}
+
 void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
 {
     if (m_sdlWindowData)
     {
-        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)args->CurrentPoint->Position.X, (int)args->CurrentPoint->Position.Y);
+        Point transformedPoint = TransformCursor(args->CurrentPoint->Position);
+        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
     }
 }
 
--- a/src/video/windowsrt/SDL_WinRTApp.h	Sun Nov 25 19:13:45 2012 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.h	Sun Nov 25 23:27:12 2012 -0500
@@ -28,6 +28,7 @@
     void SetSDLWindowData(const SDL_WindowData * windowData);
     void UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects);
     void ResizeMainTexture(int w, int h);
+    Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
 
 protected:
 	// Event Handlers.