Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor positi…

…on data is now attached to mouse button events
  • Loading branch information
DavidLudwig committed Oct 29, 2012
1 parent 6d9be94 commit fa5f07249974406b7501076d6ad38355615ff833
@@ -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
@@ -1,6 +1,7 @@
#pragma once

#include "SDLmain_WinRT_common.h"
#include "SDL_winrtvideo.h"
#include "CubeRenderer.h"
#include <vector>

@@ -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
@@ -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: */
@@ -33,6 +33,11 @@ extern "C" {
}
#endif

struct SDL_WindowData
{
SDL_Window *sdlWindow;
};

#endif /* _SDL_winrtvideo_h */

/* vi: set ts=4 sw=4 expandtab: */
@@ -10,3 +10,6 @@
extern "C" {
#include "../SDL_sysvideo.h"
}

#include "SDL_winrtvideo.h"

0 comments on commit fa5f072

Please sign in to comment.