WinRT: added touch input event support for Windows 8/RT devices
authorDavid Ludwig <dludwig@pobox.com>
Sun, 01 Sep 2013 10:20:17 -0400
changeset 85148ba600edd93f
parent 8513 0bcf3970deba
child 8515 bc6cf9201dab
WinRT: added touch input event support for Windows 8/RT devices
src/video/winrt/SDL_winrtmouse.cpp
     1.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Thu Aug 29 10:32:16 2013 -0400
     1.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Sun Sep 01 10:20:17 2013 -0400
     1.3 @@ -157,10 +157,8 @@
     1.4      SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
     1.5  #endif
     1.6  
     1.7 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
     1.8      /* Init touch: */
     1.9      SDL_AddTouch(WINRT_TouchID, "");
    1.10 -#endif
    1.11  }
    1.12  
    1.13  void
    1.14 @@ -378,6 +376,23 @@
    1.15  //    return "";
    1.16  //}
    1.17  
    1.18 +static bool
    1.19 +WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
    1.20 +{
    1.21 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.22 +    return true;
    1.23 +#else
    1.24 +    using namespace Windows::Devices::Input;
    1.25 +    switch (pointerPoint->PointerDevice->PointerDeviceType) {
    1.26 +        case PointerDeviceType::Touch:
    1.27 +        case PointerDeviceType::Pen:
    1.28 +            return true;
    1.29 +        default:
    1.30 +            return false;
    1.31 +    }
    1.32 +#endif
    1.33 +}
    1.34 +
    1.35  void
    1.36  WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
    1.37  {
    1.38 @@ -391,15 +406,14 @@
    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 +    if (WINRT_IsTouchEvent(pointerPoint)) {
    1.52 +        SDL_SendTouchMotion(
    1.53 +            WINRT_TouchID,
    1.54 +            (SDL_FingerID) pointerPoint->PointerId,
    1.55 +            transformedPoint.X,
    1.56 +            transformedPoint.Y,
    1.57 +            pointerPoint->Properties->Pressure);
    1.58 +    }
    1.59  }
    1.60  
    1.61  void
    1.62 @@ -430,15 +444,15 @@
    1.63          WINRT_LeftFingerDown = 0;
    1.64      }
    1.65  
    1.66 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.67 -    SDL_SendTouch(
    1.68 -        WINRT_TouchID,
    1.69 -        (SDL_FingerID) pointerPoint->PointerId,
    1.70 -        SDL_FALSE,
    1.71 -        transformedPoint.X,
    1.72 -        transformedPoint.Y,
    1.73 -        pointerPoint->Properties->Pressure);
    1.74 -#endif
    1.75 +    if (WINRT_IsTouchEvent(pointerPoint)) {
    1.76 +        SDL_SendTouch(
    1.77 +            WINRT_TouchID,
    1.78 +            (SDL_FingerID) pointerPoint->PointerId,
    1.79 +            SDL_FALSE,
    1.80 +            transformedPoint.X,
    1.81 +            transformedPoint.Y,
    1.82 +            pointerPoint->Properties->Pressure);
    1.83 +    }
    1.84  }
    1.85  
    1.86  void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
    1.87 @@ -461,15 +475,15 @@
    1.88          WINRT_LeftFingerDown = pointerPoint->PointerId;
    1.89      }
    1.90  
    1.91 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.92 -    SDL_SendTouch(
    1.93 -        WINRT_TouchID,
    1.94 -        (SDL_FingerID) pointerPoint->PointerId,
    1.95 -        SDL_TRUE,
    1.96 -        transformedPoint.X,
    1.97 -        transformedPoint.Y,
    1.98 -        pointerPoint->Properties->Pressure);
    1.99 -#endif
   1.100 +    if (WINRT_IsTouchEvent(pointerPoint)) {
   1.101 +        SDL_SendTouch(
   1.102 +            WINRT_TouchID,
   1.103 +            (SDL_FingerID) pointerPoint->PointerId,
   1.104 +            SDL_TRUE,
   1.105 +            transformedPoint.X,
   1.106 +            transformedPoint.Y,
   1.107 +            pointerPoint->Properties->Pressure);
   1.108 +    }
   1.109  }
   1.110  
   1.111  #endif /* SDL_VIDEO_DRIVER_WINRT */