Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: added code to help debug events related to window-sizing and d…
Browse files Browse the repository at this point in the history
…evice-orientation
  • Loading branch information
DavidLudwig committed May 26, 2013
1 parent 2d643bd commit cc3517c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
58 changes: 56 additions & 2 deletions src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -152,6 +155,9 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
CoreApplication::Resuming +=
ref new EventHandler<Platform::Object^>(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.
Expand All @@ -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<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/video/windowsrt/SDL_WinRTApp.h
Expand Up @@ -27,6 +27,7 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo

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);
Expand Down

0 comments on commit cc3517c

Please sign in to comment.