WinRT: fixed bug: touch input coordinates weren't normalized [0..1] Thanks to Pierre-Yves for pointing this out and providing a fix!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp
index a5027fa..05a7487 100644
--- a/src/core/winrt/SDL_winrtapp_direct3d.cpp
+++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp
@@ -495,7 +495,7 @@ WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
{
#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
+ WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
#endif
WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
@@ -504,7 +504,7 @@ void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
{
#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
+ WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
#endif
WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
@@ -513,7 +513,7 @@ void SDL_WinRTApp::OnPointerMoved(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));
+ WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
#endif
WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
@@ -522,7 +522,7 @@ void SDL_WinRTApp::OnPointerReleased(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));
+ WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
#endif
WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
diff --git a/src/video/winrt/SDL_winrtevents_c.h b/src/video/winrt/SDL_winrtevents_c.h
index ea09347..a6ae7a2 100644
--- a/src/video/winrt/SDL_winrtevents_c.h
+++ b/src/video/winrt/SDL_winrtevents_c.h
@@ -46,7 +46,13 @@ extern void WINRT_PumpEvents(_THIS);
#ifdef __cplusplus_winrt
/* Pointers (Mice, Touch, etc.) */
-extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition);
+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);
diff --git a/src/video/winrt/SDL_winrtpointerinput.cpp b/src/video/winrt/SDL_winrtpointerinput.cpp
index 9e64138..bb1a771 100644
--- a/src/video/winrt/SDL_winrtpointerinput.cpp
+++ b/src/video/winrt/SDL_winrtpointerinput.cpp
@@ -47,9 +47,14 @@ 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_TransformCursorPosition(SDL_Window * window,
+ Windows::Foundation::Point rawPosition,
+ WINRT_CursorNormalizationType normalization)
{
using namespace Windows::UI::Core;
using namespace Windows::Graphics::Display;
@@ -64,6 +69,8 @@ WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point ra
// 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;
}
@@ -73,33 +80,41 @@ WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point ra
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 * (((float32)window->w) / nativeWindow->Bounds.Width);
- outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
+ 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 * (((float32)window->w) / nativeWindow->Bounds.Width);
- outputPosition.Y = rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
+ outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
+ outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
break;
case DisplayOrientations::PortraitFlipped:
- outputPosition.X = (float32)window->w - rawPosition.X * (((float32)window->w) / nativeWindow->Bounds.Width);
- outputPosition.Y = (float32)window->h - rawPosition.Y * (((float32)window->h) / nativeWindow->Bounds.Height);
+ 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 * (((float32)window->w) / nativeWindow->Bounds.Height);
- outputPosition.Y = (float32)window->h - rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
+ outputPosition.X = rawPosition.Y / nativeWindow->Bounds.Height;
+ outputPosition.Y = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
break;
case DisplayOrientations::LandscapeFlipped:
- outputPosition.X = (float32)window->w - rawPosition.Y * (((float32)window->w) / nativeWindow->Bounds.Height);
- outputPosition.Y = rawPosition.X * (((float32)window->h) / nativeWindow->Bounds.Width);
+ 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;
}
@@ -208,15 +223,17 @@ void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::Po
return;
}
- Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
- if (!WINRT_IsTouchEvent(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)transformedPoint.X, (int)transformedPoint.Y);
+ SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
}
@@ -227,8 +244,8 @@ void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::Po
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
SDL_TRUE,
- transformedPoint.X,
- transformedPoint.Y,
+ normalizedPoint.X,
+ normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
@@ -240,20 +257,21 @@ WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPo
return;
}
- Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
+ 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)transformedPoint.X, (int)transformedPoint.Y);
+ 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)transformedPoint.X, (int)transformedPoint.Y);
+ SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
}
SDL_SendTouchMotion(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
- transformedPoint.X,
- transformedPoint.Y,
+ normalizedPoint.X,
+ normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
@@ -264,12 +282,13 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P
return;
}
- Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
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);
@@ -281,8 +300,8 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
SDL_FALSE,
- transformedPoint.X,
- transformedPoint.Y,
+ normalizedPoint.X,
+ normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
@@ -363,7 +382,7 @@ WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::Mouse
// 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);
+ const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs, TransformToSDLWindowSize);
SDL_SendMouseMotion(
window,
0,