WinRT: minor code cleanup regarding events Some event handling functions got sorted in a somewhat consistent manner, and in some cases, were also segregated a bit from app-lifecycle code.
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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
diff --git a/src/core/winrt/SDL_winrtapp.cpp b/src/core/winrt/SDL_winrtapp.cpp
index 6b4de54..f421ea4 100644
--- a/src/core/winrt/SDL_winrtapp.cpp
+++ b/src/core/winrt/SDL_winrtapp.cpp
@@ -299,15 +299,15 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window)
window->PointerPressed +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
+ window->PointerMoved +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
+
window->PointerReleased +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
window->PointerWheelChanged +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
- window->PointerMoved +=
- ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
-
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
// Retrieves relative-only mouse movements:
Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
@@ -409,71 +409,6 @@ void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
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)
-{
-#if LOG_POINTER_EVENTS
- WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
-#endif
-
- WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
-}
-
-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);
-}
-
-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);
-}
-
-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)
-{
- WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
-}
-
-void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
-{
- WINRT_ProcessKeyDownEvent(args);
-}
-
-void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
-{
- WINRT_ProcessKeyUpEvent(args);
-}
-
void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
CoreWindow::GetForCurrentThread()->Activate();
@@ -547,3 +482,68 @@ void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
}
}
+
+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)
+{
+#if LOG_POINTER_EVENTS
+ WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position));
+#endif
+
+ WINRT_ProcessPointerPressedEvent(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::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);
+}
+
+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);
+}
+
+void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
+{
+ WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
+}
+
+void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
+{
+ WINRT_ProcessKeyDownEvent(args);
+}
+
+void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
+{
+ WINRT_ProcessKeyUpEvent(args);
+}
diff --git a/src/core/winrt/SDL_winrtxaml.cpp b/src/core/winrt/SDL_winrtxaml.cpp
index 8b78a1f..42500c3 100644
--- a/src/core/winrt/SDL_winrtxaml.cpp
+++ b/src/core/winrt/SDL_winrtxaml.cpp
@@ -58,21 +58,21 @@ WINRT_OnPointerPressedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input
}
static void
-WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
+WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
{
- WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
+ WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
}
static void
-WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
+WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
{
- WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
+ WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
}
static void
-WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
+WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
{
- WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
+ WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
}
#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
diff --git a/src/video/winrt/SDL_winrtevents_c.h b/src/video/winrt/SDL_winrtevents_c.h
index 4d9ae6d..ea09347 100644
--- a/src/video/winrt/SDL_winrtevents_c.h
+++ b/src/video/winrt/SDL_winrtevents_c.h
@@ -45,18 +45,18 @@ extern void WINRT_PumpEvents(_THIS);
*/
#ifdef __cplusplus_winrt
-/* Keyboard */
-extern void WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args);
-extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args);
-
/* Pointers (Mice, Touch, etc.) */
-extern void WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args);
+extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition);
+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_ProcessPointerWheelChangedEvent(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 Uint8 WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt);
-extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window, Windows::Foundation::Point rawPosition);
+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();
diff --git a/src/video/winrt/SDL_winrtpointerinput.cpp b/src/video/winrt/SDL_winrtpointerinput.cpp
index ec95b2b..962ec3c 100644
--- a/src/video/winrt/SDL_winrtpointerinput.cpp
+++ b/src/video/winrt/SDL_winrtpointerinput.cpp
@@ -47,7 +47,6 @@ 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)
@@ -114,79 +113,6 @@ _lround(float arg)
}
}
-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);
- SDL_SendMouseMotion(
- window,
- 0,
- 1,
- _lround(mouseDeltaInSDLWindowCoords.X),
- _lround(mouseDeltaInSDLWindowCoords.Y));
-}
-
Uint8
WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
{
@@ -276,39 +202,58 @@ WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
#endif
}
-void
-WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
- if (!window || WINRT_UsingRelativeMouseMode) {
+ if (!window) {
return;
}
Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
- if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
- SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
+ if (!WINRT_LeftFingerDown) {
+ Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
+ if (button) {
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
+#endif
+ SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
+ }
+
+ WINRT_LeftFingerDown = pointerPoint->PointerId;
}
if (WINRT_IsTouchEvent(pointerPoint)) {
- SDL_SendTouchMotion(
+ SDL_SendTouch(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
+ SDL_TRUE,
transformedPoint.X,
transformedPoint.Y,
pointerPoint->Properties->Pressure);
}
-}
+}
void
-WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
- if (!window) {
+ if (!window || WINRT_UsingRelativeMouseMode) {
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);
+ Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
+
+ if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
+ SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
+ }
+
+ if (WINRT_IsTouchEvent(pointerPoint)) {
+ SDL_SendTouchMotion(
+ WINRT_TouchID,
+ (SDL_FingerID) pointerPoint->PointerId,
+ transformedPoint.X,
+ transformedPoint.Y,
+ pointerPoint->Properties->Pressure);
+ }
}
void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
@@ -337,36 +282,90 @@ void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::P
pointerPoint->Properties->Pressure);
}
}
-
-void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+
+void
+WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window) {
return;
}
- Windows::Foundation::Point transformedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position);
-
- if (!WINRT_LeftFingerDown) {
- Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
- if (button) {
-#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
- SDL_SendMouseMotion(window, 0, 0, (int)transformedPoint.X, (int)transformedPoint.Y);
-#endif
- SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
- }
-
- WINRT_LeftFingerDown = pointerPoint->PointerId;
+ // 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;
}
- if (WINRT_IsTouchEvent(pointerPoint)) {
- SDL_SendTouch(
- WINRT_TouchID,
- (SDL_FingerID) pointerPoint->PointerId,
- SDL_TRUE,
- transformedPoint.X,
- transformedPoint.Y,
- pointerPoint->Properties->Pressure);
- }
+ // 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);
+ SDL_SendMouseMotion(
+ window,
+ 0,
+ 1,
+ _lround(mouseDeltaInSDLWindowCoords.X),
+ _lround(mouseDeltaInSDLWindowCoords.Y));
}
#endif // SDL_VIDEO_DRIVER_WINRT