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

static bool IsSDLWindowEventPending ( SDL_WindowEventID  windowEventID)
static

Definition at line 434 of file SDL_winrtapp_direct3d.cpp.

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

{
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;
}
int SDL_WinRTInitNonXAMLApp ( int(*)(int, char **)  mainFunction)

Definition at line 116 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;
}
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.

References SDL_Log.

{
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));
}
template<typename BackButtonEventArgs >
static void WINRT_OnBackButtonPressed ( BackButtonEventArgs^  args)
static
static void WINRT_ProcessWindowSizeChange ( )
static

Definition at line 187 of file SDL_winrtapp_direct3d.cpp.

References SDL_Window::driverdata, 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().

{
CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
if (coreWindow) {
if (WINRT_GlobalSDLWindow) {
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) {
} else {
}
/* The window can move during a resize event, such as when maximizing
or resizing from a corner */
}
}
}
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.

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

Variable Documentation

SDL_WinRTApp SDL_WinRTGlobalApp = nullptr

Definition at line 94 of file SDL_winrtapp_direct3d.cpp.