Merge pull request #10508 from JosJuice/android-pointer-down

Android: Only use getActionIndex for ACTION_POINTER_DOWN/ACTION_POINTER_UP
This commit is contained in:
Mai M 2022-04-08 20:53:52 -04:00 committed by GitHub
commit f92b7f4c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 33 deletions

View File

@ -198,14 +198,17 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
return onTouchWhileEditing(event);
}
int pointerIndex = event.getActionIndex();
int action = event.getActionMasked();
boolean firstPointer = action != MotionEvent.ACTION_POINTER_DOWN &&
action != MotionEvent.ACTION_POINTER_UP;
int pointerIndex = firstPointer ? 0 : event.getActionIndex();
// Tracks if any button/joystick is pressed down
boolean pressed = false;
for (InputOverlayDrawableButton button : overlayButtons)
{
// Determine the button state to apply based on the MotionEvent action flag.
switch (event.getAction() & MotionEvent.ACTION_MASK)
switch (action)
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:

View File

@ -71,22 +71,19 @@ public final class InputOverlayDrawableButton
public void onConfigureTouch(MotionEvent event)
{
int pointerIndex = event.getActionIndex();
int fingerPositionX = (int) event.getX(pointerIndex);
int fingerPositionY = (int) event.getY(pointerIndex);
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mPreviousTouchX = fingerPositionX;
mPreviousTouchY = fingerPositionY;
mPreviousTouchX = (int) event.getX();
mPreviousTouchY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
mControlPositionX += fingerPositionX - mPreviousTouchX;
mControlPositionY += fingerPositionY - mPreviousTouchY;
mControlPositionX += (int) event.getX() - mPreviousTouchX;
mControlPositionY += (int) event.getY() - mPreviousTouchY;
setBounds(mControlPositionX, mControlPositionY, getWidth() + mControlPositionX,
getHeight() + mControlPositionY);
mPreviousTouchX = fingerPositionX;
mPreviousTouchY = fingerPositionY;
mPreviousTouchX = (int) event.getX();
mPreviousTouchY = (int) event.getY();
break;
}
}

View File

@ -149,22 +149,19 @@ public final class InputOverlayDrawableDpad
public void onConfigureTouch(MotionEvent event)
{
int pointerIndex = event.getActionIndex();
int fingerPositionX = (int) event.getX(pointerIndex);
int fingerPositionY = (int) event.getY(pointerIndex);
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mPreviousTouchX = fingerPositionX;
mPreviousTouchY = fingerPositionY;
mPreviousTouchX = (int) event.getX();
mPreviousTouchY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
mControlPositionX += fingerPositionX - mPreviousTouchX;
mControlPositionY += fingerPositionY - mPreviousTouchY;
mControlPositionX += (int) event.getX() - mPreviousTouchX;
mControlPositionY += (int) event.getY() - mPreviousTouchY;
setBounds(mControlPositionX, mControlPositionY, getWidth() + mControlPositionX,
getHeight() + mControlPositionY);
mPreviousTouchX = fingerPositionX;
mPreviousTouchY = fingerPositionY;
mPreviousTouchX = (int) event.getX();
mPreviousTouchY = (int) event.getY();
break;
}
}

View File

@ -95,10 +95,13 @@ public final class InputOverlayDrawableJoystick
public boolean TrackEvent(MotionEvent event)
{
boolean reCenter = BooleanSetting.MAIN_JOYSTICK_REL_CENTER.getBooleanGlobal();
int pointerIndex = event.getActionIndex();
int action = event.getActionMasked();
boolean firstPointer = action != MotionEvent.ACTION_POINTER_DOWN &&
action != MotionEvent.ACTION_POINTER_UP;
int pointerIndex = firstPointer ? 0 : event.getActionIndex();
boolean pressed = false;
switch (event.getAction() & MotionEvent.ACTION_MASK)
switch (action)
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
@ -163,18 +166,15 @@ public final class InputOverlayDrawableJoystick
public void onConfigureTouch(MotionEvent event)
{
int pointerIndex = event.getActionIndex();
int fingerPositionX = (int) event.getX(pointerIndex);
int fingerPositionY = (int) event.getY(pointerIndex);
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mPreviousTouchX = fingerPositionX;
mPreviousTouchY = fingerPositionY;
mPreviousTouchX = (int) event.getX();
mPreviousTouchY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
int deltaX = fingerPositionX - mPreviousTouchX;
int deltaY = fingerPositionY - mPreviousTouchY;
int deltaX = (int) event.getX() - mPreviousTouchX;
int deltaY = (int) event.getY() - mPreviousTouchY;
mControlPositionX += deltaX;
mControlPositionY += deltaY;
setBounds(new Rect(mControlPositionX, mControlPositionY,
@ -187,8 +187,8 @@ public final class InputOverlayDrawableJoystick
setOrigBounds(new Rect(new Rect(mControlPositionX, mControlPositionY,
mOuterBitmap.getIntrinsicWidth() + mControlPositionX,
mOuterBitmap.getIntrinsicHeight() + mControlPositionY)));
mPreviousTouchX = fingerPositionX;
mPreviousTouchY = fingerPositionY;
mPreviousTouchX = (int) event.getX();
mPreviousTouchY = (int) event.getY();
break;
}
}

View File

@ -82,9 +82,12 @@ public class InputOverlayPointer
public void onTouch(MotionEvent event)
{
int pointerIndex = event.getActionIndex();
int action = event.getActionMasked();
boolean firstPointer = action != MotionEvent.ACTION_POINTER_DOWN &&
action != MotionEvent.ACTION_POINTER_UP;
int pointerIndex = firstPointer ? 0 : event.getActionIndex();
switch (event.getAction() & MotionEvent.ACTION_MASK)
switch (action)
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: