WinRT: added touch-event support for Windows Phone devices Support for touch events in Windows 8/RT is pending on further R+D.
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 114 115 116 117 118 119
diff --git a/src/video/winrt/SDL_winrtmouse.cpp b/src/video/winrt/SDL_winrtmouse.cpp
index fb6f5af..4b200db 100644
--- a/src/video/winrt/SDL_winrtmouse.cpp
+++ b/src/video/winrt/SDL_winrtmouse.cpp
@@ -36,6 +36,7 @@ using Windows::UI::Core::CoreCursor;
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 @@ extern "C" {
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 @@ WINRT_InitMouse(_THIS)
SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
#endif
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ /* Init touch: */
+ SDL_AddTouch(WINRT_TouchID, "");
+#endif
}
void
@@ -378,7 +386,20 @@ WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPo
}
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 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P
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 @@ void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::Po
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 */