Remove touch points on touch up events on Android (#2711)
Fixes #2683 Remove elements from touch point related arrays when touch up and similar events are processed. This makes GetTouchPointCount() always report the actual count of touch points, and all positions returned by GetTouchPosition() correspond to positions of currently happening touches.
This commit is contained in:
parent
7e3a50b4ac
commit
27781a4767
1 changed files with 19 additions and 3 deletions
22
src/rcore.c
22
src/rcore.c
|
@ -5755,9 +5755,6 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
int32_t action = AMotionEvent_getAction(event);
|
int32_t action = AMotionEvent_getAction(event);
|
||||||
unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
|
unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
|
||||||
|
|
||||||
if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_MOVE) CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 1;
|
|
||||||
else if (flags == AMOTION_EVENT_ACTION_UP) CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 0;
|
|
||||||
|
|
||||||
#if defined(SUPPORT_GESTURES_SYSTEM) // PLATFORM_ANDROID
|
#if defined(SUPPORT_GESTURES_SYSTEM) // PLATFORM_ANDROID
|
||||||
GestureEvent gestureEvent = { 0 };
|
GestureEvent gestureEvent = { 0 };
|
||||||
|
|
||||||
|
@ -5779,6 +5776,25 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
ProcessGestureEvent(gestureEvent);
|
ProcessGestureEvent(gestureEvent);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
||||||
|
|
||||||
|
if (flags == AMOTION_EVENT_ACTION_POINTER_UP || flags == AMOTION_EVENT_ACTION_UP)
|
||||||
|
{
|
||||||
|
// One of the touchpoints is released, remove it from touch point arrays
|
||||||
|
for (int i = pointerIndex; (i < CORE.Input.Touch.pointCount-1) && (i < MAX_TOUCH_POINTS); i++)
|
||||||
|
{
|
||||||
|
CORE.Input.Touch.pointId[i] = CORE.Input.Touch.pointId[i+1];
|
||||||
|
CORE.Input.Touch.position[i] = CORE.Input.Touch.position[i+1];
|
||||||
|
}
|
||||||
|
CORE.Input.Touch.pointCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When all touchpoints are tapped and released really quickly, this event is generated
|
||||||
|
if (flags == AMOTION_EVENT_ACTION_CANCEL) CORE.Input.Touch.pointCount = 0;
|
||||||
|
|
||||||
|
if (CORE.Input.Touch.pointCount > 0) CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 1;
|
||||||
|
else CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue