summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java109
1 files changed, 6 insertions, 103 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java
index 96868f965..c316a63b1 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java
@@ -376,110 +376,13 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
}
for (InputOverlayDrawableDpad dpad : overlayDpads) {
- // Determine the button state to apply based on the MotionEvent action flag.
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
- case MotionEvent.ACTION_DOWN:
- case MotionEvent.ACTION_POINTER_DOWN:
- // If a pointer enters the bounds of a button, press that button.
- if (dpad.getBounds()
- .contains((int) event.getX(pointerIndex), (int) event.getY(pointerIndex))) {
- dpad.setTrackId(event.getPointerId(pointerIndex));
- }
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_POINTER_UP:
- // If a pointer ends, release the buttons.
- if (dpad.getTrackId() == event.getPointerId(pointerIndex)) {
- for (int i = 0; i < 4; i++) {
- dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT);
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i),
- NativeLibrary.ButtonState.RELEASED);
- }
- dpad.setTrackId(-1);
- }
- break;
- }
-
- if (dpad.getTrackId() != -1) {
- for (int i = 0; i < event.getPointerCount(); i++) {
- if (dpad.getTrackId() == event.getPointerId(i)) {
- float touchX = event.getX(i);
- float touchY = event.getY(i);
- float maxY = dpad.getBounds().bottom;
- float maxX = dpad.getBounds().right;
- touchX -= dpad.getBounds().centerX();
- maxX -= dpad.getBounds().centerX();
- touchY -= dpad.getBounds().centerY();
- maxY -= dpad.getBounds().centerY();
- final float AxisX = touchX / maxX;
- final float AxisY = touchY / maxY;
-
- boolean up = false;
- boolean down = false;
- boolean left = false;
- boolean right = false;
- if (EmulationMenuSettings.getDpadSlideEnable() ||
- (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN ||
- (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
- if (AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0),
- NativeLibrary.ButtonState.PRESSED);
- up = true;
- } else {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0),
- NativeLibrary.ButtonState.RELEASED);
- }
- if (AxisY > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1),
- NativeLibrary.ButtonState.PRESSED);
- down = true;
- } else {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1),
- NativeLibrary.ButtonState.RELEASED);
- }
- if (AxisX < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2),
- NativeLibrary.ButtonState.PRESSED);
- left = true;
- } else {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2),
- NativeLibrary.ButtonState.RELEASED);
- }
- if (AxisX > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3),
- NativeLibrary.ButtonState.PRESSED);
- right = true;
- } else {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3),
- NativeLibrary.ButtonState.RELEASED);
- }
-
- // Set state
- if (up) {
- if (left)
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_LEFT);
- else if (right)
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_RIGHT);
- else
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP);
- } else if (down) {
- if (left)
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_LEFT);
- else if (right)
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_RIGHT);
- else
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN);
- } else if (left) {
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_LEFT);
- } else if (right) {
- dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_RIGHT);
- } else {
- dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT);
- }
- }
- }
- }
+ if (!dpad.updateStatus(event, EmulationMenuSettings.getDpadSlideEnable())) {
+ continue;
}
+ NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getUpId(), dpad.getUpStatus());
+ NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getDownId(), dpad.getDownStatus());
+ NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getLeftId(), dpad.getLeftStatus());
+ NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getRightId(), dpad.getRightStatus());
}
for (InputOverlayDrawableJoystick joystick : overlayJoysticks) {