WinRT: made simulated-mouse (via touch) input work on Windows Phone in Portrait mode
authorDavid Ludwig <dludwig@pobox.com>
Wed, 28 Aug 2013 16:14:27 -0400
changeset 8511326b43e1276b
parent 8510 b828c4cc5cd8
child 8512 5b345a756965
WinRT: made simulated-mouse (via touch) input work on Windows Phone in Portrait mode

Proper SDL_MOUSE* event support for non-Portrait orientations in Windows Phone is pending.
src/core/winrt/SDL_winrtapp.cpp
src/core/winrt/SDL_winrtapp.h
src/video/winrt/SDL_winrtevents_c.h
src/video/winrt/SDL_winrtmouse.cpp
     1.1 --- a/src/core/winrt/SDL_winrtapp.cpp	Wed Aug 28 15:27:01 2013 -0400
     1.2 +++ b/src/core/winrt/SDL_winrtapp.cpp	Wed Aug 28 16:14:27 2013 -0400
     1.3 @@ -412,31 +412,61 @@
     1.4      m_windowClosed = true;
     1.5  }
     1.6  
     1.7 +static void
     1.8 +WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
     1.9 +{
    1.10 +    Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
    1.11 +    SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
    1.12 +        header,
    1.13 +        pt->Position.X, pt->Position.Y,
    1.14 +        transformedPoint.X, transformedPoint.Y,
    1.15 +        pt->Properties->MouseWheelDelta,
    1.16 +        pt->FrameId,
    1.17 +        pt->PointerId,
    1.18 +        WINRT_GetSDLButtonForPointerPoint(pt));
    1.19 +}
    1.20 +
    1.21  void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
    1.22  {
    1.23 +#if LOG_POINTER_EVENTS
    1.24 +    WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
    1.25 +#endif
    1.26 +
    1.27      WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
    1.28  }
    1.29  
    1.30  void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
    1.31  {
    1.32 +#if LOG_POINTER_EVENTS
    1.33 +    WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
    1.34 +#endif
    1.35 +
    1.36      WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
    1.37  }
    1.38  
    1.39  void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
    1.40  {
    1.41 +#if LOG_POINTER_EVENTS
    1.42 +    WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
    1.43 +#endif
    1.44 +
    1.45      WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
    1.46  }
    1.47  
    1.48 +void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
    1.49 +{
    1.50 +#if LOG_POINTER_EVENTS
    1.51 +    WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
    1.52 +#endif
    1.53 +
    1.54 +    WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
    1.55 +}
    1.56 +
    1.57  void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
    1.58  {
    1.59      WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
    1.60  }
    1.61  
    1.62 -void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
    1.63 -{
    1.64 -    WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
    1.65 -}
    1.66 -
    1.67  void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
    1.68  {
    1.69      WINRT_ProcessKeyDownEvent(args);
     2.1 --- a/src/core/winrt/SDL_winrtapp.h	Wed Aug 28 15:27:01 2013 -0400
     2.2 +++ b/src/core/winrt/SDL_winrtapp.h	Wed Aug 28 16:14:27 2013 -0400
     2.3 @@ -15,7 +15,6 @@
     2.4  internal:
     2.5      // SDL-specific methods
     2.6      void PumpEvents();
     2.7 -    Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
     2.8  
     2.9  protected:
    2.10      // Event Handlers.
     3.1 --- a/src/video/winrt/SDL_winrtevents_c.h	Wed Aug 28 15:27:01 2013 -0400
     3.2 +++ b/src/video/winrt/SDL_winrtevents_c.h	Wed Aug 28 16:14:27 2013 -0400
     3.3 @@ -54,6 +54,8 @@
     3.4  extern void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
     3.5  extern void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
     3.6  extern void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
     3.7 +extern Uint8 WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt);
     3.8 +extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition);
     3.9  
    3.10  /* XAML Thread Management */
    3.11  extern void WINRT_CycleXAMLThread();
     4.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 15:27:01 2013 -0400
     4.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 16:14:27 2013 -0400
     4.3 @@ -160,8 +160,8 @@
     4.4  }
     4.5  
     4.6  // Applies necessary geometric transformations to raw cursor positions:
     4.7 -static Windows::Foundation::Point
     4.8 -TransformCursor(SDL_Window * window, Windows::Foundation::Point rawPosition)
     4.9 +Windows::Foundation::Point
    4.10 +WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition)
    4.11  {
    4.12      if (!window) {
    4.13          return rawPosition;
    4.14 @@ -247,7 +247,7 @@
    4.15      // to SDL window coordinates.
    4.16      //
    4.17      const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
    4.18 -    const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = TransformCursor(window, mouseDeltaInDIPs);
    4.19 +    const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs);
    4.20      SDL_SendMouseMotion(
    4.21          window,
    4.22          0,
    4.23 @@ -256,11 +256,14 @@
    4.24          _lround(mouseDeltaInSDLWindowCoords.Y));
    4.25  }
    4.26  
    4.27 -static Uint8
    4.28 +Uint8
    4.29  WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
    4.30  {
    4.31      using namespace Windows::UI::Input;
    4.32  
    4.33 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    4.34 +    return SDL_BUTTON_LEFT;
    4.35 +#else
    4.36      switch (pt->Properties->PointerUpdateKind)
    4.37      {
    4.38          case PointerUpdateKind::LeftButtonPressed:
    4.39 @@ -286,80 +289,59 @@
    4.40          default:
    4.41              break;
    4.42      }
    4.43 +#endif
    4.44  
    4.45      return 0;
    4.46  }
    4.47  
    4.48 -static const char *
    4.49 -WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
    4.50 -{
    4.51 -    using namespace Windows::UI::Input;
    4.52 -
    4.53 -    switch (kind)
    4.54 -    {
    4.55 -        case PointerUpdateKind::Other:
    4.56 -            return "Other";
    4.57 -        case PointerUpdateKind::LeftButtonPressed:
    4.58 -            return "LeftButtonPressed";
    4.59 -        case PointerUpdateKind::LeftButtonReleased:
    4.60 -            return "LeftButtonReleased";
    4.61 -        case PointerUpdateKind::RightButtonPressed:
    4.62 -            return "RightButtonPressed";
    4.63 -        case PointerUpdateKind::RightButtonReleased:
    4.64 -            return "RightButtonReleased";
    4.65 -        case PointerUpdateKind::MiddleButtonPressed:
    4.66 -            return "MiddleButtonPressed";
    4.67 -        case PointerUpdateKind::MiddleButtonReleased:
    4.68 -            return "MiddleButtonReleased";
    4.69 -        case PointerUpdateKind::XButton1Pressed:
    4.70 -            return "XButton1Pressed";
    4.71 -        case PointerUpdateKind::XButton1Released:
    4.72 -            return "XButton1Released";
    4.73 -        case PointerUpdateKind::XButton2Pressed:
    4.74 -            return "XButton2Pressed";
    4.75 -        case PointerUpdateKind::XButton2Released:
    4.76 -            return "XButton2Released";
    4.77 -    }
    4.78 -
    4.79 -    return "";
    4.80 -}
    4.81 -
    4.82 -static void
    4.83 -WINRT_LogPointerEvent(const char * header, PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
    4.84 -{
    4.85 -    Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
    4.86 -    SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, PointerUpdateKind=%s\n",
    4.87 -        header,
    4.88 -        pt->Position.X, pt->Position.Y,
    4.89 -        transformedPoint.X, transformedPoint.Y,
    4.90 -        pt->Properties->MouseWheelDelta,
    4.91 -        pt->FrameId,
    4.92 -        pt->PointerId,
    4.93 -        WINRT_ConvertPointerUpdateKindToString(args->CurrentPoint->Properties->PointerUpdateKind));
    4.94 -}
    4.95 +//const char *
    4.96 +//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
    4.97 +//{
    4.98 +//    using namespace Windows::UI::Input;
    4.99 +//
   4.100 +//    switch (kind)
   4.101 +//    {
   4.102 +//        case PointerUpdateKind::Other:
   4.103 +//            return "Other";
   4.104 +//        case PointerUpdateKind::LeftButtonPressed:
   4.105 +//            return "LeftButtonPressed";
   4.106 +//        case PointerUpdateKind::LeftButtonReleased:
   4.107 +//            return "LeftButtonReleased";
   4.108 +//        case PointerUpdateKind::RightButtonPressed:
   4.109 +//            return "RightButtonPressed";
   4.110 +//        case PointerUpdateKind::RightButtonReleased:
   4.111 +//            return "RightButtonReleased";
   4.112 +//        case PointerUpdateKind::MiddleButtonPressed:
   4.113 +//            return "MiddleButtonPressed";
   4.114 +//        case PointerUpdateKind::MiddleButtonReleased:
   4.115 +//            return "MiddleButtonReleased";
   4.116 +//        case PointerUpdateKind::XButton1Pressed:
   4.117 +//            return "XButton1Pressed";
   4.118 +//        case PointerUpdateKind::XButton1Released:
   4.119 +//            return "XButton1Released";
   4.120 +//        case PointerUpdateKind::XButton2Pressed:
   4.121 +//            return "XButton2Pressed";
   4.122 +//        case PointerUpdateKind::XButton2Released:
   4.123 +//            return "XButton2Released";
   4.124 +//    }
   4.125 +//
   4.126 +//    return "";
   4.127 +//}
   4.128  
   4.129  void
   4.130  WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
   4.131  {
   4.132 -#if LOG_POINTER_EVENTS
   4.133 -    WINRT_LogPointerEvent("pointer moved", args, TransformCursor(pointerPoint->Position));
   4.134 -#endif
   4.135 -
   4.136      if (!window || WINRT_UseRelativeMouseMode) {
   4.137          return;
   4.138      }
   4.139  
   4.140 -    Windows::Foundation::Point transformedPoint = TransformCursor(window, pointerPoint->Position);
   4.141 +    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
   4.142      SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
   4.143  }
   4.144  
   4.145  void
   4.146  WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
   4.147  {
   4.148 -#if LOG_POINTER_EVENTS
   4.149 -    WINRT_LogPointerEvent("wheel changed", args, TransformCursor(pointerPoint->Position));
   4.150 -#endif
   4.151 -
   4.152      if (!window) {
   4.153          return;
   4.154      }
   4.155 @@ -371,10 +353,6 @@
   4.156  
   4.157  void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
   4.158  {
   4.159 -#if LOG_POINTER_EVENTS
   4.160 -    WINRT_LogPointerEvent("mouse up", args, TransformCursor(args->CurrentPoint->Position));
   4.161 -#endif
   4.162 -
   4.163      if (!window) {
   4.164          return;
   4.165      }
   4.166 @@ -387,16 +365,16 @@
   4.167  
   4.168  void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
   4.169  {
   4.170 -#if LOG_POINTER_EVENTS
   4.171 -    WINRT_LogPointerEvent("mouse down", args, TransformCursor(args->CurrentPoint->Position));
   4.172 -#endif
   4.173 -
   4.174      if (!window) {
   4.175          return;
   4.176      }
   4.177  
   4.178      Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
   4.179      if (button) {
   4.180 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   4.181 +        Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
   4.182 +        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
   4.183 +#endif
   4.184          SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
   4.185      }
   4.186  }