WinRT: misc code cleanups regarding touch and mouse events, and also SDL-internal globals
authorDavid Ludwig <dludwig@pobox.com>
Mon, 02 Sep 2013 15:23:33 -0400
changeset 8515bc6cf9201dab
parent 8514 8ba600edd93f
child 8516 f3e0e381bdcd
WinRT: misc code cleanups regarding touch and mouse events, and also SDL-internal globals
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/core/winrt/SDL_winrtxaml.cpp
src/core/winrt/SDL_winrtxaml_cpp.h
src/video/winrt/SDL_winrtevents.cpp
src/video/winrt/SDL_winrtevents_c.h
src/video/winrt/SDL_winrtmouse.cpp
src/video/winrt/SDL_winrtmouse.h
src/video/winrt/SDL_winrtpointerinput.cpp
src/video/winrt/SDL_winrtvideo.cpp
src/video/winrt/SDL_winrtvideo_cpp.h
     1.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Sun Sep 01 10:20:17 2013 -0400
     1.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Mon Sep 02 15:23:33 2013 -0400
     1.3 @@ -198,6 +198,7 @@
     1.4      <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2_winrthelpers.h" />
     1.5      <ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
     1.6      <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp.h" />
     1.7 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h" />
     1.8      <ClInclude Include="..\..\src\events\blank_cursor.h" />
     1.9      <ClInclude Include="..\..\src\events\default_cursor.h" />
    1.10      <ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" />
    1.11 @@ -381,6 +382,12 @@
    1.12        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.13        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.14      </ClCompile>
    1.15 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
    1.16 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.17 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.18 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.19 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.20 +    </ClCompile>
    1.21      <ClCompile Include="..\..\src\video\winrt\SDL_winrtvideo.cpp">
    1.22        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.23        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
     2.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Sun Sep 01 10:20:17 2013 -0400
     2.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Mon Sep 02 15:23:33 2013 -0400
     2.3 @@ -336,6 +336,9 @@
     2.4      <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClInclude>
     2.7 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClInclude>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    2.13 @@ -599,6 +602,9 @@
    2.14      <ClCompile Include="..\..\src\core\winrt\SDL_winrtxaml.cpp">
    2.15        <Filter>Source Files</Filter>
    2.16      </ClCompile>
    2.17 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
    2.18 +      <Filter>Source Files</Filter>
    2.19 +    </ClCompile>
    2.20    </ItemGroup>
    2.21    <ItemGroup>
    2.22      <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
     3.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Sun Sep 01 10:20:17 2013 -0400
     3.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Mon Sep 02 15:23:33 2013 -0400
     3.3 @@ -176,6 +176,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_winrtpointerinput.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_winrtvideo.cpp">
    3.16        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.17        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.18 @@ -244,6 +252,7 @@
    3.19      <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2_winrthelpers.h" />
    3.20      <ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
    3.21      <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp.h" />
    3.22 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h" />
    3.23      <ClInclude Include="..\..\src\events\blank_cursor.h" />
    3.24      <ClInclude Include="..\..\src\events\default_cursor.h" />
    3.25      <ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" />
     4.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Sun Sep 01 10:20:17 2013 -0400
     4.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Mon Sep 02 15:23:33 2013 -0400
     4.3 @@ -270,6 +270,9 @@
     4.4      <ClCompile Include="..\..\src\joystick\winrt\SDL_xinputjoystick.c">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClCompile>
     4.7 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
     4.8 +      <Filter>Source Files</Filter>
     4.9 +    </ClCompile>
    4.10      <ClCompile Include="..\..\src\core\winrt\SDL_winrtxaml.cpp">
    4.11        <Filter>Source Files</Filter>
    4.12      </ClCompile>
    4.13 @@ -602,6 +605,9 @@
    4.14      <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h">
    4.15        <Filter>Source Files</Filter>
    4.16      </ClInclude>
    4.17 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h">
    4.18 +      <Filter>Source Files</Filter>
    4.19 +    </ClInclude>
    4.20    </ItemGroup>
    4.21    <ItemGroup>
    4.22      <Filter Include="Header Files">
     5.1 --- a/src/core/winrt/SDL_winrtapp.cpp	Sun Sep 01 10:20:17 2013 -0400
     5.2 +++ b/src/core/winrt/SDL_winrtapp.cpp	Mon Sep 02 15:23:33 2013 -0400
     5.3 @@ -37,12 +37,9 @@
     5.4  }
     5.5  
     5.6  #include "../../video/winrt/SDL_winrtevents_c.h"
     5.7 +#include "../../video/winrt/SDL_winrtvideo_cpp.h"
     5.8  #include "SDL_winrtapp.h"
     5.9  
    5.10 -extern SDL_Window * WINRT_GlobalSDLWindow;
    5.11 -extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice;
    5.12 -extern SDL_DisplayMode WINRT_CalcDisplayModeUsingNativeWindow();
    5.13 -
    5.14  
    5.15  // Compile-time debugging options:
    5.16  // To enable, uncomment; to disable, comment them out.
     6.1 --- a/src/core/winrt/SDL_winrtapp.h	Sun Sep 01 10:20:17 2013 -0400
     6.2 +++ b/src/core/winrt/SDL_winrtapp.h	Mon Sep 02 15:23:33 2013 -0400
     6.3 @@ -38,3 +38,5 @@
     6.4      bool m_windowClosed;
     6.5      bool m_windowVisible;
     6.6  };
     6.7 +
     6.8 +extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
     7.1 --- a/src/core/winrt/SDL_winrtxaml.cpp	Sun Sep 01 10:20:17 2013 -0400
     7.2 +++ b/src/core/winrt/SDL_winrtxaml.cpp	Mon Sep 02 15:23:33 2013 -0400
     7.3 @@ -30,18 +30,13 @@
     7.4  
     7.5  /* SDL includes */
     7.6  #include "SDL.h"
     7.7 -//#include "SDL_error.h"
     7.8 -//#include "SDL_log.h"
     7.9 -//#include "SDL_main.h"
    7.10 -//#include "SDL_system.h"
    7.11  #include "../../video/winrt/SDL_winrtevents_c.h"
    7.12 +#include "../../video/winrt/SDL_winrtvideo_cpp.h"
    7.13 +#include "SDL_winrtxaml_cpp.h"
    7.14  
    7.15  
    7.16 -/* External globals: */
    7.17 -extern SDL_Window * WINRT_GlobalSDLWindow;
    7.18  
    7.19 -
    7.20 -/* Internal globals: */
    7.21 +/* SDL-internal globals: */
    7.22  SDL_bool WINRT_XAMLWasEnabled = SDL_FALSE;
    7.23  int (*WINRT_XAMLAppMainFunction)(int, char **) = NULL;
    7.24  
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/core/winrt/SDL_winrtxaml_cpp.h	Mon Sep 02 15:23:33 2013 -0400
     8.3 @@ -0,0 +1,33 @@
     8.4 +/*
     8.5 +  Simple DirectMedia Layer
     8.6 +  Copyright (C) 1997-2012 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 +#ifndef _SDL_winrtxaml_h
    8.27 +#define _SDL_winrtxaml_h
    8.28 +
    8.29 +#include "SDL_types.h"
    8.30 +
    8.31 +#ifdef __cplusplus
    8.32 +extern SDL_bool WINRT_XAMLWasEnabled;
    8.33 +extern int (*WINRT_XAMLAppMainFunction)(int, char **);
    8.34 +#endif // ifdef __cplusplus
    8.35 +
    8.36 +#endif // ifndef _SDL_winrtxaml_h
     9.1 --- a/src/video/winrt/SDL_winrtevents.cpp	Sun Sep 01 10:20:17 2013 -0400
     9.2 +++ b/src/video/winrt/SDL_winrtevents.cpp	Mon Sep 02 15:23:33 2013 -0400
     9.3 @@ -22,9 +22,19 @@
     9.4  
     9.5  #if SDL_VIDEO_DRIVER_WINRT
     9.6  
     9.7 -/* SDL includes */
     9.8 +/*
     9.9 + * Windows includes:
    9.10 + */
    9.11 +#include <Windows.h>
    9.12 +using namespace Windows::UI::Core;
    9.13 +using Windows::UI::Core::CoreCursor;
    9.14 +
    9.15 +/*
    9.16 + * SDL includes:
    9.17 + */
    9.18  #include "SDL_winrtevents_c.h"
    9.19  #include "../../core/winrt/SDL_winrtapp.h"
    9.20 +#include "../../core/winrt/SDL_winrtxaml_cpp.h"
    9.21  #include "SDL_assert.h"
    9.22  #include "SDL_system.h"
    9.23  
    9.24 @@ -34,10 +44,8 @@
    9.25  }
    9.26  
    9.27  
    9.28 -/* Forward declarations and globals */
    9.29 -extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
    9.30 -extern int (*WINRT_XAMLAppMainFunction)(int, char **);
    9.31 -extern void WINRT_YieldXAMLThread();
    9.32 +/* Forward declarations */
    9.33 +static void WINRT_YieldXAMLThread();
    9.34  
    9.35  
    9.36  /* Global event management */
    9.37 @@ -135,7 +143,6 @@
    9.38      }
    9.39  }
    9.40  
    9.41 -
    9.42  #endif /* SDL_VIDEO_DRIVER_WINRT */
    9.43  
    9.44  /* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/video/winrt/SDL_winrtevents_c.h	Sun Sep 01 10:20:17 2013 -0400
    10.2 +++ b/src/video/winrt/SDL_winrtevents_c.h	Mon Sep 02 15:23:33 2013 -0400
    10.3 @@ -32,6 +32,7 @@
    10.4  extern "C" {
    10.5  #endif
    10.6  
    10.7 +extern void WINRT_InitTouch(_THIS);
    10.8  extern void WINRT_PumpEvents(_THIS);
    10.9  
   10.10  #ifdef __cplusplus
   10.11 @@ -60,6 +61,6 @@
   10.12  /* XAML Thread Management */
   10.13  extern void WINRT_CycleXAMLThread();
   10.14  
   10.15 -#endif
   10.16 +#endif // ifdef __cplusplus_winrt
   10.17  
   10.18  /* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Sun Sep 01 10:20:17 2013 -0400
    11.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Mon Sep 02 15:23:33 2013 -0400
    11.3 @@ -47,9 +47,7 @@
    11.4  #include "SDL_winrtmouse.h"
    11.5  
    11.6  
    11.7 -static SDL_bool WINRT_UseRelativeMouseMode = SDL_FALSE;
    11.8 -static SDL_TouchID WINRT_TouchID = 1;
    11.9 -static unsigned int WINRT_LeftFingerDown = 0;
   11.10 +extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
   11.11  
   11.12  
   11.13  static SDL_Cursor *
   11.14 @@ -131,7 +129,7 @@
   11.15  static int
   11.16  WINRT_SetRelativeMouseMode(SDL_bool enabled)
   11.17  {
   11.18 -    WINRT_UseRelativeMouseMode = enabled;
   11.19 +    WINRT_UsingRelativeMouseMode = enabled;
   11.20      return 0;
   11.21  }
   11.22  
   11.23 @@ -156,9 +154,6 @@
   11.24  
   11.25      SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
   11.26  #endif
   11.27 -
   11.28 -    /* Init touch: */
   11.29 -    SDL_AddTouch(WINRT_TouchID, "");
   11.30  }
   11.31  
   11.32  void
   11.33 @@ -166,326 +161,6 @@
   11.34  {
   11.35  }
   11.36  
   11.37 -// Applies necessary geometric transformations to raw cursor positions:
   11.38 -Windows::Foundation::Point
   11.39 -WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition)
   11.40 -{
   11.41 -    using namespace Windows::Graphics::Display;
   11.42 -
   11.43 -    if (!window) {
   11.44 -        return rawPosition;
   11.45 -    }
   11.46 -
   11.47 -    SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
   11.48 -    if (windowData->coreWindow == nullptr) {
   11.49 -        // For some reason, the window isn't associated with a CoreWindow.
   11.50 -        // This might end up being the case as XAML support is extended.
   11.51 -        // For now, if there's no CoreWindow attached to the SDL_Window,
   11.52 -        // don't do any transforms.
   11.53 -        return rawPosition;
   11.54 -    }
   11.55 -
   11.56 -    // The CoreWindow can only be accessed on certain thread(s).
   11.57 -    SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
   11.58 -
   11.59 -    CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
   11.60 -    Windows::Foundation::Point outputPosition;
   11.61 -
   11.62 -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   11.63 -    outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
   11.64 -    outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
   11.65 -#else
   11.66 -    switch (DisplayProperties::CurrentOrientation)
   11.67 -    {
   11.68 -        case DisplayOrientations::Portrait:
   11.69 -            outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
   11.70 -            outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
   11.71 -            break;
   11.72 -        case DisplayOrientations::PortraitFlipped:
   11.73 -            outputPosition.X = (float32)window->w - rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
   11.74 -            outputPosition.Y = (float32)window->h - rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
   11.75 -            break;
   11.76 -        case DisplayOrientations::Landscape:
   11.77 -            outputPosition.X = rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
   11.78 -            outputPosition.Y = (float32)window->h - rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
   11.79 -            break;
   11.80 -        case DisplayOrientations::LandscapeFlipped:
   11.81 -            outputPosition.X = (float32)window->w - rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
   11.82 -            outputPosition.Y = rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
   11.83 -            break;
   11.84 -        default:
   11.85 -            break;
   11.86 -    }
   11.87 -#endif
   11.88 -
   11.89 -    return outputPosition;
   11.90 -}
   11.91 -
   11.92 -static inline int
   11.93 -_lround(float arg)
   11.94 -{
   11.95 -    if (arg >= 0.0f) {
   11.96 -        return (int)floor(arg + 0.5f);
   11.97 -    } else {
   11.98 -        return (int)ceil(arg - 0.5f);
   11.99 -    }
  11.100 -}
  11.101 -
  11.102 -void
  11.103 -WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args)
  11.104 -{
  11.105 -    if (!window || !WINRT_UseRelativeMouseMode) {
  11.106 -        return;
  11.107 -    }
  11.108 -
  11.109 -    // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
  11.110 -    // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
  11.111 -    // MouseDelta field often reports very large values.  More information
  11.112 -    // on this can be found at the following pages on MSDN:
  11.113 -    //  - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
  11.114 -    //  - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
  11.115 -    //
  11.116 -    // The values do not appear to be as large when running on some systems,
  11.117 -    // most notably a Surface RT.  Furthermore, the values returned by
  11.118 -    // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
  11.119 -    // method, do not ever appear to be large, even when MouseEventArgs'
  11.120 -    // MouseDelta is reporting to the contrary.
  11.121 -    //
  11.122 -    // On systems with the large-values behavior, it appears that the values
  11.123 -    // get reported as if the screen's size is 65536 units in both the X and Y
  11.124 -    // dimensions.  This can be viewed by using Windows' now-private, "Raw Input"
  11.125 -    // APIs.  (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
  11.126 -    //
  11.127 -    // MSDN's documentation on MouseEventArgs' MouseDelta field (at
  11.128 -    // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
  11.129 -    // does not seem to indicate (to me) that its values should be so large.  It
  11.130 -    // says that its values should be a "change in screen location".  I could
  11.131 -    // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: 
  11.132 -    // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
  11.133 -    // indicates that these values are in DIPs, which is the same unit used
  11.134 -    // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
  11.135 -    // property.  See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
  11.136 -    // for details.)
  11.137 -    //
  11.138 -    // To note, PointerMoved events are sent a 'RawPosition' value (via the
  11.139 -    // CurrentPoint property in MouseEventArgs), however these do not seem
  11.140 -    // to exhibit the same large-value behavior.
  11.141 -    //
  11.142 -    // The values passed via PointerMoved events can't always be used for relative
  11.143 -    // mouse motion, unfortunately.  Its values are bound to the cursor's position,
  11.144 -    // which stops when it hits one of the screen's edges.  This can be a problem in
  11.145 -    // first person shooters, whereby it is normal for mouse motion to travel far
  11.146 -    // along any one axis for a period of time.  MouseMoved events do not have the
  11.147 -    // screen-bounding limitation, and can be used regardless of where the system's
  11.148 -    // cursor is.
  11.149 -    //
  11.150 -    // One possible workaround would be to programmatically set the cursor's
  11.151 -    // position to the screen's center (when SDL's relative mouse mode is enabled),
  11.152 -    // however WinRT does not yet seem to have the ability to set the cursor's
  11.153 -    // position via a public API.  Win32 did this via an API call, SetCursorPos,
  11.154 -    // however WinRT makes this function be private.  Apps that use it won't get
  11.155 -    // approved for distribution in the Windows Store.  I've yet to be able to find
  11.156 -    // a suitable, store-friendly counterpart for WinRT.
  11.157 -    //
  11.158 -    // There may be some room for a workaround whereby OnPointerMoved's values
  11.159 -    // are compared to the values from OnMouseMoved in order to detect
  11.160 -    // when this bug is active.  A suitable transformation could then be made to
  11.161 -    // OnMouseMoved's values.  For now, however, the system-reported values are sent
  11.162 -    // to SDL with minimal transformation: from native screen coordinates (in DIPs)
  11.163 -    // to SDL window coordinates.
  11.164 -    //
  11.165 -    const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
  11.166 -    const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs);
  11.167 -    SDL_SendMouseMotion(
  11.168 -        window,
  11.169 -        0,
  11.170 -        1,
  11.171 -        _lround(mouseDeltaInSDLWindowCoords.X),
  11.172 -        _lround(mouseDeltaInSDLWindowCoords.Y));
  11.173 -}
  11.174 -
  11.175 -Uint8
  11.176 -WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
  11.177 -{
  11.178 -    using namespace Windows::UI::Input;
  11.179 -
  11.180 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  11.181 -    return SDL_BUTTON_LEFT;
  11.182 -#else
  11.183 -    switch (pt->Properties->PointerUpdateKind)
  11.184 -    {
  11.185 -        case PointerUpdateKind::LeftButtonPressed:
  11.186 -        case PointerUpdateKind::LeftButtonReleased:
  11.187 -            return SDL_BUTTON_LEFT;
  11.188 -
  11.189 -        case PointerUpdateKind::RightButtonPressed:
  11.190 -        case PointerUpdateKind::RightButtonReleased:
  11.191 -            return SDL_BUTTON_RIGHT;
  11.192 -
  11.193 -        case PointerUpdateKind::MiddleButtonPressed:
  11.194 -        case PointerUpdateKind::MiddleButtonReleased:
  11.195 -            return SDL_BUTTON_MIDDLE;
  11.196 -
  11.197 -        case PointerUpdateKind::XButton1Pressed:
  11.198 -        case PointerUpdateKind::XButton1Released:
  11.199 -            return SDL_BUTTON_X1;
  11.200 -
  11.201 -        case PointerUpdateKind::XButton2Pressed:
  11.202 -        case PointerUpdateKind::XButton2Released:
  11.203 -            return SDL_BUTTON_X2;
  11.204 -
  11.205 -        default:
  11.206 -            break;
  11.207 -    }
  11.208 -#endif
  11.209 -
  11.210 -    return 0;
  11.211 -}
  11.212 -
  11.213 -//const char *
  11.214 -//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
  11.215 -//{
  11.216 -//    using namespace Windows::UI::Input;
  11.217 -//
  11.218 -//    switch (kind)
  11.219 -//    {
  11.220 -//        case PointerUpdateKind::Other:
  11.221 -//            return "Other";
  11.222 -//        case PointerUpdateKind::LeftButtonPressed:
  11.223 -//            return "LeftButtonPressed";
  11.224 -//        case PointerUpdateKind::LeftButtonReleased:
  11.225 -//            return "LeftButtonReleased";
  11.226 -//        case PointerUpdateKind::RightButtonPressed:
  11.227 -//            return "RightButtonPressed";
  11.228 -//        case PointerUpdateKind::RightButtonReleased:
  11.229 -//            return "RightButtonReleased";
  11.230 -//        case PointerUpdateKind::MiddleButtonPressed:
  11.231 -//            return "MiddleButtonPressed";
  11.232 -//        case PointerUpdateKind::MiddleButtonReleased:
  11.233 -//            return "MiddleButtonReleased";
  11.234 -//        case PointerUpdateKind::XButton1Pressed:
  11.235 -//            return "XButton1Pressed";
  11.236 -//        case PointerUpdateKind::XButton1Released:
  11.237 -//            return "XButton1Released";
  11.238 -//        case PointerUpdateKind::XButton2Pressed:
  11.239 -//            return "XButton2Pressed";
  11.240 -//        case PointerUpdateKind::XButton2Released:
  11.241 -//            return "XButton2Released";
  11.242 -//    }
  11.243 -//
  11.244 -//    return "";
  11.245 -//}
  11.246 -
  11.247 -static bool
  11.248 -WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
  11.249 -{
  11.250 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  11.251 -    return true;
  11.252 -#else
  11.253 -    using namespace Windows::Devices::Input;
  11.254 -    switch (pointerPoint->PointerDevice->PointerDeviceType) {
  11.255 -        case PointerDeviceType::Touch:
  11.256 -        case PointerDeviceType::Pen:
  11.257 -            return true;
  11.258 -        default:
  11.259 -            return false;
  11.260 -    }
  11.261 -#endif
  11.262 -}
  11.263 -
  11.264 -void
  11.265 -WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  11.266 -{
  11.267 -    if (!window || WINRT_UseRelativeMouseMode) {
  11.268 -        return;
  11.269 -    }
  11.270 -
  11.271 -    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
  11.272 -
  11.273 -    if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
  11.274 -        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
  11.275 -    }
  11.276 -
  11.277 -    if (WINRT_IsTouchEvent(pointerPoint)) {
  11.278 -        SDL_SendTouchMotion(
  11.279 -            WINRT_TouchID,
  11.280 -            (SDL_FingerID) pointerPoint->PointerId,
  11.281 -            transformedPoint.X,
  11.282 -            transformedPoint.Y,
  11.283 -            pointerPoint->Properties->Pressure);
  11.284 -    }
  11.285 -}
  11.286 -
  11.287 -void
  11.288 -WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  11.289 -{
  11.290 -    if (!window) {
  11.291 -        return;
  11.292 -    }
  11.293 -
  11.294 -    // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
  11.295 -    short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
  11.296 -    SDL_SendMouseWheel(window, 0, 0, motion);
  11.297 -}
  11.298 -
  11.299 -void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  11.300 -{
  11.301 -    if (!window) {
  11.302 -        return;
  11.303 -    }
  11.304 -
  11.305 -    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
  11.306 -
  11.307 -    if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
  11.308 -        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
  11.309 -        if (button) {
  11.310 -            SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
  11.311 -        }
  11.312 -        WINRT_LeftFingerDown = 0;
  11.313 -    }
  11.314 -
  11.315 -    if (WINRT_IsTouchEvent(pointerPoint)) {
  11.316 -        SDL_SendTouch(
  11.317 -            WINRT_TouchID,
  11.318 -            (SDL_FingerID) pointerPoint->PointerId,
  11.319 -            SDL_FALSE,
  11.320 -            transformedPoint.X,
  11.321 -            transformedPoint.Y,
  11.322 -            pointerPoint->Properties->Pressure);
  11.323 -    }
  11.324 -}
  11.325 -
  11.326 -void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  11.327 -{
  11.328 -    if (!window) {
  11.329 -        return;
  11.330 -    }
  11.331 -
  11.332 -    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
  11.333 -
  11.334 -    if (!WINRT_LeftFingerDown) {
  11.335 -        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
  11.336 -        if (button) {
  11.337 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  11.338 -            SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
  11.339 -#endif
  11.340 -            SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
  11.341 -        }
  11.342 -
  11.343 -        WINRT_LeftFingerDown = pointerPoint->PointerId;
  11.344 -    }
  11.345 -
  11.346 -    if (WINRT_IsTouchEvent(pointerPoint)) {
  11.347 -        SDL_SendTouch(
  11.348 -            WINRT_TouchID,
  11.349 -            (SDL_FingerID) pointerPoint->PointerId,
  11.350 -            SDL_TRUE,
  11.351 -            transformedPoint.X,
  11.352 -            transformedPoint.Y,
  11.353 -            pointerPoint->Properties->Pressure);
  11.354 -    }
  11.355 -}
  11.356 -
  11.357  #endif /* SDL_VIDEO_DRIVER_WINRT */
  11.358  
  11.359  /* vi: set ts=4 sw=4 expandtab: */
    12.1 --- a/src/video/winrt/SDL_winrtmouse.h	Sun Sep 01 10:20:17 2013 -0400
    12.2 +++ b/src/video/winrt/SDL_winrtmouse.h	Mon Sep 02 15:23:33 2013 -0400
    12.3 @@ -20,11 +20,20 @@
    12.4  */
    12.5  #include "SDL_config.h"
    12.6  
    12.7 -#ifndef _SDL_windowsmouse_h
    12.8 -#define _SDL_windowsmouse_h
    12.9 +#ifndef _SDL_winrtmouse_h
   12.10 +#define _SDL_winrtmouse_h
   12.11 +
   12.12 +#ifdef __cplusplus
   12.13 +extern "C" {
   12.14 +#endif
   12.15  
   12.16  extern void WINRT_InitMouse(_THIS);
   12.17  extern void WINRT_QuitMouse(_THIS);
   12.18 +extern SDL_bool WINRT_UsingRelativeMouseMode;
   12.19 +
   12.20 +#ifdef __cplusplus
   12.21 +}
   12.22 +#endif
   12.23  
   12.24  #endif /* _SDL_windowsmouse_h */
   12.25  
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/video/winrt/SDL_winrtpointerinput.cpp	Mon Sep 02 15:23:33 2013 -0400
    13.3 @@ -0,0 +1,372 @@
    13.4 +/*
    13.5 +  Simple DirectMedia Layer
    13.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
    13.7 +
    13.8 +  This software is provided 'as-is', without any express or implied
    13.9 +  warranty.  In no event will the authors be held liable for any damages
   13.10 +  arising from the use of this software.
   13.11 +
   13.12 +  Permission is granted to anyone to use this software for any purpose,
   13.13 +  including commercial applications, and to alter it and redistribute it
   13.14 +  freely, subject to the following restrictions:
   13.15 +
   13.16 +  1. The origin of this software must not be misrepresented; you must not
   13.17 +     claim that you wrote the original software. If you use this software
   13.18 +     in a product, an acknowledgment in the product documentation would be
   13.19 +     appreciated but is not required.
   13.20 +  2. Altered source versions must be plainly marked as such, and must not be
   13.21 +     misrepresented as being the original software.
   13.22 +  3. This notice may not be removed or altered from any source distribution.
   13.23 +*/
   13.24 +#include "SDL_config.h"
   13.25 +
   13.26 +#if SDL_VIDEO_DRIVER_WINRT
   13.27 +
   13.28 +/* SDL includes */
   13.29 +#include "SDL_winrtevents_c.h"
   13.30 +#include "SDL_winrtmouse.h"
   13.31 +#include "SDL_winrtvideo_cpp.h"
   13.32 +#include "SDL_assert.h"
   13.33 +#include "SDL_system.h"
   13.34 +
   13.35 +extern "C" {
   13.36 +#include "../SDL_sysvideo.h"
   13.37 +#include "../../events/SDL_events_c.h"
   13.38 +#include "../../events/SDL_mouse_c.h"
   13.39 +#include "../../events/SDL_touch_c.h"
   13.40 +}
   13.41 +
   13.42 +/* File-specific globals: */
   13.43 +static SDL_TouchID WINRT_TouchID = 1;
   13.44 +static unsigned int WINRT_LeftFingerDown = 0;
   13.45 +
   13.46 +
   13.47 +void
   13.48 +WINRT_InitTouch(_THIS)
   13.49 +{
   13.50 +    SDL_AddTouch(WINRT_TouchID, "");
   13.51 +}
   13.52 +
   13.53 +
   13.54 +// Applies necessary geometric transformations to raw cursor positions:
   13.55 +Windows::Foundation::Point
   13.56 +WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition)
   13.57 +{
   13.58 +    using namespace Windows::UI::Core;
   13.59 +    using namespace Windows::Graphics::Display;
   13.60 +
   13.61 +    if (!window) {
   13.62 +        return rawPosition;
   13.63 +    }
   13.64 +
   13.65 +    SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
   13.66 +    if (windowData->coreWindow == nullptr) {
   13.67 +        // For some reason, the window isn't associated with a CoreWindow.
   13.68 +        // This might end up being the case as XAML support is extended.
   13.69 +        // For now, if there's no CoreWindow attached to the SDL_Window,
   13.70 +        // don't do any transforms.
   13.71 +        return rawPosition;
   13.72 +    }
   13.73 +
   13.74 +    // The CoreWindow can only be accessed on certain thread(s).
   13.75 +    SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
   13.76 +
   13.77 +    CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
   13.78 +    Windows::Foundation::Point outputPosition;
   13.79 +
   13.80 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   13.81 +    outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
   13.82 +    outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
   13.83 +#else
   13.84 +    switch (DisplayProperties::CurrentOrientation)
   13.85 +    {
   13.86 +        case DisplayOrientations::Portrait:
   13.87 +            outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
   13.88 +            outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
   13.89 +            break;
   13.90 +        case DisplayOrientations::PortraitFlipped:
   13.91 +            outputPosition.X = (float32)window->w - rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
   13.92 +            outputPosition.Y = (float32)window->h - rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
   13.93 +            break;
   13.94 +        case DisplayOrientations::Landscape:
   13.95 +            outputPosition.X = rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
   13.96 +            outputPosition.Y = (float32)window->h - rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
   13.97 +            break;
   13.98 +        case DisplayOrientations::LandscapeFlipped:
   13.99 +            outputPosition.X = (float32)window->w - rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
  13.100 +            outputPosition.Y = rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
  13.101 +            break;
  13.102 +        default:
  13.103 +            break;
  13.104 +    }
  13.105 +#endif
  13.106 +
  13.107 +    return outputPosition;
  13.108 +}
  13.109 +
  13.110 +static inline int
  13.111 +_lround(float arg)
  13.112 +{
  13.113 +    if (arg >= 0.0f) {
  13.114 +        return (int)floor(arg + 0.5f);
  13.115 +    } else {
  13.116 +        return (int)ceil(arg - 0.5f);
  13.117 +    }
  13.118 +}
  13.119 +
  13.120 +void
  13.121 +WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args)
  13.122 +{
  13.123 +    if (!window || !WINRT_UsingRelativeMouseMode) {
  13.124 +        return;
  13.125 +    }
  13.126 +
  13.127 +    // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
  13.128 +    // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
  13.129 +    // MouseDelta field often reports very large values.  More information
  13.130 +    // on this can be found at the following pages on MSDN:
  13.131 +    //  - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
  13.132 +    //  - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
  13.133 +    //
  13.134 +    // The values do not appear to be as large when running on some systems,
  13.135 +    // most notably a Surface RT.  Furthermore, the values returned by
  13.136 +    // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
  13.137 +    // method, do not ever appear to be large, even when MouseEventArgs'
  13.138 +    // MouseDelta is reporting to the contrary.
  13.139 +    //
  13.140 +    // On systems with the large-values behavior, it appears that the values
  13.141 +    // get reported as if the screen's size is 65536 units in both the X and Y
  13.142 +    // dimensions.  This can be viewed by using Windows' now-private, "Raw Input"
  13.143 +    // APIs.  (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
  13.144 +    //
  13.145 +    // MSDN's documentation on MouseEventArgs' MouseDelta field (at
  13.146 +    // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
  13.147 +    // does not seem to indicate (to me) that its values should be so large.  It
  13.148 +    // says that its values should be a "change in screen location".  I could
  13.149 +    // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: 
  13.150 +    // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
  13.151 +    // indicates that these values are in DIPs, which is the same unit used
  13.152 +    // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
  13.153 +    // property.  See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
  13.154 +    // for details.)
  13.155 +    //
  13.156 +    // To note, PointerMoved events are sent a 'RawPosition' value (via the
  13.157 +    // CurrentPoint property in MouseEventArgs), however these do not seem
  13.158 +    // to exhibit the same large-value behavior.
  13.159 +    //
  13.160 +    // The values passed via PointerMoved events can't always be used for relative
  13.161 +    // mouse motion, unfortunately.  Its values are bound to the cursor's position,
  13.162 +    // which stops when it hits one of the screen's edges.  This can be a problem in
  13.163 +    // first person shooters, whereby it is normal for mouse motion to travel far
  13.164 +    // along any one axis for a period of time.  MouseMoved events do not have the
  13.165 +    // screen-bounding limitation, and can be used regardless of where the system's
  13.166 +    // cursor is.
  13.167 +    //
  13.168 +    // One possible workaround would be to programmatically set the cursor's
  13.169 +    // position to the screen's center (when SDL's relative mouse mode is enabled),
  13.170 +    // however WinRT does not yet seem to have the ability to set the cursor's
  13.171 +    // position via a public API.  Win32 did this via an API call, SetCursorPos,
  13.172 +    // however WinRT makes this function be private.  Apps that use it won't get
  13.173 +    // approved for distribution in the Windows Store.  I've yet to be able to find
  13.174 +    // a suitable, store-friendly counterpart for WinRT.
  13.175 +    //
  13.176 +    // There may be some room for a workaround whereby OnPointerMoved's values
  13.177 +    // are compared to the values from OnMouseMoved in order to detect
  13.178 +    // when this bug is active.  A suitable transformation could then be made to
  13.179 +    // OnMouseMoved's values.  For now, however, the system-reported values are sent
  13.180 +    // to SDL with minimal transformation: from native screen coordinates (in DIPs)
  13.181 +    // to SDL window coordinates.
  13.182 +    //
  13.183 +    const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
  13.184 +    const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs);
  13.185 +    SDL_SendMouseMotion(
  13.186 +        window,
  13.187 +        0,
  13.188 +        1,
  13.189 +        _lround(mouseDeltaInSDLWindowCoords.X),
  13.190 +        _lround(mouseDeltaInSDLWindowCoords.Y));
  13.191 +}
  13.192 +
  13.193 +Uint8
  13.194 +WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
  13.195 +{
  13.196 +    using namespace Windows::UI::Input;
  13.197 +
  13.198 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  13.199 +    return SDL_BUTTON_LEFT;
  13.200 +#else
  13.201 +    switch (pt->Properties->PointerUpdateKind)
  13.202 +    {
  13.203 +        case PointerUpdateKind::LeftButtonPressed:
  13.204 +        case PointerUpdateKind::LeftButtonReleased:
  13.205 +            return SDL_BUTTON_LEFT;
  13.206 +
  13.207 +        case PointerUpdateKind::RightButtonPressed:
  13.208 +        case PointerUpdateKind::RightButtonReleased:
  13.209 +            return SDL_BUTTON_RIGHT;
  13.210 +
  13.211 +        case PointerUpdateKind::MiddleButtonPressed:
  13.212 +        case PointerUpdateKind::MiddleButtonReleased:
  13.213 +            return SDL_BUTTON_MIDDLE;
  13.214 +
  13.215 +        case PointerUpdateKind::XButton1Pressed:
  13.216 +        case PointerUpdateKind::XButton1Released:
  13.217 +            return SDL_BUTTON_X1;
  13.218 +
  13.219 +        case PointerUpdateKind::XButton2Pressed:
  13.220 +        case PointerUpdateKind::XButton2Released:
  13.221 +            return SDL_BUTTON_X2;
  13.222 +
  13.223 +        default:
  13.224 +            break;
  13.225 +    }
  13.226 +#endif
  13.227 +
  13.228 +    return 0;
  13.229 +}
  13.230 +
  13.231 +//const char *
  13.232 +//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
  13.233 +//{
  13.234 +//    using namespace Windows::UI::Input;
  13.235 +//
  13.236 +//    switch (kind)
  13.237 +//    {
  13.238 +//        case PointerUpdateKind::Other:
  13.239 +//            return "Other";
  13.240 +//        case PointerUpdateKind::LeftButtonPressed:
  13.241 +//            return "LeftButtonPressed";
  13.242 +//        case PointerUpdateKind::LeftButtonReleased:
  13.243 +//            return "LeftButtonReleased";
  13.244 +//        case PointerUpdateKind::RightButtonPressed:
  13.245 +//            return "RightButtonPressed";
  13.246 +//        case PointerUpdateKind::RightButtonReleased:
  13.247 +//            return "RightButtonReleased";
  13.248 +//        case PointerUpdateKind::MiddleButtonPressed:
  13.249 +//            return "MiddleButtonPressed";
  13.250 +//        case PointerUpdateKind::MiddleButtonReleased:
  13.251 +//            return "MiddleButtonReleased";
  13.252 +//        case PointerUpdateKind::XButton1Pressed:
  13.253 +//            return "XButton1Pressed";
  13.254 +//        case PointerUpdateKind::XButton1Released:
  13.255 +//            return "XButton1Released";
  13.256 +//        case PointerUpdateKind::XButton2Pressed:
  13.257 +//            return "XButton2Pressed";
  13.258 +//        case PointerUpdateKind::XButton2Released:
  13.259 +//            return "XButton2Released";
  13.260 +//    }
  13.261 +//
  13.262 +//    return "";
  13.263 +//}
  13.264 +
  13.265 +static bool
  13.266 +WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
  13.267 +{
  13.268 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  13.269 +    return true;
  13.270 +#else
  13.271 +    using namespace Windows::Devices::Input;
  13.272 +    switch (pointerPoint->PointerDevice->PointerDeviceType) {
  13.273 +        case PointerDeviceType::Touch:
  13.274 +        case PointerDeviceType::Pen:
  13.275 +            return true;
  13.276 +        default:
  13.277 +            return false;
  13.278 +    }
  13.279 +#endif
  13.280 +}
  13.281 +
  13.282 +void
  13.283 +WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  13.284 +{
  13.285 +    if (!window || WINRT_UsingRelativeMouseMode) {
  13.286 +        return;
  13.287 +    }
  13.288 +
  13.289 +    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
  13.290 +
  13.291 +    if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
  13.292 +        SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
  13.293 +    }
  13.294 +
  13.295 +    if (WINRT_IsTouchEvent(pointerPoint)) {
  13.296 +        SDL_SendTouchMotion(
  13.297 +            WINRT_TouchID,
  13.298 +            (SDL_FingerID) pointerPoint->PointerId,
  13.299 +            transformedPoint.X,
  13.300 +            transformedPoint.Y,
  13.301 +            pointerPoint->Properties->Pressure);
  13.302 +    }
  13.303 +}
  13.304 +
  13.305 +void
  13.306 +WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  13.307 +{
  13.308 +    if (!window) {
  13.309 +        return;
  13.310 +    }
  13.311 +
  13.312 +    // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
  13.313 +    short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
  13.314 +    SDL_SendMouseWheel(window, 0, 0, motion);
  13.315 +}
  13.316 +
  13.317 +void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  13.318 +{
  13.319 +    if (!window) {
  13.320 +        return;
  13.321 +    }
  13.322 +
  13.323 +    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
  13.324 +
  13.325 +    if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
  13.326 +        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
  13.327 +        if (button) {
  13.328 +            SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
  13.329 +        }
  13.330 +        WINRT_LeftFingerDown = 0;
  13.331 +    }
  13.332 +
  13.333 +    if (WINRT_IsTouchEvent(pointerPoint)) {
  13.334 +        SDL_SendTouch(
  13.335 +            WINRT_TouchID,
  13.336 +            (SDL_FingerID) pointerPoint->PointerId,
  13.337 +            SDL_FALSE,
  13.338 +            transformedPoint.X,
  13.339 +            transformedPoint.Y,
  13.340 +            pointerPoint->Properties->Pressure);
  13.341 +    }
  13.342 +}
  13.343 +
  13.344 +void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
  13.345 +{
  13.346 +    if (!window) {
  13.347 +        return;
  13.348 +    }
  13.349 +
  13.350 +    Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
  13.351 +
  13.352 +    if (!WINRT_LeftFingerDown) {
  13.353 +        Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
  13.354 +        if (button) {
  13.355 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  13.356 +            SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
  13.357 +#endif
  13.358 +            SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
  13.359 +        }
  13.360 +
  13.361 +        WINRT_LeftFingerDown = pointerPoint->PointerId;
  13.362 +    }
  13.363 +
  13.364 +    if (WINRT_IsTouchEvent(pointerPoint)) {
  13.365 +        SDL_SendTouch(
  13.366 +            WINRT_TouchID,
  13.367 +            (SDL_FingerID) pointerPoint->PointerId,
  13.368 +            SDL_TRUE,
  13.369 +            transformedPoint.X,
  13.370 +            transformedPoint.Y,
  13.371 +            pointerPoint->Properties->Pressure);
  13.372 +    }
  13.373 +}
  13.374 +
  13.375 +#endif // SDL_VIDEO_DRIVER_WINRT
    14.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Sun Sep 01 10:20:17 2013 -0400
    14.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Mon Sep 02 15:23:33 2013 -0400
    14.3 @@ -45,15 +45,13 @@
    14.4  }
    14.5  
    14.6  #include "../../core/winrt/SDL_winrtapp.h"
    14.7 +#include "../../core/winrt/SDL_winrtxaml_cpp.h"
    14.8  #include "SDL_winrtvideo_cpp.h"
    14.9  #include "SDL_winrtevents_c.h"
   14.10  #include "SDL_winrtmouse.h"
   14.11  #include "SDL_main.h"
   14.12  #include "SDL_system.h"
   14.13  
   14.14 -extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
   14.15 -extern SDL_bool WINRT_XAMLWasEnabled;
   14.16 -
   14.17  
   14.18  /* Initialization/Query functions */
   14.19  static int WINRT_VideoInit(_THIS);
   14.20 @@ -68,19 +66,11 @@
   14.21  static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
   14.22  
   14.23  
   14.24 -/* The global, WinRT, SDL Window.
   14.25 -   For now, SDL/WinRT only supports one window (due to platform limitations of
   14.26 -   WinRT.
   14.27 -*/
   14.28 +/* SDL-internal globals: */
   14.29  SDL_Window * WINRT_GlobalSDLWindow = NULL;
   14.30 -
   14.31 -
   14.32 -/* The global, WinRT, video device.
   14.33 -*/
   14.34  SDL_VideoDevice * WINRT_GlobalSDLVideoDevice = NULL;
   14.35  
   14.36  
   14.37 -
   14.38  /* WinRT driver bootstrap functions */
   14.39  
   14.40  static int
   14.41 @@ -140,6 +130,7 @@
   14.42          return -1;
   14.43      }
   14.44      WINRT_InitMouse(_this);
   14.45 +    WINRT_InitTouch(_this);
   14.46  
   14.47      return 0;
   14.48  }
    15.1 --- a/src/video/winrt/SDL_winrtvideo_cpp.h	Sun Sep 01 10:20:17 2013 -0400
    15.2 +++ b/src/video/winrt/SDL_winrtvideo_cpp.h	Mon Sep 02 15:23:33 2013 -0400
    15.3 @@ -29,6 +29,19 @@
    15.4  #include "SDL_events.h"
    15.5  
    15.6  
    15.7 +/* The global, WinRT, SDL Window.
    15.8 +   For now, SDL/WinRT only supports one window (due to platform limitations of
    15.9 +   WinRT.
   15.10 +*/
   15.11 +extern SDL_Window * WINRT_GlobalSDLWindow;
   15.12 +
   15.13 +/* The global, WinRT, video device. */
   15.14 +extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice;
   15.15 +
   15.16 +/* Computes the current display mode for Plain Direct3D (non-XAML) apps */
   15.17 +extern SDL_DisplayMode WINRT_CalcDisplayModeUsingNativeWindow();
   15.18 +
   15.19 +
   15.20  #ifdef __cplusplus_winrt
   15.21  
   15.22  /* Internal window data */