mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
Add library SDL2
This commit is contained in:
parent
33a0579735
commit
674133ac86
767 changed files with 295058 additions and 10 deletions
153
Engine/lib/sdl/src/video/winrt/SDL_winrtevents.cpp
Normal file
153
Engine/lib/sdl/src/video/winrt/SDL_winrtevents.cpp
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/*
|
||||
* Windows includes:
|
||||
*/
|
||||
#include <Windows.h>
|
||||
using namespace Windows::UI::Core;
|
||||
using Windows::UI::Core::CoreCursor;
|
||||
|
||||
/*
|
||||
* SDL includes:
|
||||
*/
|
||||
#include "SDL_winrtevents_c.h"
|
||||
#include "../../core/winrt/SDL_winrtapp_common.h"
|
||||
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
|
||||
#include "../../core/winrt/SDL_winrtapp_xaml.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
}
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
static void WINRT_YieldXAMLThread();
|
||||
|
||||
|
||||
/* Global event management */
|
||||
|
||||
void
|
||||
WINRT_PumpEvents(_THIS)
|
||||
{
|
||||
if (SDL_WinRTGlobalApp) {
|
||||
SDL_WinRTGlobalApp->PumpEvents();
|
||||
} else if (WINRT_XAMLWasEnabled) {
|
||||
WINRT_YieldXAMLThread();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* XAML Thread management */
|
||||
|
||||
enum SDL_XAMLAppThreadState
|
||||
{
|
||||
ThreadState_NotLaunched = 0,
|
||||
ThreadState_Running,
|
||||
ThreadState_Yielding
|
||||
};
|
||||
|
||||
static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched;
|
||||
static SDL_Thread * _XAMLThread = nullptr;
|
||||
static SDL_mutex * _mutex = nullptr;
|
||||
static SDL_cond * _cond = nullptr;
|
||||
|
||||
static void
|
||||
WINRT_YieldXAMLThread()
|
||||
{
|
||||
SDL_LockMutex(_mutex);
|
||||
SDL_assert(_threadState == ThreadState_Running);
|
||||
_threadState = ThreadState_Yielding;
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
SDL_CondSignal(_cond);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Running) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_XAMLThreadMain(void * userdata)
|
||||
{
|
||||
// TODO, WinRT: pass the C-style main() a reasonably realistic
|
||||
// representation of command line arguments.
|
||||
int argc = 0;
|
||||
char **argv = NULL;
|
||||
return WINRT_SDLAppEntryPoint(argc, argv);
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_CycleXAMLThread()
|
||||
{
|
||||
switch (_threadState) {
|
||||
case ThreadState_NotLaunched:
|
||||
{
|
||||
_cond = SDL_CreateCond();
|
||||
|
||||
_mutex = SDL_CreateMutex();
|
||||
_threadState = ThreadState_Running;
|
||||
_XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Yielding) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ThreadState_Running:
|
||||
{
|
||||
SDL_assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
case ThreadState_Yielding:
|
||||
{
|
||||
SDL_LockMutex(_mutex);
|
||||
SDL_assert(_threadState == ThreadState_Yielding);
|
||||
_threadState = ThreadState_Running;
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
SDL_CondSignal(_cond);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Yielding) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
72
Engine/lib/sdl/src/video/winrt/SDL_winrtevents_c.h
Normal file
72
Engine/lib/sdl/src/video/winrt/SDL_winrtevents_c.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../SDL_sysvideo.h"
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal-use, C-style functions:
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void WINRT_InitTouch(_THIS);
|
||||
extern void WINRT_PumpEvents(_THIS);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Internal-use, C++/CX functions:
|
||||
*/
|
||||
#ifdef __cplusplus_winrt
|
||||
|
||||
/* Pointers (Mice, Touch, etc.) */
|
||||
typedef enum {
|
||||
NormalizeZeroToOne,
|
||||
TransformToSDLWindowSize
|
||||
} WINRT_CursorNormalizationType;
|
||||
extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window,
|
||||
Windows::Foundation::Point rawPosition,
|
||||
WINRT_CursorNormalizationType normalization);
|
||||
extern Uint8 WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt);
|
||||
extern void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
||||
extern void WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
||||
extern void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
||||
extern void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
||||
extern void WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args);
|
||||
|
||||
/* Keyboard */
|
||||
extern void WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args);
|
||||
extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args);
|
||||
|
||||
/* XAML Thread Management */
|
||||
extern void WINRT_CycleXAMLThread();
|
||||
|
||||
#endif // ifdef __cplusplus_winrt
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
301
Engine/lib/sdl/src/video/winrt/SDL_winrtkeyboard.cpp
Normal file
301
Engine/lib/sdl/src/video/winrt/SDL_winrtkeyboard.cpp
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/* Standard C++11 includes */
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
/* Windows-specific includes */
|
||||
#include <Windows.h>
|
||||
#include <agile.h>
|
||||
|
||||
|
||||
/* SDL-specific includes */
|
||||
#include <SDL.h>
|
||||
#include "SDL_winrtevents_c.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../../events/scancodes_windows.h"
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
}
|
||||
|
||||
|
||||
static SDL_Scancode WinRT_Official_Keycodes[] = {
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
|
||||
SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
|
||||
SDL_SCANCODE_UNKNOWN, // -- 7
|
||||
SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
|
||||
SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
|
||||
SDL_SCANCODE_UNKNOWN, // -- 10
|
||||
SDL_SCANCODE_UNKNOWN, // -- 11
|
||||
SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
|
||||
SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
|
||||
SDL_SCANCODE_UNKNOWN, // -- 14
|
||||
SDL_SCANCODE_UNKNOWN, // -- 15
|
||||
SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
|
||||
SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
|
||||
SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
|
||||
SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
|
||||
SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
|
||||
SDL_SCANCODE_UNKNOWN, // -- 22
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
|
||||
SDL_SCANCODE_UNKNOWN, // -- 26
|
||||
SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31 (maybe SDL_SCANCODE_MODE ?)
|
||||
SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
|
||||
SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
|
||||
SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
|
||||
SDL_SCANCODE_END, // VirtualKey.End -- 35
|
||||
SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
|
||||
SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
|
||||
SDL_SCANCODE_UP, // VirtualKey.Up -- 38
|
||||
SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
|
||||
SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
|
||||
SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42 (maybe SDL_SCANCODE_PRINTSCREEN ?)
|
||||
SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
|
||||
SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
|
||||
SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
|
||||
SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
|
||||
SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
|
||||
SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
|
||||
SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
|
||||
SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
|
||||
SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
|
||||
SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
|
||||
SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
|
||||
SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
|
||||
SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
|
||||
SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
|
||||
SDL_SCANCODE_UNKNOWN, // -- 58
|
||||
SDL_SCANCODE_UNKNOWN, // -- 59
|
||||
SDL_SCANCODE_UNKNOWN, // -- 60
|
||||
SDL_SCANCODE_UNKNOWN, // -- 61
|
||||
SDL_SCANCODE_UNKNOWN, // -- 62
|
||||
SDL_SCANCODE_UNKNOWN, // -- 63
|
||||
SDL_SCANCODE_UNKNOWN, // -- 64
|
||||
SDL_SCANCODE_A, // VirtualKey.A -- 65
|
||||
SDL_SCANCODE_B, // VirtualKey.B -- 66
|
||||
SDL_SCANCODE_C, // VirtualKey.C -- 67
|
||||
SDL_SCANCODE_D, // VirtualKey.D -- 68
|
||||
SDL_SCANCODE_E, // VirtualKey.E -- 69
|
||||
SDL_SCANCODE_F, // VirtualKey.F -- 70
|
||||
SDL_SCANCODE_G, // VirtualKey.G -- 71
|
||||
SDL_SCANCODE_H, // VirtualKey.H -- 72
|
||||
SDL_SCANCODE_I, // VirtualKey.I -- 73
|
||||
SDL_SCANCODE_J, // VirtualKey.J -- 74
|
||||
SDL_SCANCODE_K, // VirtualKey.K -- 75
|
||||
SDL_SCANCODE_L, // VirtualKey.L -- 76
|
||||
SDL_SCANCODE_M, // VirtualKey.M -- 77
|
||||
SDL_SCANCODE_N, // VirtualKey.N -- 78
|
||||
SDL_SCANCODE_O, // VirtualKey.O -- 79
|
||||
SDL_SCANCODE_P, // VirtualKey.P -- 80
|
||||
SDL_SCANCODE_Q, // VirtualKey.Q -- 81
|
||||
SDL_SCANCODE_R, // VirtualKey.R -- 82
|
||||
SDL_SCANCODE_S, // VirtualKey.S -- 83
|
||||
SDL_SCANCODE_T, // VirtualKey.T -- 84
|
||||
SDL_SCANCODE_U, // VirtualKey.U -- 85
|
||||
SDL_SCANCODE_V, // VirtualKey.V -- 86
|
||||
SDL_SCANCODE_W, // VirtualKey.W -- 87
|
||||
SDL_SCANCODE_X, // VirtualKey.X -- 88
|
||||
SDL_SCANCODE_Y, // VirtualKey.Y -- 89
|
||||
SDL_SCANCODE_Z, // VirtualKey.Z -- 90
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
|
||||
SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
|
||||
SDL_SCANCODE_UNKNOWN, // -- 94
|
||||
SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
|
||||
SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
|
||||
SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
|
||||
SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
|
||||
SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
|
||||
SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
|
||||
SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
|
||||
SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
|
||||
SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
|
||||
SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
|
||||
SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
|
||||
SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
|
||||
SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
|
||||
SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110 (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
|
||||
SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
|
||||
SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
|
||||
SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
|
||||
SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
|
||||
SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
|
||||
SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
|
||||
SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
|
||||
SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
|
||||
SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
|
||||
SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
|
||||
SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
|
||||
SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
|
||||
SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
|
||||
SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
|
||||
SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
|
||||
SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
|
||||
SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
|
||||
SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
|
||||
SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
|
||||
SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
|
||||
SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
|
||||
SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
|
||||
SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
|
||||
SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
|
||||
SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
|
||||
SDL_SCANCODE_UNKNOWN, // -- 136
|
||||
SDL_SCANCODE_UNKNOWN, // -- 137
|
||||
SDL_SCANCODE_UNKNOWN, // -- 138
|
||||
SDL_SCANCODE_UNKNOWN, // -- 139
|
||||
SDL_SCANCODE_UNKNOWN, // -- 140
|
||||
SDL_SCANCODE_UNKNOWN, // -- 141
|
||||
SDL_SCANCODE_UNKNOWN, // -- 142
|
||||
SDL_SCANCODE_UNKNOWN, // -- 143
|
||||
SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
|
||||
SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
|
||||
SDL_SCANCODE_UNKNOWN, // -- 146
|
||||
SDL_SCANCODE_UNKNOWN, // -- 147
|
||||
SDL_SCANCODE_UNKNOWN, // -- 148
|
||||
SDL_SCANCODE_UNKNOWN, // -- 149
|
||||
SDL_SCANCODE_UNKNOWN, // -- 150
|
||||
SDL_SCANCODE_UNKNOWN, // -- 151
|
||||
SDL_SCANCODE_UNKNOWN, // -- 152
|
||||
SDL_SCANCODE_UNKNOWN, // -- 153
|
||||
SDL_SCANCODE_UNKNOWN, // -- 154
|
||||
SDL_SCANCODE_UNKNOWN, // -- 155
|
||||
SDL_SCANCODE_UNKNOWN, // -- 156
|
||||
SDL_SCANCODE_UNKNOWN, // -- 157
|
||||
SDL_SCANCODE_UNKNOWN, // -- 158
|
||||
SDL_SCANCODE_UNKNOWN, // -- 159
|
||||
SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
|
||||
SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
|
||||
SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
|
||||
SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
|
||||
SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
|
||||
SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
|
||||
};
|
||||
|
||||
static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
|
||||
|
||||
static SDL_Scancode
|
||||
TranslateKeycode(int keycode)
|
||||
{
|
||||
if (WinRT_Unofficial_Keycodes.empty()) {
|
||||
/* Set up a table of undocumented (by Microsoft), WinRT-specific,
|
||||
key codes: */
|
||||
// TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible
|
||||
WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE;
|
||||
WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH;
|
||||
}
|
||||
|
||||
/* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
|
||||
http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
|
||||
If that fails, fall back to a Win32 virtual key.
|
||||
*/
|
||||
// TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
|
||||
//SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
|
||||
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
|
||||
if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
|
||||
scancode = WinRT_Official_Keycodes[keycode];
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
|
||||
scancode = WinRT_Unofficial_Keycodes[keycode];
|
||||
}
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
if (keycode < SDL_arraysize(windows_scancode_table)) {
|
||||
scancode = windows_scancode_table[keycode];
|
||||
}
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
|
||||
}
|
||||
return scancode;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
|
||||
{
|
||||
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
|
||||
#if 0
|
||||
SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
|
||||
SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
|
||||
(args->Handled ? "1" : "0"),
|
||||
(args->KeyStatus.IsExtendedKey ? "1" : "0"),
|
||||
(args->KeyStatus.IsKeyReleased ? "1" : "0"),
|
||||
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
|
||||
args->KeyStatus.RepeatCount,
|
||||
args->KeyStatus.ScanCode,
|
||||
(args->KeyStatus.WasKeyDown ? "1" : "0"),
|
||||
args->VirtualKey,
|
||||
sdlScancode,
|
||||
SDL_GetScancodeName(sdlScancode),
|
||||
keycode,
|
||||
SDL_GetKeyName(keycode));
|
||||
//args->Handled = true;
|
||||
//VirtualKey vkey = args->VirtualKey;
|
||||
#endif
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
|
||||
{
|
||||
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
|
||||
#if 0
|
||||
SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
|
||||
SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
|
||||
(args->Handled ? "1" : "0"),
|
||||
(args->KeyStatus.IsExtendedKey ? "1" : "0"),
|
||||
(args->KeyStatus.IsKeyReleased ? "1" : "0"),
|
||||
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
|
||||
args->KeyStatus.RepeatCount,
|
||||
args->KeyStatus.ScanCode,
|
||||
(args->KeyStatus.WasKeyDown ? "1" : "0"),
|
||||
args->VirtualKey,
|
||||
sdlScancode,
|
||||
SDL_GetScancodeName(sdlScancode),
|
||||
keycode,
|
||||
SDL_GetKeyName(keycode));
|
||||
//args->Handled = true;
|
||||
#endif
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
|
||||
}
|
||||
|
||||
#endif // SDL_VIDEO_DRIVER_WINRT
|
||||
165
Engine/lib/sdl/src/video/winrt/SDL_winrtmouse.cpp
Normal file
165
Engine/lib/sdl/src/video/winrt/SDL_winrtmouse.cpp
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/*
|
||||
* Windows includes:
|
||||
*/
|
||||
#include <Windows.h>
|
||||
using namespace Windows::UI::Core;
|
||||
using Windows::UI::Core::CoreCursor;
|
||||
|
||||
/*
|
||||
* SDL includes:
|
||||
*/
|
||||
extern "C" {
|
||||
#include "SDL_assert.h"
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_log.h"
|
||||
}
|
||||
|
||||
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
#include "SDL_winrtmouse_c.h"
|
||||
|
||||
|
||||
extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
|
||||
|
||||
|
||||
static SDL_Cursor *
|
||||
WINRT_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
CoreCursorType cursorType = CoreCursorType::Arrow;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
default:
|
||||
SDL_assert(0);
|
||||
return NULL;
|
||||
case SDL_SYSTEM_CURSOR_ARROW: cursorType = CoreCursorType::Arrow; break;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM: cursorType = CoreCursorType::IBeam; break;
|
||||
case SDL_SYSTEM_CURSOR_WAIT: cursorType = CoreCursorType::Wait; break;
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE: cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW: cursorType = CoreCursorType::SizeNortheastSouthwest; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE: cursorType = CoreCursorType::SizeWestEast; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS: cursorType = CoreCursorType::SizeNorthSouth; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL: cursorType = CoreCursorType::SizeAll; break;
|
||||
case SDL_SYSTEM_CURSOR_NO: cursorType = CoreCursorType::UniversalNo; break;
|
||||
case SDL_SYSTEM_CURSOR_HAND: cursorType = CoreCursorType::Hand; break;
|
||||
}
|
||||
|
||||
cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
|
||||
if (cursor) {
|
||||
/* Create a pointer to a COM reference to a cursor. The extra
|
||||
pointer is used (on top of the COM reference) to allow the cursor
|
||||
to be referenced by the SDL_cursor's driverdata field, which is
|
||||
a void pointer.
|
||||
*/
|
||||
CoreCursor ^* theCursor = new CoreCursor^(nullptr);
|
||||
*theCursor = ref new CoreCursor(cursorType, 0);
|
||||
cursor->driverdata = (void *) theCursor;
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
WINRT_CreateDefaultCursor()
|
||||
{
|
||||
return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||
}
|
||||
|
||||
static void
|
||||
WINRT_FreeCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
if (cursor->driverdata) {
|
||||
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
|
||||
*theCursor = nullptr; // Release the COM reference to the CoreCursor
|
||||
delete theCursor; // Delete the pointer to the COM reference
|
||||
}
|
||||
SDL_free(cursor);
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_ShowCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
// TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
|
||||
if ( ! CoreWindow::GetForCurrentThread()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cursor) {
|
||||
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
|
||||
CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
|
||||
} else {
|
||||
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
WINRT_UsingRelativeMouseMode = enabled;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_InitMouse(_THIS)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
/* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
|
||||
the following features, AFAIK:
|
||||
- custom cursors (multiple system cursors are, however, available)
|
||||
- programmatically moveable cursors
|
||||
*/
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
//mouse->CreateCursor = WINRT_CreateCursor;
|
||||
mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
|
||||
mouse->ShowCursor = WINRT_ShowCursor;
|
||||
mouse->FreeCursor = WINRT_FreeCursor;
|
||||
//mouse->WarpMouse = WINRT_WarpMouse;
|
||||
mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
|
||||
|
||||
SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_QuitMouse(_THIS)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
40
Engine/lib/sdl/src/video/winrt/SDL_winrtmouse_c.h
Normal file
40
Engine/lib/sdl/src/video/winrt/SDL_winrtmouse_c.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_winrtmouse_h
|
||||
#define _SDL_winrtmouse_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void WINRT_InitMouse(_THIS);
|
||||
extern void WINRT_QuitMouse(_THIS);
|
||||
extern SDL_bool WINRT_UsingRelativeMouseMode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SDL_windowsmouse_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
50
Engine/lib/sdl/src/video/winrt/SDL_winrtopengles.cpp
Normal file
50
Engine/lib/sdl/src/video/winrt/SDL_winrtopengles.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
// TODO: WinRT, make this file compile via C code
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
extern "C" {
|
||||
#include "SDL_winrtopengles.h"
|
||||
}
|
||||
|
||||
#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3)
|
||||
|
||||
extern "C" int
|
||||
WINRT_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
SDL_EGL_CreateContext_impl(WINRT)
|
||||
SDL_EGL_SwapWindow_impl(WINRT)
|
||||
SDL_EGL_MakeCurrent_impl(WINRT)
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
48
Engine/lib/sdl/src/video/winrt/SDL_winrtopengles.h
Normal file
48
Engine/lib/sdl/src/video/winrt/SDL_winrtopengles.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_winrtopengles_h
|
||||
#define _SDL_winrtopengles_h
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
||||
#define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
|
||||
#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext
|
||||
|
||||
extern int WINRT_GLES_LoadLibrary(_THIS, const char *path);
|
||||
extern SDL_GLContext WINRT_GLES_CreateContext(_THIS, SDL_Window * window);
|
||||
extern void WINRT_GLES_SwapWindow(_THIS, SDL_Window * window);
|
||||
extern int WINRT_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
#endif /* _SDL_winrtopengles_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
394
Engine/lib/sdl/src/video/winrt/SDL_winrtpointerinput.cpp
Normal file
394
Engine/lib/sdl/src/video/winrt/SDL_winrtpointerinput.cpp
Normal file
|
|
@ -0,0 +1,394 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/* SDL includes */
|
||||
#include "SDL_winrtevents_c.h"
|
||||
#include "SDL_winrtmouse_c.h"
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
}
|
||||
|
||||
/* File-specific globals: */
|
||||
static SDL_TouchID WINRT_TouchID = 1;
|
||||
static unsigned int WINRT_LeftFingerDown = 0;
|
||||
|
||||
|
||||
void
|
||||
WINRT_InitTouch(_THIS)
|
||||
{
|
||||
SDL_AddTouch(WINRT_TouchID, "");
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Applies necessary geometric transformations to raw cursor positions:
|
||||
//
|
||||
Windows::Foundation::Point
|
||||
WINRT_TransformCursorPosition(SDL_Window * window,
|
||||
Windows::Foundation::Point rawPosition,
|
||||
WINRT_CursorNormalizationType normalization)
|
||||
{
|
||||
using namespace Windows::UI::Core;
|
||||
using namespace Windows::Graphics::Display;
|
||||
|
||||
if (!window) {
|
||||
return rawPosition;
|
||||
}
|
||||
|
||||
SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
|
||||
if (windowData->coreWindow == nullptr) {
|
||||
// For some reason, the window isn't associated with a CoreWindow.
|
||||
// This might end up being the case as XAML support is extended.
|
||||
// For now, if there's no CoreWindow attached to the SDL_Window,
|
||||
// don't do any transforms.
|
||||
|
||||
// TODO, WinRT: make sure touch input coordinate ranges are correct when using XAML support
|
||||
return rawPosition;
|
||||
}
|
||||
|
||||
// The CoreWindow can only be accessed on certain thread(s).
|
||||
SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
|
||||
|
||||
CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
|
||||
Windows::Foundation::Point outputPosition;
|
||||
|
||||
// Compute coordinates normalized from 0..1.
|
||||
// If the coordinates need to be sized to the SDL window,
|
||||
// we'll do that after.
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
|
||||
outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
|
||||
#else
|
||||
switch (DisplayProperties::CurrentOrientation)
|
||||
{
|
||||
case DisplayOrientations::Portrait:
|
||||
outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
|
||||
outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
|
||||
break;
|
||||
case DisplayOrientations::PortraitFlipped:
|
||||
outputPosition.X = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
|
||||
outputPosition.Y = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
|
||||
break;
|
||||
case DisplayOrientations::Landscape:
|
||||
outputPosition.X = rawPosition.Y / nativeWindow->Bounds.Height;
|
||||
outputPosition.Y = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
|
||||
break;
|
||||
case DisplayOrientations::LandscapeFlipped:
|
||||
outputPosition.X = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
|
||||
outputPosition.Y = rawPosition.X / nativeWindow->Bounds.Width;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (normalization == TransformToSDLWindowSize) {
|
||||
outputPosition.X *= ((float32) window->w);
|
||||
outputPosition.Y *= ((float32) window->h);
|
||||
}
|
||||
|
||||
return outputPosition;
|
||||
}
|
||||
|
||||
static inline int
|
||||
_lround(float arg)
|
||||
{
|
||||
if (arg >= 0.0f) {
|
||||
return (int)floor(arg + 0.5f);
|
||||
} else {
|
||||
return (int)ceil(arg - 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
Uint8
|
||||
WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
|
||||
{
|
||||
using namespace Windows::UI::Input;
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
return SDL_BUTTON_LEFT;
|
||||
#else
|
||||
switch (pt->Properties->PointerUpdateKind)
|
||||
{
|
||||
case PointerUpdateKind::LeftButtonPressed:
|
||||
case PointerUpdateKind::LeftButtonReleased:
|
||||
return SDL_BUTTON_LEFT;
|
||||
|
||||
case PointerUpdateKind::RightButtonPressed:
|
||||
case PointerUpdateKind::RightButtonReleased:
|
||||
return SDL_BUTTON_RIGHT;
|
||||
|
||||
case PointerUpdateKind::MiddleButtonPressed:
|
||||
case PointerUpdateKind::MiddleButtonReleased:
|
||||
return SDL_BUTTON_MIDDLE;
|
||||
|
||||
case PointerUpdateKind::XButton1Pressed:
|
||||
case PointerUpdateKind::XButton1Released:
|
||||
return SDL_BUTTON_X1;
|
||||
|
||||
case PointerUpdateKind::XButton2Pressed:
|
||||
case PointerUpdateKind::XButton2Released:
|
||||
return SDL_BUTTON_X2;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//const char *
|
||||
//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
|
||||
//{
|
||||
// using namespace Windows::UI::Input;
|
||||
//
|
||||
// switch (kind)
|
||||
// {
|
||||
// case PointerUpdateKind::Other:
|
||||
// return "Other";
|
||||
// case PointerUpdateKind::LeftButtonPressed:
|
||||
// return "LeftButtonPressed";
|
||||
// case PointerUpdateKind::LeftButtonReleased:
|
||||
// return "LeftButtonReleased";
|
||||
// case PointerUpdateKind::RightButtonPressed:
|
||||
// return "RightButtonPressed";
|
||||
// case PointerUpdateKind::RightButtonReleased:
|
||||
// return "RightButtonReleased";
|
||||
// case PointerUpdateKind::MiddleButtonPressed:
|
||||
// return "MiddleButtonPressed";
|
||||
// case PointerUpdateKind::MiddleButtonReleased:
|
||||
// return "MiddleButtonReleased";
|
||||
// case PointerUpdateKind::XButton1Pressed:
|
||||
// return "XButton1Pressed";
|
||||
// case PointerUpdateKind::XButton1Released:
|
||||
// return "XButton1Released";
|
||||
// case PointerUpdateKind::XButton2Pressed:
|
||||
// return "XButton2Pressed";
|
||||
// case PointerUpdateKind::XButton2Released:
|
||||
// return "XButton2Released";
|
||||
// }
|
||||
//
|
||||
// return "";
|
||||
//}
|
||||
|
||||
static bool
|
||||
WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||
{
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
return true;
|
||||
#else
|
||||
using namespace Windows::Devices::Input;
|
||||
switch (pointerPoint->PointerDevice->PointerDeviceType) {
|
||||
case PointerDeviceType::Touch:
|
||||
case PointerDeviceType::Pen:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||
{
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
|
||||
|
||||
if ( ! WINRT_IsTouchEvent(pointerPoint)) {
|
||||
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
|
||||
} else {
|
||||
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
|
||||
Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
|
||||
|
||||
if (!WINRT_LeftFingerDown) {
|
||||
if (button) {
|
||||
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
|
||||
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
|
||||
}
|
||||
|
||||
WINRT_LeftFingerDown = pointerPoint->PointerId;
|
||||
}
|
||||
|
||||
SDL_SendTouch(
|
||||
WINRT_TouchID,
|
||||
(SDL_FingerID) pointerPoint->PointerId,
|
||||
SDL_TRUE,
|
||||
normalizedPoint.X,
|
||||
normalizedPoint.Y,
|
||||
pointerPoint->Properties->Pressure);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||
{
|
||||
if (!window || WINRT_UsingRelativeMouseMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
|
||||
Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
|
||||
|
||||
if ( ! WINRT_IsTouchEvent(pointerPoint)) {
|
||||
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
|
||||
} else if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
|
||||
if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
|
||||
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
|
||||
}
|
||||
|
||||
SDL_SendTouchMotion(
|
||||
WINRT_TouchID,
|
||||
(SDL_FingerID) pointerPoint->PointerId,
|
||||
normalizedPoint.X,
|
||||
normalizedPoint.Y,
|
||||
pointerPoint->Properties->Pressure);
|
||||
}
|
||||
}
|
||||
|
||||
void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||
{
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
|
||||
|
||||
if (!WINRT_IsTouchEvent(pointerPoint)) {
|
||||
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
|
||||
} else {
|
||||
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
|
||||
|
||||
if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
|
||||
if (button) {
|
||||
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
|
||||
}
|
||||
WINRT_LeftFingerDown = 0;
|
||||
}
|
||||
|
||||
SDL_SendTouch(
|
||||
WINRT_TouchID,
|
||||
(SDL_FingerID) pointerPoint->PointerId,
|
||||
SDL_FALSE,
|
||||
normalizedPoint.X,
|
||||
normalizedPoint.Y,
|
||||
pointerPoint->Properties->Pressure);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||
{
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: This may need to accumulate deltas up to WHEEL_DELTA
|
||||
short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
|
||||
SDL_SendMouseWheel(window, 0, 0, motion);
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args)
|
||||
{
|
||||
if (!window || !WINRT_UsingRelativeMouseMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
|
||||
// Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
|
||||
// MouseDelta field often reports very large values. More information
|
||||
// on this can be found at the following pages on MSDN:
|
||||
// - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
|
||||
// - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
|
||||
//
|
||||
// The values do not appear to be as large when running on some systems,
|
||||
// most notably a Surface RT. Furthermore, the values returned by
|
||||
// CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
|
||||
// method, do not ever appear to be large, even when MouseEventArgs'
|
||||
// MouseDelta is reporting to the contrary.
|
||||
//
|
||||
// On systems with the large-values behavior, it appears that the values
|
||||
// get reported as if the screen's size is 65536 units in both the X and Y
|
||||
// dimensions. This can be viewed by using Windows' now-private, "Raw Input"
|
||||
// APIs. (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
|
||||
//
|
||||
// MSDN's documentation on MouseEventArgs' MouseDelta field (at
|
||||
// http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
|
||||
// does not seem to indicate (to me) that its values should be so large. It
|
||||
// says that its values should be a "change in screen location". I could
|
||||
// be misinterpreting this, however a post on MSDN from a Microsoft engineer (see:
|
||||
// http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
|
||||
// indicates that these values are in DIPs, which is the same unit used
|
||||
// by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
|
||||
// property. See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
|
||||
// for details.)
|
||||
//
|
||||
// To note, PointerMoved events are sent a 'RawPosition' value (via the
|
||||
// CurrentPoint property in MouseEventArgs), however these do not seem
|
||||
// to exhibit the same large-value behavior.
|
||||
//
|
||||
// The values passed via PointerMoved events can't always be used for relative
|
||||
// mouse motion, unfortunately. Its values are bound to the cursor's position,
|
||||
// which stops when it hits one of the screen's edges. This can be a problem in
|
||||
// first person shooters, whereby it is normal for mouse motion to travel far
|
||||
// along any one axis for a period of time. MouseMoved events do not have the
|
||||
// screen-bounding limitation, and can be used regardless of where the system's
|
||||
// cursor is.
|
||||
//
|
||||
// One possible workaround would be to programmatically set the cursor's
|
||||
// position to the screen's center (when SDL's relative mouse mode is enabled),
|
||||
// however WinRT does not yet seem to have the ability to set the cursor's
|
||||
// position via a public API. Win32 did this via an API call, SetCursorPos,
|
||||
// however WinRT makes this function be private. Apps that use it won't get
|
||||
// approved for distribution in the Windows Store. I've yet to be able to find
|
||||
// a suitable, store-friendly counterpart for WinRT.
|
||||
//
|
||||
// There may be some room for a workaround whereby OnPointerMoved's values
|
||||
// are compared to the values from OnMouseMoved in order to detect
|
||||
// when this bug is active. A suitable transformation could then be made to
|
||||
// OnMouseMoved's values. For now, however, the system-reported values are sent
|
||||
// to SDL with minimal transformation: from native screen coordinates (in DIPs)
|
||||
// to SDL window coordinates.
|
||||
//
|
||||
const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
|
||||
const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs, TransformToSDLWindowSize);
|
||||
SDL_SendMouseMotion(
|
||||
window,
|
||||
0,
|
||||
1,
|
||||
_lround(mouseDeltaInSDLWindowCoords.X),
|
||||
_lround(mouseDeltaInSDLWindowCoords.Y));
|
||||
}
|
||||
|
||||
#endif // SDL_VIDEO_DRIVER_WINRT
|
||||
409
Engine/lib/sdl/src/video/winrt/SDL_winrtvideo.cpp
Normal file
409
Engine/lib/sdl/src/video/winrt/SDL_winrtvideo.cpp
Normal file
|
|
@ -0,0 +1,409 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/* WinRT SDL video driver implementation
|
||||
|
||||
Initial work on this was done by David Ludwig (dludwig@pobox.com), and
|
||||
was based off of SDL's "dummy" video driver.
|
||||
*/
|
||||
|
||||
/* Windows includes */
|
||||
#include <agile.h>
|
||||
using namespace Windows::UI::Core;
|
||||
|
||||
|
||||
/* SDL includes */
|
||||
extern "C" {
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_mouse.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_pixels_c.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "../../render/SDL_sysrender.h"
|
||||
#include "SDL_syswm.h"
|
||||
#include "SDL_winrtopengles.h"
|
||||
}
|
||||
|
||||
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
|
||||
#include "../../core/winrt/SDL_winrtapp_xaml.h"
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
#include "SDL_winrtevents_c.h"
|
||||
#include "SDL_winrtmouse_c.h"
|
||||
#include "SDL_main.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
|
||||
/* Initialization/Query functions */
|
||||
static int WINRT_VideoInit(_THIS);
|
||||
static int WINRT_InitModes(_THIS);
|
||||
static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
static void WINRT_VideoQuit(_THIS);
|
||||
|
||||
|
||||
/* Window functions */
|
||||
static int WINRT_CreateWindow(_THIS, SDL_Window * window);
|
||||
static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
|
||||
static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
|
||||
|
||||
|
||||
/* SDL-internal globals: */
|
||||
SDL_Window * WINRT_GlobalSDLWindow = NULL;
|
||||
SDL_VideoDevice * WINRT_GlobalSDLVideoDevice = NULL;
|
||||
|
||||
|
||||
/* WinRT driver bootstrap functions */
|
||||
|
||||
static int
|
||||
WINRT_Available(void)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
WINRT_DeleteDevice(SDL_VideoDevice * device)
|
||||
{
|
||||
if (device == WINRT_GlobalSDLVideoDevice) {
|
||||
WINRT_GlobalSDLVideoDevice = NULL;
|
||||
}
|
||||
SDL_free(device);
|
||||
}
|
||||
|
||||
static SDL_VideoDevice *
|
||||
WINRT_CreateDevice(int devindex)
|
||||
{
|
||||
SDL_VideoDevice *device;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
if (!device) {
|
||||
SDL_OutOfMemory();
|
||||
if (device) {
|
||||
SDL_free(device);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
device->VideoInit = WINRT_VideoInit;
|
||||
device->VideoQuit = WINRT_VideoQuit;
|
||||
device->CreateWindow = WINRT_CreateWindow;
|
||||
device->DestroyWindow = WINRT_DestroyWindow;
|
||||
device->SetDisplayMode = WINRT_SetDisplayMode;
|
||||
device->PumpEvents = WINRT_PumpEvents;
|
||||
device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
|
||||
#ifdef SDL_VIDEO_OPENGL_EGL
|
||||
device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
|
||||
device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
|
||||
device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
|
||||
device->GL_CreateContext = WINRT_GLES_CreateContext;
|
||||
device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
|
||||
device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
|
||||
device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
|
||||
device->GL_SwapWindow = WINRT_GLES_SwapWindow;
|
||||
device->GL_DeleteContext = WINRT_GLES_DeleteContext;
|
||||
#endif
|
||||
device->free = WINRT_DeleteDevice;
|
||||
WINRT_GlobalSDLVideoDevice = device;
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
#define WINRTVID_DRIVER_NAME "winrt"
|
||||
VideoBootStrap WINRT_bootstrap = {
|
||||
WINRTVID_DRIVER_NAME, "SDL WinRT video driver",
|
||||
WINRT_Available, WINRT_CreateDevice
|
||||
};
|
||||
|
||||
int
|
||||
WINRT_VideoInit(_THIS)
|
||||
{
|
||||
if (WINRT_InitModes(_this) < 0) {
|
||||
return -1;
|
||||
}
|
||||
WINRT_InitMouse(_this);
|
||||
WINRT_InitTouch(_this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode)
|
||||
{
|
||||
SDL_DisplayModeData * driverdata;
|
||||
|
||||
using namespace Windows::Graphics::Display;
|
||||
|
||||
// Go no further if a native window cannot be accessed. This can happen,
|
||||
// for example, if this function is called from certain threads, such as
|
||||
// the SDL/XAML thread.
|
||||
if (!CoreWindow::GetForCurrentThread()) {
|
||||
return SDL_SetError("SDL/WinRT display modes cannot be calculated outside of the main thread, such as in SDL's XAML thread");
|
||||
}
|
||||
|
||||
// Calculate the display size given the window size, taking into account
|
||||
// the current display's DPI:
|
||||
#if NTDDI_VERSION > NTDDI_WIN8
|
||||
const float currentDPI = DisplayInformation::GetForCurrentView()->LogicalDpi;
|
||||
#else
|
||||
const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi;
|
||||
#endif
|
||||
const float dipsPerInch = 96.0f;
|
||||
const int w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
|
||||
const int h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
|
||||
if (w == 0 || w == h) {
|
||||
return SDL_SetError("Unable to calculate the WinRT window/display's size");
|
||||
}
|
||||
|
||||
// Create a driverdata field:
|
||||
driverdata = (SDL_DisplayModeData *) SDL_malloc(sizeof(*driverdata));
|
||||
if (!driverdata) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_zerop(driverdata);
|
||||
|
||||
// Fill in most fields:
|
||||
SDL_zerop(mode);
|
||||
mode->format = SDL_PIXELFORMAT_RGB888;
|
||||
mode->refresh_rate = 0; // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
|
||||
mode->w = w;
|
||||
mode->h = h;
|
||||
mode->driverdata = driverdata;
|
||||
#if NTDDI_VERSION > NTDDI_WIN8
|
||||
driverdata->currentOrientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
|
||||
#else
|
||||
driverdata->currentOrientation = DisplayProperties::CurrentOrientation;
|
||||
#endif
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
// On Windows Phone, the native window's size is always in portrait,
|
||||
// regardless of the device's orientation. This is in contrast to
|
||||
// Windows 8/RT, which will resize the native window as the device's
|
||||
// orientation changes. In order to compensate for this behavior,
|
||||
// on Windows Phone, the mode's width and height will be swapped when
|
||||
// the device is in a landscape (non-portrait) mode.
|
||||
switch (DisplayProperties::CurrentOrientation) {
|
||||
case DisplayOrientations::Landscape:
|
||||
case DisplayOrientations::LandscapeFlipped:
|
||||
{
|
||||
const int tmp = mode->h;
|
||||
mode->h = mode->w;
|
||||
mode->w = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src)
|
||||
{
|
||||
SDL_DisplayModeData * driverdata;
|
||||
driverdata = (SDL_DisplayModeData *) SDL_malloc(sizeof(*driverdata));
|
||||
if (!driverdata) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memcpy(driverdata, src->driverdata, sizeof(SDL_DisplayModeData));
|
||||
SDL_memcpy(dest, src, sizeof(SDL_DisplayMode));
|
||||
dest->driverdata = driverdata;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WINRT_InitModes(_THIS)
|
||||
{
|
||||
// Retrieve the display mode:
|
||||
SDL_DisplayMode mode, desktop_mode;
|
||||
if (WINRT_CalcDisplayModeUsingNativeWindow(&mode) != 0) {
|
||||
return -1; // If WINRT_CalcDisplayModeUsingNativeWindow fails, it'll already have set the SDL error
|
||||
}
|
||||
|
||||
if (WINRT_DuplicateDisplayMode(&desktop_mode, &mode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (SDL_AddBasicVideoDisplay(&desktop_mode) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_AddDisplayMode(&_this->displays[0], &mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_VideoQuit(_THIS)
|
||||
{
|
||||
WINRT_QuitMouse(_this);
|
||||
}
|
||||
|
||||
int
|
||||
WINRT_CreateWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
// Make sure that only one window gets created, at least until multimonitor
|
||||
// support is added.
|
||||
if (WINRT_GlobalSDLWindow != NULL) {
|
||||
SDL_SetError("WinRT only supports one window");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_WindowData *data = new SDL_WindowData;
|
||||
if (!data) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
window->driverdata = data;
|
||||
data->sdlWindow = window;
|
||||
|
||||
/* To note, when XAML support is enabled, access to the CoreWindow will not
|
||||
be possible, at least not via the SDL/XAML thread. Attempts to access it
|
||||
from there will throw exceptions. As such, the SDL_WindowData's
|
||||
'coreWindow' field will only be set (to a non-null value) if XAML isn't
|
||||
enabled.
|
||||
*/
|
||||
if (!WINRT_XAMLWasEnabled) {
|
||||
data->coreWindow = CoreWindow::GetForCurrentThread();
|
||||
}
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
/* Setup the EGL surface, but only if OpenGL ES 2 was requested. */
|
||||
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
||||
/* OpenGL ES 2 wasn't requested. Don't set up an EGL surface. */
|
||||
data->egl_surface = EGL_NO_SURFACE;
|
||||
} else {
|
||||
/* OpenGL ES 2 was reuqested. Set up an EGL surface. */
|
||||
|
||||
/* HACK: ANGLE/WinRT currently uses non-pointer, C++ objects to represent
|
||||
native windows. The object only contains a single pointer to a COM
|
||||
interface pointer, which on x86 appears to be castable to the object
|
||||
without apparant problems. On other platforms, notable ARM and x64,
|
||||
doing so will cause a crash. To avoid this crash, we'll bypass
|
||||
SDL's normal call to eglCreateWindowSurface, which is invoked from C
|
||||
code, and call it here, where an appropriate C++ object may be
|
||||
passed in.
|
||||
*/
|
||||
typedef EGLSurface (*eglCreateWindowSurfaceFunction)(EGLDisplay dpy, EGLConfig config,
|
||||
Microsoft::WRL::ComPtr<IUnknown> win,
|
||||
const EGLint *attrib_list);
|
||||
eglCreateWindowSurfaceFunction WINRT_eglCreateWindowSurface =
|
||||
(eglCreateWindowSurfaceFunction) _this->egl_data->eglCreateWindowSurface;
|
||||
|
||||
Microsoft::WRL::ComPtr<IUnknown> nativeWindow = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
|
||||
data->egl_surface = WINRT_eglCreateWindowSurface(
|
||||
_this->egl_data->egl_display,
|
||||
_this->egl_data->egl_config,
|
||||
nativeWindow, NULL);
|
||||
if (data->egl_surface == NULL) {
|
||||
// TODO, WinRT: see if eglCreateWindowSurface, or its callee(s), sets an error message. If so, attach it to the SDL error.
|
||||
return SDL_SetError("eglCreateWindowSurface failed");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure the window is considered to be positioned at {0,0},
|
||||
and is considered fullscreen, shown, and the like.
|
||||
*/
|
||||
window->x = 0;
|
||||
window->y = 0;
|
||||
window->flags =
|
||||
SDL_WINDOW_FULLSCREEN |
|
||||
SDL_WINDOW_SHOWN |
|
||||
SDL_WINDOW_BORDERLESS |
|
||||
SDL_WINDOW_MAXIMIZED |
|
||||
SDL_WINDOW_INPUT_GRABBED;
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
if (data->egl_surface) {
|
||||
window->flags |= SDL_WINDOW_OPENGL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* WinRT does not, as of this writing, appear to support app-adjustable
|
||||
window sizes. Set the window size to whatever the native WinRT
|
||||
CoreWindow is set at.
|
||||
|
||||
TODO, WinRT: if and when non-fullscreen XAML control support is added to SDL, consider making those resizable via SDL_Window's interfaces.
|
||||
*/
|
||||
window->w = _this->displays[0].current_mode.w;
|
||||
window->h = _this->displays[0].current_mode.h;
|
||||
|
||||
/* For now, treat WinRT apps as if they always have focus.
|
||||
TODO, WinRT: try tracking keyboard and mouse focus state with respect to snapped apps
|
||||
*/
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SetKeyboardFocus(window);
|
||||
|
||||
/* Make sure the WinRT app's IFramworkView can post events on
|
||||
behalf of SDL:
|
||||
*/
|
||||
WINRT_GlobalSDLWindow = window;
|
||||
|
||||
/* All done! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if (WINRT_GlobalSDLWindow == window) {
|
||||
WINRT_GlobalSDLWindow = NULL;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
// Delete the internal window data:
|
||||
delete data;
|
||||
data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
||||
{
|
||||
SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if (info->version.major <= SDL_MAJOR_VERSION) {
|
||||
info->subsystem = SDL_SYSWM_WINRT;
|
||||
info->info.winrt.window = reinterpret_cast<IInspectable *>(data->coreWindow.Get());
|
||||
return SDL_TRUE;
|
||||
} else {
|
||||
SDL_SetError("Application not compiled with SDL %d.%d\n",
|
||||
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
79
Engine/lib/sdl/src/video/winrt/SDL_winrtvideo_cpp.h
Normal file
79
Engine/lib/sdl/src/video/winrt/SDL_winrtvideo_cpp.h
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* Windows includes: */
|
||||
#include <windows.h>
|
||||
#ifdef __cplusplus_winrt
|
||||
#include <agile.h>
|
||||
#endif
|
||||
|
||||
/* SDL includes: */
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_events.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
}
|
||||
|
||||
|
||||
/* The global, WinRT, SDL Window.
|
||||
For now, SDL/WinRT only supports one window (due to platform limitations of
|
||||
WinRT.
|
||||
*/
|
||||
extern SDL_Window * WINRT_GlobalSDLWindow;
|
||||
|
||||
/* The global, WinRT, video device. */
|
||||
extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice;
|
||||
|
||||
/* Creates a display mode for Plain Direct3D (non-XAML) apps, using the lone, native window's settings.
|
||||
|
||||
Pass in an allocated SDL_DisplayMode field to store the data in.
|
||||
|
||||
This function will return 0 on success, -1 on failure.
|
||||
|
||||
If this function succeeds, be sure to call SDL_free on the
|
||||
SDL_DisplayMode's driverdata field.
|
||||
*/
|
||||
extern int WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode);
|
||||
|
||||
/* Duplicates a display mode, copying over driverdata as necessary */
|
||||
extern int WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src);
|
||||
|
||||
/* Display mode internals */
|
||||
typedef struct
|
||||
{
|
||||
Windows::Graphics::Display::DisplayOrientations currentOrientation;
|
||||
} SDL_DisplayModeData;
|
||||
|
||||
#ifdef __cplusplus_winrt
|
||||
|
||||
/* Internal window data */
|
||||
struct SDL_WindowData
|
||||
{
|
||||
SDL_Window *sdlWindow;
|
||||
Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
|
||||
#ifdef SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // ifdef __cplusplus_winrt
|
||||
Loading…
Add table
Add a link
Reference in a new issue