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 833349973bfb8d23
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
     1.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Oct 28 20:47:33 2012 -0400
     1.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Oct 28 23:01:31 2012 -0400
     1.3 @@ -7,6 +7,7 @@
     1.4  #include "../SDL_sysvideo.h"
     1.5  #include "../../events/SDL_mouse_c.h"
     1.6  #include "SDL_events.h"
     1.7 +#include "SDL_log.h"
     1.8  }
     1.9  
    1.10  // HACK, DLudwig: The C-style main() will get loaded via the app's
    1.11 @@ -36,7 +37,8 @@
    1.12  
    1.13  SDL_WinRTApp::SDL_WinRTApp() :
    1.14  	m_windowClosed(false),
    1.15 -	m_windowVisible(true)
    1.16 +	m_windowVisible(true),
    1.17 +    m_sdlWindowData(NULL)
    1.18  {
    1.19  }
    1.20  
    1.21 @@ -134,19 +136,26 @@
    1.22  
    1.23  void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
    1.24  {
    1.25 -    // TODO, WinRT: consider attaching the SDL_Window to the mouse down button event
    1.26 -	SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.27 +    if (m_sdlWindowData)
    1.28 +    {
    1.29 +    	SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.30 +    }
    1.31  }
    1.32  
    1.33  void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
    1.34  {
    1.35 -    // TODO, WinRT: consider attaching the SDL_Window to the mouse up button event
    1.36 -	SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.37 +    if (m_sdlWindowData)
    1.38 +    {
    1.39 +    	SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.40 +    }
    1.41  }
    1.42  
    1.43  void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
    1.44  {
    1.45 -	// Insert your code here.
    1.46 +    if (m_sdlWindowData)
    1.47 +    {
    1.48 +        SDL_SendMouseMotion(m_sdlWindowData->sdlWindow, 0, (int)args->CurrentPoint->Position.X, (int)args->CurrentPoint->Position.Y);
    1.49 +    }
    1.50  }
    1.51  
    1.52  void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
    1.53 @@ -189,6 +198,11 @@
    1.54      return mode;
    1.55  }
    1.56  
    1.57 +void SDL_WinRTApp::SetSDLWindowData(const SDL_WindowData* windowData)
    1.58 +{
    1.59 +    m_sdlWindowData = windowData;
    1.60 +}
    1.61 +
    1.62  IFrameworkView^ Direct3DApplicationSource::CreateView()
    1.63  {
    1.64      // TODO, WinRT: see if this function (CreateView) can ever get called
     2.1 --- a/src/video/windowsrt/SDL_WinRTApp.h	Sun Oct 28 20:47:33 2012 -0400
     2.2 +++ b/src/video/windowsrt/SDL_WinRTApp.h	Sun Oct 28 23:01:31 2012 -0400
     2.3 @@ -1,6 +1,7 @@
     2.4  #pragma once
     2.5  
     2.6  #include "SDLmain_WinRT_common.h"
     2.7 +#include "SDL_winrtvideo.h"
     2.8  #include "CubeRenderer.h"
     2.9  #include <vector>
    2.10  
    2.11 @@ -22,6 +23,7 @@
    2.12      // SDL-specific methods
    2.13      SDL_DisplayMode GetMainDisplayMode();
    2.14      void PumpEvents();
    2.15 +    void SetSDLWindowData(const SDL_WindowData* windowData);
    2.16  
    2.17  protected:
    2.18  	// Event Handlers.
    2.19 @@ -40,6 +42,7 @@
    2.20  	CubeRenderer^ m_renderer;
    2.21  	bool m_windowClosed;
    2.22  	bool m_windowVisible;
    2.23 +    const SDL_WindowData* m_sdlWindowData;
    2.24  };
    2.25  
    2.26  ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
     3.1 --- a/src/video/windowsrt/SDL_winrtvideo.cpp	Sun Oct 28 20:47:33 2012 -0400
     3.2 +++ b/src/video/windowsrt/SDL_winrtvideo.cpp	Sun Oct 28 23:01:31 2012 -0400
     3.3 @@ -41,6 +41,11 @@
     3.4  #include "SDL_winrtevents_c.h"
     3.5  #include "SDL_winrtframebuffer_c.h"
     3.6  
     3.7 +/* On Windows, windows.h defines CreateWindow */
     3.8 +#ifdef CreateWindow
     3.9 +#undef CreateWindow
    3.10 +#endif
    3.11 +
    3.12  extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
    3.13  
    3.14  #define WINRTVID_DRIVER_NAME "dummy"
    3.15 @@ -50,6 +55,10 @@
    3.16  static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
    3.17  static void WINRT_VideoQuit(_THIS);
    3.18  
    3.19 +/* Window functions */
    3.20 +static int WINRT_CreateWindow(_THIS, SDL_Window * window);
    3.21 +static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
    3.22 +
    3.23  /* WinRT driver bootstrap functions */
    3.24  
    3.25  static int
    3.26 @@ -82,6 +91,8 @@
    3.27      /* Set the function pointers */
    3.28      device->VideoInit = WINRT_VideoInit;
    3.29      device->VideoQuit = WINRT_VideoQuit;
    3.30 +    device->CreateWindow = WINRT_CreateWindow;
    3.31 +    device->DestroyWindow = WINRT_DestroyWindow;
    3.32      device->SetDisplayMode = WINRT_SetDisplayMode;
    3.33      device->PumpEvents = WINRT_PumpEvents;
    3.34      device->CreateWindowFramebuffer = SDL_WINRT_CreateWindowFramebuffer;
    3.35 @@ -123,6 +134,39 @@
    3.36  {
    3.37  }
    3.38  
    3.39 +int
    3.40 +WINRT_CreateWindow(_THIS, SDL_Window * window)
    3.41 +{
    3.42 +    // TODO, WinRT: modify WINRT_Createwindow to ensure that, for now, only one window gets created
    3.43 +    // (until multimonitor support is added to the WinRT port).
    3.44 +
    3.45 +    SDL_WindowData *data;
    3.46 +    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    3.47 +    if (!data) {
    3.48 +        SDL_OutOfMemory();
    3.49 +        return -1;
    3.50 +    }
    3.51 +    SDL_zerop(data);
    3.52 +    data->sdlWindow = window;
    3.53 +
    3.54 +    /* Adjust the window data to match the screen */
    3.55 +    window->x = 0;
    3.56 +    window->y = 0;
    3.57 +    window->w = _this->displays->desktop_mode.w;
    3.58 +    window->h = _this->displays->desktop_mode.h;
    3.59 +
    3.60 +    SDL_WinRTGlobalApp->SetSDLWindowData(data);
    3.61 +
    3.62 +    return 0;
    3.63 +}
    3.64 +
    3.65 +void
    3.66 +WINRT_DestroyWindow(_THIS, SDL_Window * window)
    3.67 +{
    3.68 +    SDL_WinRTGlobalApp->SetSDLWindowData(NULL);
    3.69 +}
    3.70 +
    3.71 +
    3.72  #endif /* SDL_VIDEO_DRIVER_WINRT */
    3.73  
    3.74  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/windowsrt/SDL_winrtvideo.h	Sun Oct 28 20:47:33 2012 -0400
     4.2 +++ b/src/video/windowsrt/SDL_winrtvideo.h	Sun Oct 28 23:01:31 2012 -0400
     4.3 @@ -33,6 +33,11 @@
     4.4  }
     4.5  #endif
     4.6  
     4.7 +struct SDL_WindowData
     4.8 +{
     4.9 +    SDL_Window *sdlWindow;
    4.10 +};
    4.11 +
    4.12  #endif /* _SDL_winrtvideo_h */
    4.13  
    4.14  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/video/windowsrt/SDLmain_WinRT_common.h	Sun Oct 28 20:47:33 2012 -0400
     5.2 +++ b/src/video/windowsrt/SDLmain_WinRT_common.h	Sun Oct 28 23:01:31 2012 -0400
     5.3 @@ -10,3 +10,6 @@
     5.4  extern "C" {
     5.5  #include "../SDL_sysvideo.h"
     5.6  }
     5.7 +
     5.8 +#include "SDL_winrtvideo.h"
     5.9 +