src/core/winrt/SDL_winrtapp_direct3d.cpp
author David Ludwig <dludwig@pobox.com>
Sun, 22 Sep 2013 12:26:53 -0400
changeset 8531 d481485a1b85
parent 8522 3ae9dc9c439f
child 8542 97dcef41e4a7
permissions -rw-r--r--
WinRT: unified the two, public, app-init functions

This function, SDL_WinRTRunApp, can be used to help launch either XAML or non-XAML/Direct3D-only based apps.
     1 
     2 /* Standard C++11 includes */
     3 #include <functional>
     4 #include <string>
     5 #include <sstream>
     6 using namespace std;
     7 
     8 
     9 /* Windows includes */
    10 #include "ppltasks.h"
    11 using namespace concurrency;
    12 using namespace Windows::ApplicationModel;
    13 using namespace Windows::ApplicationModel::Core;
    14 using namespace Windows::ApplicationModel::Activation;
    15 using namespace Windows::Devices::Input;
    16 using namespace Windows::Graphics::Display;
    17 using namespace Windows::Foundation;
    18 using namespace Windows::System;
    19 using namespace Windows::UI::Core;
    20 using namespace Windows::UI::Input;
    21 
    22 
    23 /* SDL includes */
    24 extern "C" {
    25 #include "SDL_assert.h"
    26 #include "SDL_events.h"
    27 #include "SDL_hints.h"
    28 #include "SDL_log.h"
    29 #include "SDL_main.h"
    30 #include "SDL_stdinc.h"
    31 #include "SDL_render.h"
    32 #include "../../video/SDL_sysvideo.h"
    33 //#include "../../SDL_hints_c.h"
    34 #include "../../events/SDL_mouse_c.h"
    35 #include "../../events/SDL_windowevents_c.h"
    36 #include "../../render/SDL_sysrender.h"
    37 }
    38 
    39 #include "../../video/winrt/SDL_winrtevents_c.h"
    40 #include "../../video/winrt/SDL_winrtvideo_cpp.h"
    41 #include "SDL_winrtapp_common.h"
    42 #include "SDL_winrtapp_direct3d.h"
    43 
    44 
    45 // Compile-time debugging options:
    46 // To enable, uncomment; to disable, comment them out.
    47 //#define LOG_POINTER_EVENTS 1
    48 //#define LOG_WINDOW_EVENTS 1
    49 //#define LOG_ORIENTATION_EVENTS 1
    50 
    51 
    52 // HACK, DLudwig: record a reference to the global, WinRT 'app'/view.
    53 // SDL/WinRT will use this throughout its code.
    54 //
    55 // TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
    56 // non-global, such as something created inside
    57 // SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
    58 // SDL_CreateWindow().
    59 SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
    60 
    61 ref class SDLApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
    62 {
    63 public:
    64     virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
    65 };
    66 
    67 IFrameworkView^ SDLApplicationSource::CreateView()
    68 {
    69     // TODO, WinRT: see if this function (CreateView) can ever get called
    70     // more than once.  For now, just prevent it from ever assigning
    71     // SDL_WinRTGlobalApp more than once.
    72     SDL_assert(!SDL_WinRTGlobalApp);
    73     SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
    74     if (!SDL_WinRTGlobalApp)
    75     {
    76         SDL_WinRTGlobalApp = app;
    77     }
    78     return app;
    79 }
    80 
    81 int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **))
    82 {
    83     WINRT_SDLAppEntryPoint = mainFunction;
    84     auto direct3DApplicationSource = ref new SDLApplicationSource();
    85     CoreApplication::Run(direct3DApplicationSource);
    86     return 0;
    87 }
    88 
    89 static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
    90 {
    91     SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
    92 
    93     // Start with no orientation flags, then add each in as they're parsed
    94     // from newValue.
    95     unsigned int orientationFlags = 0;
    96     if (newValue) {
    97         std::istringstream tokenizer(newValue);
    98         while (!tokenizer.eof()) {
    99             std::string orientationName;
   100             std::getline(tokenizer, orientationName, ' ');
   101             if (orientationName == "LandscapeLeft") {
   102                 orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
   103             } else if (orientationName == "LandscapeRight") {
   104                 orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
   105             } else if (orientationName == "Portrait") {
   106                 orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
   107             } else if (orientationName == "PortraitUpsideDown") {
   108                 orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
   109             }
   110         }
   111     }
   112 
   113     // If no valid orientation flags were specified, use a reasonable set of defaults:
   114     if (!orientationFlags) {
   115         // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
   116         orientationFlags = (unsigned int) ( \
   117             DisplayOrientations::Landscape |
   118             DisplayOrientations::LandscapeFlipped |
   119             DisplayOrientations::Portrait |
   120             DisplayOrientations::PortraitFlipped);
   121     }
   122 
   123     // Set the orientation/rotation preferences.  Please note that this does
   124     // not constitute a 100%-certain lock of a given set of possible
   125     // orientations.  According to Microsoft's documentation on WinRT [1]
   126     // when a device is not capable of being rotated, Windows may ignore
   127     // the orientation preferences, and stick to what the device is capable of
   128     // displaying.
   129     //
   130     // [1] Documentation on the 'InitialRotationPreference' setting for a
   131     // Windows app's manifest file describes how some orientation/rotation
   132     // preferences may be ignored.  See
   133     // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
   134     // for details.  Microsoft's "Display orientation sample" also gives an
   135     // outline of how Windows treats device rotation
   136     // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
   137     DisplayProperties::AutoRotationPreferences = (DisplayOrientations) orientationFlags;
   138 }
   139 
   140 static void
   141 WINRT_ProcessWindowSizeChange()
   142 {
   143     // Make the new window size be the one true fullscreen mode.
   144     // This change was initially done, in part, to allow the Direct3D 11.1
   145     // renderer to receive window-resize events as a device rotates.
   146     // Before, rotating a device from landscape, to portrait, and then
   147     // back to landscape would cause the Direct3D 11.1 swap buffer to
   148     // not get resized appropriately.  SDL would, on the rotation from
   149     // landscape to portrait, re-resize the SDL window to it's initial
   150     // size (landscape).  On the subsequent rotation, SDL would drop the
   151     // window-resize event as it appeared the SDL window didn't change
   152     // size, and the Direct3D 11.1 renderer wouldn't resize its swap
   153     // chain.
   154     SDL_DisplayMode resizedDisplayMode = WINRT_CalcDisplayModeUsingNativeWindow();
   155     if (resizedDisplayMode.w == 0 || resizedDisplayMode.h == 0) {
   156         return;
   157     }
   158 
   159     SDL_DisplayMode oldDisplayMode;
   160     SDL_zero(oldDisplayMode);
   161     if (WINRT_GlobalSDLVideoDevice) {
   162         oldDisplayMode = WINRT_GlobalSDLVideoDevice->displays[0].desktop_mode;
   163         WINRT_GlobalSDLVideoDevice->displays[0].current_mode = resizedDisplayMode;
   164         WINRT_GlobalSDLVideoDevice->displays[0].desktop_mode = resizedDisplayMode;
   165         WINRT_GlobalSDLVideoDevice->displays[0].display_modes[0] = resizedDisplayMode;
   166     }
   167 
   168     if (WINRT_GlobalSDLWindow) {
   169         // Send a window-resize event to the rest of SDL, and to apps:
   170         SDL_SendWindowEvent(
   171             WINRT_GlobalSDLWindow,
   172             SDL_WINDOWEVENT_RESIZED,
   173             resizedDisplayMode.w,
   174             resizedDisplayMode.h);
   175 
   176 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   177         // HACK: On Windows Phone, make sure that orientation changes from
   178         // Landscape to LandscapeFlipped, Portrait to PortraitFlipped,
   179         // or vice-versa on either of those two, lead to the Direct3D renderer
   180         // getting updated.
   181         const DisplayOrientations oldOrientation = (DisplayOrientations) (unsigned int) oldDisplayMode.driverdata;
   182         const DisplayOrientations newOrientation = (DisplayOrientations) (unsigned int) resizedDisplayMode.driverdata;
   183 
   184         if ((oldOrientation == DisplayOrientations::Landscape && newOrientation == DisplayOrientations::LandscapeFlipped) ||
   185             (oldOrientation == DisplayOrientations::LandscapeFlipped && newOrientation == DisplayOrientations::Landscape) ||
   186             (oldOrientation == DisplayOrientations::Portrait && newOrientation == DisplayOrientations::PortraitFlipped) ||
   187             (oldOrientation == DisplayOrientations::PortraitFlipped && newOrientation == DisplayOrientations::Portrait))
   188         {
   189             // One of the reasons this event is getting sent out is because SDL
   190             // will ignore requests to send out SDL_WINDOWEVENT_RESIZED events
   191             // if and when the event size doesn't change (and the Direct3D 11.1
   192             // renderer doesn't get the memo).
   193             //
   194             // Make sure that the display/window size really didn't change.  If
   195             // it did, then a SDL_WINDOWEVENT_SIZE_CHANGED event got sent, and
   196             // the Direct3D 11.1 renderer picked it up, presumably.
   197             if (oldDisplayMode.w == resizedDisplayMode.w &&
   198                 oldDisplayMode.h == resizedDisplayMode.h)
   199             {
   200                 SDL_SendWindowEvent(
   201                     WINRT_GlobalSDLWindow,
   202                     SDL_WINDOWEVENT_SIZE_CHANGED,
   203                     resizedDisplayMode.w,
   204                     resizedDisplayMode.h);
   205             }
   206         }
   207 #endif
   208     }
   209 }
   210 
   211 SDL_WinRTApp::SDL_WinRTApp() :
   212     m_windowClosed(false),
   213     m_windowVisible(true)
   214 {
   215 }
   216 
   217 void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
   218 {
   219     applicationView->Activated +=
   220         ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
   221 
   222     CoreApplication::Suspending +=
   223         ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
   224 
   225     CoreApplication::Resuming +=
   226         ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
   227 
   228     DisplayProperties::OrientationChanged +=
   229         ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
   230 
   231     // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.  This needs to be
   232     // done before the hint's callback is registered (as of Feb 22, 2013),
   233     // otherwise the hint callback won't get registered.
   234     //
   235     // 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.
   236     //SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");   // DavidL: this is no longer needed (for SDL_AddHintCallback)
   237     SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
   238 }
   239 
   240 void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
   241 {
   242 #if LOG_ORIENTATION_EVENTS==1
   243     CoreWindow^ window = CoreWindow::GetForCurrentThread();
   244     if (window) {
   245         SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Size={%f,%f}\n",
   246             __FUNCTION__,
   247             (int)DisplayProperties::CurrentOrientation,
   248             (int)DisplayProperties::NativeOrientation,
   249             (int)DisplayProperties::AutoRotationPreferences,
   250             window->Bounds.Width,
   251             window->Bounds.Height);
   252     } else {
   253         SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
   254             __FUNCTION__,
   255             (int)DisplayProperties::CurrentOrientation,
   256             (int)DisplayProperties::NativeOrientation,
   257             (int)DisplayProperties::AutoRotationPreferences);
   258     }
   259 #endif
   260 
   261 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   262     // On Windows Phone, treat an orientation change as a change in window size.
   263     // The native window's size doesn't seem to change, however SDL will simulate
   264     // a window size change.
   265     WINRT_ProcessWindowSizeChange();
   266 #endif
   267 }
   268 
   269 void SDL_WinRTApp::SetWindow(CoreWindow^ window)
   270 {
   271 #if LOG_WINDOW_EVENTS==1
   272     SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window Size={%f,%f}\n",
   273         __FUNCTION__,
   274         (int)DisplayProperties::CurrentOrientation,
   275         (int)DisplayProperties::NativeOrientation,
   276         (int)DisplayProperties::AutoRotationPreferences,
   277         window->Bounds.Width,
   278         window->Bounds.Height);
   279 #endif
   280 
   281     window->SizeChanged += 
   282         ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
   283 
   284     window->VisibilityChanged +=
   285         ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
   286 
   287     window->Closed += 
   288         ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
   289 
   290 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   291     window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
   292 #endif
   293 
   294     window->PointerPressed +=
   295         ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
   296 
   297     window->PointerMoved +=
   298         ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
   299 
   300     window->PointerReleased +=
   301         ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
   302 
   303     window->PointerWheelChanged +=
   304         ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
   305 
   306 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
   307     // Retrieves relative-only mouse movements:
   308     Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
   309         ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
   310 #endif
   311 
   312     window->KeyDown +=
   313         ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
   314 
   315     window->KeyUp +=
   316         ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
   317 }
   318 
   319 void SDL_WinRTApp::Load(Platform::String^ entryPoint)
   320 {
   321 }
   322 
   323 void SDL_WinRTApp::Run()
   324 {
   325     SDL_SetMainReady();
   326     if (WINRT_SDLAppEntryPoint)
   327     {
   328         // TODO, WinRT: pass the C-style main() a reasonably realistic
   329         // representation of command line arguments.
   330         int argc = 0;
   331         char **argv = NULL;
   332         WINRT_SDLAppEntryPoint(argc, argv);
   333     }
   334 }
   335 
   336 void SDL_WinRTApp::PumpEvents()
   337 {
   338     if (!m_windowClosed)
   339     {
   340         if (m_windowVisible)
   341         {
   342             CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
   343         }
   344         else
   345         {
   346             CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
   347         }
   348     }
   349 }
   350 
   351 void SDL_WinRTApp::Uninitialize()
   352 {
   353 }
   354 
   355 void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
   356 {
   357 #if LOG_WINDOW_EVENTS==1
   358     SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
   359         __FUNCTION__,
   360         args->Size.Width, args->Size.Height,
   361         (int)DisplayProperties::CurrentOrientation,
   362         (int)DisplayProperties::NativeOrientation,
   363         (int)DisplayProperties::AutoRotationPreferences,
   364         (WINRT_GlobalSDLWindow ? "yes" : "no"));
   365 #endif
   366 
   367     WINRT_ProcessWindowSizeChange();
   368 }
   369 
   370 void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
   371 {
   372 #if LOG_WINDOW_EVENTS==1
   373     SDL_Log("%s, visible?=%s, WINRT_GlobalSDLWindow?=%s\n",
   374         __FUNCTION__,
   375         (args->Visible ? "yes" : "no"),
   376         (WINRT_GlobalSDLWindow ? "yes" : "no"));
   377 #endif
   378 
   379     m_windowVisible = args->Visible;
   380     if (WINRT_GlobalSDLWindow) {
   381         SDL_bool wasSDLWindowSurfaceValid = WINRT_GlobalSDLWindow->surface_valid;
   382 
   383         if (args->Visible) {
   384             SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
   385         } else {
   386             SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   387         }
   388 
   389         // HACK: Prevent SDL's window-hide handling code, which currently
   390         // triggers a fake window resize (possibly erronously), from
   391         // marking the SDL window's surface as invalid.
   392         //
   393         // A better solution to this probably involves figuring out if the
   394         // fake window resize can be prevented.
   395         WINRT_GlobalSDLWindow->surface_valid = wasSDLWindowSurfaceValid;
   396     }
   397 }
   398 
   399 void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
   400 {
   401 #if LOG_WINDOW_EVENTS==1
   402     SDL_Log("%s\n", __FUNCTION__);
   403 #endif
   404     m_windowClosed = true;
   405 }
   406 
   407 void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
   408 {
   409     CoreWindow::GetForCurrentThread()->Activate();
   410 }
   411 
   412 static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event * event)
   413 {
   414     if (event->type == SDL_WINDOWEVENT)
   415     {
   416         switch (event->window.event)
   417         {
   418             case SDL_WINDOWEVENT_MINIMIZED:
   419             case SDL_WINDOWEVENT_RESTORED:
   420                 // Return 0 to indicate that the event should be removed from the
   421                 // event queue:
   422                 return 0;
   423             default:
   424                 break;
   425         }
   426     }
   427 
   428     // Return 1 to indicate that the event should stay in the event queue:
   429     return 1;
   430 }
   431 
   432 void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
   433 {
   434     // Save app state asynchronously after requesting a deferral. Holding a deferral
   435     // indicates that the application is busy performing suspending operations. Be
   436     // aware that a deferral may not be held indefinitely. After about five seconds,
   437     // the app will be forced to exit.
   438     SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
   439     create_task([this, deferral]()
   440     {
   441         // Send a window-minimized event immediately to observers.
   442         // CoreDispatcher::ProcessEvents, which is the backbone on which
   443         // SDL_WinRTApp::PumpEvents is built, will not return to its caller
   444         // once it sends out a suspend event.  Any events posted to SDL's
   445         // event queue won't get received until the WinRT app is resumed.
   446         // SDL_AddEventWatch() may be used to receive app-suspend events on
   447         // WinRT.
   448         //
   449         // In order to prevent app-suspend events from being received twice:
   450         // first via a callback passed to SDL_AddEventWatch, and second via
   451         // SDL's event queue, the event will be sent to SDL, then immediately
   452         // removed from the queue.
   453         if (WINRT_GlobalSDLWindow)
   454         {
   455             SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);   // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
   456             SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
   457         }
   458         deferral->Complete();
   459     });
   460 }
   461 
   462 void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
   463 {
   464     // Restore any data or state that was unloaded on suspend. By default, data
   465     // and state are persisted when resuming from suspend. Note that this event
   466     // does not occur if the app was previously terminated.
   467     if (WINRT_GlobalSDLWindow)
   468     {
   469         SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_RESTORED, 0, 0);    // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
   470 
   471         // Remove the app-resume event from the queue, as is done with the
   472         // app-suspend event.
   473         //
   474         // TODO, WinRT: consider posting this event to the queue even though
   475         // its counterpart, the app-suspend event, effectively has to be
   476         // processed immediately.
   477         SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
   478     }
   479 }
   480 
   481 static void
   482 WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
   483 {
   484     Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
   485     SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
   486         header,
   487         pt->Position.X, pt->Position.Y,
   488         transformedPoint.X, transformedPoint.Y,
   489         pt->Properties->MouseWheelDelta,
   490         pt->FrameId,
   491         pt->PointerId,
   492         WINRT_GetSDLButtonForPointerPoint(pt));
   493 }
   494 
   495 void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
   496 {
   497 #if LOG_POINTER_EVENTS
   498     WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   499 #endif
   500 
   501     WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   502 }
   503 
   504 void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
   505 {
   506 #if LOG_POINTER_EVENTS
   507     WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   508 #endif
   509 
   510     WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   511 }
   512 
   513 void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
   514 {
   515 #if LOG_POINTER_EVENTS
   516     WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   517 #endif
   518 
   519     WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   520 }
   521 
   522 void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
   523 {
   524 #if LOG_POINTER_EVENTS
   525     WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
   526 #endif
   527 
   528     WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
   529 }
   530 
   531 void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
   532 {
   533     WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
   534 }
   535 
   536 void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   537 {
   538     WINRT_ProcessKeyDownEvent(args);
   539 }
   540 
   541 void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
   542 {
   543     WINRT_ProcessKeyUpEvent(args);
   544 }