mirror of https://github.com/encounter/SDL.git
WinRT: made simulated-mouse (via touch) input work on Windows Phone in Portrait mode
Proper SDL_MOUSE* event support for non-Portrait orientations in Windows Phone is pending.
This commit is contained in:
parent
31235b4b99
commit
13c87e712b
|
@ -412,31 +412,61 @@ void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
|
||||||
m_windowClosed = true;
|
m_windowClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
|
||||||
|
{
|
||||||
|
Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
|
||||||
|
SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
|
||||||
|
header,
|
||||||
|
pt->Position.X, pt->Position.Y,
|
||||||
|
transformedPoint.X, transformedPoint.Y,
|
||||||
|
pt->Properties->MouseWheelDelta,
|
||||||
|
pt->FrameId,
|
||||||
|
pt->PointerId,
|
||||||
|
WINRT_GetSDLButtonForPointerPoint(pt));
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
|
#if LOG_POINTER_EVENTS
|
||||||
|
WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
|
||||||
|
#endif
|
||||||
|
|
||||||
WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
|
#if LOG_POINTER_EVENTS
|
||||||
|
WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
|
||||||
|
#endif
|
||||||
|
|
||||||
WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
|
void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
{
|
{
|
||||||
|
#if LOG_POINTER_EVENTS
|
||||||
|
WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
|
||||||
|
#endif
|
||||||
|
|
||||||
WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
|
||||||
|
{
|
||||||
|
#if LOG_POINTER_EVENTS
|
||||||
|
WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
|
void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
|
||||||
{
|
{
|
||||||
WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
|
WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
|
|
||||||
{
|
|
||||||
WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
WINRT_ProcessKeyDownEvent(args);
|
WINRT_ProcessKeyDownEvent(args);
|
||||||
|
|
|
@ -15,7 +15,6 @@ public:
|
||||||
internal:
|
internal:
|
||||||
// SDL-specific methods
|
// SDL-specific methods
|
||||||
void PumpEvents();
|
void PumpEvents();
|
||||||
Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Event Handlers.
|
// Event Handlers.
|
||||||
|
|
|
@ -54,6 +54,8 @@ extern void WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Inpu
|
||||||
extern void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
extern void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
||||||
extern void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
extern void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
||||||
extern void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
extern void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
|
||||||
|
extern Uint8 WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt);
|
||||||
|
extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition);
|
||||||
|
|
||||||
/* XAML Thread Management */
|
/* XAML Thread Management */
|
||||||
extern void WINRT_CycleXAMLThread();
|
extern void WINRT_CycleXAMLThread();
|
||||||
|
|
|
@ -160,8 +160,8 @@ WINRT_QuitMouse(_THIS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applies necessary geometric transformations to raw cursor positions:
|
// Applies necessary geometric transformations to raw cursor positions:
|
||||||
static Windows::Foundation::Point
|
Windows::Foundation::Point
|
||||||
TransformCursor(SDL_Window * window, Windows::Foundation::Point rawPosition)
|
WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition)
|
||||||
{
|
{
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return rawPosition;
|
return rawPosition;
|
||||||
|
@ -247,7 +247,7 @@ WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::Mouse
|
||||||
// to SDL window coordinates.
|
// to SDL window coordinates.
|
||||||
//
|
//
|
||||||
const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
|
const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
|
||||||
const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = TransformCursor(window, mouseDeltaInDIPs);
|
const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs);
|
||||||
SDL_SendMouseMotion(
|
SDL_SendMouseMotion(
|
||||||
window,
|
window,
|
||||||
0,
|
0,
|
||||||
|
@ -256,11 +256,14 @@ WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::Mouse
|
||||||
_lround(mouseDeltaInSDLWindowCoords.Y));
|
_lround(mouseDeltaInSDLWindowCoords.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8
|
Uint8
|
||||||
WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
|
WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
|
||||||
{
|
{
|
||||||
using namespace Windows::UI::Input;
|
using namespace Windows::UI::Input;
|
||||||
|
|
||||||
|
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||||
|
return SDL_BUTTON_LEFT;
|
||||||
|
#else
|
||||||
switch (pt->Properties->PointerUpdateKind)
|
switch (pt->Properties->PointerUpdateKind)
|
||||||
{
|
{
|
||||||
case PointerUpdateKind::LeftButtonPressed:
|
case PointerUpdateKind::LeftButtonPressed:
|
||||||
|
@ -286,80 +289,59 @@ WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
//const char *
|
||||||
WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
|
//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
|
||||||
{
|
//{
|
||||||
using namespace Windows::UI::Input;
|
// using namespace Windows::UI::Input;
|
||||||
|
//
|
||||||
switch (kind)
|
// switch (kind)
|
||||||
{
|
// {
|
||||||
case PointerUpdateKind::Other:
|
// case PointerUpdateKind::Other:
|
||||||
return "Other";
|
// return "Other";
|
||||||
case PointerUpdateKind::LeftButtonPressed:
|
// case PointerUpdateKind::LeftButtonPressed:
|
||||||
return "LeftButtonPressed";
|
// return "LeftButtonPressed";
|
||||||
case PointerUpdateKind::LeftButtonReleased:
|
// case PointerUpdateKind::LeftButtonReleased:
|
||||||
return "LeftButtonReleased";
|
// return "LeftButtonReleased";
|
||||||
case PointerUpdateKind::RightButtonPressed:
|
// case PointerUpdateKind::RightButtonPressed:
|
||||||
return "RightButtonPressed";
|
// return "RightButtonPressed";
|
||||||
case PointerUpdateKind::RightButtonReleased:
|
// case PointerUpdateKind::RightButtonReleased:
|
||||||
return "RightButtonReleased";
|
// return "RightButtonReleased";
|
||||||
case PointerUpdateKind::MiddleButtonPressed:
|
// case PointerUpdateKind::MiddleButtonPressed:
|
||||||
return "MiddleButtonPressed";
|
// return "MiddleButtonPressed";
|
||||||
case PointerUpdateKind::MiddleButtonReleased:
|
// case PointerUpdateKind::MiddleButtonReleased:
|
||||||
return "MiddleButtonReleased";
|
// return "MiddleButtonReleased";
|
||||||
case PointerUpdateKind::XButton1Pressed:
|
// case PointerUpdateKind::XButton1Pressed:
|
||||||
return "XButton1Pressed";
|
// return "XButton1Pressed";
|
||||||
case PointerUpdateKind::XButton1Released:
|
// case PointerUpdateKind::XButton1Released:
|
||||||
return "XButton1Released";
|
// return "XButton1Released";
|
||||||
case PointerUpdateKind::XButton2Pressed:
|
// case PointerUpdateKind::XButton2Pressed:
|
||||||
return "XButton2Pressed";
|
// return "XButton2Pressed";
|
||||||
case PointerUpdateKind::XButton2Released:
|
// case PointerUpdateKind::XButton2Released:
|
||||||
return "XButton2Released";
|
// return "XButton2Released";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return "";
|
// return "";
|
||||||
}
|
//}
|
||||||
|
|
||||||
static void
|
|
||||||
WINRT_LogPointerEvent(const char * header, PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
|
|
||||||
{
|
|
||||||
Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
|
|
||||||
SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, PointerUpdateKind=%s\n",
|
|
||||||
header,
|
|
||||||
pt->Position.X, pt->Position.Y,
|
|
||||||
transformedPoint.X, transformedPoint.Y,
|
|
||||||
pt->Properties->MouseWheelDelta,
|
|
||||||
pt->FrameId,
|
|
||||||
pt->PointerId,
|
|
||||||
WINRT_ConvertPointerUpdateKindToString(args->CurrentPoint->Properties->PointerUpdateKind));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||||
{
|
{
|
||||||
#if LOG_POINTER_EVENTS
|
|
||||||
WINRT_LogPointerEvent("pointer moved", args, TransformCursor(pointerPoint->Position));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!window || WINRT_UseRelativeMouseMode) {
|
if (!window || WINRT_UseRelativeMouseMode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Windows::Foundation::Point transformedPoint = TransformCursor(window, pointerPoint->Position);
|
Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
|
||||||
SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
|
SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||||
{
|
{
|
||||||
#if LOG_POINTER_EVENTS
|
|
||||||
WINRT_LogPointerEvent("wheel changed", args, TransformCursor(pointerPoint->Position));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -371,10 +353,6 @@ WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::Po
|
||||||
|
|
||||||
void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||||
{
|
{
|
||||||
#if LOG_POINTER_EVENTS
|
|
||||||
WINRT_LogPointerEvent("mouse up", args, TransformCursor(args->CurrentPoint->Position));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -387,16 +365,16 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P
|
||||||
|
|
||||||
void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
|
||||||
{
|
{
|
||||||
#if LOG_POINTER_EVENTS
|
|
||||||
WINRT_LogPointerEvent("mouse down", args, TransformCursor(args->CurrentPoint->Position));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
|
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
|
||||||
if (button) {
|
if (button) {
|
||||||
|
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||||
|
Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
|
||||||
|
SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
|
||||||
|
#endif
|
||||||
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
|
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue