WinRT: added touch-event support for Windows Phone devices

Support for touch events in Windows 8/RT is pending on further R+D.
This commit is contained in:
David Ludwig 2013-08-29 10:32:16 -04:00
parent 1d5082d815
commit dbdc4b84ec
1 changed files with 60 additions and 9 deletions

View File

@ -36,6 +36,7 @@ using Windows::UI::Core::CoreCursor;
extern "C" { extern "C" {
#include "SDL_assert.h" #include "SDL_assert.h"
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_touch_c.h"
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#include "SDL_events.h" #include "SDL_events.h"
#include "SDL_log.h" #include "SDL_log.h"
@ -47,6 +48,8 @@ extern "C" {
static SDL_bool WINRT_UseRelativeMouseMode = SDL_FALSE; static SDL_bool WINRT_UseRelativeMouseMode = SDL_FALSE;
static SDL_TouchID WINRT_TouchID = 1;
static unsigned int WINRT_LeftFingerDown = 0;
static SDL_Cursor * static SDL_Cursor *
@ -153,6 +156,11 @@ WINRT_InitMouse(_THIS)
SDL_SetDefaultCursor(WINRT_CreateDefaultCursor()); SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
#endif #endif
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
/* Init touch: */
SDL_AddTouch(WINRT_TouchID, "");
#endif
} }
void void
@ -378,9 +386,22 @@ WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPo
} }
Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position); Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y); 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 void
WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint) WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{ {
@ -399,10 +420,25 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P
return; return;
} }
Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint); Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
if (button) { if (button) {
SDL_SendMouseButton(window, 0, SDL_RELEASED, 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) 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; return;
} }
Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
if (!WINRT_LeftFingerDown) {
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint); Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
if (button) { if (button) {
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP #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 #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 */ #endif /* SDL_VIDEO_DRIVER_WINRT */