Fix touch events on mobile Windows 10

This commit is contained in:
Henrik Rydgard 2017-03-04 13:00:12 +01:00 committed by Henrik Rydgård
parent 94bfad95e7
commit c02060594d
3 changed files with 61 additions and 10 deletions

View File

@ -1,4 +1,6 @@
#include "pch.h"
#include "ppsspp_config.h"
#include "pch.h"
#include "App.h"
#include <mutex>
@ -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);
}

View File

@ -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<PPSSPP_UWPMain> m_main;
bool m_windowClosed;
bool m_windowVisible;
TouchMapper touchMap_;
};
}

View File

@ -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;