Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: SDL_GetWindowSize and SDL_MOUSEMOTION works, and cursor positi…
Browse files Browse the repository at this point in the history
…on data is now attached to mouse button events
  • Loading branch information
DavidLudwig committed Oct 29, 2012
1 parent 6d9be94 commit fa5f072
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -36,7 +37,8 @@ using namespace concurrency;

SDL_WinRTApp::SDL_WinRTApp() :
m_windowClosed(false),
m_windowVisible(true)
m_windowVisible(true),
m_sdlWindowData(NULL)
{
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions 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 <vector>

Expand All @@ -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.
Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions src/video/windowsrt/SDL_winrtvideo.cpp
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: */
5 changes: 5 additions & 0 deletions src/video/windowsrt/SDL_winrtvideo.h
Expand Up @@ -33,6 +33,11 @@ extern "C" {
}
#endif

struct SDL_WindowData
{
SDL_Window *sdlWindow;
};

#endif /* _SDL_winrtvideo_h */

/* vi: set ts=4 sw=4 expandtab: */
3 changes: 3 additions & 0 deletions src/video/windowsrt/SDLmain_WinRT_common.h
Expand Up @@ -10,3 +10,6 @@
extern "C" {
#include "../SDL_sysvideo.h"
}

#include "SDL_winrtvideo.h"

0 comments on commit fa5f072

Please sign in to comment.