Permalink
Browse files

Android: Enhance Dpad movements/touches

Allows you to 'slide' your finger to move across the dpad like a joystick.
  • Loading branch information...
zackhow committed Aug 16, 2018
1 parent 8e5c3d5 commit 4c281f72b64a29d27732f84c2b729749fcaa78b5
Showing with 18 additions and 22 deletions.
  1. +18 −22 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
@@ -163,35 +163,31 @@ public boolean onTouch(View v, MotionEvent event)
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_MOVE:
// Up, Down, Left, Right
boolean[] pressed = {false, false, false, false};
// If a pointer enters the bounds of a button, press that button.
if (dpad.getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex)))
{
boolean up = false;
boolean down = false;
boolean left = false;
boolean right = false;
if (dpad.getBounds().top + (dpad.getHeight() / 3) > (int)event.getY(pointerIndex))
{
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0), ButtonState.PRESSED);
up = true;
}
pressed[0] = true;
if (dpad.getBounds().bottom - (dpad.getHeight() / 3) < (int)event.getY(pointerIndex))
{
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1), ButtonState.PRESSED);
down = true;
}
pressed[1] = true;
if (dpad.getBounds().left + (dpad.getWidth() / 3) > (int)event.getX(pointerIndex))
{
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2), ButtonState.PRESSED);
left = true;
}
pressed[2] = true;
if (dpad.getBounds().right - (dpad.getWidth() / 3) < (int)event.getX(pointerIndex))
{
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3), ButtonState.PRESSED);
right = true;
}
setDpadState(dpad, up, down, left, right);
pressed[3] = true;
// Release the buttons first, then press
for(int i = 0; i < pressed.length; i++)
if (!pressed[i])
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i), ButtonState.RELEASED);
// Press buttons
for(int i = 0; i < pressed.length; i++)
if (pressed[i])
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i), ButtonState.PRESSED);
setDpadState(dpad, pressed[0], pressed[1], pressed[2], pressed[3]);
dpad.setTrackId(event.getPointerId(pointerIndex));
}
break;

0 comments on commit 4c281f7

Please sign in to comment.