WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
authorDavid Ludwig <dludwig@pobox.com>
Sun, 28 Oct 2012 23:01:31 -0400
changeset 8333 49973bfb8d23
parent 8332 ea83d191cc17
child 8334 09b0670fece4
WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor position data is now attached to mouse button events
src/video/windowsrt/SDL_WinRTApp.cpp
src/video/windowsrt/SDL_WinRTApp.h
src/video/windowsrt/SDL_winrtvideo.cpp
src/video/windowsrt/SDL_winrtvideo.h
src/video/windowsrt/SDLmain_WinRT_common.h
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Oct 28 20:47:33 2012 -0400
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Oct 28 23:01:31 2012 -0400
@@ -7,6 +7,7 @@
 #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 @@
 
 SDL_WinRTApp::SDL_WinRTApp() :
 	m_windowClosed(false),
-	m_windowVisible(true)
+	m_windowVisible(true),
+    m_sdlWindowData(NULL)
 {
 }
 
@@ -134,19 +136,26 @@
 
 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 @@
     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
--- a/src/video/windowsrt/SDL_WinRTApp.h	Sun Oct 28 20:47:33 2012 -0400
+++ b/src/video/windowsrt/SDL_WinRTApp.h	Sun Oct 28 23:01:31 2012 -0400
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "SDLmain_WinRT_common.h"
+#include "SDL_winrtvideo.h"
 #include "CubeRenderer.h"
 #include <vector>
 
@@ -22,6 +23,7 @@
     // SDL-specific methods
     SDL_DisplayMode GetMainDisplayMode();
     void PumpEvents();
+    void SetSDLWindowData(const SDL_WindowData* windowData);
 
 protected:
 	// Event Handlers.
@@ -40,6 +42,7 @@
 	CubeRenderer^ m_renderer;
 	bool m_windowClosed;
 	bool m_windowVisible;
+    const SDL_WindowData* m_sdlWindowData;
 };
 
 ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
--- a/src/video/windowsrt/SDL_winrtvideo.cpp	Sun Oct 28 20:47:33 2012 -0400
+++ b/src/video/windowsrt/SDL_winrtvideo.cpp	Sun Oct 28 23:01:31 2012 -0400
@@ -41,6 +41,11 @@
 #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_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 @@
     /* 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 @@
 {
 }
 
+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: */
--- a/src/video/windowsrt/SDL_winrtvideo.h	Sun Oct 28 20:47:33 2012 -0400
+++ b/src/video/windowsrt/SDL_winrtvideo.h	Sun Oct 28 23:01:31 2012 -0400
@@ -33,6 +33,11 @@
 }
 #endif
 
+struct SDL_WindowData
+{
+    SDL_Window *sdlWindow;
+};
+
 #endif /* _SDL_winrtvideo_h */
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/windowsrt/SDLmain_WinRT_common.h	Sun Oct 28 20:47:33 2012 -0400
+++ b/src/video/windowsrt/SDLmain_WinRT_common.h	Sun Oct 28 23:01:31 2012 -0400
@@ -10,3 +10,6 @@
 extern "C" {
 #include "../SDL_sysvideo.h"
 }
+
+#include "SDL_winrtvideo.h"
+