WinRT: added touch input event support for Windows 8/RT devices
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
diff --git a/src/video/winrt/SDL_winrtmouse.cpp b/src/video/winrt/SDL_winrtmouse.cpp
index 4b200db..d639210 100644
--- a/src/video/winrt/SDL_winrtmouse.cpp
+++ b/src/video/winrt/SDL_winrtmouse.cpp
@@ -157,10 +157,8 @@ WINRT_InitMouse(_THIS)
SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
#endif
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
/* Init touch: */
SDL_AddTouch(WINRT_TouchID, "");
-#endif
}
void
@@ -378,6 +376,23 @@ WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
// 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 @@ WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPo
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 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P
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 @@ void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::Po
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 */