SDL_winrtapp_direct3d.cpp File Reference
`#include "../../SDL_internal.h"`
`#include <functional>`
`#include <string>`
`#include <sstream>`
`#include "ppltasks.h"`
`#include "SDL_assert.h"`
`#include "SDL_events.h"`
`#include "SDL_hints.h"`
`#include "SDL_log.h"`
`#include "SDL_main.h"`
`#include "SDL_stdinc.h"`
`#include "SDL_render.h"`
`#include "../../video/SDL_sysvideo.h"`
`#include "../../events/SDL_events_c.h"`
`#include "../../events/SDL_keyboard_c.h"`
`#include "../../events/SDL_mouse_c.h"`
`#include "../../events/SDL_windowevents_c.h"`
`#include "../../render/SDL_sysrender.h"`
`#include "../windows/SDL_windows.h"`
`#include "../../video/winrt/SDL_winrtevents_c.h"`
`#include "../../video/winrt/SDL_winrtvideo_cpp.h"`
`#include "SDL_winrtapp_common.h"`
`#include "SDL_winrtapp_direct3d.h"`
Include dependency graph for SDL_winrtapp_direct3d.cpp:

Go to the source code of this file.

## Data Structures

class | sealed

## Functions

int | SDL_WinRTInitNonXAMLApp (int(*mainFunction)(int, char **))
static void | WINRT_SetDisplayOrientationsPreference (void *userdata, const char *name, const char *oldValue, const char *newValue)
static void | WINRT_ProcessWindowSizeChange ()
static bool | IsSDLWindowEventPending (SDL_WindowEventID windowEventID)
static void | WINRT_LogPointerEvent (const char *header, Windows::UI::Core::PointerEventArgs^args, Windows::Foundation::Point transformedPoint)
template<typename BackButtonEventArgs >
static void | WINRT_OnBackButtonPressed (BackButtonEventArgs^args)

## Variables

SDL_WinRTApp | SDL_WinRTGlobalApp = nullptr

## Function Documentation

static bool IsSDLWindowEventPending | ( | SDL_WindowEventID | windowEventID | ) |

static

Definition at line 422 of file SDL_winrtapp_direct3d.cpp.

References events, i, SDL_Renderer::info, SDL_RendererInfo::name, NULL, renderer, SDL_APP_DIDENTERBACKGROUND, SDL_APP_DIDENTERFOREGROUND, SDL_APP_TERMINATING, SDL_APP_WILLENTERBACKGROUND, SDL_APP_WILLENTERFOREGROUND, SDL_free(), SDL_GetHint, SDL_GetKeyboardFocus, SDL_GetRenderer, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL, SDL_HINT_WINRT_PRIVACY_POLICY_URL, SDL_Log, SDL_PEEKEVENT, SDL_PeepEvents, SDL_SendAppEvent(), SDL_SendMouseMotion(), SDL_SendWindowEvent(), SDL_SetCursor, SDL_SetKeyboardFocus(), SDL_strcmp, SDL_WINDOW_MAXIMIZED, SDL_WINDOWEVENT, SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_FOCUS_LOST, SDL_WINDOWEVENT_HIDDEN, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MINIMIZED, SDL_WINDOWEVENT_RESTORED, SDL_WINDOWEVENT_SHOWN, SDL_Window::surface_valid, WIN_UTF8ToString, WINRT_DetectWindowFlags(), WINRT_GlobalSDLWindow, and WINRT_ProcessWindowSizeChange().

{
SDL_Event events[128];
const int count = SDL_PeepEvents(events, sizeof(events)/sizeof(SDL_Event), SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT);
for (int i = 0; i < count; ++i) {
if (events[i].window.event == windowEventID) {
return true;
}
}
return false;
}
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
window
SDL_Window * window
Definition: testautomation_render.c:26
SDL_PEEKEVENT
Definition: SDL_events.h:575
events
static SDL_Event events[EVENT_BUF_SIZE]
Definition: testgesture.c:36
SDL_PeepEvents
#define SDL_PeepEvents
Definition: SDL_dynapi_overrides.h:123
SDL_WINDOWEVENT
Definition: SDL_events.h:89
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
SDL_Event
General event structure.
Definition: SDL_events.h:521

int SDL_WinRTInitNonXAMLApp | ( | int(*)(int, char **) | mainFunction | ) |

Definition at line 117 of file SDL_winrtapp_direct3d.cpp.

References Run(), and WINRT_SDLAppEntryPoint.

Referenced by SDL_WinRTRunApp().

{
WINRT_SDLAppEntryPoint = mainFunction;
auto direct3DApplicationSource = ref new SDLApplicationSource();
CoreApplication::Run(direct3DApplicationSource);
return 0;
}
Run
int Run(void *data)
Definition: testlock.c:65
WINRT_SDLAppEntryPoint
int(* WINRT_SDLAppEntryPoint)(int, char **)
Definition: SDL_winrtapp_common.cpp:27
ref
GLenum GLint ref
Definition: SDL_opengl_glext.h:657

static void WINRT_LogPointerEvent | ( | const char * | header,
|  | Windows::UI::Core::PointerEventArgs^ | args,
|  | Windows::Foundation::Point | transformedPoint
| ) |  |

static

Definition at line 720 of file SDL_winrtapp_direct3d.cpp.

References SDL_Log, and WINRT_GlobalSDLWindow.

{
Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
header,
pt->Position.X, pt->Position.Y,
transformedPoint.X, transformedPoint.Y,
pt->Properties->MouseWheelDelta,
pt->FrameId,
pt->PointerId,
WINRT_GetSDLButtonForPointerPoint(pt));
}
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:37
template<typename BackButtonEventArgs >

static void WINRT_OnBackButtonPressed | ( | BackButtonEventArgs^ | args | ) |

static

Definition at line 808 of file SDL_winrtapp_direct3d.cpp.

References SDL_GetHint, SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_PRESSED, SDL_RELEASED, SDL_SCANCODE_AC_BACK, and SDL_SendKeyboardKey().

{
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK);
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK);
const char *hint = SDL_GetHint(SDL_HINT_WINRT_HANDLE_BACK_BUTTON);
if (hint) {
if (*hint == '1') {
args->Handled = true;
}
}
}
SDL_GetHint
#define SDL_GetHint
Definition: SDL_dynapi_overrides.h:197
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:661
SDL_SCANCODE_AC_BACK
Definition: SDL_scancode.h:363
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_HINT_WINRT_HANDLE_BACK_BUTTON
#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON
Allows back-button-press events on Windows Phone to be marked as handled.
Definition: SDL_hints.h:521
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49

static void WINRT_ProcessWindowSizeChange | ( |  | ) |

static

Definition at line 187 of file SDL_winrtapp_direct3d.cpp.

References SDL_Window::driverdata, NULL, Run(), SDL_AddHintCallback, SDL_HINT_ORIENTATIONS, SDL_Log, SDL_SendWindowEvent(), SDL_SetMainReady, SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_MAXIMIZED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MOVED, SDL_WINDOWEVENT_RESIZED, SDL_WINDOWEVENT_RESTORED, SDL_WINDOWEVENT_SIZE_CHANGED, window, WINRT_DetectWindowFlags(), WINRT_GlobalSDLWindow, WINRT_SDLAppEntryPoint, WINRT_SetDisplayOrientationsPreference(), and WINRT_UpdateWindowFlags().

Referenced by IsSDLWindowEventPending().

{
CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
if (coreWindow) {
if (WINRT_GlobalSDLWindow) {
SDL_Window * window = WINRT_GlobalSDLWindow;
SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
int x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
int y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
/* WinPhone 8.0 always keeps its native window size in portrait,
regardless of orientation. This changes in WinPhone 8.1,
in which the native window's size changes along with
orientation.
Attempt to emulate WinPhone 8.1's behavior on WinPhone 8.0, with
regards to window size. This fixes a rendering bug that occurs
when a WinPhone 8.0 app is rotated to either 90 or 270 degrees.
*/
const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
switch (currentOrientation) {
case DisplayOrientations::Landscape:
case DisplayOrientations::LandscapeFlipped: {
int tmp = w;
w = h;
h = tmp;
} break;
}
#endif
const Uint32 latestFlags = WINRT_DetectWindowFlags(window);
if (latestFlags & SDL_WINDOW_MAXIMIZED) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
} else {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
}
WINRT_UpdateWindowFlags(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
/* The window can move during a resize event, such as when maximizing
or resizing from a corner */
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
}
}
}
WINRT_UpdateWindowFlags
void WINRT_UpdateWindowFlags(SDL_Window *window, Uint32 mask)
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
window
SDL_Window * window
Definition: testautomation_render.c:26
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_WINDOWEVENT_MAXIMIZED
Definition: SDL_video.h:150
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
SDL_WindowData
Definition: SDL_androidwindow.h:34
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
SDL_WINDOWEVENT_RESTORED
Definition: SDL_video.h:151
WINRT_DetectWindowFlags
Uint32 WINRT_DetectWindowFlags(SDL_Window *window)
WINRT_GlobalSDLWindow
SDL_Window * WINRT_GlobalSDLWindow
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_WINDOW_MAXIMIZED
Definition: SDL_video.h:105
SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:145
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:106
SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:143
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_WINDOW_FULLSCREEN_DESKTOP
Definition: SDL_video.h:109

static void WINRT_SetDisplayOrientationsPreference | ( | void * | userdata,
|  | const char * | name,
|  | const char * | oldValue,
|  | const char * | newValue
| ) |  |

static

Definition at line 125 of file SDL_winrtapp_direct3d.cpp.

References NULL, SDL_assert, SDL_HINT_ORIENTATIONS, and SDL_strcmp.

Referenced by WINRT_ProcessWindowSizeChange().

{
SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
/* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
* from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
* is getting registered.
*
* TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
*/
if ((oldValue == NULL) && (newValue == NULL)) {
return;
}
// Start with no orientation flags, then add each in as they're parsed
// from newValue.
unsigned int orientationFlags = 0;
if (newValue) {
std::istringstream tokenizer(newValue);
while (!tokenizer.eof()) {
std::string orientationName;
std::getline(tokenizer, orientationName, ' ');
if (orientationName == "LandscapeLeft") {
orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
} else if (orientationName == "LandscapeRight") {
orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
} else if (orientationName == "Portrait") {
orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
} else if (orientationName == "PortraitUpsideDown") {
orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
}
}
}
// If no valid orientation flags were specified, use a reasonable set of defaults:
if (!orientationFlags) {
// TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
orientationFlags = (unsigned int) ( \
DisplayOrientations::Landscape |
DisplayOrientations::LandscapeFlipped |
DisplayOrientations::Portrait |
DisplayOrientations::PortraitFlipped);
}
// Set the orientation/rotation preferences. Please note that this does
// not constitute a 100%-certain lock of a given set of possible
// orientations. According to Microsoft's documentation on WinRT [1]
// when a device is not capable of being rotated, Windows may ignore
// the orientation preferences, and stick to what the device is capable of
// displaying.
//
// [1] Documentation on the 'InitialRotationPreference' setting for a
// Windows app's manifest file describes how some orientation/rotation
// preferences may be ignored. See
// http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
// for details. Microsoft's "Display orientation sample" also gives an
// outline of how Windows treats device rotation
// (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
}
string
GLsizei const GLchar *const * string
Definition: SDL_opengl_glext.h:688
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_HINT_ORIENTATIONS
#define SDL_HINT_ORIENTATIONS
A variable controlling which orientations are allowed on iOS.
Definition: SDL_hints.h:278
NULL
#define NULL
Definition: begin_code.h:143
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:423

## Variable Documentation

SDL_WinRTApp SDL_WinRTGlobalApp = nullptr

Definition at line 95 of file SDL_winrtapp_direct3d.cpp.