Fixed broken rotation detection routines on WinRT Rotation detection and handling should now work across all, publicly-released, WinRT-based platforms (Windows 8.0, Windows 8.1, and Windows Phone 8.0).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
diff --git a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj
index 09348b3..1a450ea 100644
--- a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj
+++ b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj
@@ -320,7 +320,12 @@
<ClCompile Include="..\..\src\power\SDL_power.c" />
<ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
<ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
- <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp" />
+ <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp">
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+ </ClCompile>
<ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
<ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
diff --git a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
index d236e6f..9649279 100644
--- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
+++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
@@ -100,7 +100,14 @@
<ClCompile Include="..\..\src\power\SDL_power.c" />
<ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
<ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.c" />
- <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp" />
+ <ClCompile Include="..\..\src\render\direct3d11\SDL_render_winrt.cpp">
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
+ <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
+ </ClCompile>
<ClCompile Include="..\..\src\render\opengles2\SDL_render_gles2.c" />
<ClCompile Include="..\..\src\render\opengles2\SDL_shaders_gles2.c" />
<ClCompile Include="..\..\src\render\SDL_d3dmath.c" />
diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp
index 19d4afc..2fd20a8 100644
--- a/src/core/winrt/SDL_winrtapp_direct3d.cpp
+++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp
@@ -163,7 +163,11 @@ static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *n
// for details. Microsoft's "Display orientation sample" also gives an
// outline of how Windows treats device rotation
// (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
+#if NTDDI_VERSION > NTDDI_WIN8
+ DisplayInformation::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
+#else
DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
+#endif
}
static void
@@ -283,20 +287,13 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
CoreApplication::Exiting +=
ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnExiting);
-
- DisplayProperties::OrientationChanged +=
- ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
-
- // Register the hint, SDL_HINT_ORIENTATIONS, with SDL. This needs to be
- // done before the hint's callback is registered (as of Feb 22, 2013),
- // otherwise the hint callback won't get registered.
- //
- // 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.
- //SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown"); // DavidL: this is no longer needed (for SDL_AddHintCallback)
- SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
}
+#if NTDDI_VERSION > NTDDI_WIN8
+void SDL_WinRTApp::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
+#else
void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
+#endif
{
#if LOG_ORIENTATION_EVENTS==1
CoreWindow^ window = CoreWindow::GetForCurrentThread();
@@ -379,6 +376,18 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window)
ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
#endif
+#if NTDDI_VERSION > NTDDI_WIN8
+ DisplayInformation::GetForCurrentView()->OrientationChanged +=
+ ref new TypedEventHandler<Windows::Graphics::Display::DisplayInformation^, Object^>(this, &SDL_WinRTApp::OnOrientationChanged);
+#else
+ DisplayProperties::OrientationChanged +=
+ ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
+#endif
+
+ // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.
+ // 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.
+ SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
+
#if WINAPI_FAMILY == WINAPI_FAMILY_APP // for Windows 8/8.1/RT apps... (and not Phone apps)
// Make sure we know when a user has opened the app's settings pane.
// This is needed in order to display a privacy policy, which needs
diff --git a/src/core/winrt/SDL_winrtapp_direct3d.h b/src/core/winrt/SDL_winrtapp_direct3d.h
index 929fd87..6dc9a6c 100644
--- a/src/core/winrt/SDL_winrtapp_direct3d.h
+++ b/src/core/winrt/SDL_winrtapp_direct3d.h
@@ -47,7 +47,11 @@ protected:
Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
#endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#if NTDDI_VERSION > NTDDI_WIN8
+ void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
+#else
void OnOrientationChanged(Platform::Object^ sender);
+#endif
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
void OnLogicalDpiChanged(Platform::Object^ sender);
void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
diff --git a/src/render/direct3d11/SDL_render_winrt.cpp b/src/render/direct3d11/SDL_render_winrt.cpp
index 1b21b2f..9ed67fd 100644
--- a/src/render/direct3d11/SDL_render_winrt.cpp
+++ b/src/render/direct3d11/SDL_render_winrt.cpp
@@ -34,7 +34,6 @@ extern "C" {
#include <windows.ui.xaml.media.dxinterop.h>
#endif
-using namespace ABI;
using namespace Windows::UI::Core;
using namespace Windows::Graphics::Display;
@@ -80,8 +79,14 @@ D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
extern "C" DXGI_MODE_ROTATION
D3D11_GetCurrentRotation()
{
-#if 0 /* FIXME: This doesn't compile on Visual Studio 2013 */
- switch (DisplayProperties::CurrentOrientation) {
+#if NTDDI_VERSION > NTDDI_WIN8
+ const DisplayOrientations currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
+#else
+ const DisplayOrientations currentOrientation = DisplayProperties::CurrentOrientation;
+#endif
+
+ switch (currentOrientation) {
+
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
/* Windows Phone rotations */
case DisplayOrientations::Landscape:
@@ -104,7 +109,7 @@ D3D11_GetCurrentRotation()
return DXGI_MODE_ROTATION_ROTATE90;
#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
}
-#endif
+
return DXGI_MODE_ROTATION_IDENTITY;
}
diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp
index a8518da..4a5301f 100644
--- a/src/video/winrt/SDL_winrtvideo.cpp
+++ b/src/video/winrt/SDL_winrtvideo.cpp
@@ -163,7 +163,11 @@ WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode)
// Calculate the display size given the window size, taking into account
// the current display's DPI:
- const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
+#if NTDDI_VERSION > NTDDI_WIN8
+ const float currentDPI = DisplayInformation::GetForCurrentView()->LogicalDpi;
+#else
+ const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
+#endif
const float dipsPerInch = 96.0f;
const int w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
const int h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
@@ -185,7 +189,11 @@ WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode)
mode->w = w;
mode->h = h;
mode->driverdata = driverdata;
+#if NTDDI_VERSION > NTDDI_WIN8
+ driverdata->currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
+#else
driverdata->currentOrientation = DisplayProperties::CurrentOrientation;
+#endif
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
// On Windows Phone, the native window's size is always in portrait,