From 2b39466c251a10c41212f7afc8fefd491a77de5f Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sun, 26 May 2013 19:40:12 -0400 Subject: [PATCH] WinRT: added code to help debug events related to window-sizing and device-orientation --- src/video/windowsrt/SDL_WinRTApp.cpp | 58 +++++++++++++++++++++++++++- src/video/windowsrt/SDL_WinRTApp.h | 1 + 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/video/windowsrt/SDL_WinRTApp.cpp b/src/video/windowsrt/SDL_WinRTApp.cpp index fdc3582ed..a807bda7f 100644 --- a/src/video/windowsrt/SDL_WinRTApp.cpp +++ b/src/video/windowsrt/SDL_WinRTApp.cpp @@ -39,6 +39,9 @@ using namespace Windows::UI::Input; // Compile-time debugging options: // To enable, uncomment; to disable, comment them out. //#define LOG_POINTER_EVENTS 1 +//#define LOG_WINDOW_EVENTS 1 +//#define LOG_ORIENTATION_EVENTS 1 + // HACK, DLudwig: The C-style main() will get loaded via the app's // WinRT-styled main(), which is part of SDLmain_for_WinRT.cpp. @@ -152,6 +155,9 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView) CoreApplication::Resuming += ref new EventHandler(this, &SDL_WinRTApp::OnResuming); + 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. @@ -161,8 +167,40 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView) SDL_RegisterHintChangedCb(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference); } +void SDL_WinRTApp::OnOrientationChanged(Object^ sender) +{ +#if LOG_ORIENTATION_EVENTS==1 + CoreWindow^ window = CoreWindow::GetForCurrentThread(); + if (window) { + SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Size={%f,%f}\n", + __FUNCTION__, + (int)DisplayProperties::CurrentOrientation, + (int)DisplayProperties::NativeOrientation, + (int)DisplayProperties::AutoRotationPreferences, + window->Bounds.Width, + window->Bounds.Height); + } else { + SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n", + __FUNCTION__, + (int)DisplayProperties::CurrentOrientation, + (int)DisplayProperties::NativeOrientation, + (int)DisplayProperties::AutoRotationPreferences); + } +#endif +} + void SDL_WinRTApp::SetWindow(CoreWindow^ window) { +#if LOG_WINDOW_EVENTS==1 + SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window Size={%f,%f}\n", + __FUNCTION__, + (int)DisplayProperties::CurrentOrientation, + (int)DisplayProperties::NativeOrientation, + (int)DisplayProperties::AutoRotationPreferences, + window->Bounds.Width, + window->Bounds.Height); +#endif + window->SizeChanged += ref new TypedEventHandler(this, &SDL_WinRTApp::OnWindowSizeChanged); @@ -238,8 +276,14 @@ void SDL_WinRTApp::Uninitialize() void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) { -#if 0 - SDL_Log("%s, {%f,%f}\n", __FUNCTION__, args->Size.Width, args->Size.Height); +#if LOG_WINDOW_EVENTS==1 + SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, m_sdlWindowData?=%s\n", + __FUNCTION__, + args->Size.Width, args->Size.Height, + (int)DisplayProperties::CurrentOrientation, + (int)DisplayProperties::NativeOrientation, + (int)DisplayProperties::AutoRotationPreferences, + (m_sdlWindowData ? "yes" : "no")); #endif if (m_sdlWindowData) { @@ -300,6 +344,13 @@ void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEven void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) { +#if LOG_WINDOW_EVENTS==1 + SDL_Log("%s, visible?=%s, m_sdlWindowData?=%s\n", + __FUNCTION__, + (args->Visible ? "yes" : "no"), + (m_sdlWindowData ? "yes" : "no")); +#endif + m_windowVisible = args->Visible; if (m_sdlWindowData) { SDL_bool wasSDLWindowSurfaceValid = m_sdlWindowData->sdlWindow->surface_valid; @@ -322,6 +373,9 @@ void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEven void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) { +#if LOG_WINDOW_EVENTS==1 + SDL_Log("%s\n", __FUNCTION__); +#endif m_windowClosed = true; } diff --git a/src/video/windowsrt/SDL_WinRTApp.h b/src/video/windowsrt/SDL_WinRTApp.h index 8712d51e0..cd0c379fc 100644 --- a/src/video/windowsrt/SDL_WinRTApp.h +++ b/src/video/windowsrt/SDL_WinRTApp.h @@ -27,6 +27,7 @@ internal: protected: // Event Handlers. + void OnOrientationChanged(Platform::Object^ sender); 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);