From c02060594d6790c3cf5abc2ccd324c38a1e1a215 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 4 Mar 2017 13:00:12 +0100 Subject: [PATCH] Fix touch events on mobile Windows 10 --- UWP/App.cpp | 23 ++++++++++++++++----- UWP/App.h | 45 ++++++++++++++++++++++++++++++++++++++++-- UWP/PPSSPP_UWPMain.cpp | 3 --- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/UWP/App.cpp b/UWP/App.cpp index 48cd5997c8..964b12232d 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -1,4 +1,6 @@ -#include "pch.h" +#include "ppsspp_config.h" + +#include "pch.h" #include "App.h" #include @@ -100,7 +102,9 @@ void App::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyE } void App::OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - int pointerId = args->CurrentPoint->PointerId; + int pointerId = touchMap_.TouchId(args->CurrentPoint->PointerId); + if (pointerId < 0) + return; float X = args->CurrentPoint->Position.X; float Y = args->CurrentPoint->Position.Y; int64_t timestamp = args->CurrentPoint->Timestamp; @@ -114,28 +118,37 @@ void App::OnPointerExited(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Co } void App::OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - int pointerId = args->CurrentPoint->PointerId; + int pointerId = touchMap_.TouchId(args->CurrentPoint->PointerId); + if (pointerId < 0) + pointerId = touchMap_.AddNewTouch(args->CurrentPoint->PointerId); + float X = args->CurrentPoint->Position.X; float Y = args->CurrentPoint->Position.Y; int64_t timestamp = args->CurrentPoint->Timestamp; m_main->OnTouchEvent(TOUCH_DOWN|TOUCH_MOVE, pointerId, X, Y, timestamp); +#if !PPSSPP_ARCH(ARM) sender->SetPointerCapture(); +#endif } void App::OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - int pointerId = args->CurrentPoint->PointerId; + int pointerId = touchMap_.RemoveTouch(args->CurrentPoint->PointerId); + if (pointerId < 0) + return; float X = args->CurrentPoint->Position.X; float Y = args->CurrentPoint->Position.Y; int64_t timestamp = args->CurrentPoint->Timestamp; m_main->OnTouchEvent(TOUCH_UP|TOUCH_MOVE, pointerId, X, Y, timestamp); +#if !PPSSPP_ARCH(ARM) sender->ReleasePointerCapture(); +#endif } void App::OnPointerCaptureLost(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { } void App::OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - int pointerId = args->CurrentPoint->PointerId; + int pointerId = 0; // irrelevant float delta = args->CurrentPoint->GetCurrentPoint(args->CurrentPoint->PointerId)->Properties->MouseWheelDelta; m_main->OnMouseWheel(delta); } diff --git a/UWP/App.h b/UWP/App.h index 69a6d1397e..b34558f924 100644 --- a/UWP/App.h +++ b/UWP/App.h @@ -4,8 +4,47 @@ #include "Common/DeviceResources.h" #include "PPSSPP_UWPMain.h" -namespace UWP -{ +namespace UWP { + struct Touch { + bool inUse = false; + unsigned uid; + }; + + class TouchMapper { + public: + int TouchId(unsigned touch) { + for (int touchIx = 0; touchIx < maxTouches; touchIx++) + if (touches[touchIx].inUse && touches[touchIx].uid == touch) + return touchIx; + return -1; + } + + int AddNewTouch(unsigned touch) { + for (int touchIx = 0; touchIx < maxTouches; touchIx++) { + if (!touches[touchIx].inUse) { + touches[touchIx].inUse = true; + touches[touchIx].uid = touch; + return touchIx; + } + } + return -1; + } + + int RemoveTouch(unsigned touch) { + for (int touchIx = 0; touchIx < maxTouches; touchIx++) { + if (touches[touchIx].inUse && touches[touchIx].uid == touch) { + touches[touchIx].inUse = false; + return touchIx; + } + } + return -1; + } + + private: + enum { maxTouches = 11 }; + Touch touches[maxTouches]{}; + }; + // Main entry point for our app. Connects the app with the Windows shell and handles application lifecycle events. ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView { public: @@ -51,6 +90,8 @@ namespace UWP std::unique_ptr m_main; bool m_windowClosed; bool m_windowVisible; + + TouchMapper touchMap_; }; } diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 3eed25ecc4..78d80f7bce 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -236,9 +236,6 @@ void PPSSPP_UWPMain::OnMouseWheel(float delta) { } void PPSSPP_UWPMain::OnTouchEvent(int touchEvent, int touchId, float x, float y, double timestamp) { - // It appears that Windows' touchIds start from 1. Let's fix that. - touchId--; - TouchInput input{}; input.id = touchId; input.x = x;