Correct touch id generation.

GestureDetector still has a max of 10.
This commit is contained in:
Unknown W. Brackets 2017-03-14 22:16:09 -07:00
parent e1ef359e80
commit b00e788648
3 changed files with 21 additions and 18 deletions

View File

@ -44,15 +44,20 @@ void TouchInputHandler::handleTouchEvent(HWND hWnd, UINT message, WPARAM wParam,
sizeof(TOUCHINPUT)))
{
for (UINT i = 0; i < inputCount; i++) {
int id = 0;
int id = -1;
// Find or allocate an id for the touch.
auto it = touchTranslate.find(inputs[i].dwID);
if (it != touchTranslate.end()) {
id = it->second;
} else {
id = (int)touchTranslate.size();
touchTranslate[inputs[i].dwID] = id;
// Find or allocate an id for the touch. Avoid 0 (mouse.)
for (int localId = 1; localId < (int)ARRAY_SIZE(touchIds); ++localId) {
if (touchIds[localId] == inputs[i].dwID || touchIds[localId] == 0) {
touchIds[localId] = inputs[i].dwID;
id = localId;
break;
}
}
if (id == -1) {
id = 0;
// TODO: Better to just ignore this touch instead?
touchUp(id, 0, 0);
}
POINT point;
@ -71,7 +76,7 @@ void TouchInputHandler::handleTouchEvent(HWND hWnd, UINT message, WPARAM wParam,
if (inputs[i].dwFlags & TOUCHEVENTF_UP)
{
touchUp(id, point.x, point.y);
touchTranslate.erase(touchTranslate.find(inputs[i].dwID));
touchIds[id] = 0;
}
}
}

View File

@ -1,7 +1,5 @@
#pragma once
#include <map>
typedef BOOL(WINAPI *getTouchInputProc)(
HTOUCHINPUT hTouchInput,
UINT cInputs,
@ -20,22 +18,22 @@ typedef BOOL(WINAPI *registerTouchProc)(
class TouchInputHandler
{
private:
std::map<int, int> touchTranslate;
getTouchInputProc touchInfo;
closeTouchInputProc closeTouch;
registerTouchProc registerTouch;
public:
TouchInputHandler();
~TouchInputHandler();
void handleTouchEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void registerTouchWindow(HWND wnd);
bool hasTouch();
private:
void disablePressAndHold(HWND hWnd);
void touchUp(int id, float x, float y);
void touchDown(int id, float x, float y);
void touchMove(int id, float x, float y);
int touchIds[10];
getTouchInputProc touchInfo;
closeTouchInputProc closeTouch;
registerTouchProc registerTouch;
};

View File

@ -122,7 +122,7 @@ enum {
struct TouchInput {
float x;
float y;
int id;
int id; // Needs to be <= GestureDetector::MAX_PTRS (10.)
int flags;
double timestamp;
};