WinRT: added touch-event support for Windows Phone devices
authorDavid Ludwig <dludwig@pobox.com>
Thu, 29 Aug 2013 10:32:16 -0400
changeset 85130bcf3970deba
parent 8512 5b345a756965
child 8514 8ba600edd93f
WinRT: added touch-event support for Windows Phone devices

Support for touch events in Windows 8/RT is pending on further R+D.
src/video/winrt/SDL_winrtmouse.cpp
     1.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 16:51:07 2013 -0400
     1.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Thu Aug 29 10:32:16 2013 -0400
     1.3 @@ -36,6 +36,7 @@
     1.4  extern "C" {
     1.5  #include "SDL_assert.h"
     1.6  #include "../../events/SDL_mouse_c.h"
     1.7 +#include "../../events/SDL_touch_c.h"
     1.8  #include "../SDL_sysvideo.h"
     1.9  #include "SDL_events.h"
    1.10  #include "SDL_log.h"
    1.11 @@ -47,6 +48,8 @@
    1.12  
    1.13  
    1.14  static SDL_bool WINRT_UseRelativeMouseMode = SDL_FALSE;
    1.15 +static SDL_TouchID WINRT_TouchID = 1;
    1.16 +static unsigned int WINRT_LeftFingerDown = 0;
    1.17  
    1.18  
    1.19  static SDL_Cursor *
    1.20 @@ -153,6 +156,11 @@
    1.21  
    1.22      SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
    1.23  #endif
    1.24 +
    1.25 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.26 +    /* Init touch: */
    1.27 +    SDL_AddTouch(WINRT_TouchID, "");
    1.28 +#endif
    1.29  }
    1.30  
    1.31  void
    1.32 @@ -378,7 +386,20 @@
    1.33      }
    1.34  
    1.35      Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
    1.36 -    SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
    1.37 +
    1.38 +    if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
    1.39 +        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
    1.40 +    }
    1.41 +
    1.42 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.43 +    // TODO, WinRT: make touch input work with Windows 8/RT, seeing if touches can be distinguished from mouse input.
    1.44 +    SDL_SendTouchMotion(
    1.45 +        WINRT_TouchID,
    1.46 +        (SDL_FingerID) pointerPoint->PointerId,
    1.47 +        transformedPoint.X,
    1.48 +        transformedPoint.Y,
    1.49 +        pointerPoint->Properties->Pressure);
    1.50 +#endif
    1.51  }
    1.52  
    1.53  void
    1.54 @@ -399,10 +420,25 @@
    1.55          return;
    1.56      }
    1.57  
    1.58 -    Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
    1.59 -    if (button) {
    1.60 -        SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
    1.61 +    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
    1.62 +
    1.63 +    if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
    1.64 +        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
    1.65 +        if (button) {
    1.66 +            SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
    1.67 +        }
    1.68 +        WINRT_LeftFingerDown = 0;
    1.69      }
    1.70 +
    1.71 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.72 +    SDL_SendTouch(
    1.73 +        WINRT_TouchID,
    1.74 +        (SDL_FingerID) pointerPoint->PointerId,
    1.75 +        SDL_FALSE,
    1.76 +        transformedPoint.X,
    1.77 +        transformedPoint.Y,
    1.78 +        pointerPoint->Properties->Pressure);
    1.79 +#endif
    1.80  }
    1.81  
    1.82  void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
    1.83 @@ -411,14 +447,29 @@
    1.84          return;
    1.85      }
    1.86  
    1.87 -    Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
    1.88 -    if (button) {
    1.89 +    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
    1.90 +
    1.91 +    if (!WINRT_LeftFingerDown) {
    1.92 +        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
    1.93 +        if (button) {
    1.94  #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.95 -        Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
    1.96 -        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
    1.97 +            SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
    1.98  #endif
    1.99 -        SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
   1.100 +            SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
   1.101 +        }
   1.102 +
   1.103 +        WINRT_LeftFingerDown = pointerPoint->PointerId;
   1.104      }
   1.105 +
   1.106 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   1.107 +    SDL_SendTouch(
   1.108 +        WINRT_TouchID,
   1.109 +        (SDL_FingerID) pointerPoint->PointerId,
   1.110 +        SDL_TRUE,
   1.111 +        transformedPoint.X,
   1.112 +        transformedPoint.Y,
   1.113 +        pointerPoint->Properties->Pressure);
   1.114 +#endif
   1.115  }
   1.116  
   1.117  #endif /* SDL_VIDEO_DRIVER_WINRT */