WinRT: moved most platform-specific keyboard and mouse code to shared locations
authorDavid Ludwig <dludwig@pobox.com>
Mon, 26 Aug 2013 17:17:53 -0400
changeset 84897fd62b320c31
parent 8488 bb48911cd9c8
child 8490 b05c6db83a07
WinRT: moved most platform-specific keyboard and mouse code to shared locations
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
src/core/winrt/SDL_winrtapp.cpp
src/core/winrt/SDL_winrtapp.h
src/video/winrt/SDL_winrtevents_c.h
src/video/winrt/SDL_winrtkeyboard.cpp
src/video/winrt/SDL_winrtmouse.cpp
     1.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Tue Aug 20 22:18:48 2013 -0400
     1.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Mon Aug 26 17:17:53 2013 -0400
     1.3 @@ -363,6 +363,7 @@
     1.4        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
     1.5        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
     1.6      </ClCompile>
     1.7 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp" />
     1.8      <ClCompile Include="..\..\src\video\winrt\SDL_winrtmouse.cpp">
     1.9        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.10        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
     2.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Tue Aug 20 22:18:48 2013 -0400
     2.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Mon Aug 26 17:17:53 2013 -0400
     2.3 @@ -593,6 +593,9 @@
     2.4      <ClCompile Include="..\..\src\video\winrt\SDL_winrtvideo.cpp">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClCompile>
     2.7 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClCompile>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
     3.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Tue Aug 20 22:18:48 2013 -0400
     3.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Mon Aug 26 17:17:53 2013 -0400
     3.3 @@ -152,6 +152,14 @@
     3.4        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
     3.5        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
     3.6      </ClCompile>
     3.7 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
     3.8 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
     3.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    3.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    3.13 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    3.14 +    </ClCompile>
    3.15      <ClCompile Include="..\..\src\video\winrt\SDL_winrtmouse.cpp">
    3.16        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.17        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
     4.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Tue Aug 20 22:18:48 2013 -0400
     4.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Mon Aug 26 17:17:53 2013 -0400
     4.3 @@ -267,6 +267,9 @@
     4.4      <ClCompile Include="..\..\src\core\winrt\SDL_winrtpaths.cpp">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClCompile>
     4.7 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
     4.8 +      <Filter>Source Files</Filter>
     4.9 +    </ClCompile>
    4.10    </ItemGroup>
    4.11    <ItemGroup>
    4.12      <ClInclude Include="..\..\include\begin_code.h">
     5.1 --- a/src/core/winrt/SDL_winrtapp.cpp	Tue Aug 20 22:18:48 2013 -0400
     5.2 +++ b/src/core/winrt/SDL_winrtapp.cpp	Mon Aug 26 17:17:53 2013 -0400
     5.3 @@ -1,6 +1,6 @@
     5.4  
     5.5 +#include <functional>
     5.6  #include <string>
     5.7 -#include <unordered_map>
     5.8  #include <sstream>
     5.9  
    5.10  #include "ppltasks.h"
    5.11 @@ -15,13 +15,12 @@
    5.12  #include "SDL_render.h"
    5.13  #include "../../video/SDL_sysvideo.h"
    5.14  //#include "../../SDL_hints_c.h"
    5.15 -#include "../../events/scancodes_windows.h"
    5.16  #include "../../events/SDL_mouse_c.h"
    5.17 -#include "../../events/SDL_keyboard_c.h"
    5.18  #include "../../events/SDL_windowevents_c.h"
    5.19  #include "../../render/SDL_sysrender.h"
    5.20  }
    5.21  
    5.22 +#include "../../video/winrt/SDL_winrtevents_c.h"
    5.23  #include "../../video/winrt/SDL_winrtvideo.h"
    5.24  #include "SDL_winrtapp.h"
    5.25  
    5.26 @@ -142,8 +141,7 @@
    5.27      m_windowClosed(false),
    5.28      m_windowVisible(true),
    5.29      m_sdlWindowData(NULL),
    5.30 -    m_sdlVideoDevice(NULL),
    5.31 -    m_useRelativeMouseMode(false)
    5.32 +    m_sdlVideoDevice(NULL)
    5.33  {
    5.34  }
    5.35  
    5.36 @@ -387,482 +385,44 @@
    5.37      m_windowClosed = true;
    5.38  }
    5.39  
    5.40 -static Uint8
    5.41 -WINRT_GetSDLButtonForPointerPoint(PointerPoint ^ pt)
    5.42 -{
    5.43 -    switch (pt->Properties->PointerUpdateKind)
    5.44 -    {
    5.45 -        case PointerUpdateKind::LeftButtonPressed:
    5.46 -        case PointerUpdateKind::LeftButtonReleased:
    5.47 -            return SDL_BUTTON_LEFT;
    5.48 -
    5.49 -        case PointerUpdateKind::RightButtonPressed:
    5.50 -        case PointerUpdateKind::RightButtonReleased:
    5.51 -            return SDL_BUTTON_RIGHT;
    5.52 -
    5.53 -        case PointerUpdateKind::MiddleButtonPressed:
    5.54 -        case PointerUpdateKind::MiddleButtonReleased:
    5.55 -            return SDL_BUTTON_MIDDLE;
    5.56 -
    5.57 -        case PointerUpdateKind::XButton1Pressed:
    5.58 -        case PointerUpdateKind::XButton1Released:
    5.59 -            return SDL_BUTTON_X1;
    5.60 -
    5.61 -        case PointerUpdateKind::XButton2Pressed:
    5.62 -        case PointerUpdateKind::XButton2Released:
    5.63 -            return SDL_BUTTON_X2;
    5.64 -
    5.65 -        default:
    5.66 -            break;
    5.67 -    }
    5.68 -
    5.69 -    return 0;
    5.70 -}
    5.71 -
    5.72 -static const char *
    5.73 -WINRT_ConvertPointerUpdateKindToString(PointerUpdateKind kind)
    5.74 -{
    5.75 -    switch (kind)
    5.76 -    {
    5.77 -        case PointerUpdateKind::Other:
    5.78 -            return "Other";
    5.79 -        case PointerUpdateKind::LeftButtonPressed:
    5.80 -            return "LeftButtonPressed";
    5.81 -        case PointerUpdateKind::LeftButtonReleased:
    5.82 -            return "LeftButtonReleased";
    5.83 -        case PointerUpdateKind::RightButtonPressed:
    5.84 -            return "RightButtonPressed";
    5.85 -        case PointerUpdateKind::RightButtonReleased:
    5.86 -            return "RightButtonReleased";
    5.87 -        case PointerUpdateKind::MiddleButtonPressed:
    5.88 -            return "MiddleButtonPressed";
    5.89 -        case PointerUpdateKind::MiddleButtonReleased:
    5.90 -            return "MiddleButtonReleased";
    5.91 -        case PointerUpdateKind::XButton1Pressed:
    5.92 -            return "XButton1Pressed";
    5.93 -        case PointerUpdateKind::XButton1Released:
    5.94 -            return "XButton1Released";
    5.95 -        case PointerUpdateKind::XButton2Pressed:
    5.96 -            return "XButton2Pressed";
    5.97 -        case PointerUpdateKind::XButton2Released:
    5.98 -            return "XButton2Released";
    5.99 -    }
   5.100 -
   5.101 -    return "";
   5.102 -}
   5.103 -
   5.104 -static void
   5.105 -WINRT_LogPointerEvent(const string & header, PointerEventArgs ^ args, Point transformedPoint)
   5.106 -{
   5.107 -    PointerPoint ^ pt = args->CurrentPoint;
   5.108 -    SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, PointerUpdateKind=%s\n",
   5.109 -        header.c_str(),
   5.110 -        pt->Position.X, pt->Position.Y,
   5.111 -        transformedPoint.X, transformedPoint.Y,
   5.112 -        pt->Properties->MouseWheelDelta,
   5.113 -        pt->FrameId,
   5.114 -        pt->PointerId,
   5.115 -        WINRT_ConvertPointerUpdateKindToString(args->CurrentPoint->Properties->PointerUpdateKind));
   5.116 -}
   5.117 -
   5.118  void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
   5.119  {
   5.120 -#if LOG_POINTER_EVENTS
   5.121 -    WINRT_LogPointerEvent("mouse down", args, TransformCursor(args->CurrentPoint->Position));
   5.122 -#endif
   5.123 -
   5.124 -    if (m_sdlWindowData) {
   5.125 -        Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
   5.126 -        if (button) {
   5.127 -            SDL_SendMouseButton(m_sdlWindowData->sdlWindow, 0, SDL_PRESSED, button);
   5.128 -        }
   5.129 -    }
   5.130 +    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
   5.131 +    WINRT_ProcessPointerPressedEvent(window, args);
   5.132  }
   5.133  
   5.134  void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
   5.135  {
   5.136 -#if LOG_POINTER_EVENTS
   5.137 -    WINRT_LogPointerEvent("mouse up", args, TransformCursor(args->CurrentPoint->Position));
   5.138 -#endif
   5.139 -
   5.140 -    if (m_sdlWindowData) {
   5.141 -        Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
   5.142 -        if (button) {
   5.143 -            SDL_SendMouseButton(m_sdlWindowData->sdlWindow, 0, SDL_RELEASED, button);
   5.144 -        }
   5.145 -    }
   5.146 +    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
   5.147 +    WINRT_ProcessPointerReleasedEvent(window, args);
   5.148  }
   5.149  
   5.150  void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
   5.151  {
   5.152 -#if LOG_POINTER_EVENTS
   5.153 -    WINRT_LogPointerEvent("wheel changed", args, TransformCursor(args->CurrentPoint->Position));
   5.154 -#endif
   5.155 -
   5.156 -    if (m_sdlWindowData) {
   5.157 -        // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
   5.158 -        short motion = args->CurrentPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
   5.159 -        SDL_SendMouseWheel(m_sdlWindowData->sdlWindow, 0, 0, motion);
   5.160 -    }
   5.161 -}
   5.162 -
   5.163 -static inline int _lround(float arg) {
   5.164 -    if (arg >= 0.0f) {
   5.165 -        return (int)floor(arg + 0.5f);
   5.166 -    } else {
   5.167 -        return (int)ceil(arg - 0.5f);
   5.168 -    }
   5.169 +    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
   5.170 +    WINRT_ProcessPointerWheelChangedEvent(window, args);
   5.171  }
   5.172  
   5.173  void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
   5.174  {
   5.175 -    if (m_sdlWindowData && m_useRelativeMouseMode) {
   5.176 -        // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
   5.177 -        // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
   5.178 -        // MouseDelta field often reports very large values.  More information
   5.179 -        // on this can be found at the following pages on MSDN:
   5.180 -        //  - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
   5.181 -        //  - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
   5.182 -        //
   5.183 -        // The values do not appear to be as large when running on some systems,
   5.184 -        // most notably a Surface RT.  Furthermore, the values returned by
   5.185 -        // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
   5.186 -        // method, do not ever appear to be large, even when MouseEventArgs'
   5.187 -        // MouseDelta is reporting to the contrary.
   5.188 -        //
   5.189 -        // On systems with the large-values behavior, it appears that the values
   5.190 -        // get reported as if the screen's size is 65536 units in both the X and Y
   5.191 -        // dimensions.  This can be viewed by using Windows' now-private, "Raw Input"
   5.192 -        // APIs.  (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
   5.193 -        //
   5.194 -        // MSDN's documentation on MouseEventArgs' MouseDelta field (at
   5.195 -        // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
   5.196 -        // does not seem to indicate (to me) that its values should be so large.  It
   5.197 -        // says that its values should be a "change in screen location".  I could
   5.198 -        // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: 
   5.199 -        // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
   5.200 -        // indicates that these values are in DIPs, which is the same unit used
   5.201 -        // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
   5.202 -        // property.  See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
   5.203 -        // for details.)
   5.204 -        //
   5.205 -        // To note, PointerMoved events are sent a 'RawPosition' value (via the
   5.206 -        // CurrentPoint property in MouseEventArgs), however these do not seem
   5.207 -        // to exhibit the same large-value behavior.
   5.208 -        //
   5.209 -        // The values passed via PointerMoved events can't always be used for relative
   5.210 -        // mouse motion, unfortunately.  Its values are bound to the cursor's position,
   5.211 -        // which stops when it hits one of the screen's edges.  This can be a problem in
   5.212 -        // first person shooters, whereby it is normal for mouse motion to travel far
   5.213 -        // along any one axis for a period of time.  MouseMoved events do not have the
   5.214 -        // screen-bounding limitation, and can be used regardless of where the system's
   5.215 -        // cursor is.
   5.216 -        //
   5.217 -        // One possible workaround would be to programmatically set the cursor's
   5.218 -        // position to the screen's center (when SDL's relative mouse mode is enabled),
   5.219 -        // however Windows RT does not yet seem to have the ability to set the cursor's
   5.220 -        // position via a public API.  Win32 did this via an API call, SetCursorPos,
   5.221 -        // however WinRT makes this function be private.  Apps that use it won't get
   5.222 -        // approved for distribution in the Windows Store.  I've yet to be able to find
   5.223 -        // a suitable, store-friendly counterpart for WinRT.
   5.224 -        //
   5.225 -        // There may be some room for a workaround whereby OnPointerMoved's values
   5.226 -        // are compared to the values from OnMouseMoved in order to detect
   5.227 -        // when this bug is active.  A suitable transformation could then be made to
   5.228 -        // OnMouseMoved's values.  For now, however, the system-reported values are sent
   5.229 -        // to SDL with minimal transformation: from native screen coordinates (in DIPs)
   5.230 -        // to SDL window coordinates.
   5.231 -        //
   5.232 -        const Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
   5.233 -        const Point mouseDeltaInSDLWindowCoords = TransformCursor(mouseDeltaInDIPs);
   5.234 -        SDL_SendMouseMotion(
   5.235 -            m_sdlWindowData->sdlWindow,
   5.236 -            0,
   5.237 -            1,
   5.238 -            _lround(mouseDeltaInSDLWindowCoords.X),
   5.239 -            _lround(mouseDeltaInSDLWindowCoords.Y));
   5.240 -    }
   5.241 -}
   5.242 -
   5.243 -// Applies necessary geometric transformations to raw cursor positions:
   5.244 -Point SDL_WinRTApp::TransformCursor(Point rawPosition)
   5.245 -{
   5.246 -    if ( ! m_sdlWindowData || ! m_sdlWindowData->sdlWindow ) {
   5.247 -        return rawPosition;
   5.248 -    }
   5.249 -    CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
   5.250 -    Point outputPosition;
   5.251 -    outputPosition.X = rawPosition.X * (((float32)m_sdlWindowData->sdlWindow->w) / nativeWindow->Bounds.Width);
   5.252 -    outputPosition.Y = rawPosition.Y * (((float32)m_sdlWindowData->sdlWindow->h) / nativeWindow->Bounds.Height);
   5.253 -    return outputPosition;
   5.254 +    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
   5.255 +    WINRT_ProcessMouseMovedEvent(window, args);
   5.256  }
   5.257  
   5.258  void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
   5.259  {
   5.260 -#if LOG_POINTER_EVENTS
   5.261 -    WINRT_LogPointerEvent("pointer moved", args, TransformCursor(args->CurrentPoint->Position));
   5.262 -#endif
   5.263 -
   5.264 -    if (m_sdlWindowData && ! m_useRelativeMouseMode)
   5.265 -    {
   5.266 -        Point transformedPoint = TransformCursor(args->CurrentPoint->Position);
   5.267 -        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
   5.268 -    }
   5.269 -}
   5.270 -
   5.271 -static SDL_Scancode WinRT_Official_Keycodes[] = {
   5.272 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
   5.273 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
   5.274 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
   5.275 -    SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
   5.276 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
   5.277 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
   5.278 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
   5.279 -    SDL_SCANCODE_UNKNOWN, // -- 7
   5.280 -    SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
   5.281 -    SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
   5.282 -    SDL_SCANCODE_UNKNOWN, // -- 10
   5.283 -    SDL_SCANCODE_UNKNOWN, // -- 11
   5.284 -    SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
   5.285 -    SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
   5.286 -    SDL_SCANCODE_UNKNOWN, // -- 14
   5.287 -    SDL_SCANCODE_UNKNOWN, // -- 15
   5.288 -    SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
   5.289 -    SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
   5.290 -    SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
   5.291 -    SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
   5.292 -    SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
   5.293 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
   5.294 -    SDL_SCANCODE_UNKNOWN, // -- 22
   5.295 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
   5.296 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
   5.297 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
   5.298 -    SDL_SCANCODE_UNKNOWN, // -- 26
   5.299 -    SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
   5.300 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
   5.301 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
   5.302 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
   5.303 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31  (maybe SDL_SCANCODE_MODE ?)
   5.304 -    SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
   5.305 -    SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
   5.306 -    SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
   5.307 -    SDL_SCANCODE_END, // VirtualKey.End -- 35
   5.308 -    SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
   5.309 -    SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
   5.310 -    SDL_SCANCODE_UP, // VirtualKey.Up -- 38
   5.311 -    SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
   5.312 -    SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
   5.313 -    SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
   5.314 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42  (maybe SDL_SCANCODE_PRINTSCREEN ?)
   5.315 -    SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
   5.316 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
   5.317 -    SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
   5.318 -    SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
   5.319 -    SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
   5.320 -    SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
   5.321 -    SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
   5.322 -    SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
   5.323 -    SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
   5.324 -    SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
   5.325 -    SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
   5.326 -    SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
   5.327 -    SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
   5.328 -    SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
   5.329 -    SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
   5.330 -    SDL_SCANCODE_UNKNOWN, // -- 58
   5.331 -    SDL_SCANCODE_UNKNOWN, // -- 59
   5.332 -    SDL_SCANCODE_UNKNOWN, // -- 60
   5.333 -    SDL_SCANCODE_UNKNOWN, // -- 61
   5.334 -    SDL_SCANCODE_UNKNOWN, // -- 62
   5.335 -    SDL_SCANCODE_UNKNOWN, // -- 63
   5.336 -    SDL_SCANCODE_UNKNOWN, // -- 64
   5.337 -    SDL_SCANCODE_A, // VirtualKey.A -- 65
   5.338 -    SDL_SCANCODE_B, // VirtualKey.B -- 66
   5.339 -    SDL_SCANCODE_C, // VirtualKey.C -- 67
   5.340 -    SDL_SCANCODE_D, // VirtualKey.D -- 68
   5.341 -    SDL_SCANCODE_E, // VirtualKey.E -- 69
   5.342 -    SDL_SCANCODE_F, // VirtualKey.F -- 70
   5.343 -    SDL_SCANCODE_G, // VirtualKey.G -- 71
   5.344 -    SDL_SCANCODE_H, // VirtualKey.H -- 72
   5.345 -    SDL_SCANCODE_I, // VirtualKey.I -- 73
   5.346 -    SDL_SCANCODE_J, // VirtualKey.J -- 74
   5.347 -    SDL_SCANCODE_K, // VirtualKey.K -- 75
   5.348 -    SDL_SCANCODE_L, // VirtualKey.L -- 76
   5.349 -    SDL_SCANCODE_M, // VirtualKey.M -- 77
   5.350 -    SDL_SCANCODE_N, // VirtualKey.N -- 78
   5.351 -    SDL_SCANCODE_O, // VirtualKey.O -- 79
   5.352 -    SDL_SCANCODE_P, // VirtualKey.P -- 80
   5.353 -    SDL_SCANCODE_Q, // VirtualKey.Q -- 81
   5.354 -    SDL_SCANCODE_R, // VirtualKey.R -- 82
   5.355 -    SDL_SCANCODE_S, // VirtualKey.S -- 83
   5.356 -    SDL_SCANCODE_T, // VirtualKey.T -- 84
   5.357 -    SDL_SCANCODE_U, // VirtualKey.U -- 85
   5.358 -    SDL_SCANCODE_V, // VirtualKey.V -- 86
   5.359 -    SDL_SCANCODE_W, // VirtualKey.W -- 87
   5.360 -    SDL_SCANCODE_X, // VirtualKey.X -- 88
   5.361 -    SDL_SCANCODE_Y, // VirtualKey.Y -- 89
   5.362 -    SDL_SCANCODE_Z, // VirtualKey.Z -- 90
   5.363 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
   5.364 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
   5.365 -    SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
   5.366 -    SDL_SCANCODE_UNKNOWN, // -- 94
   5.367 -    SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
   5.368 -    SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
   5.369 -    SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
   5.370 -    SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
   5.371 -    SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
   5.372 -    SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
   5.373 -    SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
   5.374 -    SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
   5.375 -    SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
   5.376 -    SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
   5.377 -    SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
   5.378 -    SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
   5.379 -    SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
   5.380 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
   5.381 -    SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
   5.382 -    SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110  (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
   5.383 -    SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
   5.384 -    SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
   5.385 -    SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
   5.386 -    SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
   5.387 -    SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
   5.388 -    SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
   5.389 -    SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
   5.390 -    SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
   5.391 -    SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
   5.392 -    SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
   5.393 -    SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
   5.394 -    SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
   5.395 -    SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
   5.396 -    SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
   5.397 -    SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
   5.398 -    SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
   5.399 -    SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
   5.400 -    SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
   5.401 -    SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
   5.402 -    SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
   5.403 -    SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
   5.404 -    SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
   5.405 -    SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
   5.406 -    SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
   5.407 -    SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
   5.408 -    SDL_SCANCODE_UNKNOWN, // -- 136
   5.409 -    SDL_SCANCODE_UNKNOWN, // -- 137
   5.410 -    SDL_SCANCODE_UNKNOWN, // -- 138
   5.411 -    SDL_SCANCODE_UNKNOWN, // -- 139
   5.412 -    SDL_SCANCODE_UNKNOWN, // -- 140
   5.413 -    SDL_SCANCODE_UNKNOWN, // -- 141
   5.414 -    SDL_SCANCODE_UNKNOWN, // -- 142
   5.415 -    SDL_SCANCODE_UNKNOWN, // -- 143
   5.416 -    SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
   5.417 -    SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
   5.418 -    SDL_SCANCODE_UNKNOWN, // -- 146
   5.419 -    SDL_SCANCODE_UNKNOWN, // -- 147
   5.420 -    SDL_SCANCODE_UNKNOWN, // -- 148
   5.421 -    SDL_SCANCODE_UNKNOWN, // -- 149
   5.422 -    SDL_SCANCODE_UNKNOWN, // -- 150
   5.423 -    SDL_SCANCODE_UNKNOWN, // -- 151
   5.424 -    SDL_SCANCODE_UNKNOWN, // -- 152
   5.425 -    SDL_SCANCODE_UNKNOWN, // -- 153
   5.426 -    SDL_SCANCODE_UNKNOWN, // -- 154
   5.427 -    SDL_SCANCODE_UNKNOWN, // -- 155
   5.428 -    SDL_SCANCODE_UNKNOWN, // -- 156
   5.429 -    SDL_SCANCODE_UNKNOWN, // -- 157
   5.430 -    SDL_SCANCODE_UNKNOWN, // -- 158
   5.431 -    SDL_SCANCODE_UNKNOWN, // -- 159
   5.432 -    SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
   5.433 -    SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
   5.434 -    SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
   5.435 -    SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
   5.436 -    SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
   5.437 -    SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
   5.438 -};
   5.439 -
   5.440 -static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
   5.441 -
   5.442 -static SDL_Scancode
   5.443 -TranslateKeycode(int keycode)
   5.444 -{
   5.445 -    if (WinRT_Unofficial_Keycodes.empty()) {
   5.446 -        /* Set up a table of undocumented (by Microsoft), WinRT-specific,
   5.447 -           key codes: */
   5.448 -        // TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible
   5.449 -        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE;
   5.450 -        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH;
   5.451 -    }
   5.452 -
   5.453 -    /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
   5.454 -       http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
   5.455 -       If that fails, fall back to a Win32 virtual key.
   5.456 -    */
   5.457 -    // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
   5.458 -    //SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
   5.459 -    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
   5.460 -    if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
   5.461 -        scancode = WinRT_Official_Keycodes[keycode];
   5.462 -    }
   5.463 -    if (scancode == SDL_SCANCODE_UNKNOWN) {
   5.464 -        if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
   5.465 -            scancode = WinRT_Unofficial_Keycodes[keycode];
   5.466 -        }
   5.467 -    }
   5.468 -    if (scancode == SDL_SCANCODE_UNKNOWN) {
   5.469 -        if (keycode < SDL_arraysize(windows_scancode_table)) {
   5.470 -            scancode = windows_scancode_table[keycode];
   5.471 -        }
   5.472 -    }
   5.473 -    if (scancode == SDL_SCANCODE_UNKNOWN) {
   5.474 -        SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
   5.475 -    }
   5.476 -    return scancode;
   5.477 +    SDL_Window * window = (m_sdlWindowData ? m_sdlWindowData->sdlWindow : nullptr);
   5.478 +    WINRT_ProcessPointerMovedEvent(window, args);
   5.479  }
   5.480  
   5.481  void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   5.482  {
   5.483 -    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   5.484 -#if 0
   5.485 -    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   5.486 -    SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
   5.487 -        (args->Handled ? "1" : "0"),
   5.488 -        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   5.489 -        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   5.490 -        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   5.491 -        args->KeyStatus.RepeatCount,
   5.492 -        args->KeyStatus.ScanCode,
   5.493 -        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   5.494 -        args->VirtualKey,
   5.495 -        sdlScancode,
   5.496 -        SDL_GetScancodeName(sdlScancode),
   5.497 -        keycode,
   5.498 -        SDL_GetKeyName(keycode));
   5.499 -    //args->Handled = true;
   5.500 -    //VirtualKey vkey = args->VirtualKey;
   5.501 -#endif
   5.502 -    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
   5.503 +    WINRT_ProcessKeyDownEvent(args);
   5.504  }
   5.505  
   5.506  void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   5.507  {
   5.508 -    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   5.509 -#if 0
   5.510 -    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   5.511 -    SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
   5.512 -        (args->Handled ? "1" : "0"),
   5.513 -        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   5.514 -        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   5.515 -        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   5.516 -        args->KeyStatus.RepeatCount,
   5.517 -        args->KeyStatus.ScanCode,
   5.518 -        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   5.519 -        args->VirtualKey,
   5.520 -        sdlScancode,
   5.521 -        SDL_GetScancodeName(sdlScancode),
   5.522 -        keycode,
   5.523 -        SDL_GetKeyName(keycode));
   5.524 -    //args->Handled = true;
   5.525 -#endif
   5.526 -    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
   5.527 +    WINRT_ProcessKeyUpEvent(args);
   5.528  }
   5.529  
   5.530  void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
   5.531 @@ -970,11 +530,6 @@
   5.532      return (m_sdlWindowData != NULL);
   5.533  }
   5.534  
   5.535 -void SDL_WinRTApp::SetRelativeMouseMode(bool enable)
   5.536 -{
   5.537 -    m_useRelativeMouseMode = enable;
   5.538 -}
   5.539 -
   5.540  void SDL_WinRTApp::SetSDLWindowData(const SDL_WindowData * windowData)
   5.541  {
   5.542      m_sdlWindowData = windowData;
     6.1 --- a/src/core/winrt/SDL_winrtapp.h	Tue Aug 20 22:18:48 2013 -0400
     6.2 +++ b/src/core/winrt/SDL_winrtapp.h	Mon Aug 26 17:17:53 2013 -0400
     6.3 @@ -20,7 +20,6 @@
     6.4      void PumpEvents();
     6.5      const SDL_WindowData * GetSDLWindowData() const;
     6.6      bool HasSDLWindowData() const;
     6.7 -    void SetRelativeMouseMode(bool enable);
     6.8      void SetSDLWindowData(const SDL_WindowData * windowData);
     6.9      void SetSDLVideoDevice(const SDL_VideoDevice * videoDevice);
    6.10      Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
    6.11 @@ -48,5 +47,4 @@
    6.12      bool m_windowVisible;
    6.13      const SDL_WindowData* m_sdlWindowData;
    6.14      const SDL_VideoDevice* m_sdlVideoDevice;
    6.15 -    bool m_useRelativeMouseMode;
    6.16  };
     7.1 --- a/src/video/winrt/SDL_winrtevents_c.h	Tue Aug 20 22:18:48 2013 -0400
     7.2 +++ b/src/video/winrt/SDL_winrtevents_c.h	Mon Aug 26 17:17:53 2013 -0400
     7.3 @@ -19,9 +19,39 @@
     7.4    3. This notice may not be removed or altered from any source distribution.
     7.5  */
     7.6  #include "SDL_config.h"
     7.7 +#include "SDL_winrtvideo.h"
     7.8  
     7.9 -#include "SDL_winrtvideo.h"
    7.10 +/*
    7.11 + * Internal-use, C-style functions:
    7.12 + */
    7.13 +
    7.14 +#ifdef __cplusplus
    7.15 +extern "C" {
    7.16 +#endif
    7.17  
    7.18  extern void WINRT_PumpEvents(_THIS);
    7.19  
    7.20 +#ifdef __cplusplus
    7.21 +}
    7.22 +#endif
    7.23 +
    7.24 +
    7.25 +/*
    7.26 + * Internal-use, C++/CX functions:
    7.27 + */
    7.28 +#ifdef __cplusplus_winrt
    7.29 +
    7.30 +/* Keyboard */
    7.31 +extern void WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args);
    7.32 +extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args);
    7.33 +
    7.34 +/* Pointers (Mice, Touch, etc.) */
    7.35 +extern void WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args);
    7.36 +extern void WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args);
    7.37 +extern void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args);
    7.38 +extern void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args);
    7.39 +extern void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args);
    7.40 +
    7.41 +#endif
    7.42 +
    7.43  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/winrt/SDL_winrtkeyboard.cpp	Mon Aug 26 17:17:53 2013 -0400
     8.3 @@ -0,0 +1,300 @@
     8.4 +/*
     8.5 +  Simple DirectMedia Layer
     8.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     8.7 +
     8.8 +  This software is provided 'as-is', without any express or implied
     8.9 +  warranty.  In no event will the authors be held liable for any damages
    8.10 +  arising from the use of this software.
    8.11 +
    8.12 +  Permission is granted to anyone to use this software for any purpose,
    8.13 +  including commercial applications, and to alter it and redistribute it
    8.14 +  freely, subject to the following restrictions:
    8.15 +
    8.16 +  1. The origin of this software must not be misrepresented; you must not
    8.17 +     claim that you wrote the original software. If you use this software
    8.18 +     in a product, an acknowledgment in the product documentation would be
    8.19 +     appreciated but is not required.
    8.20 +  2. Altered source versions must be plainly marked as such, and must not be
    8.21 +     misrepresented as being the original software.
    8.22 +  3. This notice may not be removed or altered from any source distribution.
    8.23 +*/
    8.24 +#include "SDL_config.h"
    8.25 +
    8.26 +#if SDL_VIDEO_DRIVER_WINRT
    8.27 +
    8.28 +// Standard C++11 headers:
    8.29 +#include <unordered_map>
    8.30 +
    8.31 +
    8.32 +// Windows-specific headers:
    8.33 +#include <Windows.h>
    8.34 +
    8.35 +
    8.36 +// SDL-specific headers:
    8.37 +#include <SDL.h>
    8.38 +#include "SDL_winrtevents_c.h"
    8.39 +
    8.40 +extern "C" {
    8.41 +#include "../../events/scancodes_windows.h"
    8.42 +#include "../../events/SDL_keyboard_c.h"
    8.43 +}
    8.44 +
    8.45 +
    8.46 +static SDL_Scancode WinRT_Official_Keycodes[] = {
    8.47 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
    8.48 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
    8.49 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
    8.50 +    SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
    8.51 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
    8.52 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
    8.53 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
    8.54 +    SDL_SCANCODE_UNKNOWN, // -- 7
    8.55 +    SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
    8.56 +    SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
    8.57 +    SDL_SCANCODE_UNKNOWN, // -- 10
    8.58 +    SDL_SCANCODE_UNKNOWN, // -- 11
    8.59 +    SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
    8.60 +    SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
    8.61 +    SDL_SCANCODE_UNKNOWN, // -- 14
    8.62 +    SDL_SCANCODE_UNKNOWN, // -- 15
    8.63 +    SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
    8.64 +    SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
    8.65 +    SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
    8.66 +    SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
    8.67 +    SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
    8.68 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
    8.69 +    SDL_SCANCODE_UNKNOWN, // -- 22
    8.70 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
    8.71 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
    8.72 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
    8.73 +    SDL_SCANCODE_UNKNOWN, // -- 26
    8.74 +    SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
    8.75 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
    8.76 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
    8.77 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
    8.78 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31  (maybe SDL_SCANCODE_MODE ?)
    8.79 +    SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
    8.80 +    SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
    8.81 +    SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
    8.82 +    SDL_SCANCODE_END, // VirtualKey.End -- 35
    8.83 +    SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
    8.84 +    SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
    8.85 +    SDL_SCANCODE_UP, // VirtualKey.Up -- 38
    8.86 +    SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
    8.87 +    SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
    8.88 +    SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
    8.89 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42  (maybe SDL_SCANCODE_PRINTSCREEN ?)
    8.90 +    SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
    8.91 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
    8.92 +    SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
    8.93 +    SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
    8.94 +    SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
    8.95 +    SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
    8.96 +    SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
    8.97 +    SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
    8.98 +    SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
    8.99 +    SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
   8.100 +    SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
   8.101 +    SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
   8.102 +    SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
   8.103 +    SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
   8.104 +    SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
   8.105 +    SDL_SCANCODE_UNKNOWN, // -- 58
   8.106 +    SDL_SCANCODE_UNKNOWN, // -- 59
   8.107 +    SDL_SCANCODE_UNKNOWN, // -- 60
   8.108 +    SDL_SCANCODE_UNKNOWN, // -- 61
   8.109 +    SDL_SCANCODE_UNKNOWN, // -- 62
   8.110 +    SDL_SCANCODE_UNKNOWN, // -- 63
   8.111 +    SDL_SCANCODE_UNKNOWN, // -- 64
   8.112 +    SDL_SCANCODE_A, // VirtualKey.A -- 65
   8.113 +    SDL_SCANCODE_B, // VirtualKey.B -- 66
   8.114 +    SDL_SCANCODE_C, // VirtualKey.C -- 67
   8.115 +    SDL_SCANCODE_D, // VirtualKey.D -- 68
   8.116 +    SDL_SCANCODE_E, // VirtualKey.E -- 69
   8.117 +    SDL_SCANCODE_F, // VirtualKey.F -- 70
   8.118 +    SDL_SCANCODE_G, // VirtualKey.G -- 71
   8.119 +    SDL_SCANCODE_H, // VirtualKey.H -- 72
   8.120 +    SDL_SCANCODE_I, // VirtualKey.I -- 73
   8.121 +    SDL_SCANCODE_J, // VirtualKey.J -- 74
   8.122 +    SDL_SCANCODE_K, // VirtualKey.K -- 75
   8.123 +    SDL_SCANCODE_L, // VirtualKey.L -- 76
   8.124 +    SDL_SCANCODE_M, // VirtualKey.M -- 77
   8.125 +    SDL_SCANCODE_N, // VirtualKey.N -- 78
   8.126 +    SDL_SCANCODE_O, // VirtualKey.O -- 79
   8.127 +    SDL_SCANCODE_P, // VirtualKey.P -- 80
   8.128 +    SDL_SCANCODE_Q, // VirtualKey.Q -- 81
   8.129 +    SDL_SCANCODE_R, // VirtualKey.R -- 82
   8.130 +    SDL_SCANCODE_S, // VirtualKey.S -- 83
   8.131 +    SDL_SCANCODE_T, // VirtualKey.T -- 84
   8.132 +    SDL_SCANCODE_U, // VirtualKey.U -- 85
   8.133 +    SDL_SCANCODE_V, // VirtualKey.V -- 86
   8.134 +    SDL_SCANCODE_W, // VirtualKey.W -- 87
   8.135 +    SDL_SCANCODE_X, // VirtualKey.X -- 88
   8.136 +    SDL_SCANCODE_Y, // VirtualKey.Y -- 89
   8.137 +    SDL_SCANCODE_Z, // VirtualKey.Z -- 90
   8.138 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
   8.139 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92  (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
   8.140 +    SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
   8.141 +    SDL_SCANCODE_UNKNOWN, // -- 94
   8.142 +    SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
   8.143 +    SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
   8.144 +    SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
   8.145 +    SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
   8.146 +    SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
   8.147 +    SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
   8.148 +    SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
   8.149 +    SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
   8.150 +    SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
   8.151 +    SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
   8.152 +    SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
   8.153 +    SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
   8.154 +    SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
   8.155 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
   8.156 +    SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
   8.157 +    SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110  (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
   8.158 +    SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
   8.159 +    SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
   8.160 +    SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
   8.161 +    SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
   8.162 +    SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
   8.163 +    SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
   8.164 +    SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
   8.165 +    SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
   8.166 +    SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
   8.167 +    SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
   8.168 +    SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
   8.169 +    SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
   8.170 +    SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
   8.171 +    SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
   8.172 +    SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
   8.173 +    SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
   8.174 +    SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
   8.175 +    SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
   8.176 +    SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
   8.177 +    SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
   8.178 +    SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
   8.179 +    SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
   8.180 +    SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
   8.181 +    SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
   8.182 +    SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
   8.183 +    SDL_SCANCODE_UNKNOWN, // -- 136
   8.184 +    SDL_SCANCODE_UNKNOWN, // -- 137
   8.185 +    SDL_SCANCODE_UNKNOWN, // -- 138
   8.186 +    SDL_SCANCODE_UNKNOWN, // -- 139
   8.187 +    SDL_SCANCODE_UNKNOWN, // -- 140
   8.188 +    SDL_SCANCODE_UNKNOWN, // -- 141
   8.189 +    SDL_SCANCODE_UNKNOWN, // -- 142
   8.190 +    SDL_SCANCODE_UNKNOWN, // -- 143
   8.191 +    SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
   8.192 +    SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
   8.193 +    SDL_SCANCODE_UNKNOWN, // -- 146
   8.194 +    SDL_SCANCODE_UNKNOWN, // -- 147
   8.195 +    SDL_SCANCODE_UNKNOWN, // -- 148
   8.196 +    SDL_SCANCODE_UNKNOWN, // -- 149
   8.197 +    SDL_SCANCODE_UNKNOWN, // -- 150
   8.198 +    SDL_SCANCODE_UNKNOWN, // -- 151
   8.199 +    SDL_SCANCODE_UNKNOWN, // -- 152
   8.200 +    SDL_SCANCODE_UNKNOWN, // -- 153
   8.201 +    SDL_SCANCODE_UNKNOWN, // -- 154
   8.202 +    SDL_SCANCODE_UNKNOWN, // -- 155
   8.203 +    SDL_SCANCODE_UNKNOWN, // -- 156
   8.204 +    SDL_SCANCODE_UNKNOWN, // -- 157
   8.205 +    SDL_SCANCODE_UNKNOWN, // -- 158
   8.206 +    SDL_SCANCODE_UNKNOWN, // -- 159
   8.207 +    SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
   8.208 +    SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
   8.209 +    SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
   8.210 +    SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
   8.211 +    SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
   8.212 +    SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
   8.213 +};
   8.214 +
   8.215 +static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
   8.216 +
   8.217 +static SDL_Scancode
   8.218 +TranslateKeycode(int keycode)
   8.219 +{
   8.220 +    if (WinRT_Unofficial_Keycodes.empty()) {
   8.221 +        /* Set up a table of undocumented (by Microsoft), WinRT-specific,
   8.222 +           key codes: */
   8.223 +        // TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible
   8.224 +        WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE;
   8.225 +        WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH;
   8.226 +    }
   8.227 +
   8.228 +    /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
   8.229 +       http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
   8.230 +       If that fails, fall back to a Win32 virtual key.
   8.231 +    */
   8.232 +    // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
   8.233 +    //SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
   8.234 +    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
   8.235 +    if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
   8.236 +        scancode = WinRT_Official_Keycodes[keycode];
   8.237 +    }
   8.238 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   8.239 +        if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
   8.240 +            scancode = WinRT_Unofficial_Keycodes[keycode];
   8.241 +        }
   8.242 +    }
   8.243 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   8.244 +        if (keycode < SDL_arraysize(windows_scancode_table)) {
   8.245 +            scancode = windows_scancode_table[keycode];
   8.246 +        }
   8.247 +    }
   8.248 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   8.249 +        SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
   8.250 +    }
   8.251 +    return scancode;
   8.252 +}
   8.253 +
   8.254 +void
   8.255 +WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
   8.256 +{
   8.257 +    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   8.258 +#if 0
   8.259 +    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   8.260 +    SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
   8.261 +        (args->Handled ? "1" : "0"),
   8.262 +        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   8.263 +        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   8.264 +        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   8.265 +        args->KeyStatus.RepeatCount,
   8.266 +        args->KeyStatus.ScanCode,
   8.267 +        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   8.268 +        args->VirtualKey,
   8.269 +        sdlScancode,
   8.270 +        SDL_GetScancodeName(sdlScancode),
   8.271 +        keycode,
   8.272 +        SDL_GetKeyName(keycode));
   8.273 +    //args->Handled = true;
   8.274 +    //VirtualKey vkey = args->VirtualKey;
   8.275 +#endif
   8.276 +    SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
   8.277 +}
   8.278 +
   8.279 +void
   8.280 +WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
   8.281 +{
   8.282 +    SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
   8.283 +#if 0
   8.284 +    SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
   8.285 +    SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
   8.286 +        (args->Handled ? "1" : "0"),
   8.287 +        (args->KeyStatus.IsExtendedKey ? "1" : "0"),
   8.288 +        (args->KeyStatus.IsKeyReleased ? "1" : "0"),
   8.289 +        (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
   8.290 +        args->KeyStatus.RepeatCount,
   8.291 +        args->KeyStatus.ScanCode,
   8.292 +        (args->KeyStatus.WasKeyDown ? "1" : "0"),
   8.293 +        args->VirtualKey,
   8.294 +        sdlScancode,
   8.295 +        SDL_GetScancodeName(sdlScancode),
   8.296 +        keycode,
   8.297 +        SDL_GetKeyName(keycode));
   8.298 +    //args->Handled = true;
   8.299 +#endif
   8.300 +    SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
   8.301 +}
   8.302 +
   8.303 +#endif // SDL_VIDEO_DRIVER_WINRT
     9.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Tue Aug 20 22:18:48 2013 -0400
     9.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Mon Aug 26 17:17:53 2013 -0400
     9.3 @@ -23,19 +23,29 @@
     9.4  
     9.5  #if SDL_VIDEO_DRIVER_WINRT
     9.6  
     9.7 +/*
     9.8 + * Windows includes:
     9.9 + */
    9.10 +#include <Windows.h>
    9.11 +using namespace Windows::UI::Core;
    9.12 +using Windows::UI::Core::CoreCursor;
    9.13 +
    9.14 +/*
    9.15 + * SDL includes:
    9.16 + */
    9.17  extern "C" {
    9.18  #include "SDL_assert.h"
    9.19  #include "../../events/SDL_mouse_c.h"
    9.20  #include "../SDL_sysvideo.h"
    9.21 +#include "SDL_events.h"
    9.22 +#include "SDL_log.h"
    9.23  }
    9.24  
    9.25  #include "../../core/winrt/SDL_winrtapp.h"
    9.26  #include "SDL_winrtmouse.h"
    9.27  
    9.28 -using namespace Windows::UI::Core;
    9.29 -using Windows::UI::Core::CoreCursor;
    9.30  
    9.31 -extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
    9.32 +static SDL_bool WINRT_UseRelativeMouseMode = SDL_FALSE;
    9.33  
    9.34  
    9.35  static SDL_Cursor *
    9.36 @@ -112,7 +122,7 @@
    9.37  static int
    9.38  WINRT_SetRelativeMouseMode(SDL_bool enabled)
    9.39  {
    9.40 -    SDL_WinRTGlobalApp->SetRelativeMouseMode(enabled ? true : false);
    9.41 +    WINRT_UseRelativeMouseMode = enabled;
    9.42      return 0;
    9.43  }
    9.44  
    9.45 @@ -144,6 +154,248 @@
    9.46  {
    9.47  }
    9.48  
    9.49 +// Applies necessary geometric transformations to raw cursor positions:
    9.50 +static Windows::Foundation::Point
    9.51 +TransformCursor(SDL_Window * window, Windows::Foundation::Point rawPosition)
    9.52 +{
    9.53 +    if (!window) {
    9.54 +        return rawPosition;
    9.55 +    }
    9.56 +    CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
    9.57 +    Windows::Foundation::Point outputPosition;
    9.58 +    outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
    9.59 +    outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
    9.60 +    return outputPosition;
    9.61 +}
    9.62 +
    9.63 +static inline int
    9.64 +_lround(float arg)
    9.65 +{
    9.66 +    if (arg >= 0.0f) {
    9.67 +        return (int)floor(arg + 0.5f);
    9.68 +    } else {
    9.69 +        return (int)ceil(arg - 0.5f);
    9.70 +    }
    9.71 +}
    9.72 +
    9.73 +void
    9.74 +WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args)
    9.75 +{
    9.76 +    if (!window || !WINRT_UseRelativeMouseMode) {
    9.77 +        return;
    9.78 +    }
    9.79 +
    9.80 +    // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
    9.81 +    // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
    9.82 +    // MouseDelta field often reports very large values.  More information
    9.83 +    // on this can be found at the following pages on MSDN:
    9.84 +    //  - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
    9.85 +    //  - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
    9.86 +    //
    9.87 +    // The values do not appear to be as large when running on some systems,
    9.88 +    // most notably a Surface RT.  Furthermore, the values returned by
    9.89 +    // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
    9.90 +    // method, do not ever appear to be large, even when MouseEventArgs'
    9.91 +    // MouseDelta is reporting to the contrary.
    9.92 +    //
    9.93 +    // On systems with the large-values behavior, it appears that the values
    9.94 +    // get reported as if the screen's size is 65536 units in both the X and Y
    9.95 +    // dimensions.  This can be viewed by using Windows' now-private, "Raw Input"
    9.96 +    // APIs.  (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
    9.97 +    //
    9.98 +    // MSDN's documentation on MouseEventArgs' MouseDelta field (at
    9.99 +    // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
   9.100 +    // does not seem to indicate (to me) that its values should be so large.  It
   9.101 +    // says that its values should be a "change in screen location".  I could
   9.102 +    // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: 
   9.103 +    // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
   9.104 +    // indicates that these values are in DIPs, which is the same unit used
   9.105 +    // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
   9.106 +    // property.  See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
   9.107 +    // for details.)
   9.108 +    //
   9.109 +    // To note, PointerMoved events are sent a 'RawPosition' value (via the
   9.110 +    // CurrentPoint property in MouseEventArgs), however these do not seem
   9.111 +    // to exhibit the same large-value behavior.
   9.112 +    //
   9.113 +    // The values passed via PointerMoved events can't always be used for relative
   9.114 +    // mouse motion, unfortunately.  Its values are bound to the cursor's position,
   9.115 +    // which stops when it hits one of the screen's edges.  This can be a problem in
   9.116 +    // first person shooters, whereby it is normal for mouse motion to travel far
   9.117 +    // along any one axis for a period of time.  MouseMoved events do not have the
   9.118 +    // screen-bounding limitation, and can be used regardless of where the system's
   9.119 +    // cursor is.
   9.120 +    //
   9.121 +    // One possible workaround would be to programmatically set the cursor's
   9.122 +    // position to the screen's center (when SDL's relative mouse mode is enabled),
   9.123 +    // however Windows RT does not yet seem to have the ability to set the cursor's
   9.124 +    // position via a public API.  Win32 did this via an API call, SetCursorPos,
   9.125 +    // however WinRT makes this function be private.  Apps that use it won't get
   9.126 +    // approved for distribution in the Windows Store.  I've yet to be able to find
   9.127 +    // a suitable, store-friendly counterpart for WinRT.
   9.128 +    //
   9.129 +    // There may be some room for a workaround whereby OnPointerMoved's values
   9.130 +    // are compared to the values from OnMouseMoved in order to detect
   9.131 +    // when this bug is active.  A suitable transformation could then be made to
   9.132 +    // OnMouseMoved's values.  For now, however, the system-reported values are sent
   9.133 +    // to SDL with minimal transformation: from native screen coordinates (in DIPs)
   9.134 +    // to SDL window coordinates.
   9.135 +    //
   9.136 +    const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
   9.137 +    const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = TransformCursor(window, mouseDeltaInDIPs);
   9.138 +    SDL_SendMouseMotion(
   9.139 +        window,
   9.140 +        0,
   9.141 +        1,
   9.142 +        _lround(mouseDeltaInSDLWindowCoords.X),
   9.143 +        _lround(mouseDeltaInSDLWindowCoords.Y));
   9.144 +}
   9.145 +
   9.146 +static Uint8
   9.147 +WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
   9.148 +{
   9.149 +    using namespace Windows::UI::Input;
   9.150 +
   9.151 +    switch (pt->Properties->PointerUpdateKind)
   9.152 +    {
   9.153 +        case PointerUpdateKind::LeftButtonPressed:
   9.154 +        case PointerUpdateKind::LeftButtonReleased:
   9.155 +            return SDL_BUTTON_LEFT;
   9.156 +
   9.157 +        case PointerUpdateKind::RightButtonPressed:
   9.158 +        case PointerUpdateKind::RightButtonReleased:
   9.159 +            return SDL_BUTTON_RIGHT;
   9.160 +
   9.161 +        case PointerUpdateKind::MiddleButtonPressed:
   9.162 +        case PointerUpdateKind::MiddleButtonReleased:
   9.163 +            return SDL_BUTTON_MIDDLE;
   9.164 +
   9.165 +        case PointerUpdateKind::XButton1Pressed:
   9.166 +        case PointerUpdateKind::XButton1Released:
   9.167 +            return SDL_BUTTON_X1;
   9.168 +
   9.169 +        case PointerUpdateKind::XButton2Pressed:
   9.170 +        case PointerUpdateKind::XButton2Released:
   9.171 +            return SDL_BUTTON_X2;
   9.172 +
   9.173 +        default:
   9.174 +            break;
   9.175 +    }
   9.176 +
   9.177 +    return 0;
   9.178 +}
   9.179 +
   9.180 +static const char *
   9.181 +WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
   9.182 +{
   9.183 +    using namespace Windows::UI::Input;
   9.184 +
   9.185 +    switch (kind)
   9.186 +    {
   9.187 +        case PointerUpdateKind::Other:
   9.188 +            return "Other";
   9.189 +        case PointerUpdateKind::LeftButtonPressed:
   9.190 +            return "LeftButtonPressed";
   9.191 +        case PointerUpdateKind::LeftButtonReleased:
   9.192 +            return "LeftButtonReleased";
   9.193 +        case PointerUpdateKind::RightButtonPressed:
   9.194 +            return "RightButtonPressed";
   9.195 +        case PointerUpdateKind::RightButtonReleased:
   9.196 +            return "RightButtonReleased";
   9.197 +        case PointerUpdateKind::MiddleButtonPressed:
   9.198 +            return "MiddleButtonPressed";
   9.199 +        case PointerUpdateKind::MiddleButtonReleased:
   9.200 +            return "MiddleButtonReleased";
   9.201 +        case PointerUpdateKind::XButton1Pressed:
   9.202 +            return "XButton1Pressed";
   9.203 +        case PointerUpdateKind::XButton1Released:
   9.204 +            return "XButton1Released";
   9.205 +        case PointerUpdateKind::XButton2Pressed:
   9.206 +            return "XButton2Pressed";
   9.207 +        case PointerUpdateKind::XButton2Released:
   9.208 +            return "XButton2Released";
   9.209 +    }
   9.210 +
   9.211 +    return "";
   9.212 +}
   9.213 +
   9.214 +static void
   9.215 +WINRT_LogPointerEvent(const char * header, PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
   9.216 +{
   9.217 +    Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
   9.218 +    SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, PointerUpdateKind=%s\n",
   9.219 +        header,
   9.220 +        pt->Position.X, pt->Position.Y,
   9.221 +        transformedPoint.X, transformedPoint.Y,
   9.222 +        pt->Properties->MouseWheelDelta,
   9.223 +        pt->FrameId,
   9.224 +        pt->PointerId,
   9.225 +        WINRT_ConvertPointerUpdateKindToString(args->CurrentPoint->Properties->PointerUpdateKind));
   9.226 +}
   9.227 +
   9.228 +void
   9.229 +WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args)
   9.230 +{
   9.231 +#if LOG_POINTER_EVENTS
   9.232 +    WINRT_LogPointerEvent("pointer moved", args, TransformCursor(args->CurrentPoint->Position));
   9.233 +#endif
   9.234 +
   9.235 +    if (!window || WINRT_UseRelativeMouseMode) {
   9.236 +        return;
   9.237 +    }
   9.238 +
   9.239 +    Windows::Foundation::Point transformedPoint = TransformCursor(window, args->CurrentPoint->Position);
   9.240 +    SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
   9.241 +}
   9.242 +
   9.243 +void
   9.244 +WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args)
   9.245 +{
   9.246 +#if LOG_POINTER_EVENTS
   9.247 +    WINRT_LogPointerEvent("wheel changed", args, TransformCursor(args->CurrentPoint->Position));
   9.248 +#endif
   9.249 +
   9.250 +    if (!window) {
   9.251 +        return;
   9.252 +    }
   9.253 +
   9.254 +    // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
   9.255 +    short motion = args->CurrentPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
   9.256 +    SDL_SendMouseWheel(window, 0, 0, motion);
   9.257 +}
   9.258 +
   9.259 +void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args)
   9.260 +{
   9.261 +#if LOG_POINTER_EVENTS
   9.262 +    WINRT_LogPointerEvent("mouse up", args, TransformCursor(args->CurrentPoint->Position));
   9.263 +#endif
   9.264 +
   9.265 +    if (!window) {
   9.266 +        return;
   9.267 +    }
   9.268 +
   9.269 +    Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
   9.270 +    if (button) {
   9.271 +        SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
   9.272 +    }
   9.273 +}
   9.274 +
   9.275 +void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Core::PointerEventArgs ^args)
   9.276 +{
   9.277 +#if LOG_POINTER_EVENTS
   9.278 +    WINRT_LogPointerEvent("mouse down", args, TransformCursor(args->CurrentPoint->Position));
   9.279 +#endif
   9.280 +
   9.281 +    if (!window) {
   9.282 +        return;
   9.283 +    }
   9.284 +
   9.285 +    Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
   9.286 +    if (button) {
   9.287 +        SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
   9.288 +    }
   9.289 +}
   9.290 +
   9.291  #endif /* SDL_VIDEO_DRIVER_WINRT */
   9.292  
   9.293  /* vi: set ts=4 sw=4 expandtab: */