SDL  2.0
SDL_winrtapp_direct3d.cpp File Reference
#include "../../SDL_internal.h"
#include <functional>
#include <string>
#include <sstream>
#include "ppltasks.h"
#include "SDL_events.h"
#include "SDL_hints.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 432 of file SDL_winrtapp_direct3d.cpp.

433 {
434  SDL_Event events[128];
436  for (int i = 0; i < count; ++i) {
437  if (events[i].window.event == windowEventID) {
438  return true;
439  }
440  }
441  return false;
442 }
#define SDL_PeepEvents
@ SDL_WINDOWEVENT
Definition: SDL_events.h:94
@ SDL_PEEKEVENT
Definition: SDL_events.h:652
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:592

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

◆ SDL_WinRTInitNonXAMLApp()

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

Definition at line 114 of file SDL_winrtapp_direct3d.cpp.

115 {
116  WINRT_SDLAppEntryPoint = mainFunction;
117  auto direct3DApplicationSource = ref new SDLApplicationSource();
118  CoreApplication::Run(direct3DApplicationSource);
119  return 0;
120 }
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 730 of file SDL_winrtapp_direct3d.cpp.

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

References SDL_Log.

◆ WINRT_OnBackButtonPressed()

template<typename BackButtonEventArgs >
static void WINRT_OnBackButtonPressed ( BackButtonEventArgs ^  args)
static

Definition at line 818 of file SDL_winrtapp_direct3d.cpp.

819 {
822 
824  args->Handled = true;
825  }
826 }
#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:981
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:806
@ SDL_SCANCODE_AC_BACK
Definition: SDL_scancode.h:363
@ SDL_FALSE
Definition: SDL_stdinc.h:169

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 185 of file SDL_winrtapp_direct3d.cpp.

186 {
187  CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
188  if (coreWindow) {
189  if (WINRT_GlobalSDLWindow) {
191  SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
192 
193  int x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
194  int y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
195  int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
196  int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
197 
198 #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
199  /* WinPhone 8.0 always keeps its native window size in portrait,
200  regardless of orientation. This changes in WinPhone 8.1,
201  in which the native window's size changes along with
202  orientation.
203 
204  Attempt to emulate WinPhone 8.1's behavior on WinPhone 8.0, with
205  regards to window size. This fixes a rendering bug that occurs
206  when a WinPhone 8.0 app is rotated to either 90 or 270 degrees.
207  */
208  const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
209  switch (currentOrientation) {
210  case DisplayOrientations::Landscape:
211  case DisplayOrientations::LandscapeFlipped: {
212  int tmp = w;
213  w = h;
214  h = tmp;
215  } break;
216  }
217 #endif
218 
219  const Uint32 latestFlags = WINRT_DetectWindowFlags(window);
220  if (latestFlags & SDL_WINDOW_MAXIMIZED) {
222  } else {
224  }
225 
227 
228  /* The window can move during a resize event, such as when maximizing
229  or resizing from a corner */
232  }
233  }
234 }
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:209
@ SDL_WINDOW_FULLSCREEN_DESKTOP
Definition: SDL_video.h:110
@ SDL_WINDOW_MAXIMIZED
Definition: SDL_video.h:106
@ 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:75

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 123 of file SDL_winrtapp_direct3d.cpp.

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

References int(), NULL, SDL_assert, SDL_HINT_ORIENTATIONS, and SDL_strcmp.

Variable Documentation

◆ SDL_WinRTGlobalApp

SDL_WinRTApp SDL_WinRTGlobalApp = nullptr

Definition at line 92 of file SDL_winrtapp_direct3d.cpp.