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).
This commit is contained in:
David Ludwig 2014-03-15 14:54:23 -04:00
parent 4f443b34f0
commit 1126e9c461
6 changed files with 56 additions and 18 deletions

View file

@ -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

View file

@ -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);