Navigation Menu

Skip to content

Commit

Permalink
WinRT: added touch-event support for Windows Phone devices
Browse files Browse the repository at this point in the history
Support for touch events in Windows 8/RT is pending on further R+D.
  • Loading branch information
DavidLudwig committed Aug 29, 2013
1 parent 1d5082d commit dbdc4b8
Showing 1 changed file with 60 additions and 9 deletions.
69 changes: 60 additions & 9 deletions src/video/winrt/SDL_winrtmouse.cpp
Expand Up @@ -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"
Expand All @@ -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 *
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 */
Expand Down

0 comments on commit dbdc4b8

Please sign in to comment.