WinRT: added touch-event support for Windows Phone devices
authorDavid Ludwig <dludwig@pobox.com>
Thu, 29 Aug 2013 10:32:16 -0400
changeset 8513 0bcf3970deba
parent 8512 5b345a756965
child 8514 8ba600edd93f
WinRT: added touch-event support for Windows Phone devices Support for touch events in Windows 8/RT is pending on further R+D.
src/video/winrt/SDL_winrtmouse.cpp
--- a/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 16:51:07 2013 -0400
+++ b/src/video/winrt/SDL_winrtmouse.cpp	Thu Aug 29 10:32:16 2013 -0400
@@ -36,6 +36,7 @@
 extern "C" {
 #include "SDL_assert.h"
 #include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
 #include "../SDL_sysvideo.h"
 #include "SDL_events.h"
 #include "SDL_log.h"
@@ -47,6 +48,8 @@
 
 
 static SDL_bool WINRT_UseRelativeMouseMode = SDL_FALSE;
+static SDL_TouchID WINRT_TouchID = 1;
+static unsigned int WINRT_LeftFingerDown = 0;
 
 
 static SDL_Cursor *
@@ -153,6 +156,11 @@
 
     SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
 #endif
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+    /* Init touch: */
+    SDL_AddTouch(WINRT_TouchID, "");
+#endif
 }
 
 void
@@ -378,7 +386,20 @@
     }
 
     Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
-    SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
+
+    if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
+        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
+    }
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+    // TODO, WinRT: make touch input work with Windows 8/RT, seeing if touches can be distinguished from mouse input.
+    SDL_SendTouchMotion(
+        WINRT_TouchID,
+        (SDL_FingerID) pointerPoint->PointerId,
+        transformedPoint.X,
+        transformedPoint.Y,
+        pointerPoint->Properties->Pressure);
+#endif
 }
 
 void
@@ -399,10 +420,25 @@
         return;
     }
 
-    Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
-    if (button) {
-        SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
+    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
+
+    if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
+        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
+        if (button) {
+            SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
+        }
+        WINRT_LeftFingerDown = 0;
     }
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+    SDL_SendTouch(
+        WINRT_TouchID,
+        (SDL_FingerID) pointerPoint->PointerId,
+        SDL_FALSE,
+        transformedPoint.X,
+        transformedPoint.Y,
+        pointerPoint->Properties->Pressure);
+#endif
 }
 
 void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
@@ -411,14 +447,29 @@
         return;
     }
 
-    Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
-    if (button) {
+    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
+
+    if (!WINRT_LeftFingerDown) {
+        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
+        if (button) {
 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
-        Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
-        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
+            SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
 #endif
-        SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
+            SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
+        }
+
+        WINRT_LeftFingerDown = pointerPoint->PointerId;
     }
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+    SDL_SendTouch(
+        WINRT_TouchID,
+        (SDL_FingerID) pointerPoint->PointerId,
+        SDL_TRUE,
+        transformedPoint.X,
+        transformedPoint.Y,
+        pointerPoint->Properties->Pressure);
+#endif
 }
 
 #endif /* SDL_VIDEO_DRIVER_WINRT */