diff options
| author | Sean <seanmaas27@gmail.com> | 2014-05-25 11:02:45 -0400 |
|---|---|---|
| committer | Sean <seanmaas27@gmail.com> | 2014-05-30 19:02:28 -0400 |
| commit | 568f3248f3476fc272d12ca357bbd2e72a14f4e1 (patch) | |
| tree | 37c66f9e455d2373fbaca133f16ac21f44187edc /Source/Android | |
| parent | d0201335c67e60fc00f149b8c3c70f60c36ea435 (diff) | |
Android: add multitouch support
Diffstat (limited to 'Source/Android')
2 files changed, 53 insertions, 48 deletions
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java index 0d5a8580da..054690a072 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java @@ -110,27 +110,26 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener @Override public boolean onTouch(View v, MotionEvent event) { - // Determine the button state to apply based on the MotionEvent action flag. - // TODO: This will not work when Axis support is added. Make sure to refactor this when that time comes - // The reason it won't work is that when moving an axis, you would get the event MotionEvent.ACTION_MOVE. - // - // TODO: Refactor this so we detect either Axis movements or button presses so we don't run two loops all the time. - // - int buttonState = (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) - ? ButtonState.PRESSED : ButtonState.RELEASED; - // Check if there was a touch within the bounds of a drawable. + int pointerIndex = event.getActionIndex(); + for (InputOverlayDrawableButton button : overlayButtons) { - if (button.getBounds().contains((int)event.getX(), (int)event.getY())) - { - NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.getId(), buttonState); - } - else + // Determine the button state to apply based on the MotionEvent action flag. + switch(event.getAction() & MotionEvent.ACTION_MASK) { - // Because the above code only changes the state for the button that is being touched, sliding off the - // button does not allow for it to be released. Release the button as soon as the touch coordinates leave - // the button bounds. - NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.getId(), ButtonState.RELEASED); + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + case MotionEvent.ACTION_MOVE: + // If a pointer enters the bounds of a button, press that button. + if (button.getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex))) + NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.getId(), ButtonState.PRESSED); + break; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + // If a pointer ends, release the button it was pressing. + if (button.getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex))) + NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.getId(), ButtonState.RELEASED); + break; } } diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java index 4f4e7d669b..a74211eabe 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java @@ -22,7 +22,7 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable private final int[] axisIDs = {0, 0, 0, 0}; private final float[] axises = {0f, 0f}; private final BitmapDrawable ringInner; - private int trackid = -1; + private int trackId = -1; /** * Constructor @@ -62,42 +62,48 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable public void TrackEvent(MotionEvent event) { int pointerIndex = event.getActionIndex(); - if (trackid == -1) - { - if (event.getAction() == MotionEvent.ACTION_DOWN) - if(getBounds().contains((int)event.getX(), (int)event.getY())) - trackid = event.getPointerId(pointerIndex); - } - else + + switch(event.getAction() & MotionEvent.ACTION_MASK) { - if (event.getAction() == MotionEvent.ACTION_UP) + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + if (getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex))) + trackId = event.getPointerId(pointerIndex); + break; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + if (trackId == event.getPointerId(pointerIndex)) { - if (trackid == event.getPointerId(pointerIndex)) - { - axises[0] = axises[1] = 0.0f; - SetInnerBounds(); - trackid = -1; - } + axises[0] = axises[1] = 0.0f; + SetInnerBounds(); + trackId = -1; } + break; } - - if (trackid == -1) + + if (trackId == -1) return; - float touchX = event.getX(); - float touchY = event.getY(); - float maxY = this.getBounds().bottom; - float maxX = this.getBounds().right; - touchX -= this.getBounds().centerX(); - maxX -= this.getBounds().centerX(); - touchY -= this.getBounds().centerY(); - maxY -= this.getBounds().centerY(); - final float AxisX = touchX / maxX; - final float AxisY = touchY/maxY; - this.axises[0] = AxisY; - this.axises[1] = AxisX; + for (int i = 0; i < event.getPointerCount(); i++) + { + if (trackId == event.getPointerId(i)) + { + float touchX = event.getX(i); + float touchY = event.getY(i); + float maxY = getBounds().bottom; + float maxX = getBounds().right; + touchX -= getBounds().centerX(); + maxX -= getBounds().centerX(); + touchY -= getBounds().centerY(); + maxY -= getBounds().centerY(); + final float AxisX = touchX / maxX; + final float AxisY = touchY / maxY; + axises[0] = AxisY; + axises[1] = AxisX; - SetInnerBounds(); + SetInnerBounds(); + } + } } public float[] getAxisValues() |
