|
|
@@ -44,8 +44,8 @@ extern "C" {
|
|
|
#include "SDL_syswm.h"
|
|
|
}
|
|
|
|
|
|
-#include "../../core/winrt/SDL_winrtapp.h"
|
|
|
-#include "../../core/winrt/SDL_winrtxaml_cpp.h"
|
|
|
+#include "../../core/winrt/SDL_winrtapp_direct3d.h"
|
|
|
+#include "../../core/winrt/SDL_winrtapp_xaml.h"
|
|
|
#include "SDL_winrtvideo_cpp.h"
|
|
|
#include "SDL_winrtevents_c.h"
|
|
|
#include "SDL_winrtmouse_c.h"
|
|
|
@@ -61,7 +61,7 @@ static void WINRT_VideoQuit(_THIS);
|
|
|
|
|
|
|
|
|
/* Window functions */
|
|
|
-static int WINRT_CreateWindow(_THIS, SDL_Window * window);
|
|
|
+static int WINRT_CreateWindow(_THIS, SDL_Window * window);
|
|
|
static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
|
|
|
static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
|
|
|
|
|
|
@@ -131,76 +131,76 @@ WINRT_VideoInit(_THIS)
|
|
|
}
|
|
|
WINRT_InitMouse(_this);
|
|
|
WINRT_InitTouch(_this);
|
|
|
-
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-SDL_DisplayMode
|
|
|
-WINRT_CalcDisplayModeUsingNativeWindow()
|
|
|
-{
|
|
|
- using namespace Windows::Graphics::Display;
|
|
|
-
|
|
|
- // Create an empty, zeroed-out display mode:
|
|
|
- SDL_DisplayMode mode;
|
|
|
- SDL_zero(mode);
|
|
|
-
|
|
|
- // Go no further if a native window cannot be accessed. This can happen,
|
|
|
- // for example, if this function is called from certain threads, such as
|
|
|
- // the SDL/XAML thread.
|
|
|
- if (!CoreWindow::GetForCurrentThread()) {
|
|
|
- return mode;
|
|
|
- }
|
|
|
-
|
|
|
- // Fill in most fields:
|
|
|
- mode.format = SDL_PIXELFORMAT_RGB888;
|
|
|
- mode.refresh_rate = 0; // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
|
|
|
- mode.driverdata = (void *) DisplayProperties::CurrentOrientation;
|
|
|
-
|
|
|
- // Calculate the display size given the window size, taking into account
|
|
|
- // the current display's DPI:
|
|
|
- const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
|
|
|
- const float dipsPerInch = 96.0f;
|
|
|
- mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
|
|
|
- mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
|
|
|
-
|
|
|
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
|
|
- // On Windows Phone, the native window's size is always in portrait,
|
|
|
- // regardless of the device's orientation. This is in contrast to
|
|
|
- // Windows 8/RT, which will resize the native window as the device's
|
|
|
- // orientation changes. In order to compensate for this behavior,
|
|
|
- // on Windows Phone, the mode's width and height will be swapped when
|
|
|
- // the device is in a landscape (non-portrait) mode.
|
|
|
- switch (DisplayProperties::CurrentOrientation) {
|
|
|
- case DisplayOrientations::Landscape:
|
|
|
- case DisplayOrientations::LandscapeFlipped:
|
|
|
- {
|
|
|
- const int tmp = mode.h;
|
|
|
- mode.h = mode.w;
|
|
|
- mode.w = tmp;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- // Attach the mode to te
|
|
|
-#endif
|
|
|
-
|
|
|
- return mode;
|
|
|
-}
|
|
|
+SDL_DisplayMode
|
|
|
+WINRT_CalcDisplayModeUsingNativeWindow()
|
|
|
+{
|
|
|
+ using namespace Windows::Graphics::Display;
|
|
|
+
|
|
|
+ // Create an empty, zeroed-out display mode:
|
|
|
+ SDL_DisplayMode mode;
|
|
|
+ SDL_zero(mode);
|
|
|
+
|
|
|
+ // Go no further if a native window cannot be accessed. This can happen,
|
|
|
+ // for example, if this function is called from certain threads, such as
|
|
|
+ // the SDL/XAML thread.
|
|
|
+ if (!CoreWindow::GetForCurrentThread()) {
|
|
|
+ return mode;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Fill in most fields:
|
|
|
+ mode.format = SDL_PIXELFORMAT_RGB888;
|
|
|
+ mode.refresh_rate = 0; // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
|
|
|
+ mode.driverdata = (void *) DisplayProperties::CurrentOrientation;
|
|
|
+
|
|
|
+ // Calculate the display size given the window size, taking into account
|
|
|
+ // the current display's DPI:
|
|
|
+ const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
|
|
|
+ const float dipsPerInch = 96.0f;
|
|
|
+ mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
|
|
|
+ mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
|
|
|
+
|
|
|
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
|
|
+ // On Windows Phone, the native window's size is always in portrait,
|
|
|
+ // regardless of the device's orientation. This is in contrast to
|
|
|
+ // Windows 8/RT, which will resize the native window as the device's
|
|
|
+ // orientation changes. In order to compensate for this behavior,
|
|
|
+ // on Windows Phone, the mode's width and height will be swapped when
|
|
|
+ // the device is in a landscape (non-portrait) mode.
|
|
|
+ switch (DisplayProperties::CurrentOrientation) {
|
|
|
+ case DisplayOrientations::Landscape:
|
|
|
+ case DisplayOrientations::LandscapeFlipped:
|
|
|
+ {
|
|
|
+ const int tmp = mode.h;
|
|
|
+ mode.h = mode.w;
|
|
|
+ mode.w = tmp;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Attach the mode to te
|
|
|
+#endif
|
|
|
+
|
|
|
+ return mode;
|
|
|
+}
|
|
|
|
|
|
int
|
|
|
WINRT_InitModes(_THIS)
|
|
|
{
|
|
|
// Retrieve the display mode:
|
|
|
- SDL_DisplayMode mode = WINRT_CalcDisplayModeUsingNativeWindow();
|
|
|
- if (mode.w == 0 || mode.h == 0) {
|
|
|
- return SDL_SetError("Unable to calculate the WinRT window/display's size");
|
|
|
- }
|
|
|
-
|
|
|
- if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
|
|
- return -1;
|
|
|
+ SDL_DisplayMode mode = WINRT_CalcDisplayModeUsingNativeWindow();
|
|
|
+ if (mode.w == 0 || mode.h == 0) {
|
|
|
+ return SDL_SetError("Unable to calculate the WinRT window/display's size");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
SDL_AddDisplayMode(&_this->displays[0], &mode);
|
|
|
@@ -219,64 +219,64 @@ WINRT_VideoQuit(_THIS)
|
|
|
WINRT_QuitMouse(_this);
|
|
|
}
|
|
|
|
|
|
-int
|
|
|
-WINRT_CreateWindow(_THIS, SDL_Window * window)
|
|
|
-{
|
|
|
- // Make sure that only one window gets created, at least until multimonitor
|
|
|
- // support is added.
|
|
|
- if (WINRT_GlobalSDLWindow != NULL) {
|
|
|
- SDL_SetError("WinRT only supports one window");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- SDL_WindowData *data = new SDL_WindowData;
|
|
|
- if (!data) {
|
|
|
- SDL_OutOfMemory();
|
|
|
- return -1;
|
|
|
- }
|
|
|
- window->driverdata = data;
|
|
|
- data->sdlWindow = window;
|
|
|
-
|
|
|
- /* To note, when XAML support is enabled, access to the CoreWindow will not
|
|
|
- be possible, at least not via the SDL/XAML thread. Attempts to access it
|
|
|
- from there will throw exceptions. As such, the SDL_WindowData's
|
|
|
- 'coreWindow' field will only be set (to a non-null value) if XAML isn't
|
|
|
- enabled.
|
|
|
- */
|
|
|
- if (!WINRT_XAMLWasEnabled) {
|
|
|
- data->coreWindow = CoreWindow::GetForCurrentThread();
|
|
|
- }
|
|
|
-
|
|
|
- /* Make sure the window is considered to be positioned at {0,0},
|
|
|
- and is considered fullscreen, shown, and the like.
|
|
|
- */
|
|
|
- window->x = 0;
|
|
|
- window->y = 0;
|
|
|
- window->flags =
|
|
|
- SDL_WINDOW_FULLSCREEN |
|
|
|
- SDL_WINDOW_SHOWN |
|
|
|
- SDL_WINDOW_BORDERLESS |
|
|
|
- SDL_WINDOW_MAXIMIZED |
|
|
|
- SDL_WINDOW_INPUT_GRABBED;
|
|
|
-
|
|
|
- /* WinRT does not, as of this writing, appear to support app-adjustable
|
|
|
- window sizes. Set the window size to whatever the native WinRT
|
|
|
- CoreWindow is set at.
|
|
|
-
|
|
|
- TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces.
|
|
|
- */
|
|
|
- window->w = _this->displays[0].current_mode.w;
|
|
|
- window->h = _this->displays[0].current_mode.h;
|
|
|
-
|
|
|
- /* Make sure the WinRT app's IFramworkView can post events on
|
|
|
- behalf of SDL:
|
|
|
- */
|
|
|
- WINRT_GlobalSDLWindow = window;
|
|
|
-
|
|
|
- /* All done! */
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
+int
|
|
|
+WINRT_CreateWindow(_THIS, SDL_Window * window)
|
|
|
+{
|
|
|
+ // Make sure that only one window gets created, at least until multimonitor
|
|
|
+ // support is added.
|
|
|
+ if (WINRT_GlobalSDLWindow != NULL) {
|
|
|
+ SDL_SetError("WinRT only supports one window");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ SDL_WindowData *data = new SDL_WindowData;
|
|
|
+ if (!data) {
|
|
|
+ SDL_OutOfMemory();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ window->driverdata = data;
|
|
|
+ data->sdlWindow = window;
|
|
|
+
|
|
|
+ /* To note, when XAML support is enabled, access to the CoreWindow will not
|
|
|
+ be possible, at least not via the SDL/XAML thread. Attempts to access it
|
|
|
+ from there will throw exceptions. As such, the SDL_WindowData's
|
|
|
+ 'coreWindow' field will only be set (to a non-null value) if XAML isn't
|
|
|
+ enabled.
|
|
|
+ */
|
|
|
+ if (!WINRT_XAMLWasEnabled) {
|
|
|
+ data->coreWindow = CoreWindow::GetForCurrentThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Make sure the window is considered to be positioned at {0,0},
|
|
|
+ and is considered fullscreen, shown, and the like.
|
|
|
+ */
|
|
|
+ window->x = 0;
|
|
|
+ window->y = 0;
|
|
|
+ window->flags =
|
|
|
+ SDL_WINDOW_FULLSCREEN |
|
|
|
+ SDL_WINDOW_SHOWN |
|
|
|
+ SDL_WINDOW_BORDERLESS |
|
|
|
+ SDL_WINDOW_MAXIMIZED |
|
|
|
+ SDL_WINDOW_INPUT_GRABBED;
|
|
|
+
|
|
|
+ /* WinRT does not, as of this writing, appear to support app-adjustable
|
|
|
+ window sizes. Set the window size to whatever the native WinRT
|
|
|
+ CoreWindow is set at.
|
|
|
+
|
|
|
+ TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces.
|
|
|
+ */
|
|
|
+ window->w = _this->displays[0].current_mode.w;
|
|
|
+ window->h = _this->displays[0].current_mode.h;
|
|
|
+
|
|
|
+ /* Make sure the WinRT app's IFramworkView can post events on
|
|
|
+ behalf of SDL:
|
|
|
+ */
|
|
|
+ WINRT_GlobalSDLWindow = window;
|
|
|
+
|
|
|
+ /* All done! */
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
void
|
|
|
WINRT_DestroyWindow(_THIS, SDL_Window * window)
|
|
|
{
|
|
|
@@ -293,21 +293,21 @@ WINRT_DestroyWindow(_THIS, SDL_Window * window)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-SDL_bool
|
|
|
-WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
|
|
-{
|
|
|
- SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
|
|
|
-
|
|
|
- if (info->version.major <= SDL_MAJOR_VERSION) {
|
|
|
- info->subsystem = SDL_SYSWM_WINRT;
|
|
|
- info->info.winrt.window = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
|
|
|
- return SDL_TRUE;
|
|
|
- } else {
|
|
|
- SDL_SetError("Application not compiled with SDL %d.%d\n",
|
|
|
- SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
|
|
|
- return SDL_FALSE;
|
|
|
- }
|
|
|
- return SDL_FALSE;
|
|
|
+SDL_bool
|
|
|
+WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
|
|
+{
|
|
|
+ SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
|
|
|
+
|
|
|
+ if (info->version.major <= SDL_MAJOR_VERSION) {
|
|
|
+ info->subsystem = SDL_SYSWM_WINRT;
|
|
|
+ info->info.winrt.window = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
|
|
|
+ return SDL_TRUE;
|
|
|
+ } else {
|
|
|
+ SDL_SetError("Application not compiled with SDL %d.%d\n",
|
|
|
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
|
|
|
+ return SDL_FALSE;
|
|
|
+ }
|
|
|
+ return SDL_FALSE;
|
|
|
}
|
|
|
|
|
|
#endif /* SDL_VIDEO_DRIVER_WINRT */
|