From fa5f07249974406b7501076d6ad38355615ff833 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sun, 28 Oct 2012 23:01:31 -0400 Subject: [PATCH] WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events --- src/video/windowsrt/SDL_WinRTApp.cpp | 26 ++++++++++--- src/video/windowsrt/SDL_WinRTApp.h | 3 ++ src/video/windowsrt/SDL_winrtvideo.cpp | 44 ++++++++++++++++++++++ src/video/windowsrt/SDL_winrtvideo.h | 5 +++ src/video/windowsrt/SDLmain_WinRT_common.h | 3 ++ 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/video/windowsrt/SDL_WinRTApp.cpp b/src/video/windowsrt/SDL_WinRTApp.cpp index 789bfd0f3..e53e0fca5 100644 --- a/src/video/windowsrt/SDL_WinRTApp.cpp +++ b/src/video/windowsrt/SDL_WinRTApp.cpp @@ -7,6 +7,7 @@ extern "C" { #include "../SDL_sysvideo.h" #include "../../events/SDL_mouse_c.h" #include "SDL_events.h" +#include "SDL_log.h" } // HACK, DLudwig: The C-style main() will get loaded via the app's @@ -36,7 +37,8 @@ using namespace concurrency; SDL_WinRTApp::SDL_WinRTApp() : m_windowClosed(false), - m_windowVisible(true) + m_windowVisible(true), + m_sdlWindowData(NULL) { } @@ -134,19 +136,26 @@ void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args) { - // TODO, WinRT: consider attaching the SDL_Window to the mouse down button event - SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); + if (m_sdlWindowData) + { + SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT); + } } void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args) { - // TODO, WinRT: consider attaching the SDL_Window to the mouse up button event - SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); + if (m_sdlWindowData) + { + SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT); + } } void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args) { - // Insert your code here. + if (m_sdlWindowData) + { + SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)args->CurrentPoint->Position.X, (int)args->CurrentPoint->Position.Y); + } } void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) @@ -189,6 +198,11 @@ SDL_DisplayMode SDL_WinRTApp::GetMainDisplayMode() return mode; } +void SDL_WinRTApp::SetSDLWindowData(const SDL_WindowData* windowData) +{ + m_sdlWindowData = windowData; +} + IFrameworkView^ Direct3DApplicationSource::CreateView() { // TODO, WinRT: see if this function (CreateView) can ever get called diff --git a/src/video/windowsrt/SDL_WinRTApp.h b/src/video/windowsrt/SDL_WinRTApp.h index d10f0e856..f7fc29b40 100644 --- a/src/video/windowsrt/SDL_WinRTApp.h +++ b/src/video/windowsrt/SDL_WinRTApp.h @@ -1,6 +1,7 @@ #pragma once #include "SDLmain_WinRT_common.h" +#include "SDL_winrtvideo.h" #include "CubeRenderer.h" #include @@ -22,6 +23,7 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo // SDL-specific methods SDL_DisplayMode GetMainDisplayMode(); void PumpEvents(); + void SetSDLWindowData(const SDL_WindowData* windowData); protected: // Event Handlers. @@ -40,6 +42,7 @@ ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFramewo CubeRenderer^ m_renderer; bool m_windowClosed; bool m_windowVisible; + const SDL_WindowData* m_sdlWindowData; }; ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource diff --git a/src/video/windowsrt/SDL_winrtvideo.cpp b/src/video/windowsrt/SDL_winrtvideo.cpp index 92aacadb6..e69826383 100644 --- a/src/video/windowsrt/SDL_winrtvideo.cpp +++ b/src/video/windowsrt/SDL_winrtvideo.cpp @@ -41,6 +41,11 @@ extern "C" { #include "SDL_winrtevents_c.h" #include "SDL_winrtframebuffer_c.h" +/* On Windows, windows.h defines CreateWindow */ +#ifdef CreateWindow +#undef CreateWindow +#endif + extern SDL_WinRTApp ^ SDL_WinRTGlobalApp; #define WINRTVID_DRIVER_NAME "dummy" @@ -50,6 +55,10 @@ static int WINRT_VideoInit(_THIS); static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); static void WINRT_VideoQuit(_THIS); +/* Window functions */ +static int WINRT_CreateWindow(_THIS, SDL_Window * window); +static void WINRT_DestroyWindow(_THIS, SDL_Window * window); + /* WinRT driver bootstrap functions */ static int @@ -82,6 +91,8 @@ WINRT_CreateDevice(int devindex) /* Set the function pointers */ device->VideoInit = WINRT_VideoInit; device->VideoQuit = WINRT_VideoQuit; + device->CreateWindow = WINRT_CreateWindow; + device->DestroyWindow = WINRT_DestroyWindow; device->SetDisplayMode = WINRT_SetDisplayMode; device->PumpEvents = WINRT_PumpEvents; device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer; @@ -123,6 +134,39 @@ WINRT_VideoQuit(_THIS) { } +int +WINRT_CreateWindow(_THIS, SDL_Window * window) +{ + // TODO, WinRT: modify WINRT_Createwindow to ensure that, for now, only one window gets created + // (until multimonitor support is added to the WinRT port). + + SDL_WindowData *data; + data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); + if (!data) { + SDL_OutOfMemory(); + return -1; + } + SDL_zerop(data); + data->sdlWindow = window; + + /* Adjust the window data to match the screen */ + window->x = 0; + window->y = 0; + window->w = _this->displays->desktop_mode.w; + window->h = _this->displays->desktop_mode.h; + + SDL_WinRTGlobalApp->SetSDLWindowData(data); + + return 0; +} + +void +WINRT_DestroyWindow(_THIS, SDL_Window * window) +{ + SDL_WinRTGlobalApp->SetSDLWindowData(NULL); +} + + #endif /* SDL_VIDEO_DRIVER_WINRT */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/windowsrt/SDL_winrtvideo.h b/src/video/windowsrt/SDL_winrtvideo.h index add24c234..fe8063f53 100644 --- a/src/video/windowsrt/SDL_winrtvideo.h +++ b/src/video/windowsrt/SDL_winrtvideo.h @@ -33,6 +33,11 @@ extern "C" { } #endif +struct SDL_WindowData +{ + SDL_Window *sdlWindow; +}; + #endif /* _SDL_winrtvideo_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/windowsrt/SDLmain_WinRT_common.h b/src/video/windowsrt/SDLmain_WinRT_common.h index 5e50662ab..4867b7a94 100644 --- a/src/video/windowsrt/SDLmain_WinRT_common.h +++ b/src/video/windowsrt/SDLmain_WinRT_common.h @@ -10,3 +10,6 @@ extern "C" { #include "../SDL_sysvideo.h" } + +#include "SDL_winrtvideo.h" +