src/video/winrt/SDL_winrtmouse.cpp
changeset 8512 5b345a756965
parent 8511 326b43e1276b
child 8513 0bcf3970deba
     1.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 16:14:27 2013 -0400
     1.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 16:51:07 2013 -0400
     1.3 @@ -42,6 +42,7 @@
     1.4  }
     1.5  
     1.6  #include "../../core/winrt/SDL_winrtapp.h"
     1.7 +#include "SDL_winrtvideo_cpp.h"
     1.8  #include "SDL_winrtmouse.h"
     1.9  
    1.10  
    1.11 @@ -163,13 +164,54 @@
    1.12  Windows::Foundation::Point
    1.13  WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition)
    1.14  {
    1.15 +    using namespace Windows::Graphics::Display;
    1.16 +
    1.17      if (!window) {
    1.18          return rawPosition;
    1.19      }
    1.20 -    CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
    1.21 +
    1.22 +    SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
    1.23 +    if (windowData->coreWindow == nullptr) {
    1.24 +        // For some reason, the window isn't associated with a CoreWindow.
    1.25 +        // This might end up being the case as XAML support is extended.
    1.26 +        // For now, if there's no CoreWindow attached to the SDL_Window,
    1.27 +        // don't do any transforms.
    1.28 +        return rawPosition;
    1.29 +    }
    1.30 +
    1.31 +    // The CoreWindow can only be accessed on certain thread(s).
    1.32 +    SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
    1.33 +
    1.34 +    CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
    1.35      Windows::Foundation::Point outputPosition;
    1.36 +
    1.37 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    1.38      outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
    1.39      outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
    1.40 +#else
    1.41 +    switch (DisplayProperties::CurrentOrientation)
    1.42 +    {
    1.43 +        case DisplayOrientations::Portrait:
    1.44 +            outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
    1.45 +            outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
    1.46 +            break;
    1.47 +        case DisplayOrientations::PortraitFlipped:
    1.48 +            outputPosition.X = (float32)window->w - rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
    1.49 +            outputPosition.Y = (float32)window->h - rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
    1.50 +            break;
    1.51 +        case DisplayOrientations::Landscape:
    1.52 +            outputPosition.X = rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
    1.53 +            outputPosition.Y = (float32)window->h - rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
    1.54 +            break;
    1.55 +        case DisplayOrientations::LandscapeFlipped:
    1.56 +            outputPosition.X = (float32)window->w - rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
    1.57 +            outputPosition.Y = rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
    1.58 +            break;
    1.59 +        default:
    1.60 +            break;
    1.61 +    }
    1.62 +#endif
    1.63 +
    1.64      return outputPosition;
    1.65  }
    1.66