SDL 2.0
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.

435{
436 SDL_Event events[128];
438 for (int i = 0; i < count; ++i) {
439 if (events[i].window.event == windowEventID) {
440 return true;
441 }
442 }
443 return false;
444}
#define SDL_PeepEvents
@ SDL_WINDOWEVENT
Definition: SDL_events.h:92
@ SDL_PEEKEVENT
Definition: SDL_events.h:616
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
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
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
static SDL_Event events[EVENT_BUF_SIZE]
Definition: testgesture.c:39
General event structure.
Definition: SDL_events.h:558

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.

117{
118 WINRT_SDLAppEntryPoint = mainFunction;
119 auto direct3DApplicationSource = ref new SDLApplicationSource();
120 CoreApplication::Run(direct3DApplicationSource);
121 return 0;
122}
GLenum GLint ref
int(* WINRT_SDLAppEntryPoint)(int, char **)
int Run(void *data)
Definition: testlock.c:65

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.

733{
734 Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
735 SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
736 header,
737 pt->Position.X, pt->Position.Y,
738 transformedPoint.X, transformedPoint.Y,
739 pt->Properties->MouseWheelDelta,
740 pt->FrameId,
741 pt->PointerId,
742 WINRT_GetSDLButtonForPointerPoint(pt));
743}
#define SDL_Log

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.

821{
824
826 args->Handled = true;
827 }
828}
#define SDL_GetHintBoolean
#define SDL_RELEASED
Definition: SDL_events.h:49
#define SDL_PRESSED
Definition: SDL_events.h:50
#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
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
@ SDL_SCANCODE_AC_BACK
Definition: SDL_scancode.h:363
@ SDL_FALSE
Definition: SDL_stdinc.h:163

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.

188{
189 CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
190 if (coreWindow) {
193 SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
194
195 int x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
196 int y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
197 int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
198 int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
199
200#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
201 /* WinPhone 8.0 always keeps its native window size in portrait,
202 regardless of orientation. This changes in WinPhone 8.1,
203 in which the native window's size changes along with
204 orientation.
205
206 Attempt to emulate WinPhone 8.1's behavior on WinPhone 8.0, with
207 regards to window size. This fixes a rendering bug that occurs
208 when a WinPhone 8.0 app is rotated to either 90 or 270 degrees.
209 */
210 const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
211 switch (currentOrientation) {
212 case DisplayOrientations::Landscape:
213 case DisplayOrientations::LandscapeFlipped: {
214 int tmp = w;
215 w = h;
216 h = tmp;
217 } break;
218 }
219#endif
220
221 const Uint32 latestFlags = WINRT_DetectWindowFlags(window);
222 if (latestFlags & SDL_WINDOW_MAXIMIZED) {
224 } else {
226 }
227
229
230 /* The window can move during a resize event, such as when maximizing
231 or resizing from a corner */
234 }
235 }
236}
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
uint32_t Uint32
Definition: SDL_stdinc.h:203
@ SDL_WINDOW_FULLSCREEN_DESKTOP
Definition: SDL_video.h:111
@ SDL_WINDOW_MAXIMIZED
Definition: SDL_video.h:107
@ SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:155
@ SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:153
@ SDL_WINDOWEVENT_MAXIMIZED
Definition: SDL_video.h:160
@ SDL_WINDOWEVENT_RESTORED
Definition: SDL_video.h:161
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Uint32 WINRT_DetectWindowFlags(SDL_Window *window)
SDL_Window * WINRT_GlobalSDLWindow
void WINRT_UpdateWindowFlags(SDL_Window *window, Uint32 mask)
The type used to identify a window.
Definition: SDL_sysvideo.h:74

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.

126{
128
129 /* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
130 * from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
131 * is getting registered.
132 *
133 * TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
134 */
135 if ((oldValue == NULL) && (newValue == NULL)) {
136 return;
137 }
138
139 // Start with no orientation flags, then add each in as they're parsed
140 // from newValue.
141 unsigned int orientationFlags = 0;
142 if (newValue) {
143 std::istringstream tokenizer(newValue);
144 while (!tokenizer.eof()) {
145 std::string orientationName;
146 std::getline(tokenizer, orientationName, ' ');
147 if (orientationName == "LandscapeLeft") {
148 orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
149 } else if (orientationName == "LandscapeRight") {
150 orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
151 } else if (orientationName == "Portrait") {
152 orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
153 } else if (orientationName == "PortraitUpsideDown") {
154 orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
155 }
156 }
157 }
158
159 // If no valid orientation flags were specified, use a reasonable set of defaults:
160 if (!orientationFlags) {
161 // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
162 orientationFlags = (unsigned int) ( \
163 DisplayOrientations::Landscape |
164 DisplayOrientations::LandscapeFlipped |
165 DisplayOrientations::Portrait |
166 DisplayOrientations::PortraitFlipped);
167 }
168
169 // Set the orientation/rotation preferences. Please note that this does
170 // not constitute a 100%-certain lock of a given set of possible
171 // orientations. According to Microsoft's documentation on WinRT [1]
172 // when a device is not capable of being rotated, Windows may ignore
173 // the orientation preferences, and stick to what the device is capable of
174 // displaying.
175 //
176 // [1] Documentation on the 'InitialRotationPreference' setting for a
177 // Windows app's manifest file describes how some orientation/rotation
178 // preferences may be ignored. See
179 // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
180 // for details. Microsoft's "Display orientation sample" also gives an
181 // outline of how Windows treats device rotation
182 // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
183 WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
184}
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define SDL_strcmp
#define SDL_HINT_ORIENTATIONS
A variable controlling which orientations are allowed on iOS/Android.
Definition: SDL_hints.h:360
GLuint const GLchar * name
GLsizei const GLchar *const * string
#define NULL
Definition: begin_code.h:167

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.