diff options
| author | 2023-02-13 13:14:02 -0600 | |
|---|---|---|
| committer | 2023-06-03 00:05:30 -0700 | |
| commit | 639a1f885cd93f51ad9214c2b7cfe30c8d154950 (patch) | |
| tree | 515c9156d195ede905a403f2b13369b8a1c74785 | |
| parent | android: Clean button overlay (diff) | |
| download | yuzu-639a1f885cd93f51ad9214c2b7cfe30c8d154950.tar.gz yuzu-639a1f885cd93f51ad9214c2b7cfe30c8d154950.tar.xz yuzu-639a1f885cd93f51ad9214c2b7cfe30c8d154950.zip | |
android: Clean dpad overlay
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.java | 109 | ||||
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java | 257 |
2 files changed, 174 insertions, 192 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 { | |||
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | for (InputOverlayDrawableDpad dpad : overlayDpads) { | 378 | for (InputOverlayDrawableDpad dpad : overlayDpads) { |
| 379 | // Determine the button state to apply based on the MotionEvent action flag. | 379 | if (!dpad.updateStatus(event, EmulationMenuSettings.getDpadSlideEnable())) { |
| 380 | switch (event.getAction() & MotionEvent.ACTION_MASK) { | 380 | continue; |
| 381 | case MotionEvent.ACTION_DOWN: | ||
| 382 | case MotionEvent.ACTION_POINTER_DOWN: | ||
| 383 | // If a pointer enters the bounds of a button, press that button. | ||
| 384 | if (dpad.getBounds() | ||
| 385 | .contains((int) event.getX(pointerIndex), (int) event.getY(pointerIndex))) { | ||
| 386 | dpad.setTrackId(event.getPointerId(pointerIndex)); | ||
| 387 | } | ||
| 388 | break; | ||
| 389 | case MotionEvent.ACTION_UP: | ||
| 390 | case MotionEvent.ACTION_POINTER_UP: | ||
| 391 | // If a pointer ends, release the buttons. | ||
| 392 | if (dpad.getTrackId() == event.getPointerId(pointerIndex)) { | ||
| 393 | for (int i = 0; i < 4; i++) { | ||
| 394 | dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT); | ||
| 395 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i), | ||
| 396 | NativeLibrary.ButtonState.RELEASED); | ||
| 397 | } | ||
| 398 | dpad.setTrackId(-1); | ||
| 399 | } | ||
| 400 | break; | ||
| 401 | } | ||
| 402 | |||
| 403 | if (dpad.getTrackId() != -1) { | ||
| 404 | for (int i = 0; i < event.getPointerCount(); i++) { | ||
| 405 | if (dpad.getTrackId() == event.getPointerId(i)) { | ||
| 406 | float touchX = event.getX(i); | ||
| 407 | float touchY = event.getY(i); | ||
| 408 | float maxY = dpad.getBounds().bottom; | ||
| 409 | float maxX = dpad.getBounds().right; | ||
| 410 | touchX -= dpad.getBounds().centerX(); | ||
| 411 | maxX -= dpad.getBounds().centerX(); | ||
| 412 | touchY -= dpad.getBounds().centerY(); | ||
| 413 | maxY -= dpad.getBounds().centerY(); | ||
| 414 | final float AxisX = touchX / maxX; | ||
| 415 | final float AxisY = touchY / maxY; | ||
| 416 | |||
| 417 | boolean up = false; | ||
| 418 | boolean down = false; | ||
| 419 | boolean left = false; | ||
| 420 | boolean right = false; | ||
| 421 | if (EmulationMenuSettings.getDpadSlideEnable() || | ||
| 422 | (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN || | ||
| 423 | (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) { | ||
| 424 | if (AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { | ||
| 425 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0), | ||
| 426 | NativeLibrary.ButtonState.PRESSED); | ||
| 427 | up = true; | ||
| 428 | } else { | ||
| 429 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0), | ||
| 430 | NativeLibrary.ButtonState.RELEASED); | ||
| 431 | } | ||
| 432 | if (AxisY > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { | ||
| 433 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1), | ||
| 434 | NativeLibrary.ButtonState.PRESSED); | ||
| 435 | down = true; | ||
| 436 | } else { | ||
| 437 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1), | ||
| 438 | NativeLibrary.ButtonState.RELEASED); | ||
| 439 | } | ||
| 440 | if (AxisX < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { | ||
| 441 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2), | ||
| 442 | NativeLibrary.ButtonState.PRESSED); | ||
| 443 | left = true; | ||
| 444 | } else { | ||
| 445 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2), | ||
| 446 | NativeLibrary.ButtonState.RELEASED); | ||
| 447 | } | ||
| 448 | if (AxisX > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { | ||
| 449 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3), | ||
| 450 | NativeLibrary.ButtonState.PRESSED); | ||
| 451 | right = true; | ||
| 452 | } else { | ||
| 453 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3), | ||
| 454 | NativeLibrary.ButtonState.RELEASED); | ||
| 455 | } | ||
| 456 | |||
| 457 | // Set state | ||
| 458 | if (up) { | ||
| 459 | if (left) | ||
| 460 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_LEFT); | ||
| 461 | else if (right) | ||
| 462 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_RIGHT); | ||
| 463 | else | ||
| 464 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP); | ||
| 465 | } else if (down) { | ||
| 466 | if (left) | ||
| 467 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_LEFT); | ||
| 468 | else if (right) | ||
| 469 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_RIGHT); | ||
| 470 | else | ||
| 471 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN); | ||
| 472 | } else if (left) { | ||
| 473 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_LEFT); | ||
| 474 | } else if (right) { | ||
| 475 | dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_RIGHT); | ||
| 476 | } else { | ||
| 477 | dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT); | ||
| 478 | } | ||
| 479 | } | ||
| 480 | } | ||
| 481 | } | ||
| 482 | } | 381 | } |
| 382 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getUpId(), dpad.getUpStatus()); | ||
| 383 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getDownId(), dpad.getDownStatus()); | ||
| 384 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getLeftId(), dpad.getLeftStatus()); | ||
| 385 | NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getRightId(), dpad.getRightStatus()); | ||
| 483 | } | 386 | } |
| 484 | 387 | ||
| 485 | for (InputOverlayDrawableJoystick joystick : overlayJoysticks) { | 388 | for (InputOverlayDrawableJoystick joystick : overlayJoysticks) { |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java index a14840d98..d8ee6895b 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlayDrawableDpad.java | |||
| @@ -13,32 +13,30 @@ import android.graphics.Rect; | |||
| 13 | import android.graphics.drawable.BitmapDrawable; | 13 | import android.graphics.drawable.BitmapDrawable; |
| 14 | import android.view.MotionEvent; | 14 | import android.view.MotionEvent; |
| 15 | 15 | ||
| 16 | import org.yuzu.yuzu_emu.NativeLibrary.ButtonState; | ||
| 17 | |||
| 16 | /** | 18 | /** |
| 17 | * Custom {@link BitmapDrawable} that is capable | 19 | * Custom {@link BitmapDrawable} that is capable |
| 18 | * of storing it's own ID. | 20 | * of storing it's own ID. |
| 19 | */ | 21 | */ |
| 20 | public final class InputOverlayDrawableDpad { | 22 | public final class InputOverlayDrawableDpad { |
| 21 | public static final int STATE_DEFAULT = 0; | ||
| 22 | public static final int STATE_PRESSED_UP = 1; | ||
| 23 | public static final int STATE_PRESSED_DOWN = 2; | ||
| 24 | public static final int STATE_PRESSED_LEFT = 3; | ||
| 25 | public static final int STATE_PRESSED_RIGHT = 4; | ||
| 26 | public static final int STATE_PRESSED_UP_LEFT = 5; | ||
| 27 | public static final int STATE_PRESSED_UP_RIGHT = 6; | ||
| 28 | public static final int STATE_PRESSED_DOWN_LEFT = 7; | ||
| 29 | public static final int STATE_PRESSED_DOWN_RIGHT = 8; | ||
| 30 | public static final float VIRT_AXIS_DEADZONE = 0.5f; | 23 | public static final float VIRT_AXIS_DEADZONE = 0.5f; |
| 31 | // The ID identifying what type of button this Drawable represents. | 24 | // The ID identifying what type of button this Drawable represents. |
| 32 | private int[] mButtonType = new int[4]; | 25 | private int mUpButtonId; |
| 26 | private int mDownButtonId; | ||
| 27 | private int mLeftButtonId; | ||
| 28 | private int mRightButtonId; | ||
| 33 | private int mTrackId; | 29 | private int mTrackId; |
| 34 | private int mPreviousTouchX, mPreviousTouchY; | ||
| 35 | private int mControlPositionX, mControlPositionY; | 30 | private int mControlPositionX, mControlPositionY; |
| 36 | private int mWidth; | 31 | private int mWidth; |
| 37 | private int mHeight; | 32 | private int mHeight; |
| 38 | private BitmapDrawable mDefaultStateBitmap; | 33 | private BitmapDrawable mDefaultStateBitmap; |
| 39 | private BitmapDrawable mPressedOneDirectionStateBitmap; | 34 | private BitmapDrawable mPressedOneDirectionStateBitmap; |
| 40 | private BitmapDrawable mPressedTwoDirectionsStateBitmap; | 35 | private BitmapDrawable mPressedTwoDirectionsStateBitmap; |
| 41 | private int mPressState = STATE_DEFAULT; | 36 | private boolean mUpButtonState; |
| 37 | private boolean mDownButtonState; | ||
| 38 | private boolean mLeftButtonState; | ||
| 39 | private boolean mRightButtonState; | ||
| 42 | 40 | ||
| 43 | /** | 41 | /** |
| 44 | * Constructor | 42 | * Constructor |
| @@ -65,64 +63,147 @@ public final class InputOverlayDrawableDpad { | |||
| 65 | mWidth = mDefaultStateBitmap.getIntrinsicWidth(); | 63 | mWidth = mDefaultStateBitmap.getIntrinsicWidth(); |
| 66 | mHeight = mDefaultStateBitmap.getIntrinsicHeight(); | 64 | mHeight = mDefaultStateBitmap.getIntrinsicHeight(); |
| 67 | 65 | ||
| 68 | mButtonType[0] = buttonUp; | 66 | mUpButtonId = buttonUp; |
| 69 | mButtonType[1] = buttonDown; | 67 | mDownButtonId = buttonDown; |
| 70 | mButtonType[2] = buttonLeft; | 68 | mLeftButtonId = buttonLeft; |
| 71 | mButtonType[3] = buttonRight; | 69 | mRightButtonId = buttonRight; |
| 72 | 70 | ||
| 73 | mTrackId = -1; | 71 | mTrackId = -1; |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 74 | public boolean updateStatus(MotionEvent event, boolean dpad_slide) { | ||
| 75 | int pointerIndex = event.getActionIndex(); | ||
| 76 | int xPosition = (int) event.getX(pointerIndex); | ||
| 77 | int yPosition = (int) event.getY(pointerIndex); | ||
| 78 | int pointerId = event.getPointerId(pointerIndex); | ||
| 79 | int motion_event = event.getAction() & MotionEvent.ACTION_MASK; | ||
| 80 | boolean isActionDown = motion_event == MotionEvent.ACTION_DOWN || motion_event == MotionEvent.ACTION_POINTER_DOWN; | ||
| 81 | boolean isActionUp = motion_event == MotionEvent.ACTION_UP || motion_event == MotionEvent.ACTION_POINTER_UP; | ||
| 82 | |||
| 83 | if (isActionDown) { | ||
| 84 | if (!getBounds().contains(xPosition, yPosition)) { | ||
| 85 | return false; | ||
| 86 | } | ||
| 87 | mTrackId = pointerId; | ||
| 88 | } | ||
| 89 | |||
| 90 | if (isActionUp) { | ||
| 91 | if (mTrackId != pointerId) { | ||
| 92 | return false; | ||
| 93 | } | ||
| 94 | mTrackId = -1; | ||
| 95 | mUpButtonState = false; | ||
| 96 | mDownButtonState = false; | ||
| 97 | mLeftButtonState = false; | ||
| 98 | mRightButtonState = false; | ||
| 99 | return true; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (mTrackId == -1) { | ||
| 103 | return false; | ||
| 104 | } | ||
| 105 | |||
| 106 | if (!dpad_slide && !isActionDown) { | ||
| 107 | return false; | ||
| 108 | } | ||
| 109 | |||
| 110 | for (int i = 0; i < event.getPointerCount(); i++) { | ||
| 111 | if (mTrackId != event.getPointerId(i)) { | ||
| 112 | continue; | ||
| 113 | } | ||
| 114 | float touchX = event.getX(i); | ||
| 115 | float touchY = event.getY(i); | ||
| 116 | float maxY = getBounds().bottom; | ||
| 117 | float maxX = getBounds().right; | ||
| 118 | touchX -= getBounds().centerX(); | ||
| 119 | maxX -= getBounds().centerX(); | ||
| 120 | touchY -= getBounds().centerY(); | ||
| 121 | maxY -= getBounds().centerY(); | ||
| 122 | final float AxisX = touchX / maxX; | ||
| 123 | final float AxisY = touchY / maxY; | ||
| 124 | |||
| 125 | mUpButtonState = AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; | ||
| 126 | mDownButtonState = AxisY > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; | ||
| 127 | mLeftButtonState = AxisX < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; | ||
| 128 | mRightButtonState = AxisX > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE; | ||
| 129 | return true; | ||
| 130 | } | ||
| 131 | |||
| 132 | return false; | ||
| 133 | } | ||
| 134 | |||
| 76 | public void draw(Canvas canvas) { | 135 | public void draw(Canvas canvas) { |
| 77 | int px = mControlPositionX + (getWidth() / 2); | 136 | int px = mControlPositionX + (getWidth() / 2); |
| 78 | int py = mControlPositionY + (getHeight() / 2); | 137 | int py = mControlPositionY + (getHeight() / 2); |
| 79 | switch (mPressState) { | 138 | |
| 80 | case STATE_DEFAULT: | 139 | // Pressed up |
| 81 | mDefaultStateBitmap.draw(canvas); | 140 | if (mUpButtonState && !mLeftButtonState && !mRightButtonState) { |
| 82 | break; | 141 | mPressedOneDirectionStateBitmap.draw(canvas); |
| 83 | case STATE_PRESSED_UP: | 142 | return; |
| 84 | mPressedOneDirectionStateBitmap.draw(canvas); | 143 | } |
| 85 | break; | 144 | |
| 86 | case STATE_PRESSED_RIGHT: | 145 | // Pressed down |
| 87 | canvas.save(); | 146 | if (mDownButtonState && !mLeftButtonState && !mRightButtonState) { |
| 88 | canvas.rotate(90, px, py); | 147 | canvas.save(); |
| 89 | mPressedOneDirectionStateBitmap.draw(canvas); | 148 | canvas.rotate(180, px, py); |
| 90 | canvas.restore(); | 149 | mPressedOneDirectionStateBitmap.draw(canvas); |
| 91 | break; | 150 | canvas.restore(); |
| 92 | case STATE_PRESSED_DOWN: | 151 | return; |
| 93 | canvas.save(); | 152 | } |
| 94 | canvas.rotate(180, px, py); | 153 | |
| 95 | mPressedOneDirectionStateBitmap.draw(canvas); | 154 | // Pressed left |
| 96 | canvas.restore(); | 155 | if (mLeftButtonState && !mUpButtonState && !mDownButtonState) { |
| 97 | break; | 156 | canvas.save(); |
| 98 | case STATE_PRESSED_LEFT: | 157 | canvas.rotate(270, px, py); |
| 99 | canvas.save(); | 158 | mPressedOneDirectionStateBitmap.draw(canvas); |
| 100 | canvas.rotate(270, px, py); | 159 | canvas.restore(); |
| 101 | mPressedOneDirectionStateBitmap.draw(canvas); | 160 | return; |
| 102 | canvas.restore(); | 161 | } |
| 103 | break; | 162 | |
| 104 | case STATE_PRESSED_UP_LEFT: | 163 | // Pressed right |
| 105 | mPressedTwoDirectionsStateBitmap.draw(canvas); | 164 | if (mRightButtonState && !mUpButtonState && !mDownButtonState) { |
| 106 | break; | 165 | canvas.save(); |
| 107 | case STATE_PRESSED_UP_RIGHT: | 166 | canvas.rotate(90, px, py); |
| 108 | canvas.save(); | 167 | mPressedOneDirectionStateBitmap.draw(canvas); |
| 109 | canvas.rotate(90, px, py); | 168 | canvas.restore(); |
| 110 | mPressedTwoDirectionsStateBitmap.draw(canvas); | 169 | return; |
| 111 | canvas.restore(); | ||
| 112 | break; | ||
| 113 | case STATE_PRESSED_DOWN_RIGHT: | ||
| 114 | canvas.save(); | ||
| 115 | canvas.rotate(180, px, py); | ||
| 116 | mPressedTwoDirectionsStateBitmap.draw(canvas); | ||
| 117 | canvas.restore(); | ||
| 118 | break; | ||
| 119 | case STATE_PRESSED_DOWN_LEFT: | ||
| 120 | canvas.save(); | ||
| 121 | canvas.rotate(270, px, py); | ||
| 122 | mPressedTwoDirectionsStateBitmap.draw(canvas); | ||
| 123 | canvas.restore(); | ||
| 124 | break; | ||
| 125 | } | 170 | } |
| 171 | |||
| 172 | // Pressed up left | ||
| 173 | if (mUpButtonState && mLeftButtonState && !mRightButtonState) { | ||
| 174 | mPressedTwoDirectionsStateBitmap.draw(canvas); | ||
| 175 | return; | ||
| 176 | } | ||
| 177 | |||
| 178 | // Pressed up right | ||
| 179 | if (mUpButtonState && !mLeftButtonState && mRightButtonState) { | ||
| 180 | canvas.save(); | ||
| 181 | canvas.rotate(180, px, py); | ||
| 182 | mPressedTwoDirectionsStateBitmap.draw(canvas); | ||
| 183 | canvas.restore(); | ||
| 184 | return; | ||
| 185 | } | ||
| 186 | |||
| 187 | // Pressed down left | ||
| 188 | if (mDownButtonState && mLeftButtonState && !mRightButtonState) { | ||
| 189 | canvas.save(); | ||
| 190 | canvas.rotate(270, px, py); | ||
| 191 | mPressedTwoDirectionsStateBitmap.draw(canvas); | ||
| 192 | canvas.restore(); | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | |||
| 196 | // Pressed down right | ||
| 197 | if (mDownButtonState && !mLeftButtonState && mRightButtonState) { | ||
| 198 | canvas.save(); | ||
| 199 | canvas.rotate(180, px, py); | ||
| 200 | mPressedTwoDirectionsStateBitmap.draw(canvas); | ||
| 201 | canvas.restore(); | ||
| 202 | return; | ||
| 203 | } | ||
| 204 | |||
| 205 | // Not pressed | ||
| 206 | mDefaultStateBitmap.draw(canvas); | ||
| 126 | } | 207 | } |
| 127 | 208 | ||
| 128 | /** | 209 | /** |
| @@ -130,38 +211,40 @@ public final class InputOverlayDrawableDpad { | |||
| 130 | * | 211 | * |
| 131 | * @return the requested InputOverlayDrawableDpad's button ID. | 212 | * @return the requested InputOverlayDrawableDpad's button ID. |
| 132 | */ | 213 | */ |
| 133 | public int getId(int direction) { | 214 | public int getUpId() { |
| 134 | return mButtonType[direction]; | 215 | return mUpButtonId; |
| 216 | } | ||
| 217 | |||
| 218 | public int getDownId() { | ||
| 219 | return mDownButtonId; | ||
| 220 | } | ||
| 221 | |||
| 222 | public int getLeftId() { | ||
| 223 | return mLeftButtonId; | ||
| 224 | } | ||
| 225 | |||
| 226 | public int getRightId() { | ||
| 227 | return mRightButtonId; | ||
| 135 | } | 228 | } |
| 136 | 229 | ||
| 137 | public int getTrackId() { | 230 | public int getTrackId() { |
| 138 | return mTrackId; | 231 | return mTrackId; |
| 139 | } | 232 | } |
| 140 | 233 | ||
| 141 | public void setTrackId(int trackId) { | 234 | public int getUpStatus() { |
| 142 | mTrackId = trackId; | 235 | return mUpButtonState ? ButtonState.PRESSED : ButtonState.RELEASED; |
| 143 | } | 236 | } |
| 144 | 237 | ||
| 145 | public boolean onConfigureTouch(MotionEvent event) { | 238 | public int getDownStatus() { |
| 146 | int pointerIndex = event.getActionIndex(); | 239 | return mDownButtonState ? ButtonState.PRESSED : ButtonState.RELEASED; |
| 147 | int fingerPositionX = (int) event.getX(pointerIndex); | 240 | } |
| 148 | int fingerPositionY = (int) event.getY(pointerIndex); | ||
| 149 | switch (event.getAction()) { | ||
| 150 | case MotionEvent.ACTION_DOWN: | ||
| 151 | mPreviousTouchX = fingerPositionX; | ||
| 152 | mPreviousTouchY = fingerPositionY; | ||
| 153 | break; | ||
| 154 | case MotionEvent.ACTION_MOVE: | ||
| 155 | mControlPositionX += fingerPositionX - mPreviousTouchX; | ||
| 156 | mControlPositionY += fingerPositionY - mPreviousTouchY; | ||
| 157 | setBounds(mControlPositionX, mControlPositionY, getWidth() + mControlPositionX, | ||
| 158 | getHeight() + mControlPositionY); | ||
| 159 | mPreviousTouchX = fingerPositionX; | ||
| 160 | mPreviousTouchY = fingerPositionY; | ||
| 161 | break; | ||
| 162 | 241 | ||
| 163 | } | 242 | public int getLeftStatus() { |
| 164 | return true; | 243 | return mLeftButtonState ? ButtonState.PRESSED : ButtonState.RELEASED; |
| 244 | } | ||
| 245 | |||
| 246 | public int getRightStatus() { | ||
| 247 | return mRightButtonState ? ButtonState.PRESSED : ButtonState.RELEASED; | ||
| 165 | } | 248 | } |
| 166 | 249 | ||
| 167 | public void setPosition(int x, int y) { | 250 | public void setPosition(int x, int y) { |
| @@ -186,8 +269,4 @@ public final class InputOverlayDrawableDpad { | |||
| 186 | public int getHeight() { | 269 | public int getHeight() { |
| 187 | return mHeight; | 270 | return mHeight; |
| 188 | } | 271 | } |
| 189 | |||
| 190 | public void setState(int pressState) { | ||
| 191 | mPressState = pressState; | ||
| 192 | } | ||
| 193 | } | 272 | } |