21 #include "../../SDL_internal.h" 43 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 50 #include "../../SDL_internal.h" 58 #include "../../video/SDL_sysvideo.h" 60 #include "../../events/SDL_events_c.h" 61 #include "../../events/SDL_keyboard_c.h" 62 #include "../../events/SDL_mouse_c.h" 63 #include "../../events/SDL_windowevents_c.h" 64 #include "../../render/SDL_sysrender.h" 65 #include "../windows/SDL_windows.h" 68 #include "../../video/winrt/SDL_winrtevents_c.h" 69 #include "../../video/winrt/SDL_winrtvideo_cpp.h" 73 #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED 97 ref class SDLApplicationSource
sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
100 virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
103 IFrameworkView^ SDLApplicationSource::CreateView()
109 SDL_WinRTApp ^ app =
ref new SDL_WinRTApp();
120 auto direct3DApplicationSource =
ref new SDLApplicationSource();
135 if ((oldValue ==
NULL) && (newValue ==
NULL)) {
141 unsigned int orientationFlags = 0;
143 std::istringstream tokenizer(newValue);
144 while (!tokenizer.eof()) {
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;
160 if (!orientationFlags) {
162 orientationFlags = (
unsigned int) ( \
163 DisplayOrientations::Landscape |
164 DisplayOrientations::LandscapeFlipped |
165 DisplayOrientations::Portrait |
166 DisplayOrientations::PortraitFlipped);
183 WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
189 CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
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);
200 #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8) 210 const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
211 switch (currentOrientation) {
212 case DisplayOrientations::Landscape:
213 case DisplayOrientations::LandscapeFlipped: {
238 SDL_WinRTApp::SDL_WinRTApp() :
239 m_windowClosed(
false),
240 m_windowVisible(
true)
244 void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
246 applicationView->Activated +=
247 ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(
this, &SDL_WinRTApp::OnAppActivated);
249 CoreApplication::Suspending +=
250 ref new EventHandler<SuspendingEventArgs^>(
this, &SDL_WinRTApp::OnSuspending);
252 CoreApplication::Resuming +=
253 ref new EventHandler<Platform::Object^>(
this, &SDL_WinRTApp::OnResuming);
255 CoreApplication::Exiting +=
256 ref new EventHandler<Platform::Object^>(
this, &SDL_WinRTApp::OnExiting);
259 #if NTDDI_VERSION > NTDDI_WIN8 260 void SDL_WinRTApp::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
262 void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
265 #if LOG_ORIENTATION_EVENTS==1 267 CoreWindow^
window = CoreWindow::GetForCurrentThread();
269 SDL_Log(
"%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Bounds={%f,%f,%f,%f}\n",
271 WINRT_DISPLAY_PROPERTY(CurrentOrientation),
272 WINRT_DISPLAY_PROPERTY(NativeOrientation),
273 WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
276 window->Bounds.Width,
277 window->Bounds.Height);
279 SDL_Log(
"%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
281 WINRT_DISPLAY_PROPERTY(CurrentOrientation),
282 WINRT_DISPLAY_PROPERTY(NativeOrientation),
283 WINRT_DISPLAY_PROPERTY(AutoRotationPreferences));
290 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 303 int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
304 int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
311 void SDL_WinRTApp::SetWindow(CoreWindow^
window)
313 #if LOG_WINDOW_EVENTS==1 314 SDL_Log(
"%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window bounds={%f, %f, %f,%f}\n",
316 WINRT_DISPLAY_PROPERTY(CurrentOrientation),
317 WINRT_DISPLAY_PROPERTY(NativeOrientation),
318 WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
321 window->Bounds.Width,
322 window->Bounds.Height);
325 window->SizeChanged +=
326 ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(
this, &SDL_WinRTApp::OnWindowSizeChanged);
328 window->VisibilityChanged +=
329 ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(
this, &SDL_WinRTApp::OnVisibilityChanged);
332 ref new TypedEventHandler<CoreWindow^, WindowActivatedEventArgs^>(
this, &SDL_WinRTApp::OnWindowActivated);
335 ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(
this, &SDL_WinRTApp::OnWindowClosed);
337 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP 338 window->PointerCursor =
ref new CoreCursor(CoreCursorType::Arrow, 0);
341 window->PointerPressed +=
342 ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
this, &SDL_WinRTApp::OnPointerPressed);
344 window->PointerMoved +=
345 ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
this, &SDL_WinRTApp::OnPointerMoved);
347 window->PointerReleased +=
348 ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
this, &SDL_WinRTApp::OnPointerReleased);
350 window->PointerEntered +=
351 ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
this, &SDL_WinRTApp::OnPointerEntered);
353 window->PointerExited +=
354 ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
this, &SDL_WinRTApp::OnPointerExited);
356 window->PointerWheelChanged +=
357 ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
this, &SDL_WinRTApp::OnPointerWheelChanged);
359 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP 361 Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
362 ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(
this, &SDL_WinRTApp::OnMouseMoved);
366 ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(
this, &SDL_WinRTApp::OnKeyDown);
369 ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(
this, &SDL_WinRTApp::OnKeyUp);
371 window->CharacterReceived +=
372 ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(
this, &SDL_WinRTApp::OnCharacterReceived);
374 #if NTDDI_VERSION >= NTDDI_WIN10 375 Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->BackRequested +=
376 ref new EventHandler<BackRequestedEventArgs^>(
this, &SDL_WinRTApp::OnBackButtonPressed);
377 #elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 378 HardwareButtons::BackPressed +=
379 ref new EventHandler<BackPressedEventArgs^>(
this, &SDL_WinRTApp::OnBackButtonPressed);
382 #if NTDDI_VERSION > NTDDI_WIN8 383 DisplayInformation::GetForCurrentView()->OrientationChanged +=
384 ref new TypedEventHandler<Windows::Graphics::Display::DisplayInformation^, Object^>(
this, &SDL_WinRTApp::OnOrientationChanged);
386 DisplayProperties::OrientationChanged +=
387 ref new DisplayPropertiesEventHandler(
this, &SDL_WinRTApp::OnOrientationChanged);
394 #if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10) // for Windows 8/8.1/RT apps... (and not Phone apps) 398 using namespace Windows::UI::ApplicationSettings;
399 SettingsPane::GetForCurrentView()->CommandsRequested +=
400 ref new TypedEventHandler<SettingsPane^, SettingsPaneCommandsRequestedEventArgs^>
401 (
this, &SDL_WinRTApp::OnSettingsPaneCommandsRequested);
405 void SDL_WinRTApp::Load(Platform::String^ entryPoint)
427 if (events[
i].window.event == windowEventID) {
434 bool SDL_WinRTApp::ShouldWaitForAppResumeEvents()
437 if (m_windowVisible) {
461 void SDL_WinRTApp::PumpEvents()
463 if (!m_windowClosed) {
464 if (!ShouldWaitForAppResumeEvents()) {
469 CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
478 CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
483 void SDL_WinRTApp::Uninitialize()
487 #if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10) 488 void SDL_WinRTApp::OnSettingsPaneCommandsRequested(
489 Windows::UI::ApplicationSettings::SettingsPane ^
p,
490 Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args)
492 using namespace Platform;
493 using namespace Windows::UI::ApplicationSettings;
494 using namespace Windows::UI::Popups;
496 String ^privacyPolicyURL =
nullptr;
497 String ^privacyPolicyLabel =
nullptr;
498 const char *tmpHintValue =
NULL;
499 wchar_t *tmpStr =
NULL;
503 if (tmpHintValue && tmpHintValue[0] !=
'\0') {
506 privacyPolicyURL =
ref new String(tmpStr);
512 if (tmpHintValue && tmpHintValue[0] !=
'\0') {
514 privacyPolicyLabel =
ref new String(tmpStr);
517 privacyPolicyLabel =
ref new String(L
"Privacy Policy");
522 auto cmd =
ref new SettingsCommand(L
"privacyPolicy", privacyPolicyLabel,
523 ref new UICommandInvokedHandler([=](IUICommand ^) {
524 Windows::System::Launcher::LaunchUriAsync(
ref new Uri(privacyPolicyURL));
526 args->Request->ApplicationCommands->Append(cmd);
529 #endif // if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10) 531 void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
533 #if LOG_WINDOW_EVENTS==1 534 SDL_Log(
"%s, size={%f,%f}, bounds={%f,%f,%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
536 args->Size.Width, args->Size.Height,
537 sender->Bounds.X, sender->Bounds.Y, sender->Bounds.Width, sender->Bounds.Height,
538 WINRT_DISPLAY_PROPERTY(CurrentOrientation),
539 WINRT_DISPLAY_PROPERTY(NativeOrientation),
540 WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
547 void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
549 #if LOG_WINDOW_EVENTS==1 550 SDL_Log(
"%s, visible?=%s, bounds={%f,%f,%f,%f}, WINRT_GlobalSDLWindow?=%s\n",
552 (args->Visible ?
"yes" :
"no"),
553 sender->Bounds.X, sender->Bounds.Y,
554 sender->Bounds.Width, sender->Bounds.Height,
558 m_windowVisible = args->Visible;
586 void SDL_WinRTApp::OnWindowActivated(CoreWindow^ sender, WindowActivatedEventArgs^ args)
588 #if LOG_WINDOW_EVENTS==1 589 SDL_Log(
"%s, WINRT_GlobalSDLWindow?=%s\n\n",
599 sender->CustomProperties->Insert(
"SDLHelperWindowActivationState", args->WindowActivationState);
603 if (args->WindowActivationState != CoreWindowActivationState::Deactivated) {
618 #if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION >= NTDDI_WINBLUE) 619 Point cursorPos = WINRT_TransformCursorPosition(window, sender->PointerPosition, TransformToSDLWindowSize);
648 void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
650 #if LOG_WINDOW_EVENTS==1 653 m_windowClosed =
true;
656 void SDL_WinRTApp::OnAppActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
658 CoreWindow::GetForCurrentThread()->Activate();
661 void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
677 SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
678 create_task([
this, deferral]()
692 #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED 696 D3D11_Trim(renderer);
701 deferral->Complete();
705 void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
714 void SDL_WinRTApp::OnExiting(Platform::Object^ sender, Platform::Object^ args)
720 WINRT_LogPointerEvent(
const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
722 Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
723 SDL_Log(
"%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
725 pt->Position.X, pt->Position.Y,
726 transformedPoint.X, transformedPoint.Y,
727 pt->Properties->MouseWheelDelta,
730 WINRT_GetSDLButtonForPointerPoint(pt));
733 void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
735 #if LOG_POINTER_EVENTS 742 void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
744 #if LOG_POINTER_EVENTS 751 void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
753 #if LOG_POINTER_EVENTS 760 void SDL_WinRTApp::OnPointerEntered(CoreWindow^ sender, PointerEventArgs^ args)
762 #if LOG_POINTER_EVENTS 769 void SDL_WinRTApp::OnPointerExited(CoreWindow^ sender, PointerEventArgs^ args)
771 #if LOG_POINTER_EVENTS 778 void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
780 #if LOG_POINTER_EVENTS 787 void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
792 void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
794 WINRT_ProcessKeyDownEvent(args);
797 void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
799 WINRT_ProcessKeyUpEvent(args);
802 void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args)
804 WINRT_ProcessCharacterReceivedEvent(args);
807 template <
typename BackButtonEventArgs>
816 args->Handled =
true;
821 #if NTDDI_VERSION == NTDDI_WIN10 822 void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args)
827 #elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 828 void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args)
#define WIN_UTF8ToString(S)
void WINRT_UpdateWindowFlags(SDL_Window *window, Uint32 mask)
void SDL_SetKeyboardFocus(SDL_Window *window)
uint32_t Uint32
An unsigned 32-bit integer type.
GLsizei const GLchar *const * string
GLuint GLuint GLsizei count
static SDL_Event events[EVENT_BUF_SIZE]
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
GLuint const GLchar * name
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
#define SDL_GetKeyboardFocus
#define SDL_HINT_WINRT_PRIVACY_POLICY_URL
A URL to a WinRT app's privacy policy.
GLint GLint GLint GLint GLint x
#define SDL_HINT_WINRT_PRIVACY_POLICY_LABEL
Label text for a WinRT app's privacy policy link.
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_WinRTInitNonXAMLApp(int(*mainFunction)(int, char **))
SDL_WinRTApp SDL_WinRTGlobalApp
static void WINRT_OnBackButtonPressed(BackButtonEventArgs^args)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
SDL_WindowEventID
Event subtype for window events.
Uint32 WINRT_DetectWindowFlags(SDL_Window *window)
SDL_Window * WINRT_GlobalSDLWindow
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)
#define SDL_assert(condition)
#define SDL_HINT_ORIENTATIONS
A variable controlling which orientations are allowed on iOS.
GLint GLint GLint GLint GLint GLint y
The type used to identify a window.
#define SDL_AddHintCallback
int(* WINRT_SDLAppEntryPoint)(int, char **)
static void WINRT_ProcessWindowSizeChange()
GLubyte GLubyte GLubyte GLubyte w
int SDL_SendAppEvent(SDL_EventType eventType)
#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON
Allows back-button-press events on Windows Phone to be marked as handled.
static void WINRT_LogPointerEvent(const char *header, Windows::UI::Core::PointerEventArgs^args, Windows::Foundation::Point transformedPoint)
GLfloat GLfloat GLfloat GLfloat h
static bool IsSDLWindowEventPending(SDL_WindowEventID windowEventID)