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

## IsSDLWindowEventPending()

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

static

Definition at line 434 of file SDL_winrtapp_direct3d.cpp.

{
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;
}

References events, i, SDL_PEEKEVENT, SDL_PeepEvents, and SDL_WINDOWEVENT.

## SDL_WinRTInitNonXAMLApp()

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

Definition at line 116 of file SDL_winrtapp_direct3d.cpp.

{
WINRT_SDLAppEntryPoint = mainFunction;
auto direct3DApplicationSource = ref new SDLApplicationSource();
CoreApplication::Run(direct3DApplicationSource);
return 0;
}

References Run(), and WINRT_SDLAppEntryPoint.

Referenced by SDL_WinRTRunApp().

## WINRT_LogPointerEvent()

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

static

Definition at line 732 of file SDL_winrtapp_direct3d.cpp.

{
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));
}

References SDL_Log.

## WINRT_OnBackButtonPressed()

template<typename BackButtonEventArgs >

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

static

Definition at line 820 of file SDL_winrtapp_direct3d.cpp.

{
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK);
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK);
if (SDL_GetHintBoolean(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_FALSE)) {
args->Handled = true;
}
}

References SDL_FALSE, SDL_GetHintBoolean, SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_PRESSED, SDL_RELEASED, SDL_SCANCODE_AC_BACK, and SDL_SendKeyboardKey().

## WINRT_ProcessWindowSizeChange()

static void WINRT_ProcessWindowSizeChange | ( |  | ) |

static

Definition at line 187 of file SDL_winrtapp_direct3d.cpp.

{
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);
}
}
}

References SDL_SendWindowEvent(), SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_MAXIMIZED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MOVED, SDL_WINDOWEVENT_RESIZED, SDL_WINDOWEVENT_RESTORED, WINRT_DetectWindowFlags(), WINRT_GlobalSDLWindow, and WINRT_UpdateWindowFlags().

## WINRT_SetDisplayOrientationsPreference()

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.

{
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;
}

References NULL, SDL_assert, SDL_HINT_ORIENTATIONS, and SDL_strcmp.

## Variable Documentation

## SDL_WinRTGlobalApp

SDL_WinRTApp SDL_WinRTGlobalApp = nullptr

Definition at line 94 of file SDL_winrtapp_direct3d.cpp.

Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
NULL
#define NULL
Definition: begin_code.h:167
SDL_WindowData
Definition: SDL_androidwindow.h:38
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_WINDOWEVENT_RESIZED
@ SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:155
SDL_WINDOW_FULLSCREEN_DESKTOP
@ SDL_WINDOW_FULLSCREEN_DESKTOP
Definition: SDL_video.h:111
SDL_WINDOW_MAXIMIZED
@ SDL_WINDOW_MAXIMIZED
Definition: SDL_video.h:107
SDL_WINDOWEVENT_MOVED
@ SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:153
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
WINRT_UpdateWindowFlags
void WINRT_UpdateWindowFlags(SDL_Window *window, Uint32 mask)
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_GetHintBoolean
#define SDL_GetHintBoolean
Definition: SDL_dynapi_overrides.h:608
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:31
ref
GLenum GLint ref
Definition: SDL_opengl_glext.h:657
WINRT_GlobalSDLWindow
SDL_Window * WINRT_GlobalSDLWindow
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_PeepEvents
#define SDL_PeepEvents
Definition: SDL_dynapi_overrides.h:117
WINRT_SDLAppEntryPoint
int(* WINRT_SDLAppEntryPoint)(int, char **)
Definition: SDL_winrtapp_common.cpp:30
SDL_SCANCODE_AC_BACK
@ SDL_SCANCODE_AC_BACK
Definition: SDL_scancode.h:363
WINRT_DetectWindowFlags
Uint32 WINRT_DetectWindowFlags(SDL_Window *window)
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
events
static SDL_Event events[EVENT_BUF_SIZE]
Definition: testgesture.c:39
SDL_HINT_ORIENTATIONS
#define SDL_HINT_ORIENTATIONS
A variable controlling which orientations are allowed on iOS/Android.
Definition: SDL_hints.h:360
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
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:794
SDL_Event
General event structure.
Definition: SDL_events.h:557
SDL_WINDOWEVENT
@ SDL_WINDOWEVENT
Definition: SDL_events.h:92
SDL_WINDOWEVENT_RESTORED
@ SDL_WINDOWEVENT_RESTORED
Definition: SDL_video.h:161
Run
int Run(void *data)
Definition: testlock.c:65
string
GLsizei const GLchar *const * string
Definition: SDL_opengl_glext.h:688
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:417
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:50
SDL_WINDOWEVENT_MAXIMIZED
@ SDL_WINDOWEVENT_MAXIMIZED
Definition: SDL_video.h:160
SDL_PEEKEVENT
@ SDL_PEEKEVENT
Definition: SDL_events.h:616
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731