mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2025-01-17 14:47:19 +01:00
WinRT: moved the pointer to the global SDL_Window to a separate variable
This is a cleanup that is being done to help with WIP XAML support. It may be reverted in the future.
This commit is contained in:
parent
7be2ad71c9
commit
253b9aae89
@ -39,6 +39,8 @@ extern "C" {
|
|||||||
#include "../../video/winrt/SDL_winrtevents_c.h"
|
#include "../../video/winrt/SDL_winrtevents_c.h"
|
||||||
#include "SDL_winrtapp.h"
|
#include "SDL_winrtapp.h"
|
||||||
|
|
||||||
|
extern SDL_Window * WINRT_GlobalSDLWindow;
|
||||||
|
|
||||||
|
|
||||||
// Compile-time debugging options:
|
// Compile-time debugging options:
|
||||||
// To enable, uncomment; to disable, comment them out.
|
// To enable, uncomment; to disable, comment them out.
|
||||||
@ -144,7 +146,6 @@ static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *n
|
|||||||
SDL_WinRTApp::SDL_WinRTApp() :
|
SDL_WinRTApp::SDL_WinRTApp() :
|
||||||
m_windowClosed(false),
|
m_windowClosed(false),
|
||||||
m_windowVisible(true),
|
m_windowVisible(true),
|
||||||
m_sdlWindow(NULL),
|
|
||||||
m_sdlVideoDevice(NULL)
|
m_sdlVideoDevice(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -283,16 +284,16 @@ void SDL_WinRTApp::Uninitialize()
|
|||||||
void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
|
void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
|
||||||
{
|
{
|
||||||
#if LOG_WINDOW_EVENTS==1
|
#if LOG_WINDOW_EVENTS==1
|
||||||
SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, m_sdlWindow?=%s\n",
|
SDL_Log("%s, size={%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
|
||||||
__FUNCTION__,
|
__FUNCTION__,
|
||||||
args->Size.Width, args->Size.Height,
|
args->Size.Width, args->Size.Height,
|
||||||
(int)DisplayProperties::CurrentOrientation,
|
(int)DisplayProperties::CurrentOrientation,
|
||||||
(int)DisplayProperties::NativeOrientation,
|
(int)DisplayProperties::NativeOrientation,
|
||||||
(int)DisplayProperties::AutoRotationPreferences,
|
(int)DisplayProperties::AutoRotationPreferences,
|
||||||
(m_sdlWindow ? "yes" : "no"));
|
(WINRT_GlobalSDLWindow ? "yes" : "no"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (m_sdlWindow) {
|
if (WINRT_GlobalSDLWindow) {
|
||||||
// Make the new window size be the one true fullscreen mode.
|
// Make the new window size be the one true fullscreen mode.
|
||||||
// This change was initially done, in part, to allow the Direct3D 11.1
|
// This change was initially done, in part, to allow the Direct3D 11.1
|
||||||
// renderer to receive window-resize events as a device rotates.
|
// renderer to receive window-resize events as a device rotates.
|
||||||
@ -313,7 +314,7 @@ void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEven
|
|||||||
const int windowWidth = (int) ceil(args->Size.Width);
|
const int windowWidth = (int) ceil(args->Size.Width);
|
||||||
const int windowHeight = (int) ceil(args->Size.Height);
|
const int windowHeight = (int) ceil(args->Size.Height);
|
||||||
SDL_SendWindowEvent(
|
SDL_SendWindowEvent(
|
||||||
m_sdlWindow,
|
WINRT_GlobalSDLWindow,
|
||||||
SDL_WINDOWEVENT_RESIZED,
|
SDL_WINDOWEVENT_RESIZED,
|
||||||
windowWidth,
|
windowWidth,
|
||||||
windowHeight);
|
windowHeight);
|
||||||
@ -323,20 +324,20 @@ void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEven
|
|||||||
void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
|
void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
|
||||||
{
|
{
|
||||||
#if LOG_WINDOW_EVENTS==1
|
#if LOG_WINDOW_EVENTS==1
|
||||||
SDL_Log("%s, visible?=%s, m_sdlWindow?=%s\n",
|
SDL_Log("%s, visible?=%s, WINRT_GlobalSDLWindow?=%s\n",
|
||||||
__FUNCTION__,
|
__FUNCTION__,
|
||||||
(args->Visible ? "yes" : "no"),
|
(args->Visible ? "yes" : "no"),
|
||||||
(m_sdlWindow ? "yes" : "no"));
|
(WINRT_GlobalSDLWindow ? "yes" : "no"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_windowVisible = args->Visible;
|
m_windowVisible = args->Visible;
|
||||||
if (m_sdlWindow) {
|
if (WINRT_GlobalSDLWindow) {
|
||||||
SDL_bool wasSDLWindowSurfaceValid = m_sdlWindow->surface_valid;
|
SDL_bool wasSDLWindowSurfaceValid = WINRT_GlobalSDLWindow->surface_valid;
|
||||||
|
|
||||||
if (args->Visible) {
|
if (args->Visible) {
|
||||||
SDL_SendWindowEvent(m_sdlWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
SDL_SendWindowEvent(m_sdlWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Prevent SDL's window-hide handling code, which currently
|
// HACK: Prevent SDL's window-hide handling code, which currently
|
||||||
@ -345,7 +346,7 @@ void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEven
|
|||||||
//
|
//
|
||||||
// A better solution to this probably involves figuring out if the
|
// A better solution to this probably involves figuring out if the
|
||||||
// fake window resize can be prevented.
|
// fake window resize can be prevented.
|
||||||
m_sdlWindow->surface_valid = wasSDLWindowSurfaceValid;
|
WINRT_GlobalSDLWindow->surface_valid = wasSDLWindowSurfaceValid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,27 +360,27 @@ void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
|
|||||||
|
|
||||||
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
WINRT_ProcessPointerPressedEvent(m_sdlWindow, args);
|
WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
WINRT_ProcessPointerReleasedEvent(m_sdlWindow, args);
|
WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
WINRT_ProcessPointerWheelChangedEvent(m_sdlWindow, args);
|
WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
|
void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
|
||||||
{
|
{
|
||||||
WINRT_ProcessMouseMovedEvent(m_sdlWindow, args);
|
WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
WINRT_ProcessPointerMovedEvent(m_sdlWindow, args);
|
WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
|
void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
|
||||||
@ -438,9 +439,9 @@ void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ a
|
|||||||
// first via a callback passed to SDL_AddEventWatch, and second via
|
// first via a callback passed to SDL_AddEventWatch, and second via
|
||||||
// SDL's event queue, the event will be sent to SDL, then immediately
|
// SDL's event queue, the event will be sent to SDL, then immediately
|
||||||
// removed from the queue.
|
// removed from the queue.
|
||||||
if (m_sdlWindow)
|
if (WINRT_GlobalSDLWindow)
|
||||||
{
|
{
|
||||||
SDL_SendWindowEvent(m_sdlWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
|
SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
|
||||||
SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
|
SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
|
||||||
}
|
}
|
||||||
deferral->Complete();
|
deferral->Complete();
|
||||||
@ -452,9 +453,9 @@ void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
|
|||||||
// Restore any data or state that was unloaded on suspend. By default, data
|
// Restore any data or state that was unloaded on suspend. By default, data
|
||||||
// and state are persisted when resuming from suspend. Note that this event
|
// and state are persisted when resuming from suspend. Note that this event
|
||||||
// does not occur if the app was previously terminated.
|
// does not occur if the app was previously terminated.
|
||||||
if (m_sdlWindow)
|
if (WINRT_GlobalSDLWindow)
|
||||||
{
|
{
|
||||||
SDL_SendWindowEvent(m_sdlWindow, SDL_WINDOWEVENT_RESTORED, 0, 0); // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
|
SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_RESTORED, 0, 0); // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
|
||||||
|
|
||||||
// Remove the app-resume event from the queue, as is done with the
|
// Remove the app-resume event from the queue, as is done with the
|
||||||
// app-suspend event.
|
// app-suspend event.
|
||||||
@ -487,16 +488,6 @@ SDL_DisplayMode SDL_WinRTApp::CalcCurrentDisplayMode()
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Window * SDL_WinRTApp::GetSDLWindow()
|
|
||||||
{
|
|
||||||
return m_sdlWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDL_WinRTApp::SetSDLWindow(SDL_Window * window)
|
|
||||||
{
|
|
||||||
m_sdlWindow = window;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDL_WinRTApp::SetSDLVideoDevice(const SDL_VideoDevice * videoDevice)
|
void SDL_WinRTApp::SetSDLVideoDevice(const SDL_VideoDevice * videoDevice)
|
||||||
{
|
{
|
||||||
m_sdlVideoDevice = videoDevice;
|
m_sdlVideoDevice = videoDevice;
|
||||||
|
@ -16,8 +16,6 @@ internal:
|
|||||||
// SDL-specific methods
|
// SDL-specific methods
|
||||||
SDL_DisplayMode CalcCurrentDisplayMode();
|
SDL_DisplayMode CalcCurrentDisplayMode();
|
||||||
void PumpEvents();
|
void PumpEvents();
|
||||||
SDL_Window * GetSDLWindow();
|
|
||||||
void SetSDLWindow(SDL_Window * window);
|
|
||||||
void SetSDLVideoDevice(const SDL_VideoDevice * videoDevice);
|
void SetSDLVideoDevice(const SDL_VideoDevice * videoDevice);
|
||||||
Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
|
Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
|
||||||
|
|
||||||
@ -42,6 +40,5 @@ protected:
|
|||||||
private:
|
private:
|
||||||
bool m_windowClosed;
|
bool m_windowClosed;
|
||||||
bool m_windowVisible;
|
bool m_windowVisible;
|
||||||
SDL_Window* m_sdlWindow;
|
|
||||||
const SDL_VideoDevice* m_sdlVideoDevice;
|
const SDL_VideoDevice* m_sdlVideoDevice;
|
||||||
};
|
};
|
||||||
|
@ -72,6 +72,13 @@ struct SDL_WindowData
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* The global, WinRT, SDL Window.
|
||||||
|
For now, SDL/WinRT only supports one window (due to platform limitations of
|
||||||
|
WinRT.
|
||||||
|
*/
|
||||||
|
SDL_Window * WINRT_GlobalSDLWindow = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* WinRT driver bootstrap functions */
|
/* WinRT driver bootstrap functions */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -164,7 +171,7 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
|
|||||||
{
|
{
|
||||||
// Make sure that only one window gets created, at least until multimonitor
|
// Make sure that only one window gets created, at least until multimonitor
|
||||||
// support is added.
|
// support is added.
|
||||||
if (SDL_WinRTGlobalApp->GetSDLWindow() != NULL) {
|
if (WINRT_GlobalSDLWindow != NULL) {
|
||||||
SDL_SetError("WinRT only supports one window");
|
SDL_SetError("WinRT only supports one window");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -202,7 +209,7 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
|
|||||||
/* Make sure the WinRT app's IFramworkView can post events on
|
/* Make sure the WinRT app's IFramworkView can post events on
|
||||||
behalf of SDL:
|
behalf of SDL:
|
||||||
*/
|
*/
|
||||||
SDL_WinRTGlobalApp->SetSDLWindow(window);
|
WINRT_GlobalSDLWindow = window;
|
||||||
|
|
||||||
/* All done! */
|
/* All done! */
|
||||||
return 0;
|
return 0;
|
||||||
@ -213,8 +220,8 @@ WINRT_DestroyWindow(_THIS, SDL_Window * window)
|
|||||||
{
|
{
|
||||||
SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
|
SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
|
||||||
|
|
||||||
if (SDL_WinRTGlobalApp->GetSDLWindow() == window) {
|
if (WINRT_GlobalSDLWindow == window) {
|
||||||
SDL_WinRTGlobalApp->SetSDLWindow(NULL);
|
WINRT_GlobalSDLWindow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user