WinRT: added touch input event support for Windows 8/RT devices
authorDavid Ludwig <dludwig@pobox.com>
Sun, 01 Sep 2013 10:20:17 -0400
changeset 8514 8ba600edd93f
parent 8513 0bcf3970deba
child 8515 bc6cf9201dab
WinRT: added touch input event support for Windows 8/RT devices
src/video/winrt/SDL_winrtmouse.cpp
--- a/src/video/winrt/SDL_winrtmouse.cpp	Thu Aug 29 10:32:16 2013 -0400
+++ b/src/video/winrt/SDL_winrtmouse.cpp	Sun Sep 01 10:20:17 2013 -0400
@@ -157,10 +157,8 @@
     SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
 #endif
 
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     /* Init touch: */
     SDL_AddTouch(WINRT_TouchID, "");
-#endif
 }
 
 void
@@ -378,6 +376,23 @@
 //    return "";
 //}
 
+static bool
+WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+    return true;
+#else
+    using namespace Windows::Devices::Input;
+    switch (pointerPoint->PointerDevice->PointerDeviceType) {
+        case PointerDeviceType::Touch:
+        case PointerDeviceType::Pen:
+            return true;
+        default:
+            return false;
+    }
+#endif
+}
+
 void
 WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
 {
@@ -391,15 +406,14 @@
         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
+    if (WINRT_IsTouchEvent(pointerPoint)) {
+        SDL_SendTouchMotion(
+            WINRT_TouchID,
+            (SDL_FingerID) pointerPoint->PointerId,
+            transformedPoint.X,
+            transformedPoint.Y,
+            pointerPoint->Properties->Pressure);
+    }
 }
 
 void
@@ -430,15 +444,15 @@
         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
+    if (WINRT_IsTouchEvent(pointerPoint)) {
+        SDL_SendTouch(
+            WINRT_TouchID,
+            (SDL_FingerID) pointerPoint->PointerId,
+            SDL_FALSE,
+            transformedPoint.X,
+            transformedPoint.Y,
+            pointerPoint->Properties->Pressure);
+    }
 }
 
 void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
@@ -461,15 +475,15 @@
         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
+    if (WINRT_IsTouchEvent(pointerPoint)) {
+        SDL_SendTouch(
+            WINRT_TouchID,
+            (SDL_FingerID) pointerPoint->PointerId,
+            SDL_TRUE,
+            transformedPoint.X,
+            transformedPoint.Y,
+            pointerPoint->Properties->Pressure);
+    }
 }
 
 #endif /* SDL_VIDEO_DRIVER_WINRT */