WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
authorDavid Ludwig <dludwig@pobox.com>
Fri, 06 Sep 2013 21:13:15 -0400
changeset 85223ae9dc9c439f
parent 8521 cefdaf414ead
child 8523 d8ff7021751e
WinRT: code cleanup: attempted to make it more clear what code is specific to what app type (plain Direct3D or XAML)
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_winrtapp_direct3d.cpp
src/core/winrt/SDL_winrtapp_direct3d.h
src/core/winrt/SDL_winrtapp_xaml.cpp
src/core/winrt/SDL_winrtapp_xaml.h
src/core/winrt/SDL_winrtxaml.cpp
src/core/winrt/SDL_winrtxaml_cpp.h
src/video/winrt/SDL_winrtevents.cpp
src/video/winrt/SDL_winrtmouse.cpp
src/video/winrt/SDL_winrtvideo.cpp
     1.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Fri Sep 06 21:00:52 2013 -0400
     1.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Fri Sep 06 21:13:15 2013 -0400
     1.3 @@ -197,8 +197,8 @@
     1.4      <ClInclude Include="..\..\src\audio\SDL_wave.h" />
     1.5      <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2_winrthelpers.h" />
     1.6      <ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
     1.7 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp.h" />
     1.8 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h" />
     1.9 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.h" />
    1.10 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_xaml.h" />
    1.11      <ClInclude Include="..\..\src\events\blank_cursor.h" />
    1.12      <ClInclude Include="..\..\src\events\default_cursor.h" />
    1.13      <ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" />
    1.14 @@ -269,7 +269,13 @@
    1.15        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.16      </ClCompile>
    1.17      <ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
    1.18 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp.cpp">
    1.19 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.cpp">
    1.20 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.21 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.22 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.23 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.24 +    </ClCompile>
    1.25 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_xaml.cpp">
    1.26        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.27        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.28        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.29 @@ -281,12 +287,6 @@
    1.30        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.31        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.32      </ClCompile>
    1.33 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtxaml.cpp">
    1.34 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.35 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.36 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.37 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.38 -    </ClCompile>
    1.39      <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
    1.40      <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
    1.41      <ClCompile Include="..\..\src\events\SDL_dropevents.c" />
     2.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Fri Sep 06 21:00:52 2013 -0400
     2.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Fri Sep 06 21:13:15 2013 -0400
     2.3 @@ -321,24 +321,24 @@
     2.4      <ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClInclude>
     2.7 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp.h">
     2.8 -      <Filter>Source Files</Filter>
     2.9 -    </ClInclude>
    2.10      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h">
    2.11        <Filter>Source Files</Filter>
    2.12      </ClInclude>
    2.13      <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h">
    2.14        <Filter>Source Files</Filter>
    2.15      </ClInclude>
    2.16 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h">
    2.17 -      <Filter>Source Files</Filter>
    2.18 -    </ClInclude>
    2.19      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h">
    2.20        <Filter>Source Files</Filter>
    2.21      </ClInclude>
    2.22      <ClInclude Include="..\..\include\SDL_config_winrt.h">
    2.23        <Filter>Header Files</Filter>
    2.24      </ClInclude>
    2.25 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.h">
    2.26 +      <Filter>Source Files</Filter>
    2.27 +    </ClInclude>
    2.28 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_xaml.h">
    2.29 +      <Filter>Source Files</Filter>
    2.30 +    </ClInclude>
    2.31    </ItemGroup>
    2.32    <ItemGroup>
    2.33      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    2.34 @@ -581,9 +581,6 @@
    2.35      <ClCompile Include="..\..\src\stdlib\SDL_malloc.c">
    2.36        <Filter>Source Files</Filter>
    2.37      </ClCompile>
    2.38 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp.cpp">
    2.39 -      <Filter>Source Files</Filter>
    2.40 -    </ClCompile>
    2.41      <ClCompile Include="..\..\src\core\winrt\SDL_winrtpaths.cpp">
    2.42        <Filter>Source Files</Filter>
    2.43      </ClCompile>
    2.44 @@ -599,10 +596,13 @@
    2.45      <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
    2.46        <Filter>Source Files</Filter>
    2.47      </ClCompile>
    2.48 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtxaml.cpp">
    2.49 +    <ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
    2.50        <Filter>Source Files</Filter>
    2.51      </ClCompile>
    2.52 -    <ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
    2.53 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.cpp">
    2.54 +      <Filter>Source Files</Filter>
    2.55 +    </ClCompile>
    2.56 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_xaml.cpp">
    2.57        <Filter>Source Files</Filter>
    2.58      </ClCompile>
    2.59    </ItemGroup>
     3.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Fri Sep 06 21:00:52 2013 -0400
     3.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Fri Sep 06 21:13:15 2013 -0400
     3.3 @@ -47,7 +47,15 @@
     3.4        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
     3.5      </ClCompile>
     3.6      <ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
     3.7 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp.cpp">
     3.8 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.cpp">
     3.9 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.10 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.11 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.12 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    3.13 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    3.14 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    3.15 +    </ClCompile>
    3.16 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_xaml.cpp">
    3.17        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.18        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.19        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.20 @@ -63,14 +71,6 @@
    3.21        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    3.22        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    3.23      </ClCompile>
    3.24 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtxaml.cpp">
    3.25 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.26 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.27 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.28 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    3.29 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    3.30 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    3.31 -    </ClCompile>
    3.32      <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
    3.33      <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
    3.34      <ClCompile Include="..\..\src\events\SDL_dropevents.c" />
    3.35 @@ -244,8 +244,8 @@
    3.36      <ClInclude Include="..\..\src\audio\SDL_wave.h" />
    3.37      <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2_winrthelpers.h" />
    3.38      <ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
    3.39 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp.h" />
    3.40 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h" />
    3.41 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.h" />
    3.42 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_xaml.h" />
    3.43      <ClInclude Include="..\..\src\events\blank_cursor.h" />
    3.44      <ClInclude Include="..\..\src\events\default_cursor.h" />
    3.45      <ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" />
     4.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Fri Sep 06 21:00:52 2013 -0400
     4.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Fri Sep 06 21:13:15 2013 -0400
     4.3 @@ -258,9 +258,6 @@
     4.4      <ClCompile Include="..\..\src\video\winrt\SDL_winrtvideo.cpp">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClCompile>
     4.7 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp.cpp">
     4.8 -      <Filter>Source Files</Filter>
     4.9 -    </ClCompile>
    4.10      <ClCompile Include="..\..\src\core\winrt\SDL_winrtpaths.cpp">
    4.11        <Filter>Source Files</Filter>
    4.12      </ClCompile>
    4.13 @@ -273,7 +270,10 @@
    4.14      <ClCompile Include="..\..\src\video\winrt\SDL_winrtpointerinput.cpp">
    4.15        <Filter>Source Files</Filter>
    4.16      </ClCompile>
    4.17 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtxaml.cpp">
    4.18 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.cpp">
    4.19 +      <Filter>Source Files</Filter>
    4.20 +    </ClCompile>
    4.21 +    <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_xaml.cpp">
    4.22        <Filter>Source Files</Filter>
    4.23      </ClCompile>
    4.24    </ItemGroup>
    4.25 @@ -593,21 +593,21 @@
    4.26      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h">
    4.27        <Filter>Source Files</Filter>
    4.28      </ClInclude>
    4.29 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp.h">
    4.30 -      <Filter>Source Files</Filter>
    4.31 -    </ClInclude>
    4.32      <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h">
    4.33        <Filter>Source Files</Filter>
    4.34      </ClInclude>
    4.35 -    <ClInclude Include="..\..\src\core\winrt\SDL_winrtxaml_cpp.h">
    4.36 -      <Filter>Source Files</Filter>
    4.37 -    </ClInclude>
    4.38      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse_c.h">
    4.39        <Filter>Source Files</Filter>
    4.40      </ClInclude>
    4.41      <ClInclude Include="..\..\include\SDL_config_winrt.h">
    4.42        <Filter>Header Files</Filter>
    4.43      </ClInclude>
    4.44 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_direct3d.h">
    4.45 +      <Filter>Source Files</Filter>
    4.46 +    </ClInclude>
    4.47 +    <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_xaml.h">
    4.48 +      <Filter>Source Files</Filter>
    4.49 +    </ClInclude>
    4.50    </ItemGroup>
    4.51    <ItemGroup>
    4.52      <Filter Include="Header Files">
     5.1 --- a/src/core/winrt/SDL_winrtapp.cpp	Fri Sep 06 21:00:52 2013 -0400
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,549 +0,0 @@
     5.4 -
     5.5 -/* Standard C++11 includes */
     5.6 -#include <functional>
     5.7 -#include <string>
     5.8 -#include <sstream>
     5.9 -using namespace std;
    5.10 -
    5.11 -
    5.12 -/* Windows includes */
    5.13 -#include "ppltasks.h"
    5.14 -using namespace concurrency;
    5.15 -using namespace Windows::ApplicationModel;
    5.16 -using namespace Windows::ApplicationModel::Core;
    5.17 -using namespace Windows::ApplicationModel::Activation;
    5.18 -using namespace Windows::Devices::Input;
    5.19 -using namespace Windows::Graphics::Display;
    5.20 -using namespace Windows::Foundation;
    5.21 -using namespace Windows::System;
    5.22 -using namespace Windows::UI::Core;
    5.23 -using namespace Windows::UI::Input;
    5.24 -
    5.25 -
    5.26 -/* SDL includes */
    5.27 -extern "C" {
    5.28 -#include "SDL_assert.h"
    5.29 -#include "SDL_events.h"
    5.30 -#include "SDL_hints.h"
    5.31 -#include "SDL_log.h"
    5.32 -#include "SDL_main.h"
    5.33 -#include "SDL_stdinc.h"
    5.34 -#include "SDL_render.h"
    5.35 -#include "../../video/SDL_sysvideo.h"
    5.36 -//#include "../../SDL_hints_c.h"
    5.37 -#include "../../events/SDL_mouse_c.h"
    5.38 -#include "../../events/SDL_windowevents_c.h"
    5.39 -#include "../../render/SDL_sysrender.h"
    5.40 -}
    5.41 -
    5.42 -#include "../../video/winrt/SDL_winrtevents_c.h"
    5.43 -#include "../../video/winrt/SDL_winrtvideo_cpp.h"
    5.44 -#include "SDL_winrtapp.h"
    5.45 -
    5.46 -
    5.47 -// Compile-time debugging options:
    5.48 -// To enable, uncomment; to disable, comment them out.
    5.49 -//#define LOG_POINTER_EVENTS 1
    5.50 -//#define LOG_WINDOW_EVENTS 1
    5.51 -//#define LOG_ORIENTATION_EVENTS 1
    5.52 -
    5.53 -
    5.54 -// HACK, DLudwig: The C-style main() will get loaded via the app's
    5.55 -// WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp.
    5.56 -// This seems wrong on some level, but does seem to work.
    5.57 -typedef int (*SDL_WinRT_MainFunction)(int, char **);
    5.58 -static SDL_WinRT_MainFunction SDL_WinRT_main = nullptr;
    5.59 -
    5.60 -// HACK, DLudwig: record a reference to the global, WinRT 'app'/view.
    5.61 -// SDL/WinRT will use this throughout its code.
    5.62 -//
    5.63 -// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
    5.64 -// non-global, such as something created inside
    5.65 -// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
    5.66 -// SDL_CreateWindow().
    5.67 -SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
    5.68 -
    5.69 -ref class SDLApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
    5.70 -{
    5.71 -public:
    5.72 -    virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
    5.73 -};
    5.74 -
    5.75 -IFrameworkView^ SDLApplicationSource::CreateView()
    5.76 -{
    5.77 -    // TODO, WinRT: see if this function (CreateView) can ever get called
    5.78 -    // more than once.  For now, just prevent it from ever assigning
    5.79 -    // SDL_WinRTGlobalApp more than once.
    5.80 -    SDL_assert(!SDL_WinRTGlobalApp);
    5.81 -    SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
    5.82 -    if (!SDL_WinRTGlobalApp)
    5.83 -    {
    5.84 -        SDL_WinRTGlobalApp = app;
    5.85 -    }
    5.86 -    return app;
    5.87 -}
    5.88 -
    5.89 -__declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFunction)
    5.90 -{
    5.91 -    SDL_WinRT_main = mainFunction;
    5.92 -    auto direct3DApplicationSource = ref new SDLApplicationSource();
    5.93 -    CoreApplication::Run(direct3DApplicationSource);
    5.94 -    return 0;
    5.95 -}
    5.96 -
    5.97 -static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
    5.98 -{
    5.99 -    SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
   5.100 -
   5.101 -    // Start with no orientation flags, then add each in as they're parsed
   5.102 -    // from newValue.
   5.103 -    unsigned int orientationFlags = 0;
   5.104 -    if (newValue) {
   5.105 -        std::istringstream tokenizer(newValue);
   5.106 -        while (!tokenizer.eof()) {
   5.107 -            std::string orientationName;
   5.108 -            std::getline(tokenizer, orientationName, ' ');
   5.109 -            if (orientationName == "LandscapeLeft") {
   5.110 -                orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
   5.111 -            } else if (orientationName == "LandscapeRight") {
   5.112 -                orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
   5.113 -            } else if (orientationName == "Portrait") {
   5.114 -                orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
   5.115 -            } else if (orientationName == "PortraitUpsideDown") {
   5.116 -                orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
   5.117 -            }
   5.118 -        }
   5.119 -    }
   5.120 -
   5.121 -    // If no valid orientation flags were specified, use a reasonable set of defaults:
   5.122 -    if (!orientationFlags) {
   5.123 -        // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
   5.124 -        orientationFlags = (unsigned int) ( \
   5.125 -            DisplayOrientations::Landscape |
   5.126 -            DisplayOrientations::LandscapeFlipped |
   5.127 -            DisplayOrientations::Portrait |
   5.128 -            DisplayOrientations::PortraitFlipped);
   5.129 -    }
   5.130 -
   5.131 -    // Set the orientation/rotation preferences.  Please note that this does
   5.132 -    // not constitute a 100%-certain lock of a given set of possible
   5.133 -    // orientations.  According to Microsoft's documentation on WinRT [1]
   5.134 -    // when a device is not capable of being rotated, Windows may ignore
   5.135 -    // the orientation preferences, and stick to what the device is capable of
   5.136 -    // displaying.
   5.137 -    //
   5.138 -    // [1] Documentation on the 'InitialRotationPreference' setting for a
   5.139 -    // Windows app's manifest file describes how some orientation/rotation
   5.140 -    // preferences may be ignored.  See
   5.141 -    // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
   5.142 -    // for details.  Microsoft's "Display orientation sample" also gives an
   5.143 -    // outline of how Windows treats device rotation
   5.144 -    // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
   5.145 -    DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
   5.146 -}
   5.147 -
   5.148 -static void
   5.149 -WINRT_ProcessWindowSizeChange()
   5.150 -{
   5.151 -    // Make the new window size be the one true fullscreen mode.
   5.152 -    // This change was initially done, in part, to allow the Direct3D 11.1
   5.153 -    // renderer to receive window-resize events as a device rotates.
   5.154 -    // Before, rotating a device from landscape, to portrait, and then
   5.155 -    // back to landscape would cause the Direct3D 11.1 swap buffer to
   5.156 -    // not get resized appropriately.  SDL would, on the rotation from
   5.157 -    // landscape to portrait, re-resize the SDL window to it's initial
   5.158 -    // size (landscape).  On the subsequent rotation, SDL would drop the
   5.159 -    // window-resize event as it appeared the SDL window didn't change
   5.160 -    // size, and the Direct3D 11.1 renderer wouldn't resize its swap
   5.161 -    // chain.
   5.162 -    SDL_DisplayMode resizedDisplayMode = WINRT_CalcDisplayModeUsingNativeWindow();
   5.163 -    if (resizedDisplayMode.w == 0 || resizedDisplayMode.h == 0) {
   5.164 -        return;
   5.165 -    }
   5.166 -
   5.167 -    SDL_DisplayMode oldDisplayMode;
   5.168 -    SDL_zero(oldDisplayMode);
   5.169 -    if (WINRT_GlobalSDLVideoDevice) {
   5.170 -        oldDisplayMode = WINRT_GlobalSDLVideoDevice->displays[0].desktop_mode;
   5.171 -        WINRT_GlobalSDLVideoDevice->displays[0].current_mode = resizedDisplayMode;
   5.172 -        WINRT_GlobalSDLVideoDevice->displays[0].desktop_mode = resizedDisplayMode;
   5.173 -        WINRT_GlobalSDLVideoDevice->displays[0].display_modes[0] = resizedDisplayMode;
   5.174 -    }
   5.175 -
   5.176 -    if (WINRT_GlobalSDLWindow) {
   5.177 -        // Send a window-resize event to the rest of SDL, and to apps:
   5.178 -        SDL_SendWindowEvent(
   5.179 -            WINRT_GlobalSDLWindow,
   5.180 -            SDL_WINDOWEVENT_RESIZED,
   5.181 -            resizedDisplayMode.w,
   5.182 -            resizedDisplayMode.h);
   5.183 -
   5.184 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   5.185 -        // HACK: On Windows Phone, make sure that orientation changes from
   5.186 -        // Landscape to LandscapeFlipped, Portrait to PortraitFlipped,
   5.187 -        // or vice-versa on either of those two, lead to the Direct3D renderer
   5.188 -        // getting updated.
   5.189 -        const DisplayOrientations oldOrientation = (DisplayOrientations) (unsigned int) oldDisplayMode.driverdata;
   5.190 -        const DisplayOrientations newOrientation = (DisplayOrientations) (unsigned int) resizedDisplayMode.driverdata;
   5.191 -
   5.192 -        if ((oldOrientation == DisplayOrientations::Landscape && newOrientation == DisplayOrientations::LandscapeFlipped) ||
   5.193 -            (oldOrientation == DisplayOrientations::LandscapeFlipped && newOrientation == DisplayOrientations::Landscape) ||
   5.194 -            (oldOrientation == DisplayOrientations::Portrait && newOrientation == DisplayOrientations::PortraitFlipped) ||
   5.195 -            (oldOrientation == DisplayOrientations::PortraitFlipped && newOrientation == DisplayOrientations::Portrait))
   5.196 -        {
   5.197 -            // One of the reasons this event is getting sent out is because SDL
   5.198 -            // will ignore requests to send out SDL_WINDOWEVENT_RESIZED events
   5.199 -            // if and when the event size doesn't change (and the Direct3D 11.1
   5.200 -            // renderer doesn't get the memo).
   5.201 -            //
   5.202 -            // Make sure that the display/window size really didn't change.  If
   5.203 -            // it did, then a SDL_WINDOWEVENT_SIZE_CHANGED event got sent, and
   5.204 -            // the Direct3D 11.1 renderer picked it up, presumably.
   5.205 -            if (oldDisplayMode.w == resizedDisplayMode.w &&
   5.206 -                oldDisplayMode.h == resizedDisplayMode.h)
   5.207 -            {
   5.208 -                SDL_SendWindowEvent(
   5.209 -                    WINRT_GlobalSDLWindow,
   5.210 -                    SDL_WINDOWEVENT_SIZE_CHANGED,
   5.211 -                    resizedDisplayMode.w,
   5.212 -                    resizedDisplayMode.h);
   5.213 -            }
   5.214 -        }
   5.215 -#endif
   5.216 -    }
   5.217 -}
   5.218 -
   5.219 -SDL_WinRTApp::SDL_WinRTApp() :
   5.220 -    m_windowClosed(false),
   5.221 -    m_windowVisible(true)
   5.222 -{
   5.223 -}
   5.224 -
   5.225 -void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
   5.226 -{
   5.227 -    applicationView->Activated +=
   5.228 -        ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
   5.229 -
   5.230 -    CoreApplication::Suspending +=
   5.231 -        ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
   5.232 -
   5.233 -    CoreApplication::Resuming +=
   5.234 -        ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
   5.235 -
   5.236 -    DisplayProperties::OrientationChanged +=
   5.237 -        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
   5.238 -
   5.239 -    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.  This needs to be
   5.240 -    // done before the hint's callback is registered (as of Feb 22, 2013),
   5.241 -    // otherwise the hint callback won't get registered.
   5.242 -    //
   5.243 -    // TODO, WinRT: see if an app's default orientation can be found out via WinRT API(s), then set the initial value of SDL_HINT_ORIENTATIONS accordingly.
   5.244 -    //SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");   // DavidL: this is no longer needed (for SDL_AddHintCallback)
   5.245 -    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
   5.246 -}
   5.247 -
   5.248 -void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
   5.249 -{
   5.250 -#if LOG_ORIENTATION_EVENTS==1
   5.251 -    CoreWindow^ window = CoreWindow::GetForCurrentThread();
   5.252 -    if (window) {
   5.253 -        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Size={%f,%f}\n",
   5.254 -            __FUNCTION__,
   5.255 -            (int)DisplayProperties::CurrentOrientation,
   5.256 -            (int)DisplayProperties::NativeOrientation,
   5.257 -            (int)DisplayProperties::AutoRotationPreferences,
   5.258 -            window->Bounds.Width,
   5.259 -            window->Bounds.Height);
   5.260 -    } else {
   5.261 -        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
   5.262 -            __FUNCTION__,
   5.263 -            (int)DisplayProperties::CurrentOrientation,
   5.264 -            (int)DisplayProperties::NativeOrientation,
   5.265 -            (int)DisplayProperties::AutoRotationPreferences);
   5.266 -    }
   5.267 -#endif
   5.268 -
   5.269 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   5.270 -    // On Windows Phone, treat an orientation change as a change in window size.
   5.271 -    // The native window's size doesn't seem to change, however SDL will simulate
   5.272 -    // a window size change.
   5.273 -    WINRT_ProcessWindowSizeChange();
   5.274 -#endif
   5.275 -}
   5.276 -
   5.277 -void SDL_WinRTApp::SetWindow(CoreWindow^ window)
   5.278 -{
   5.279 -#if LOG_WINDOW_EVENTS==1
   5.280 -    SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window Size={%f,%f}\n",
   5.281 -        __FUNCTION__,
   5.282 -        (int)DisplayProperties::CurrentOrientation,
   5.283 -        (int)DisplayProperties::NativeOrientation,
   5.284 -        (int)DisplayProperties::AutoRotationPreferences,
   5.285 -        window->Bounds.Width,
   5.286 -        window->Bounds.Height);
   5.287 -#endif
   5.288 -
   5.289 -    window->SizeChanged += 
   5.290 -        ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
   5.291 -
   5.292 -    window->VisibilityChanged +=
   5.293 -        ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
   5.294 -
   5.295 -    window->Closed += 
   5.296 -        ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
   5.297 -
   5.298 -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   5.299 -    window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
   5.300 -#endif
   5.301 -
   5.302 -    window->PointerPressed +=
   5.303 -        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
   5.304 -
   5.305 -    window->PointerMoved +=
   5.306 -        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
   5.307 -
   5.308 -    window->PointerReleased +=
   5.309 -        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
   5.310 -
   5.311 -    window->PointerWheelChanged +=
   5.312 -        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
   5.313 -
   5.314 -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   5.315 -    // Retrieves relative-only mouse movements:
   5.316 -    Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
   5.317 -        ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
   5.318 -#endif
   5.319 -
   5.320 -    window->KeyDown +=
   5.321 -        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
   5.322 -
   5.323 -    window->KeyUp +=
   5.324 -        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
   5.325 -}
   5.326 -
   5.327 -void SDL_WinRTApp::Load(Platform::String^ entryPoint)
   5.328 -{
   5.329 -}
   5.330 -
   5.331 -void SDL_WinRTApp::Run()
   5.332 -{
   5.333 -    SDL_SetMainReady();
   5.334 -    if (SDL_WinRT_main)
   5.335 -    {
   5.336 -        // TODO, WinRT: pass the C-style main() a reasonably realistic
   5.337 -        // representation of command line arguments.
   5.338 -        int argc = 0;
   5.339 -        char **argv = NULL;
   5.340 -        SDL_WinRT_main(argc, argv);
   5.341 -    }
   5.342 -}
   5.343 -
   5.344 -void SDL_WinRTApp::PumpEvents()
   5.345 -{
   5.346 -    if (!m_windowClosed)
   5.347 -    {
   5.348 -        if (m_windowVisible)
   5.349 -        {
   5.350 -            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
   5.351 -        }
   5.352 -        else
   5.353 -        {
   5.354 -            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
   5.355 -        }
   5.356 -    }
   5.357 -}
   5.358 -
   5.359 -void SDL_WinRTApp::Uninitialize()
   5.360 -{
   5.361 -}
   5.362 -
   5.363 -void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
   5.364 -{
   5.365 -#if LOG_WINDOW_EVENTS==1
   5.366 -    SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
   5.367 -        __FUNCTION__,
   5.368 -        args->Size.Width, args->Size.Height,
   5.369 -        (int)DisplayProperties::CurrentOrientation,
   5.370 -        (int)DisplayProperties::NativeOrientation,
   5.371 -        (int)DisplayProperties::AutoRotationPreferences,
   5.372 -        (WINRT_GlobalSDLWindow ? "yes" : "no"));
   5.373 -#endif
   5.374 -
   5.375 -    WINRT_ProcessWindowSizeChange();
   5.376 -}
   5.377 -
   5.378 -void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
   5.379 -{
   5.380 -#if LOG_WINDOW_EVENTS==1
   5.381 -    SDL_Log("%s, visible?=%s, WINRT_GlobalSDLWindow?=%s\n",
   5.382 -        __FUNCTION__,
   5.383 -        (args->Visible ? "yes" : "no"),
   5.384 -        (WINRT_GlobalSDLWindow ? "yes" : "no"));
   5.385 -#endif
   5.386 -
   5.387 -    m_windowVisible = args->Visible;
   5.388 -    if (WINRT_GlobalSDLWindow) {
   5.389 -        SDL_bool wasSDLWindowSurfaceValid = WINRT_GlobalSDLWindow->surface_valid;
   5.390 -
   5.391 -        if (args->Visible) {
   5.392 -            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
   5.393 -        } else {
   5.394 -            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   5.395 -        }
   5.396 -
   5.397 -        // HACK: Prevent SDL's window-hide handling code, which currently
   5.398 -        // triggers a fake window resize (possibly erronously), from
   5.399 -        // marking the SDL window's surface as invalid.
   5.400 -        //
   5.401 -        // A better solution to this probably involves figuring out if the
   5.402 -        // fake window resize can be prevented.
   5.403 -        WINRT_GlobalSDLWindow->surface_valid = wasSDLWindowSurfaceValid;
   5.404 -    }
   5.405 -}
   5.406 -
   5.407 -void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
   5.408 -{
   5.409 -#if LOG_WINDOW_EVENTS==1
   5.410 -    SDL_Log("%s\n", __FUNCTION__);
   5.411 -#endif
   5.412 -    m_windowClosed = true;
   5.413 -}
   5.414 -
   5.415 -void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
   5.416 -{
   5.417 -    CoreWindow::GetForCurrentThread()->Activate();
   5.418 -}
   5.419 -
   5.420 -static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event * event)
   5.421 -{
   5.422 -    if (event->type == SDL_WINDOWEVENT)
   5.423 -    {
   5.424 -        switch (event->window.event)
   5.425 -        {
   5.426 -            case SDL_WINDOWEVENT_MINIMIZED:
   5.427 -            case SDL_WINDOWEVENT_RESTORED:
   5.428 -                // Return 0 to indicate that the event should be removed from the
   5.429 -                // event queue:
   5.430 -                return 0;
   5.431 -            default:
   5.432 -                break;
   5.433 -        }
   5.434 -    }
   5.435 -
   5.436 -    // Return 1 to indicate that the event should stay in the event queue:
   5.437 -    return 1;
   5.438 -}
   5.439 -
   5.440 -void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
   5.441 -{
   5.442 -    // Save app state asynchronously after requesting a deferral. Holding a deferral
   5.443 -    // indicates that the application is busy performing suspending operations. Be
   5.444 -    // aware that a deferral may not be held indefinitely. After about five seconds,
   5.445 -    // the app will be forced to exit.
   5.446 -    SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
   5.447 -    create_task([this, deferral]()
   5.448 -    {
   5.449 -        // Send a window-minimized event immediately to observers.
   5.450 -        // CoreDispatcher::ProcessEvents, which is the backbone on which
   5.451 -        // SDL_WinRTApp::PumpEvents is built, will not return to its caller
   5.452 -        // once it sends out a suspend event.  Any events posted to SDL's
   5.453 -        // event queue won't get received until the WinRT app is resumed.
   5.454 -        // SDL_AddEventWatch() may be used to receive app-suspend events on
   5.455 -        // WinRT.
   5.456 -        //
   5.457 -        // In order to prevent app-suspend events from being received twice:
   5.458 -        // first via a callback passed to SDL_AddEventWatch, and second via
   5.459 -        // SDL's event queue, the event will be sent to SDL, then immediately
   5.460 -        // removed from the queue.
   5.461 -        if (WINRT_GlobalSDLWindow)
   5.462 -        {
   5.463 -            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);   // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
   5.464 -            SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
   5.465 -        }
   5.466 -        deferral->Complete();
   5.467 -    });
   5.468 -}
   5.469 -
   5.470 -void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
   5.471 -{
   5.472 -    // Restore any data or state that was unloaded on suspend. By default, data
   5.473 -    // and state are persisted when resuming from suspend. Note that this event
   5.474 -    // does not occur if the app was previously terminated.
   5.475 -    if (WINRT_GlobalSDLWindow)
   5.476 -    {
   5.477 -        SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_RESTORED, 0, 0);    // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
   5.478 -
   5.479 -        // Remove the app-resume event from the queue, as is done with the
   5.480 -        // app-suspend event.
   5.481 -        //
   5.482 -        // TODO, WinRT: consider posting this event to the queue even though
   5.483 -        // its counterpart, the app-suspend event, effectively has to be
   5.484 -        // processed immediately.
   5.485 -        SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
   5.486 -    }
   5.487 -}
   5.488 -
   5.489 -static void
   5.490 -WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
   5.491 -{
   5.492 -    Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
   5.493 -    SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
   5.494 -        header,
   5.495 -        pt->Position.X, pt->Position.Y,
   5.496 -        transformedPoint.X, transformedPoint.Y,
   5.497 -        pt->Properties->MouseWheelDelta,
   5.498 -        pt->FrameId,
   5.499 -        pt->PointerId,
   5.500 -        WINRT_GetSDLButtonForPointerPoint(pt));
   5.501 -}
   5.502 -
   5.503 -void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
   5.504 -{
   5.505 -#if LOG_POINTER_EVENTS
   5.506 -    WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   5.507 -#endif
   5.508 -
   5.509 -    WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   5.510 -}
   5.511 -
   5.512 -void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
   5.513 -{
   5.514 -#if LOG_POINTER_EVENTS
   5.515 -    WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   5.516 -#endif
   5.517 -
   5.518 -    WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   5.519 -}
   5.520 -
   5.521 -void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
   5.522 -{
   5.523 -#if LOG_POINTER_EVENTS
   5.524 -    WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   5.525 -#endif
   5.526 -
   5.527 -    WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   5.528 -}
   5.529 -
   5.530 -void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
   5.531 -{
   5.532 -#if LOG_POINTER_EVENTS
   5.533 -    WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   5.534 -#endif
   5.535 -
   5.536 -    WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   5.537 -}
   5.538 -
   5.539 -void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
   5.540 -{
   5.541 -    WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
   5.542 -}
   5.543 -
   5.544 -void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   5.545 -{
   5.546 -    WINRT_ProcessKeyDownEvent(args);
   5.547 -}
   5.548 -
   5.549 -void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   5.550 -{
   5.551 -    WINRT_ProcessKeyUpEvent(args);
   5.552 -}
     6.1 --- a/src/core/winrt/SDL_winrtapp.h	Fri Sep 06 21:00:52 2013 -0400
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,42 +0,0 @@
     6.4 -#pragma once
     6.5 -
     6.6 -ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
     6.7 -{
     6.8 -public:
     6.9 -    SDL_WinRTApp();
    6.10 -    
    6.11 -    // IFrameworkView Methods.
    6.12 -    virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
    6.13 -    virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
    6.14 -    virtual void Load(Platform::String^ entryPoint);
    6.15 -    virtual void Run();
    6.16 -    virtual void Uninitialize();
    6.17 -
    6.18 -internal:
    6.19 -    // SDL-specific methods
    6.20 -    void PumpEvents();
    6.21 -
    6.22 -protected:
    6.23 -    // Event Handlers.
    6.24 -    void OnOrientationChanged(Platform::Object^ sender);
    6.25 -    void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
    6.26 -    void OnLogicalDpiChanged(Platform::Object^ sender);
    6.27 -    void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
    6.28 -    void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
    6.29 -    void OnResuming(Platform::Object^ sender, Platform::Object^ args);
    6.30 -    void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
    6.31 -    void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
    6.32 -    void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    6.33 -    void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    6.34 -    void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    6.35 -    void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    6.36 -    void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args);
    6.37 -    void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
    6.38 -    void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
    6.39 -
    6.40 -private:
    6.41 -    bool m_windowClosed;
    6.42 -    bool m_windowVisible;
    6.43 -};
    6.44 -
    6.45 -extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp	Fri Sep 06 21:13:15 2013 -0400
     7.3 @@ -0,0 +1,549 @@
     7.4 +
     7.5 +/* Standard C++11 includes */
     7.6 +#include <functional>
     7.7 +#include <string>
     7.8 +#include <sstream>
     7.9 +using namespace std;
    7.10 +
    7.11 +
    7.12 +/* Windows includes */
    7.13 +#include "ppltasks.h"
    7.14 +using namespace concurrency;
    7.15 +using namespace Windows::ApplicationModel;
    7.16 +using namespace Windows::ApplicationModel::Core;
    7.17 +using namespace Windows::ApplicationModel::Activation;
    7.18 +using namespace Windows::Devices::Input;
    7.19 +using namespace Windows::Graphics::Display;
    7.20 +using namespace Windows::Foundation;
    7.21 +using namespace Windows::System;
    7.22 +using namespace Windows::UI::Core;
    7.23 +using namespace Windows::UI::Input;
    7.24 +
    7.25 +
    7.26 +/* SDL includes */
    7.27 +extern "C" {
    7.28 +#include "SDL_assert.h"
    7.29 +#include "SDL_events.h"
    7.30 +#include "SDL_hints.h"
    7.31 +#include "SDL_log.h"
    7.32 +#include "SDL_main.h"
    7.33 +#include "SDL_stdinc.h"
    7.34 +#include "SDL_render.h"
    7.35 +#include "../../video/SDL_sysvideo.h"
    7.36 +//#include "../../SDL_hints_c.h"
    7.37 +#include "../../events/SDL_mouse_c.h"
    7.38 +#include "../../events/SDL_windowevents_c.h"
    7.39 +#include "../../render/SDL_sysrender.h"
    7.40 +}
    7.41 +
    7.42 +#include "../../video/winrt/SDL_winrtevents_c.h"
    7.43 +#include "../../video/winrt/SDL_winrtvideo_cpp.h"
    7.44 +#include "SDL_winrtapp_direct3d.h"
    7.45 +
    7.46 +
    7.47 +// Compile-time debugging options:
    7.48 +// To enable, uncomment; to disable, comment them out.
    7.49 +//#define LOG_POINTER_EVENTS 1
    7.50 +//#define LOG_WINDOW_EVENTS 1
    7.51 +//#define LOG_ORIENTATION_EVENTS 1
    7.52 +
    7.53 +
    7.54 +// HACK, DLudwig: The C-style main() will get loaded via the app's
    7.55 +// WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp.
    7.56 +// This seems wrong on some level, but does seem to work.
    7.57 +typedef int (*SDL_WinRT_MainFunction)(int, char **);
    7.58 +static SDL_WinRT_MainFunction SDL_WinRT_main = nullptr;
    7.59 +
    7.60 +// HACK, DLudwig: record a reference to the global, WinRT 'app'/view.
    7.61 +// SDL/WinRT will use this throughout its code.
    7.62 +//
    7.63 +// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
    7.64 +// non-global, such as something created inside
    7.65 +// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
    7.66 +// SDL_CreateWindow().
    7.67 +SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
    7.68 +
    7.69 +ref class SDLApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
    7.70 +{
    7.71 +public:
    7.72 +    virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
    7.73 +};
    7.74 +
    7.75 +IFrameworkView^ SDLApplicationSource::CreateView()
    7.76 +{
    7.77 +    // TODO, WinRT: see if this function (CreateView) can ever get called
    7.78 +    // more than once.  For now, just prevent it from ever assigning
    7.79 +    // SDL_WinRTGlobalApp more than once.
    7.80 +    SDL_assert(!SDL_WinRTGlobalApp);
    7.81 +    SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
    7.82 +    if (!SDL_WinRTGlobalApp)
    7.83 +    {
    7.84 +        SDL_WinRTGlobalApp = app;
    7.85 +    }
    7.86 +    return app;
    7.87 +}
    7.88 +
    7.89 +__declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFunction)
    7.90 +{
    7.91 +    SDL_WinRT_main = mainFunction;
    7.92 +    auto direct3DApplicationSource = ref new SDLApplicationSource();
    7.93 +    CoreApplication::Run(direct3DApplicationSource);
    7.94 +    return 0;
    7.95 +}
    7.96 +
    7.97 +static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
    7.98 +{
    7.99 +    SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
   7.100 +
   7.101 +    // Start with no orientation flags, then add each in as they're parsed
   7.102 +    // from newValue.
   7.103 +    unsigned int orientationFlags = 0;
   7.104 +    if (newValue) {
   7.105 +        std::istringstream tokenizer(newValue);
   7.106 +        while (!tokenizer.eof()) {
   7.107 +            std::string orientationName;
   7.108 +            std::getline(tokenizer, orientationName, ' ');
   7.109 +            if (orientationName == "LandscapeLeft") {
   7.110 +                orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
   7.111 +            } else if (orientationName == "LandscapeRight") {
   7.112 +                orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
   7.113 +            } else if (orientationName == "Portrait") {
   7.114 +                orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
   7.115 +            } else if (orientationName == "PortraitUpsideDown") {
   7.116 +                orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
   7.117 +            }
   7.118 +        }
   7.119 +    }
   7.120 +
   7.121 +    // If no valid orientation flags were specified, use a reasonable set of defaults:
   7.122 +    if (!orientationFlags) {
   7.123 +        // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
   7.124 +        orientationFlags = (unsigned int) ( \
   7.125 +            DisplayOrientations::Landscape |
   7.126 +            DisplayOrientations::LandscapeFlipped |
   7.127 +            DisplayOrientations::Portrait |
   7.128 +            DisplayOrientations::PortraitFlipped);
   7.129 +    }
   7.130 +
   7.131 +    // Set the orientation/rotation preferences.  Please note that this does
   7.132 +    // not constitute a 100%-certain lock of a given set of possible
   7.133 +    // orientations.  According to Microsoft's documentation on WinRT [1]
   7.134 +    // when a device is not capable of being rotated, Windows may ignore
   7.135 +    // the orientation preferences, and stick to what the device is capable of
   7.136 +    // displaying.
   7.137 +    //
   7.138 +    // [1] Documentation on the 'InitialRotationPreference' setting for a
   7.139 +    // Windows app's manifest file describes how some orientation/rotation
   7.140 +    // preferences may be ignored.  See
   7.141 +    // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
   7.142 +    // for details.  Microsoft's "Display orientation sample" also gives an
   7.143 +    // outline of how Windows treats device rotation
   7.144 +    // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
   7.145 +    DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
   7.146 +}
   7.147 +
   7.148 +static void
   7.149 +WINRT_ProcessWindowSizeChange()
   7.150 +{
   7.151 +    // Make the new window size be the one true fullscreen mode.
   7.152 +    // This change was initially done, in part, to allow the Direct3D 11.1
   7.153 +    // renderer to receive window-resize events as a device rotates.
   7.154 +    // Before, rotating a device from landscape, to portrait, and then
   7.155 +    // back to landscape would cause the Direct3D 11.1 swap buffer to
   7.156 +    // not get resized appropriately.  SDL would, on the rotation from
   7.157 +    // landscape to portrait, re-resize the SDL window to it's initial
   7.158 +    // size (landscape).  On the subsequent rotation, SDL would drop the
   7.159 +    // window-resize event as it appeared the SDL window didn't change
   7.160 +    // size, and the Direct3D 11.1 renderer wouldn't resize its swap
   7.161 +    // chain.
   7.162 +    SDL_DisplayMode resizedDisplayMode = WINRT_CalcDisplayModeUsingNativeWindow();
   7.163 +    if (resizedDisplayMode.w == 0 || resizedDisplayMode.h == 0) {
   7.164 +        return;
   7.165 +    }
   7.166 +
   7.167 +    SDL_DisplayMode oldDisplayMode;
   7.168 +    SDL_zero(oldDisplayMode);
   7.169 +    if (WINRT_GlobalSDLVideoDevice) {
   7.170 +        oldDisplayMode = WINRT_GlobalSDLVideoDevice->displays[0].desktop_mode;
   7.171 +        WINRT_GlobalSDLVideoDevice->displays[0].current_mode = resizedDisplayMode;
   7.172 +        WINRT_GlobalSDLVideoDevice->displays[0].desktop_mode = resizedDisplayMode;
   7.173 +        WINRT_GlobalSDLVideoDevice->displays[0].display_modes[0] = resizedDisplayMode;
   7.174 +    }
   7.175 +
   7.176 +    if (WINRT_GlobalSDLWindow) {
   7.177 +        // Send a window-resize event to the rest of SDL, and to apps:
   7.178 +        SDL_SendWindowEvent(
   7.179 +            WINRT_GlobalSDLWindow,
   7.180 +            SDL_WINDOWEVENT_RESIZED,
   7.181 +            resizedDisplayMode.w,
   7.182 +            resizedDisplayMode.h);
   7.183 +
   7.184 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   7.185 +        // HACK: On Windows Phone, make sure that orientation changes from
   7.186 +        // Landscape to LandscapeFlipped, Portrait to PortraitFlipped,
   7.187 +        // or vice-versa on either of those two, lead to the Direct3D renderer
   7.188 +        // getting updated.
   7.189 +        const DisplayOrientations oldOrientation = (DisplayOrientations) (unsigned int) oldDisplayMode.driverdata;
   7.190 +        const DisplayOrientations newOrientation = (DisplayOrientations) (unsigned int) resizedDisplayMode.driverdata;
   7.191 +
   7.192 +        if ((oldOrientation == DisplayOrientations::Landscape && newOrientation == DisplayOrientations::LandscapeFlipped) ||
   7.193 +            (oldOrientation == DisplayOrientations::LandscapeFlipped && newOrientation == DisplayOrientations::Landscape) ||
   7.194 +            (oldOrientation == DisplayOrientations::Portrait && newOrientation == DisplayOrientations::PortraitFlipped) ||
   7.195 +            (oldOrientation == DisplayOrientations::PortraitFlipped && newOrientation == DisplayOrientations::Portrait))
   7.196 +        {
   7.197 +            // One of the reasons this event is getting sent out is because SDL
   7.198 +            // will ignore requests to send out SDL_WINDOWEVENT_RESIZED events
   7.199 +            // if and when the event size doesn't change (and the Direct3D 11.1
   7.200 +            // renderer doesn't get the memo).
   7.201 +            //
   7.202 +            // Make sure that the display/window size really didn't change.  If
   7.203 +            // it did, then a SDL_WINDOWEVENT_SIZE_CHANGED event got sent, and
   7.204 +            // the Direct3D 11.1 renderer picked it up, presumably.
   7.205 +            if (oldDisplayMode.w == resizedDisplayMode.w &&
   7.206 +                oldDisplayMode.h == resizedDisplayMode.h)
   7.207 +            {
   7.208 +                SDL_SendWindowEvent(
   7.209 +                    WINRT_GlobalSDLWindow,
   7.210 +                    SDL_WINDOWEVENT_SIZE_CHANGED,
   7.211 +                    resizedDisplayMode.w,
   7.212 +                    resizedDisplayMode.h);
   7.213 +            }
   7.214 +        }
   7.215 +#endif
   7.216 +    }
   7.217 +}
   7.218 +
   7.219 +SDL_WinRTApp::SDL_WinRTApp() :
   7.220 +    m_windowClosed(false),
   7.221 +    m_windowVisible(true)
   7.222 +{
   7.223 +}
   7.224 +
   7.225 +void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
   7.226 +{
   7.227 +    applicationView->Activated +=
   7.228 +        ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
   7.229 +
   7.230 +    CoreApplication::Suspending +=
   7.231 +        ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
   7.232 +
   7.233 +    CoreApplication::Resuming +=
   7.234 +        ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
   7.235 +
   7.236 +    DisplayProperties::OrientationChanged +=
   7.237 +        ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
   7.238 +
   7.239 +    // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.  This needs to be
   7.240 +    // done before the hint's callback is registered (as of Feb 22, 2013),
   7.241 +    // otherwise the hint callback won't get registered.
   7.242 +    //
   7.243 +    // TODO, WinRT: see if an app's default orientation can be found out via WinRT API(s), then set the initial value of SDL_HINT_ORIENTATIONS accordingly.
   7.244 +    //SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");   // DavidL: this is no longer needed (for SDL_AddHintCallback)
   7.245 +    SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
   7.246 +}
   7.247 +
   7.248 +void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
   7.249 +{
   7.250 +#if LOG_ORIENTATION_EVENTS==1
   7.251 +    CoreWindow^ window = CoreWindow::GetForCurrentThread();
   7.252 +    if (window) {
   7.253 +        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Size={%f,%f}\n",
   7.254 +            __FUNCTION__,
   7.255 +            (int)DisplayProperties::CurrentOrientation,
   7.256 +            (int)DisplayProperties::NativeOrientation,
   7.257 +            (int)DisplayProperties::AutoRotationPreferences,
   7.258 +            window->Bounds.Width,
   7.259 +            window->Bounds.Height);
   7.260 +    } else {
   7.261 +        SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
   7.262 +            __FUNCTION__,
   7.263 +            (int)DisplayProperties::CurrentOrientation,
   7.264 +            (int)DisplayProperties::NativeOrientation,
   7.265 +            (int)DisplayProperties::AutoRotationPreferences);
   7.266 +    }
   7.267 +#endif
   7.268 +
   7.269 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   7.270 +    // On Windows Phone, treat an orientation change as a change in window size.
   7.271 +    // The native window's size doesn't seem to change, however SDL will simulate
   7.272 +    // a window size change.
   7.273 +    WINRT_ProcessWindowSizeChange();
   7.274 +#endif
   7.275 +}
   7.276 +
   7.277 +void SDL_WinRTApp::SetWindow(CoreWindow^ window)
   7.278 +{
   7.279 +#if LOG_WINDOW_EVENTS==1
   7.280 +    SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window Size={%f,%f}\n",
   7.281 +        __FUNCTION__,
   7.282 +        (int)DisplayProperties::CurrentOrientation,
   7.283 +        (int)DisplayProperties::NativeOrientation,
   7.284 +        (int)DisplayProperties::AutoRotationPreferences,
   7.285 +        window->Bounds.Width,
   7.286 +        window->Bounds.Height);
   7.287 +#endif
   7.288 +
   7.289 +    window->SizeChanged += 
   7.290 +        ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
   7.291 +
   7.292 +    window->VisibilityChanged +=
   7.293 +        ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
   7.294 +
   7.295 +    window->Closed += 
   7.296 +        ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
   7.297 +
   7.298 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   7.299 +    window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
   7.300 +#endif
   7.301 +
   7.302 +    window->PointerPressed +=
   7.303 +        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
   7.304 +
   7.305 +    window->PointerMoved +=
   7.306 +        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
   7.307 +
   7.308 +    window->PointerReleased +=
   7.309 +        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
   7.310 +
   7.311 +    window->PointerWheelChanged +=
   7.312 +        ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
   7.313 +
   7.314 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   7.315 +    // Retrieves relative-only mouse movements:
   7.316 +    Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
   7.317 +        ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
   7.318 +#endif
   7.319 +
   7.320 +    window->KeyDown +=
   7.321 +        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
   7.322 +
   7.323 +    window->KeyUp +=
   7.324 +        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
   7.325 +}
   7.326 +
   7.327 +void SDL_WinRTApp::Load(Platform::String^ entryPoint)
   7.328 +{
   7.329 +}
   7.330 +
   7.331 +void SDL_WinRTApp::Run()
   7.332 +{
   7.333 +    SDL_SetMainReady();
   7.334 +    if (SDL_WinRT_main)
   7.335 +    {
   7.336 +        // TODO, WinRT: pass the C-style main() a reasonably realistic
   7.337 +        // representation of command line arguments.
   7.338 +        int argc = 0;
   7.339 +        char **argv = NULL;
   7.340 +        SDL_WinRT_main(argc, argv);
   7.341 +    }
   7.342 +}
   7.343 +
   7.344 +void SDL_WinRTApp::PumpEvents()
   7.345 +{
   7.346 +    if (!m_windowClosed)
   7.347 +    {
   7.348 +        if (m_windowVisible)
   7.349 +        {
   7.350 +            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
   7.351 +        }
   7.352 +        else
   7.353 +        {
   7.354 +            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
   7.355 +        }
   7.356 +    }
   7.357 +}
   7.358 +
   7.359 +void SDL_WinRTApp::Uninitialize()
   7.360 +{
   7.361 +}
   7.362 +
   7.363 +void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
   7.364 +{
   7.365 +#if LOG_WINDOW_EVENTS==1
   7.366 +    SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
   7.367 +        __FUNCTION__,
   7.368 +        args->Size.Width, args->Size.Height,
   7.369 +        (int)DisplayProperties::CurrentOrientation,
   7.370 +        (int)DisplayProperties::NativeOrientation,
   7.371 +        (int)DisplayProperties::AutoRotationPreferences,
   7.372 +        (WINRT_GlobalSDLWindow ? "yes" : "no"));
   7.373 +#endif
   7.374 +
   7.375 +    WINRT_ProcessWindowSizeChange();
   7.376 +}
   7.377 +
   7.378 +void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
   7.379 +{
   7.380 +#if LOG_WINDOW_EVENTS==1
   7.381 +    SDL_Log("%s, visible?=%s, WINRT_GlobalSDLWindow?=%s\n",
   7.382 +        __FUNCTION__,
   7.383 +        (args->Visible ? "yes" : "no"),
   7.384 +        (WINRT_GlobalSDLWindow ? "yes" : "no"));
   7.385 +#endif
   7.386 +
   7.387 +    m_windowVisible = args->Visible;
   7.388 +    if (WINRT_GlobalSDLWindow) {
   7.389 +        SDL_bool wasSDLWindowSurfaceValid = WINRT_GlobalSDLWindow->surface_valid;
   7.390 +
   7.391 +        if (args->Visible) {
   7.392 +            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
   7.393 +        } else {
   7.394 +            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   7.395 +        }
   7.396 +
   7.397 +        // HACK: Prevent SDL's window-hide handling code, which currently
   7.398 +        // triggers a fake window resize (possibly erronously), from
   7.399 +        // marking the SDL window's surface as invalid.
   7.400 +        //
   7.401 +        // A better solution to this probably involves figuring out if the
   7.402 +        // fake window resize can be prevented.
   7.403 +        WINRT_GlobalSDLWindow->surface_valid = wasSDLWindowSurfaceValid;
   7.404 +    }
   7.405 +}
   7.406 +
   7.407 +void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
   7.408 +{
   7.409 +#if LOG_WINDOW_EVENTS==1
   7.410 +    SDL_Log("%s\n", __FUNCTION__);
   7.411 +#endif
   7.412 +    m_windowClosed = true;
   7.413 +}
   7.414 +
   7.415 +void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
   7.416 +{
   7.417 +    CoreWindow::GetForCurrentThread()->Activate();
   7.418 +}
   7.419 +
   7.420 +static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event * event)
   7.421 +{
   7.422 +    if (event->type == SDL_WINDOWEVENT)
   7.423 +    {
   7.424 +        switch (event->window.event)
   7.425 +        {
   7.426 +            case SDL_WINDOWEVENT_MINIMIZED:
   7.427 +            case SDL_WINDOWEVENT_RESTORED:
   7.428 +                // Return 0 to indicate that the event should be removed from the
   7.429 +                // event queue:
   7.430 +                return 0;
   7.431 +            default:
   7.432 +                break;
   7.433 +        }
   7.434 +    }
   7.435 +
   7.436 +    // Return 1 to indicate that the event should stay in the event queue:
   7.437 +    return 1;
   7.438 +}
   7.439 +
   7.440 +void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
   7.441 +{
   7.442 +    // Save app state asynchronously after requesting a deferral. Holding a deferral
   7.443 +    // indicates that the application is busy performing suspending operations. Be
   7.444 +    // aware that a deferral may not be held indefinitely. After about five seconds,
   7.445 +    // the app will be forced to exit.
   7.446 +    SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
   7.447 +    create_task([this, deferral]()
   7.448 +    {
   7.449 +        // Send a window-minimized event immediately to observers.
   7.450 +        // CoreDispatcher::ProcessEvents, which is the backbone on which
   7.451 +        // SDL_WinRTApp::PumpEvents is built, will not return to its caller
   7.452 +        // once it sends out a suspend event.  Any events posted to SDL's
   7.453 +        // event queue won't get received until the WinRT app is resumed.
   7.454 +        // SDL_AddEventWatch() may be used to receive app-suspend events on
   7.455 +        // WinRT.
   7.456 +        //
   7.457 +        // In order to prevent app-suspend events from being received twice:
   7.458 +        // first via a callback passed to SDL_AddEventWatch, and second via
   7.459 +        // SDL's event queue, the event will be sent to SDL, then immediately
   7.460 +        // removed from the queue.
   7.461 +        if (WINRT_GlobalSDLWindow)
   7.462 +        {
   7.463 +            SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);   // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
   7.464 +            SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
   7.465 +        }
   7.466 +        deferral->Complete();
   7.467 +    });
   7.468 +}
   7.469 +
   7.470 +void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
   7.471 +{
   7.472 +    // Restore any data or state that was unloaded on suspend. By default, data
   7.473 +    // and state are persisted when resuming from suspend. Note that this event
   7.474 +    // does not occur if the app was previously terminated.
   7.475 +    if (WINRT_GlobalSDLWindow)
   7.476 +    {
   7.477 +        SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_RESTORED, 0, 0);    // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
   7.478 +
   7.479 +        // Remove the app-resume event from the queue, as is done with the
   7.480 +        // app-suspend event.
   7.481 +        //
   7.482 +        // TODO, WinRT: consider posting this event to the queue even though
   7.483 +        // its counterpart, the app-suspend event, effectively has to be
   7.484 +        // processed immediately.
   7.485 +        SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
   7.486 +    }
   7.487 +}
   7.488 +
   7.489 +static void
   7.490 +WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
   7.491 +{
   7.492 +    Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
   7.493 +    SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
   7.494 +        header,
   7.495 +        pt->Position.X, pt->Position.Y,
   7.496 +        transformedPoint.X, transformedPoint.Y,
   7.497 +        pt->Properties->MouseWheelDelta,
   7.498 +        pt->FrameId,
   7.499 +        pt->PointerId,
   7.500 +        WINRT_GetSDLButtonForPointerPoint(pt));
   7.501 +}
   7.502 +
   7.503 +void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
   7.504 +{
   7.505 +#if LOG_POINTER_EVENTS
   7.506 +    WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   7.507 +#endif
   7.508 +
   7.509 +    WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   7.510 +}
   7.511 +
   7.512 +void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
   7.513 +{
   7.514 +#if LOG_POINTER_EVENTS
   7.515 +    WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   7.516 +#endif
   7.517 +
   7.518 +    WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   7.519 +}
   7.520 +
   7.521 +void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
   7.522 +{
   7.523 +#if LOG_POINTER_EVENTS
   7.524 +    WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   7.525 +#endif
   7.526 +
   7.527 +    WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   7.528 +}
   7.529 +
   7.530 +void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
   7.531 +{
   7.532 +#if LOG_POINTER_EVENTS
   7.533 +    WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   7.534 +#endif
   7.535 +
   7.536 +    WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   7.537 +}
   7.538 +
   7.539 +void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
   7.540 +{
   7.541 +    WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
   7.542 +}
   7.543 +
   7.544 +void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   7.545 +{
   7.546 +    WINRT_ProcessKeyDownEvent(args);
   7.547 +}
   7.548 +
   7.549 +void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   7.550 +{
   7.551 +    WINRT_ProcessKeyUpEvent(args);
   7.552 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/core/winrt/SDL_winrtapp_direct3d.h	Fri Sep 06 21:13:15 2013 -0400
     8.3 @@ -0,0 +1,42 @@
     8.4 +#pragma once
     8.5 +
     8.6 +ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
     8.7 +{
     8.8 +public:
     8.9 +    SDL_WinRTApp();
    8.10 +    
    8.11 +    // IFrameworkView Methods.
    8.12 +    virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
    8.13 +    virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
    8.14 +    virtual void Load(Platform::String^ entryPoint);
    8.15 +    virtual void Run();
    8.16 +    virtual void Uninitialize();
    8.17 +
    8.18 +internal:
    8.19 +    // SDL-specific methods
    8.20 +    void PumpEvents();
    8.21 +
    8.22 +protected:
    8.23 +    // Event Handlers.
    8.24 +    void OnOrientationChanged(Platform::Object^ sender);
    8.25 +    void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
    8.26 +    void OnLogicalDpiChanged(Platform::Object^ sender);
    8.27 +    void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
    8.28 +    void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
    8.29 +    void OnResuming(Platform::Object^ sender, Platform::Object^ args);
    8.30 +    void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
    8.31 +    void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
    8.32 +    void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    8.33 +    void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    8.34 +    void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    8.35 +    void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    8.36 +    void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args);
    8.37 +    void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
    8.38 +    void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
    8.39 +
    8.40 +private:
    8.41 +    bool m_windowClosed;
    8.42 +    bool m_windowVisible;
    8.43 +};
    8.44 +
    8.45 +extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/core/winrt/SDL_winrtapp_xaml.cpp	Fri Sep 06 21:13:15 2013 -0400
     9.3 @@ -0,0 +1,157 @@
     9.4 +/*
     9.5 +  Simple DirectMedia Layer
     9.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     9.7 +
     9.8 +  This software is provided 'as-is', without any express or implied
     9.9 +  warranty.  In no event will the authors be held liable for any damages
    9.10 +  arising from the use of this software.
    9.11 +
    9.12 +  Permission is granted to anyone to use this software for any purpose,
    9.13 +  including commercial applications, and to alter it and redistribute it
    9.14 +  freely, subject to the following restrictions:
    9.15 +
    9.16 +  1. The origin of this software must not be misrepresented; you must not
    9.17 +     claim that you wrote the original software. If you use this software
    9.18 +     in a product, an acknowledgment in the product documentation would be
    9.19 +     appreciated but is not required.
    9.20 +  2. Altered source versions must be plainly marked as such, and must not be
    9.21 +     misrepresented as being the original software.
    9.22 +  3. This notice may not be removed or altered from any source distribution.
    9.23 +*/
    9.24 +
    9.25 +/* Windows includes */
    9.26 +#include <agile.h>
    9.27 +#include <Windows.h>
    9.28 +
    9.29 +#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    9.30 +#include <windows.ui.xaml.media.dxinterop.h>
    9.31 +#endif
    9.32 +
    9.33 +
    9.34 +/* SDL includes */
    9.35 +#include "SDL.h"
    9.36 +#include "../../video/winrt/SDL_winrtevents_c.h"
    9.37 +#include "../../video/winrt/SDL_winrtvideo_cpp.h"
    9.38 +#include "SDL_winrtapp_xaml.h"
    9.39 +
    9.40 +
    9.41 +
    9.42 +/* SDL-internal globals: */
    9.43 +SDL_bool WINRT_XAMLWasEnabled = SDL_FALSE;
    9.44 +int (*WINRT_XAMLAppMainFunction)(int, char **) = NULL;
    9.45 +
    9.46 +#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    9.47 +ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative = NULL;
    9.48 +static Windows::Foundation::EventRegistrationToken	WINRT_XAMLAppEventToken;
    9.49 +#endif
    9.50 +
    9.51 +
    9.52 +/*
    9.53 + * Input event handlers (XAML)
    9.54 + */
    9.55 +#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    9.56 +
    9.57 +static void
    9.58 +WINRT_OnPointerPressedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
    9.59 +{
    9.60 +    WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
    9.61 +}
    9.62 +
    9.63 +static void
    9.64 +WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
    9.65 +{
    9.66 +    WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
    9.67 +}
    9.68 +
    9.69 +static void
    9.70 +WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
    9.71 +{
    9.72 +    WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
    9.73 +}
    9.74 +
    9.75 +static void
    9.76 +WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
    9.77 +{
    9.78 +    WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
    9.79 +}
    9.80 +
    9.81 +#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
    9.82 +
    9.83 +
    9.84 +/*
    9.85 + * XAML-to-SDL Rendering Callback
    9.86 + */
    9.87 +#if WINAPI_FAMILY == WINAPI_FAMILY_APP
    9.88 +
    9.89 +static void
    9.90 +WINRT_OnRenderViaXAML(_In_ Platform::Object^ sender, _In_ Platform::Object^ args)
    9.91 +{
    9.92 +    WINRT_CycleXAMLThread();
    9.93 +}
    9.94 +
    9.95 +#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
    9.96 +
    9.97 +
    9.98 +/*
    9.99 + * SDL + XAML Initialization
   9.100 + */
   9.101 +
   9.102 +extern "C" int
   9.103 +SDL_WinRTInitXAMLApp(Platform::Object ^backgroundPanel, int (*mainFunction)(int, char **))
   9.104 +{
   9.105 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   9.106 +    return SDL_SetError("XAML support is not yet available in Windows Phone.");
   9.107 +#else
   9.108 +    // Declare C++/CX namespaces:
   9.109 +    using namespace Platform;
   9.110 +    using namespace Windows::Foundation;
   9.111 +    using namespace Windows::UI::Core;
   9.112 +    using namespace Windows::UI::Xaml;
   9.113 +    using namespace Windows::UI::Xaml::Controls;
   9.114 +    using namespace Windows::UI::Xaml::Input;
   9.115 +    using namespace Windows::UI::Xaml::Media;
   9.116 +
   9.117 +    // Make sure we have a valid XAML element (to draw onto):
   9.118 +    if ( ! backgroundPanel) {
   9.119 +        return SDL_SetError("'backgroundPanel' can't be NULL");
   9.120 +    }
   9.121 +
   9.122 +    SwapChainBackgroundPanel ^swapChainBackgroundPanel = dynamic_cast<SwapChainBackgroundPanel ^>(backgroundPanel);
   9.123 +    if ( ! swapChainBackgroundPanel) {
   9.124 +        return SDL_SetError("An unknown or unsupported type of XAML control was specified.");
   9.125 +    }
   9.126 +
   9.127 +    // Setup event handlers:
   9.128 +    swapChainBackgroundPanel->PointerPressed += ref new PointerEventHandler(WINRT_OnPointerPressedViaXAML);
   9.129 +    swapChainBackgroundPanel->PointerReleased += ref new PointerEventHandler(WINRT_OnPointerReleasedViaXAML);
   9.130 +    swapChainBackgroundPanel->PointerWheelChanged += ref new PointerEventHandler(WINRT_OnPointerWheelChangedViaXAML);
   9.131 +    swapChainBackgroundPanel->PointerMoved += ref new PointerEventHandler(WINRT_OnPointerMovedViaXAML);
   9.132 +
   9.133 +    // Setup for rendering:
   9.134 +    IInspectable *panelInspectable = (IInspectable*) reinterpret_cast<IInspectable*>(swapChainBackgroundPanel);
   9.135 +    panelInspectable->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&WINRT_GlobalSwapChainBackgroundPanelNative);
   9.136 +
   9.137 +    WINRT_XAMLAppEventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(WINRT_OnRenderViaXAML));
   9.138 +
   9.139 +    // Make sure the app is ready to call the SDL-centric main() function:
   9.140 +    WINRT_XAMLAppMainFunction = mainFunction;
   9.141 +    SDL_SetMainReady();
   9.142 +
   9.143 +    // Make sure video-init knows that we're initializing XAML:
   9.144 +    SDL_bool oldXAMLWasEnabledValue = WINRT_XAMLWasEnabled;
   9.145 +    WINRT_XAMLWasEnabled = SDL_TRUE;
   9.146 +
   9.147 +    // Make sure video modes are detected now, while we still have access to the WinRT
   9.148 +    // CoreWindow.  WinRT will not allow the app's CoreWindow to be accessed via the
   9.149 +    // SDL/WinRT thread.
   9.150 +    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
   9.151 +        // SDL_InitSubSystem will, on error, set the SDL error.  Let that propogate to
   9.152 +        // the caller to here:
   9.153 +        WINRT_XAMLWasEnabled = oldXAMLWasEnabledValue;
   9.154 +        return -1;
   9.155 +    }
   9.156 +
   9.157 +    // All done, for now.
   9.158 +    return 0;
   9.159 +#endif // WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP  /  else
   9.160 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/core/winrt/SDL_winrtapp_xaml.h	Fri Sep 06 21:13:15 2013 -0400
    10.3 @@ -0,0 +1,33 @@
    10.4 +/*
    10.5 +  Simple DirectMedia Layer
    10.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
    10.7 +
    10.8 +  This software is provided 'as-is', without any express or implied
    10.9 +  warranty.  In no event will the authors be held liable for any damages
   10.10 +  arising from the use of this software.
   10.11 +
   10.12 +  Permission is granted to anyone to use this software for any purpose,
   10.13 +  including commercial applications, and to alter it and redistribute it
   10.14 +  freely, subject to the following restrictions:
   10.15 +
   10.16 +  1. The origin of this software must not be misrepresented; you must not
   10.17 +     claim that you wrote the original software. If you use this software
   10.18 +     in a product, an acknowledgment in the product documentation would be
   10.19 +     appreciated but is not required.
   10.20 +  2. Altered source versions must be plainly marked as such, and must not be
   10.21 +     misrepresented as being the original software.
   10.22 +  3. This notice may not be removed or altered from any source distribution.
   10.23 +*/
   10.24 +#include "SDL_config.h"
   10.25 +
   10.26 +#ifndef _SDL_winrtapp_xaml_h
   10.27 +#define _SDL_winrtapp_xaml_h
   10.28 +
   10.29 +#include "SDL_types.h"
   10.30 +
   10.31 +#ifdef __cplusplus
   10.32 +extern SDL_bool WINRT_XAMLWasEnabled;
   10.33 +extern int (*WINRT_XAMLAppMainFunction)(int, char **);
   10.34 +#endif // ifdef __cplusplus
   10.35 +
   10.36 +#endif // ifndef _SDL_winrtapp_xaml_h
    11.1 --- a/src/core/winrt/SDL_winrtxaml.cpp	Fri Sep 06 21:00:52 2013 -0400
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,157 +0,0 @@
    11.4 -/*
    11.5 -  Simple DirectMedia Layer
    11.6 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    11.7 -
    11.8 -  This software is provided 'as-is', without any express or implied
    11.9 -  warranty.  In no event will the authors be held liable for any damages
   11.10 -  arising from the use of this software.
   11.11 -
   11.12 -  Permission is granted to anyone to use this software for any purpose,
   11.13 -  including commercial applications, and to alter it and redistribute it
   11.14 -  freely, subject to the following restrictions:
   11.15 -
   11.16 -  1. The origin of this software must not be misrepresented; you must not
   11.17 -     claim that you wrote the original software. If you use this software
   11.18 -     in a product, an acknowledgment in the product documentation would be
   11.19 -     appreciated but is not required.
   11.20 -  2. Altered source versions must be plainly marked as such, and must not be
   11.21 -     misrepresented as being the original software.
   11.22 -  3. This notice may not be removed or altered from any source distribution.
   11.23 -*/
   11.24 -
   11.25 -/* Windows includes */
   11.26 -#include <agile.h>
   11.27 -#include <Windows.h>
   11.28 -
   11.29 -#if WINAPI_FAMILY == WINAPI_FAMILY_APP
   11.30 -#include <windows.ui.xaml.media.dxinterop.h>
   11.31 -#endif
   11.32 -
   11.33 -
   11.34 -/* SDL includes */
   11.35 -#include "SDL.h"
   11.36 -#include "../../video/winrt/SDL_winrtevents_c.h"
   11.37 -#include "../../video/winrt/SDL_winrtvideo_cpp.h"
   11.38 -#include "SDL_winrtxaml_cpp.h"
   11.39 -
   11.40 -
   11.41 -
   11.42 -/* SDL-internal globals: */
   11.43 -SDL_bool WINRT_XAMLWasEnabled = SDL_FALSE;
   11.44 -int (*WINRT_XAMLAppMainFunction)(int, char **) = NULL;
   11.45 -
   11.46 -#if WINAPI_FAMILY == WINAPI_FAMILY_APP
   11.47 -ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative = NULL;
   11.48 -static Windows::Foundation::EventRegistrationToken	WINRT_XAMLAppEventToken;
   11.49 -#endif
   11.50 -
   11.51 -
   11.52 -/*
   11.53 - * Input event handlers (XAML)
   11.54 - */
   11.55 -#if WINAPI_FAMILY == WINAPI_FAMILY_APP
   11.56 -
   11.57 -static void
   11.58 -WINRT_OnPointerPressedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
   11.59 -{
   11.60 -    WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
   11.61 -}
   11.62 -
   11.63 -static void
   11.64 -WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
   11.65 -{
   11.66 -    WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
   11.67 -}
   11.68 -
   11.69 -static void
   11.70 -WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
   11.71 -{
   11.72 -    WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
   11.73 -}
   11.74 -
   11.75 -static void
   11.76 -WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
   11.77 -{
   11.78 -    WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
   11.79 -}
   11.80 -
   11.81 -#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
   11.82 -
   11.83 -
   11.84 -/*
   11.85 - * XAML-to-SDL Rendering Callback
   11.86 - */
   11.87 -#if WINAPI_FAMILY == WINAPI_FAMILY_APP
   11.88 -
   11.89 -static void
   11.90 -WINRT_OnRenderViaXAML(_In_ Platform::Object^ sender, _In_ Platform::Object^ args)
   11.91 -{
   11.92 -    WINRT_CycleXAMLThread();
   11.93 -}
   11.94 -
   11.95 -#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
   11.96 -
   11.97 -
   11.98 -/*
   11.99 - * SDL + XAML Initialization
  11.100 - */
  11.101 -
  11.102 -extern "C" int
  11.103 -SDL_WinRTInitXAMLApp(Platform::Object ^backgroundPanel, int (*mainFunction)(int, char **))
  11.104 -{
  11.105 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  11.106 -    return SDL_SetError("XAML support is not yet available in Windows Phone.");
  11.107 -#else
  11.108 -    // Declare C++/CX namespaces:
  11.109 -    using namespace Platform;
  11.110 -    using namespace Windows::Foundation;
  11.111 -    using namespace Windows::UI::Core;
  11.112 -    using namespace Windows::UI::Xaml;
  11.113 -    using namespace Windows::UI::Xaml::Controls;
  11.114 -    using namespace Windows::UI::Xaml::Input;
  11.115 -    using namespace Windows::UI::Xaml::Media;
  11.116 -
  11.117 -    // Make sure we have a valid XAML element (to draw onto):
  11.118 -    if ( ! backgroundPanel) {
  11.119 -        return SDL_SetError("'backgroundPanel' can't be NULL");
  11.120 -    }
  11.121 -
  11.122 -    SwapChainBackgroundPanel ^swapChainBackgroundPanel = dynamic_cast<SwapChainBackgroundPanel ^>(backgroundPanel);
  11.123 -    if ( ! swapChainBackgroundPanel) {
  11.124 -        return SDL_SetError("An unknown or unsupported type of XAML control was specified.");
  11.125 -    }
  11.126 -
  11.127 -    // Setup event handlers:
  11.128 -    swapChainBackgroundPanel->PointerPressed += ref new PointerEventHandler(WINRT_OnPointerPressedViaXAML);
  11.129 -    swapChainBackgroundPanel->PointerReleased += ref new PointerEventHandler(WINRT_OnPointerReleasedViaXAML);
  11.130 -    swapChainBackgroundPanel->PointerWheelChanged += ref new PointerEventHandler(WINRT_OnPointerWheelChangedViaXAML);
  11.131 -    swapChainBackgroundPanel->PointerMoved += ref new PointerEventHandler(WINRT_OnPointerMovedViaXAML);
  11.132 -
  11.133 -    // Setup for rendering:
  11.134 -    IInspectable *panelInspectable = (IInspectable*) reinterpret_cast<IInspectable*>(swapChainBackgroundPanel);
  11.135 -    panelInspectable->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&WINRT_GlobalSwapChainBackgroundPanelNative);
  11.136 -
  11.137 -    WINRT_XAMLAppEventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(WINRT_OnRenderViaXAML));
  11.138 -
  11.139 -    // Make sure the app is ready to call the SDL-centric main() function:
  11.140 -    WINRT_XAMLAppMainFunction = mainFunction;
  11.141 -    SDL_SetMainReady();
  11.142 -
  11.143 -    // Make sure video-init knows that we're initializing XAML:
  11.144 -    SDL_bool oldXAMLWasEnabledValue = WINRT_XAMLWasEnabled;
  11.145 -    WINRT_XAMLWasEnabled = SDL_TRUE;
  11.146 -
  11.147 -    // Make sure video modes are detected now, while we still have access to the WinRT
  11.148 -    // CoreWindow.  WinRT will not allow the app's CoreWindow to be accessed via the
  11.149 -    // SDL/WinRT thread.
  11.150 -    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
  11.151 -        // SDL_InitSubSystem will, on error, set the SDL error.  Let that propogate to
  11.152 -        // the caller to here:
  11.153 -        WINRT_XAMLWasEnabled = oldXAMLWasEnabledValue;
  11.154 -        return -1;
  11.155 -    }
  11.156 -
  11.157 -    // All done, for now.
  11.158 -    return 0;
  11.159 -#endif // WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP  /  else
  11.160 -}
    12.1 --- a/src/core/winrt/SDL_winrtxaml_cpp.h	Fri Sep 06 21:00:52 2013 -0400
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,33 +0,0 @@
    12.4 -/*
    12.5 -  Simple DirectMedia Layer
    12.6 -  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
    12.7 -
    12.8 -  This software is provided 'as-is', without any express or implied
    12.9 -  warranty.  In no event will the authors be held liable for any damages
   12.10 -  arising from the use of this software.
   12.11 -
   12.12 -  Permission is granted to anyone to use this software for any purpose,
   12.13 -  including commercial applications, and to alter it and redistribute it
   12.14 -  freely, subject to the following restrictions:
   12.15 -
   12.16 -  1. The origin of this software must not be misrepresented; you must not
   12.17 -     claim that you wrote the original software. If you use this software
   12.18 -     in a product, an acknowledgment in the product documentation would be
   12.19 -     appreciated but is not required.
   12.20 -  2. Altered source versions must be plainly marked as such, and must not be
   12.21 -     misrepresented as being the original software.
   12.22 -  3. This notice may not be removed or altered from any source distribution.
   12.23 -*/
   12.24 -#include "SDL_config.h"
   12.25 -
   12.26 -#ifndef _SDL_winrtxaml_h
   12.27 -#define _SDL_winrtxaml_h
   12.28 -
   12.29 -#include "SDL_types.h"
   12.30 -
   12.31 -#ifdef __cplusplus
   12.32 -extern SDL_bool WINRT_XAMLWasEnabled;
   12.33 -extern int (*WINRT_XAMLAppMainFunction)(int, char **);
   12.34 -#endif // ifdef __cplusplus
   12.35 -
   12.36 -#endif // ifndef _SDL_winrtxaml_h
    13.1 --- a/src/video/winrt/SDL_winrtevents.cpp	Fri Sep 06 21:00:52 2013 -0400
    13.2 +++ b/src/video/winrt/SDL_winrtevents.cpp	Fri Sep 06 21:13:15 2013 -0400
    13.3 @@ -33,8 +33,8 @@
    13.4   * SDL includes:
    13.5   */
    13.6  #include "SDL_winrtevents_c.h"
    13.7 -#include "../../core/winrt/SDL_winrtapp.h"
    13.8 -#include "../../core/winrt/SDL_winrtxaml_cpp.h"
    13.9 +#include "../../core/winrt/SDL_winrtapp_direct3d.h"
   13.10 +#include "../../core/winrt/SDL_winrtapp_xaml.h"
   13.11  #include "SDL_assert.h"
   13.12  #include "SDL_system.h"
   13.13  
    14.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Fri Sep 06 21:00:52 2013 -0400
    14.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Fri Sep 06 21:13:15 2013 -0400
    14.3 @@ -42,7 +42,7 @@
    14.4  #include "SDL_log.h"
    14.5  }
    14.6  
    14.7 -#include "../../core/winrt/SDL_winrtapp.h"
    14.8 +#include "../../core/winrt/SDL_winrtapp_direct3d.h"
    14.9  #include "SDL_winrtvideo_cpp.h"
   14.10  #include "SDL_winrtmouse_c.h"
   14.11  
    15.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Fri Sep 06 21:00:52 2013 -0400
    15.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Fri Sep 06 21:13:15 2013 -0400
    15.3 @@ -44,8 +44,8 @@
    15.4  #include "SDL_syswm.h"
    15.5  }
    15.6  
    15.7 -#include "../../core/winrt/SDL_winrtapp.h"
    15.8 -#include "../../core/winrt/SDL_winrtxaml_cpp.h"
    15.9 +#include "../../core/winrt/SDL_winrtapp_direct3d.h"
   15.10 +#include "../../core/winrt/SDL_winrtapp_xaml.h"
   15.11  #include "SDL_winrtvideo_cpp.h"
   15.12  #include "SDL_winrtevents_c.h"
   15.13  #include "SDL_winrtmouse_c.h"
   15.14 @@ -61,7 +61,7 @@
   15.15  
   15.16  
   15.17  /* Window functions */
   15.18 -static int WINRT_CreateWindow(_THIS, SDL_Window * window);
   15.19 +static int WINRT_CreateWindow(_THIS, SDL_Window * window);
   15.20  static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
   15.21  static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
   15.22  
   15.23 @@ -131,76 +131,76 @@
   15.24      }
   15.25      WINRT_InitMouse(_this);
   15.26      WINRT_InitTouch(_this);
   15.27 -
   15.28 +
   15.29      return 0;
   15.30  }
   15.31  
   15.32 -SDL_DisplayMode
   15.33 -WINRT_CalcDisplayModeUsingNativeWindow()
   15.34 -{
   15.35 -    using namespace Windows::Graphics::Display;
   15.36 -
   15.37 -    // Create an empty, zeroed-out display mode:
   15.38 -    SDL_DisplayMode mode;
   15.39 -    SDL_zero(mode);
   15.40 -
   15.41 -    // Go no further if a native window cannot be accessed.  This can happen,
   15.42 -    // for example, if this function is called from certain threads, such as
   15.43 -    // the SDL/XAML thread.
   15.44 -    if (!CoreWindow::GetForCurrentThread()) {
   15.45 -        return mode;
   15.46 -    }
   15.47 -
   15.48 -    // Fill in most fields:
   15.49 -    mode.format = SDL_PIXELFORMAT_RGB888;
   15.50 -    mode.refresh_rate = 0;  // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
   15.51 -    mode.driverdata = (void *) DisplayProperties::CurrentOrientation;
   15.52 -
   15.53 -    // Calculate the display size given the window size, taking into account
   15.54 -    // the current display's DPI:
   15.55 -    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
   15.56 -    const float dipsPerInch = 96.0f;
   15.57 -    mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
   15.58 -    mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
   15.59 -
   15.60 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   15.61 -    // On Windows Phone, the native window's size is always in portrait,
   15.62 -    // regardless of the device's orientation.  This is in contrast to
   15.63 -    // Windows 8/RT, which will resize the native window as the device's
   15.64 -    // orientation changes.  In order to compensate for this behavior,
   15.65 -    // on Windows Phone, the mode's width and height will be swapped when
   15.66 -    // the device is in a landscape (non-portrait) mode.
   15.67 -    switch (DisplayProperties::CurrentOrientation) {
   15.68 -        case DisplayOrientations::Landscape:
   15.69 -        case DisplayOrientations::LandscapeFlipped:
   15.70 -        {
   15.71 -            const int tmp = mode.h;
   15.72 -            mode.h = mode.w;
   15.73 -            mode.w = tmp;
   15.74 -            break;
   15.75 -        }
   15.76 -
   15.77 -        default:
   15.78 -            break;
   15.79 -    }
   15.80 -
   15.81 -    // Attach the mode to te
   15.82 -#endif
   15.83 -
   15.84 -    return mode;
   15.85 -}
   15.86 +SDL_DisplayMode
   15.87 +WINRT_CalcDisplayModeUsingNativeWindow()
   15.88 +{
   15.89 +    using namespace Windows::Graphics::Display;
   15.90 +
   15.91 +    // Create an empty, zeroed-out display mode:
   15.92 +    SDL_DisplayMode mode;
   15.93 +    SDL_zero(mode);
   15.94 +
   15.95 +    // Go no further if a native window cannot be accessed.  This can happen,
   15.96 +    // for example, if this function is called from certain threads, such as
   15.97 +    // the SDL/XAML thread.
   15.98 +    if (!CoreWindow::GetForCurrentThread()) {
   15.99 +        return mode;
  15.100 +    }
  15.101 +
  15.102 +    // Fill in most fields:
  15.103 +    mode.format = SDL_PIXELFORMAT_RGB888;
  15.104 +    mode.refresh_rate = 0;  // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
  15.105 +    mode.driverdata = (void *) DisplayProperties::CurrentOrientation;
  15.106 +
  15.107 +    // Calculate the display size given the window size, taking into account
  15.108 +    // the current display's DPI:
  15.109 +    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
  15.110 +    const float dipsPerInch = 96.0f;
  15.111 +    mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
  15.112 +    mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
  15.113 +
  15.114 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  15.115 +    // On Windows Phone, the native window's size is always in portrait,
  15.116 +    // regardless of the device's orientation.  This is in contrast to
  15.117 +    // Windows 8/RT, which will resize the native window as the device's
  15.118 +    // orientation changes.  In order to compensate for this behavior,
  15.119 +    // on Windows Phone, the mode's width and height will be swapped when
  15.120 +    // the device is in a landscape (non-portrait) mode.
  15.121 +    switch (DisplayProperties::CurrentOrientation) {
  15.122 +        case DisplayOrientations::Landscape:
  15.123 +        case DisplayOrientations::LandscapeFlipped:
  15.124 +        {
  15.125 +            const int tmp = mode.h;
  15.126 +            mode.h = mode.w;
  15.127 +            mode.w = tmp;
  15.128 +            break;
  15.129 +        }
  15.130 +
  15.131 +        default:
  15.132 +            break;
  15.133 +    }
  15.134 +
  15.135 +    // Attach the mode to te
  15.136 +#endif
  15.137 +
  15.138 +    return mode;
  15.139 +}
  15.140  
  15.141  int
  15.142  WINRT_InitModes(_THIS)
  15.143  {
  15.144      // Retrieve the display mode:
  15.145 -    SDL_DisplayMode mode = WINRT_CalcDisplayModeUsingNativeWindow();
  15.146 -    if (mode.w == 0 || mode.h == 0) {
  15.147 -        return SDL_SetError("Unable to calculate the WinRT window/display's size");
  15.148 -    }
  15.149 -
  15.150 -    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
  15.151 -        return -1;
  15.152 +    SDL_DisplayMode mode = WINRT_CalcDisplayModeUsingNativeWindow();
  15.153 +    if (mode.w == 0 || mode.h == 0) {
  15.154 +        return SDL_SetError("Unable to calculate the WinRT window/display's size");
  15.155 +    }
  15.156 +
  15.157 +    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
  15.158 +        return -1;
  15.159      }
  15.160  
  15.161      SDL_AddDisplayMode(&_this->displays[0], &mode);
  15.162 @@ -219,64 +219,64 @@
  15.163      WINRT_QuitMouse(_this);
  15.164  }
  15.165  
  15.166 -int
  15.167 -WINRT_CreateWindow(_THIS, SDL_Window * window)
  15.168 -{
  15.169 -    // Make sure that only one window gets created, at least until multimonitor
  15.170 -    // support is added.
  15.171 -    if (WINRT_GlobalSDLWindow != NULL) {
  15.172 -        SDL_SetError("WinRT only supports one window");
  15.173 -        return -1;
  15.174 -    }
  15.175 -
  15.176 -    SDL_WindowData *data = new SDL_WindowData;
  15.177 -    if (!data) {
  15.178 -        SDL_OutOfMemory();
  15.179 -        return -1;
  15.180 -    }
  15.181 -    window->driverdata = data;
  15.182 -    data->sdlWindow = window;
  15.183 -
  15.184 -    /* To note, when XAML support is enabled, access to the CoreWindow will not
  15.185 -       be possible, at least not via the SDL/XAML thread.  Attempts to access it
  15.186 -       from there will throw exceptions.  As such, the SDL_WindowData's
  15.187 -       'coreWindow' field will only be set (to a non-null value) if XAML isn't
  15.188 -       enabled.
  15.189 -    */
  15.190 -    if (!WINRT_XAMLWasEnabled) {
  15.191 -        data->coreWindow = CoreWindow::GetForCurrentThread();
  15.192 -    }
  15.193 -
  15.194 -    /* Make sure the window is considered to be positioned at {0,0},
  15.195 -       and is considered fullscreen, shown, and the like.
  15.196 -    */
  15.197 -    window->x = 0;
  15.198 -    window->y = 0;
  15.199 -    window->flags =
  15.200 -        SDL_WINDOW_FULLSCREEN |
  15.201 -        SDL_WINDOW_SHOWN |
  15.202 -        SDL_WINDOW_BORDERLESS |
  15.203 -        SDL_WINDOW_MAXIMIZED |
  15.204 -        SDL_WINDOW_INPUT_GRABBED;
  15.205 -
  15.206 -    /* WinRT does not, as of this writing, appear to support app-adjustable
  15.207 -       window sizes.  Set the window size to whatever the native WinRT
  15.208 -       CoreWindow is set at.
  15.209 -
  15.210 -       TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces.
  15.211 -    */
  15.212 -    window->w = _this->displays[0].current_mode.w;
  15.213 -    window->h = _this->displays[0].current_mode.h;
  15.214 - 
  15.215 -    /* Make sure the WinRT app's IFramworkView can post events on
  15.216 -       behalf of SDL:
  15.217 -    */
  15.218 -    WINRT_GlobalSDLWindow = window;
  15.219 -
  15.220 -    /* All done! */
  15.221 -    return 0;
  15.222 -}
  15.223 -
  15.224 +int
  15.225 +WINRT_CreateWindow(_THIS, SDL_Window * window)
  15.226 +{
  15.227 +    // Make sure that only one window gets created, at least until multimonitor
  15.228 +    // support is added.
  15.229 +    if (WINRT_GlobalSDLWindow != NULL) {
  15.230 +        SDL_SetError("WinRT only supports one window");
  15.231 +        return -1;
  15.232 +    }
  15.233 +
  15.234 +    SDL_WindowData *data = new SDL_WindowData;
  15.235 +    if (!data) {
  15.236 +        SDL_OutOfMemory();
  15.237 +        return -1;
  15.238 +    }
  15.239 +    window->driverdata = data;
  15.240 +    data->sdlWindow = window;
  15.241 +
  15.242 +    /* To note, when XAML support is enabled, access to the CoreWindow will not
  15.243 +       be possible, at least not via the SDL/XAML thread.  Attempts to access it
  15.244 +       from there will throw exceptions.  As such, the SDL_WindowData's
  15.245 +       'coreWindow' field will only be set (to a non-null value) if XAML isn't
  15.246 +       enabled.
  15.247 +    */
  15.248 +    if (!WINRT_XAMLWasEnabled) {
  15.249 +        data->coreWindow = CoreWindow::GetForCurrentThread();
  15.250 +    }
  15.251 +
  15.252 +    /* Make sure the window is considered to be positioned at {0,0},
  15.253 +       and is considered fullscreen, shown, and the like.
  15.254 +    */
  15.255 +    window->x = 0;
  15.256 +    window->y = 0;
  15.257 +    window->flags =
  15.258 +        SDL_WINDOW_FULLSCREEN |
  15.259 +        SDL_WINDOW_SHOWN |
  15.260 +        SDL_WINDOW_BORDERLESS |
  15.261 +        SDL_WINDOW_MAXIMIZED |
  15.262 +        SDL_WINDOW_INPUT_GRABBED;
  15.263 +
  15.264 +    /* WinRT does not, as of this writing, appear to support app-adjustable
  15.265 +       window sizes.  Set the window size to whatever the native WinRT
  15.266 +       CoreWindow is set at.
  15.267 +
  15.268 +       TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces.
  15.269 +    */
  15.270 +    window->w = _this->displays[0].current_mode.w;
  15.271 +    window->h = _this->displays[0].current_mode.h;
  15.272 + 
  15.273 +    /* Make sure the WinRT app's IFramworkView can post events on
  15.274 +       behalf of SDL:
  15.275 +    */
  15.276 +    WINRT_GlobalSDLWindow = window;
  15.277 +
  15.278 +    /* All done! */
  15.279 +    return 0;
  15.280 +}
  15.281 +
  15.282  void
  15.283  WINRT_DestroyWindow(_THIS, SDL_Window * window)
  15.284  {
  15.285 @@ -293,21 +293,21 @@
  15.286      }
  15.287  }
  15.288  
  15.289 -SDL_bool
  15.290 -WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
  15.291 -{
  15.292 -    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
  15.293 -
  15.294 -    if (info->version.major <= SDL_MAJOR_VERSION) {
  15.295 -        info->subsystem = SDL_SYSWM_WINRT;
  15.296 -        info->info.winrt.window = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
  15.297 -        return SDL_TRUE;
  15.298 -    } else {
  15.299 -        SDL_SetError("Application not compiled with SDL %d.%d\n",
  15.300 -                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
  15.301 -        return SDL_FALSE;
  15.302 -    }
  15.303 -    return SDL_FALSE;
  15.304 +SDL_bool
  15.305 +WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
  15.306 +{
  15.307 +    SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
  15.308 +
  15.309 +    if (info->version.major <= SDL_MAJOR_VERSION) {
  15.310 +        info->subsystem = SDL_SYSWM_WINRT;
  15.311 +        info->info.winrt.window = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
  15.312 +        return SDL_TRUE;
  15.313 +    } else {
  15.314 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
  15.315 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
  15.316 +        return SDL_FALSE;
  15.317 +    }
  15.318 +    return SDL_FALSE;
  15.319  }
  15.320  
  15.321  #endif /* SDL_VIDEO_DRIVER_WINRT */