WinRT: corrected SDL_MOUSE* coordinates in non-Portrait modes
authorDavid Ludwig <dludwig@pobox.com>
Wed, 28 Aug 2013 16:51:07 -0400
changeset 85125b345a756965
parent 8511 326b43e1276b
child 8513 0bcf3970deba
WinRT: corrected SDL_MOUSE* coordinates in non-Portrait modes

Thanks to Pierre-Yves Gueniffey for proper pointer geometry transform code!
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
src/video/winrt/SDL_winrtmouse.cpp
src/video/winrt/SDL_winrtvideo.cpp
src/video/winrt/SDL_winrtvideo_cpp.h
     1.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Wed Aug 28 16:14:27 2013 -0400
     1.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Wed Aug 28 16:51:07 2013 -0400
     1.3 @@ -247,6 +247,7 @@
     1.4      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
     1.5      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
     1.6      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse.h" />
     1.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
     2.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Wed Aug 28 16:14:27 2013 -0400
     2.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Wed Aug 28 16:51:07 2013 -0400
     2.3 @@ -333,6 +333,9 @@
     2.4      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse.h">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClInclude>
     2.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClInclude>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
     3.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Wed Aug 28 16:14:27 2013 -0400
     3.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Wed Aug 28 16:51:07 2013 -0400
     3.3 @@ -294,6 +294,7 @@
     3.4      <ClInclude Include="..\..\src\video\SDL_sysvideo.h" />
     3.5      <ClInclude Include="..\..\src\video\winrt\SDL_winrtevents_c.h" />
     3.6      <ClInclude Include="..\..\src\video\winrt\SDL_winrtmouse.h" />
     3.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h" />
     3.8    </ItemGroup>
     3.9    <ItemGroup>
    3.10      <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
     4.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Wed Aug 28 16:14:27 2013 -0400
     4.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Wed Aug 28 16:51:07 2013 -0400
     4.3 @@ -599,6 +599,9 @@
     4.4      <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp.h">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClInclude>
     4.7 +    <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h">
     4.8 +      <Filter>Source Files</Filter>
     4.9 +    </ClInclude>
    4.10    </ItemGroup>
    4.11    <ItemGroup>
    4.12      <Filter Include="Header Files">
     5.1 --- a/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 16:14:27 2013 -0400
     5.2 +++ b/src/video/winrt/SDL_winrtmouse.cpp	Wed Aug 28 16:51:07 2013 -0400
     5.3 @@ -42,6 +42,7 @@
     5.4  }
     5.5  
     5.6  #include "../../core/winrt/SDL_winrtapp.h"
     5.7 +#include "SDL_winrtvideo_cpp.h"
     5.8  #include "SDL_winrtmouse.h"
     5.9  
    5.10  
    5.11 @@ -163,13 +164,54 @@
    5.12  Windows::Foundation::Point
    5.13  WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition)
    5.14  {
    5.15 +    using namespace Windows::Graphics::Display;
    5.16 +
    5.17      if (!window) {
    5.18          return rawPosition;
    5.19      }
    5.20 -    CoreWindow ^ nativeWindow = CoreWindow::GetForCurrentThread();
    5.21 +
    5.22 +    SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
    5.23 +    if (windowData->coreWindow == nullptr) {
    5.24 +        // For some reason, the window isn't associated with a CoreWindow.
    5.25 +        // This might end up being the case as XAML support is extended.
    5.26 +        // For now, if there's no CoreWindow attached to the SDL_Window,
    5.27 +        // don't do any transforms.
    5.28 +        return rawPosition;
    5.29 +    }
    5.30 +
    5.31 +    // The CoreWindow can only be accessed on certain thread(s).
    5.32 +    SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
    5.33 +
    5.34 +    CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
    5.35      Windows::Foundation::Point outputPosition;
    5.36 +
    5.37 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    5.38      outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
    5.39      outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
    5.40 +#else
    5.41 +    switch (DisplayProperties::CurrentOrientation)
    5.42 +    {
    5.43 +        case DisplayOrientations::Portrait:
    5.44 +            outputPosition.X = rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
    5.45 +            outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
    5.46 +            break;
    5.47 +        case DisplayOrientations::PortraitFlipped:
    5.48 +            outputPosition.X = (float32)window->w - rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
    5.49 +            outputPosition.Y = (float32)window->h - rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
    5.50 +            break;
    5.51 +        case DisplayOrientations::Landscape:
    5.52 +            outputPosition.X = rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
    5.53 +            outputPosition.Y = (float32)window->h - rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
    5.54 +            break;
    5.55 +        case DisplayOrientations::LandscapeFlipped:
    5.56 +            outputPosition.X = (float32)window->w - rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
    5.57 +            outputPosition.Y = rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
    5.58 +            break;
    5.59 +        default:
    5.60 +            break;
    5.61 +    }
    5.62 +#endif
    5.63 +
    5.64      return outputPosition;
    5.65  }
    5.66  
     6.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Wed Aug 28 16:14:27 2013 -0400
     6.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Wed Aug 28 16:51:07 2013 -0400
     6.3 @@ -45,6 +45,7 @@
     6.4  }
     6.5  
     6.6  #include "../../core/winrt/SDL_winrtapp.h"
     6.7 +#include "SDL_winrtvideo_cpp.h"
     6.8  #include "SDL_winrtevents_c.h"
     6.9  #include "SDL_winrtmouse.h"
    6.10  #include "SDL_main.h"
    6.11 @@ -67,14 +68,6 @@
    6.12  static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
    6.13  
    6.14  
    6.15 -/* Internal window data */
    6.16 -struct SDL_WindowData
    6.17 -{
    6.18 -    SDL_Window *sdlWindow;
    6.19 -    Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
    6.20 -};
    6.21 -
    6.22 -
    6.23  /* The global, WinRT, SDL Window.
    6.24     For now, SDL/WinRT only supports one window (due to platform limitations of
    6.25     WinRT.
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/winrt/SDL_winrtvideo_cpp.h	Wed Aug 28 16:51:07 2013 -0400
     7.3 @@ -0,0 +1,41 @@
     7.4 +/*
     7.5 +  Simple DirectMedia Layer
     7.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     7.7 +
     7.8 +  This software is provided 'as-is', without any express or implied
     7.9 +  warranty.  In no event will the authors be held liable for any damages
    7.10 +  arising from the use of this software.
    7.11 +
    7.12 +  Permission is granted to anyone to use this software for any purpose,
    7.13 +  including commercial applications, and to alter it and redistribute it
    7.14 +  freely, subject to the following restrictions:
    7.15 +
    7.16 +  1. The origin of this software must not be misrepresented; you must not
    7.17 +     claim that you wrote the original software. If you use this software
    7.18 +     in a product, an acknowledgment in the product documentation would be
    7.19 +     appreciated but is not required.
    7.20 +  2. Altered source versions must be plainly marked as such, and must not be
    7.21 +     misrepresented as being the original software.
    7.22 +  3. This notice may not be removed or altered from any source distribution.
    7.23 +*/
    7.24 +
    7.25 +/* Windows includes: */
    7.26 +#include <windows.h>
    7.27 +#ifdef __cplusplus_winrt
    7.28 +#include <agile.h>
    7.29 +#endif
    7.30 +
    7.31 +/* SDL includes: */
    7.32 +#include "SDL_events.h"
    7.33 +
    7.34 +
    7.35 +#ifdef __cplusplus_winrt
    7.36 +
    7.37 +/* Internal window data */
    7.38 +struct SDL_WindowData
    7.39 +{
    7.40 +    SDL_Window *sdlWindow;
    7.41 +    Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
    7.42 +};
    7.43 +
    7.44 +#endif // ifdef __cplusplus_winrt