diff options
| author | LC <mathew1800@gmail.com> | 2020-07-08 08:50:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-08 08:50:47 -0400 |
| commit | 87287181dd17156170d601ca5e7c81e66afb6643 (patch) | |
| tree | 70f8e2c226da940af63f2bd534319de6bcab1627 /Source/Android/app/src/main/java | |
| parent | a5166be9952ce3486db9730f8a7e178af4415d66 (diff) | |
| parent | f8e0ececb9668e200eb0fbe932d7f8ddf2728a8b (diff) | |
Merge pull request #8907 from JosJuice/android-overlay-stick-gate
Android: Use octagonal stick gate in overlay
Diffstat (limited to 'Source/Android/app/src/main/java')
3 files changed, 24 insertions, 13 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index fef329d451..87db570275 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -269,6 +269,9 @@ public final class NativeLibrary public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled, boolean gyroscopeEnabled); + // Angle is in radians and should be non-negative + public static native double GetInputRadiusAtAngle(int emu_pad_id, int stick, double angle); + public static native void NewGameIniFile(); public static native void LoadGameIniFile(String gameId); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java index 55f6347096..a32155686e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java @@ -14,6 +14,8 @@ import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.view.MotionEvent; +import org.dolphinemu.dolphinemu.NativeLibrary; + /** * Custom {@link BitmapDrawable} that is capable * of storing it's own ID. @@ -214,21 +216,27 @@ public final class InputOverlayDrawableJoystick private void SetInnerBounds() { - int X = getVirtBounds().centerX() + (int) ((axises[1]) * (getVirtBounds().width() / 2)); - int Y = getVirtBounds().centerY() + (int) ((axises[0]) * (getVirtBounds().height() / 2)); - - if (X > getVirtBounds().centerX() + (getVirtBounds().width() / 2)) - X = getVirtBounds().centerX() + (getVirtBounds().width() / 2); - if (X < getVirtBounds().centerX() - (getVirtBounds().width() / 2)) - X = getVirtBounds().centerX() - (getVirtBounds().width() / 2); - if (Y > getVirtBounds().centerY() + (getVirtBounds().height() / 2)) - Y = getVirtBounds().centerY() + (getVirtBounds().height() / 2); - if (Y < getVirtBounds().centerY() - (getVirtBounds().height() / 2)) - Y = getVirtBounds().centerY() - (getVirtBounds().height() / 2); + double y = axises[0]; + double x = axises[1]; + + double angle = Math.atan2(y, x) + Math.PI + Math.PI; + double radius = Math.hypot(y, x); + double maxRadius = NativeLibrary.GetInputRadiusAtAngle(0, mJoystickType, angle); + if (radius > maxRadius) + { + y = maxRadius * Math.sin(angle); + x = maxRadius * Math.cos(angle); + axises[0] = (float) y; + axises[1] = (float) x; + } + + int pixelX = getVirtBounds().centerX() + (int) (x * (getVirtBounds().width() / 2)); + int pixelY = getVirtBounds().centerY() + (int) (y * (getVirtBounds().height() / 2)); int width = mPressedStateInnerBitmap.getBounds().width() / 2; int height = mPressedStateInnerBitmap.getBounds().height() / 2; - mDefaultStateInnerBitmap.setBounds(X - width, Y - height, X + width, Y + height); + mDefaultStateInnerBitmap.setBounds(pixelX - width, pixelY - height, pixelX + width, + pixelY + height); mPressedStateInnerBitmap.setBounds(mDefaultStateInnerBitmap.getBounds()); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java index ce097ec3e1..fbe5bc65ca 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java @@ -35,7 +35,7 @@ public final class DirectoryInitialization "org.dolphinemu.dolphinemu.DIRECTORY_INITIALIZATION"; public static final String EXTRA_STATE = "directoryState"; - private static final int WiimoteNewVersion = 4; // Last changed in PR 8503 + private static final int WiimoteNewVersion = 5; // Last changed in PR 8907 private static volatile DirectoryInitializationState directoryState = null; private static String userPath; private static String internalPath; |
