summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java/org
diff options
context:
space:
mode:
authorlynxnb <niccolo.betto@gmail.com>2022-01-15 19:44:11 +0100
committerlynxnb <niccolo.betto@gmail.com>2022-01-24 12:03:51 +0100
commitfe9ac4ed1d6efce98e87a9bd31e992e41f4c8785 (patch)
tree6d1c4ed10abce0ca29735f37cacfff058ddb22ca /Source/Android/app/src/main/java/org
parente8bbfc26fe27c4a5c9e6b44afc4918067a70fb58 (diff)
Android: add IR pointer modes to InputOverlayPointer
* Disabled: disables the overlay pointer * Follow: default behaviour, IR pointer follows touch position * Drag: IR pointer moves relative to the initial touch event position
Diffstat (limited to 'Source/Android/app/src/main/java/org')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java42
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java2
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java6
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java11
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java68
5 files changed, 104 insertions, 25 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
index 815b5b7396..1fa13ef399 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
@@ -9,7 +9,6 @@ import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.text.TextUtils;
import android.util.SparseIntArray;
import android.view.InputDevice;
import android.view.KeyEvent;
@@ -99,9 +98,9 @@ public final class EmulationActivity extends AppCompatActivity
MENU_ACTION_SAVE_SLOT6, MENU_ACTION_LOAD_SLOT1, MENU_ACTION_LOAD_SLOT2,
MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
- MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP,
- MENU_ACTION_MOTION_CONTROLS, MENU_ACTION_PAUSE_EMULATION, MENU_ACTION_UNPAUSE_EMULATION,
- MENU_ACTION_OVERLAY_CONTROLS, MENU_ACTION_SETTINGS})
+ MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_MODE, MENU_SET_IR_SENSITIVITY,
+ MENU_ACTION_CHOOSE_DOUBLETAP, MENU_ACTION_MOTION_CONTROLS, MENU_ACTION_PAUSE_EMULATION,
+ MENU_ACTION_UNPAUSE_EMULATION, MENU_ACTION_OVERLAY_CONTROLS, MENU_ACTION_SETTINGS})
public @interface MenuAction
{
}
@@ -133,13 +132,14 @@ public final class EmulationActivity extends AppCompatActivity
public static final int MENU_ACTION_JOYSTICK_REL_CENTER = 24;
public static final int MENU_ACTION_RUMBLE = 25;
public static final int MENU_ACTION_RESET_OVERLAY = 26;
- public static final int MENU_SET_IR_SENSITIVITY = 27;
- public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
- public static final int MENU_ACTION_MOTION_CONTROLS = 29;
- public static final int MENU_ACTION_PAUSE_EMULATION = 30;
- public static final int MENU_ACTION_UNPAUSE_EMULATION = 31;
- public static final int MENU_ACTION_OVERLAY_CONTROLS = 32;
- public static final int MENU_ACTION_SETTINGS = 33;
+ public static final int MENU_SET_IR_MODE = 27;
+ public static final int MENU_SET_IR_SENSITIVITY = 28;
+ public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 29;
+ public static final int MENU_ACTION_MOTION_CONTROLS = 30;
+ public static final int MENU_ACTION_PAUSE_EMULATION = 31;
+ public static final int MENU_ACTION_UNPAUSE_EMULATION = 32;
+ public static final int MENU_ACTION_OVERLAY_CONTROLS = 33;
+ public static final int MENU_ACTION_SETTINGS = 34;
private static final SparseIntArray buttonsActionsMap = new SparseIntArray();
@@ -158,6 +158,8 @@ public final class EmulationActivity extends AppCompatActivity
buttonsActionsMap.append(R.id.menu_emulation_rumble, EmulationActivity.MENU_ACTION_RUMBLE);
buttonsActionsMap
.append(R.id.menu_emulation_reset_overlay, EmulationActivity.MENU_ACTION_RESET_OVERLAY);
+ buttonsActionsMap.append(R.id.menu_emulation_set_ir_mode,
+ EmulationActivity.MENU_SET_IR_MODE);
buttonsActionsMap.append(R.id.menu_emulation_set_ir_sensitivity,
EmulationActivity.MENU_SET_IR_SENSITIVITY);
buttonsActionsMap.append(R.id.menu_emulation_choose_doubletap,
@@ -644,6 +646,10 @@ public final class EmulationActivity extends AppCompatActivity
startActivityForResult(intent, REQUEST_CHANGE_DISC);
break;
+ case MENU_SET_IR_MODE:
+ setIRMode();
+ break;
+
case MENU_SET_IR_SENSITIVITY:
setIRSensitivity();
break;
@@ -939,6 +945,20 @@ public final class EmulationActivity extends AppCompatActivity
builder.show();
}
+ private void setIRMode()
+ {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DolphinDialogBase);
+ builder.setTitle(R.string.emulation_ir_mode);
+ builder.setSingleChoiceItems(R.array.irModeEntries,
+ IntSetting.MAIN_IR_MODE.getInt(mSettings),
+ (dialog, indexSelected) ->
+ IntSetting.MAIN_IR_MODE.setInt(mSettings, indexSelected));
+ builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
+ mEmulationFragment.refreshOverlayPointer(mSettings));
+
+ builder.show();
+ }
+
private void setIRSensitivity()
{
// IR settings always get saved per-game since WiimoteNew.ini is wiped upon reinstall.
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java
index 152609d3b8..d28603cbef 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java
@@ -30,6 +30,8 @@ public enum IntSetting implements AbstractIntSetting
"EmulationOrientation", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
MAIN_LAST_PLATFORM_TAB(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "LastPlatformTab", 0),
MAIN_MOTION_CONTROLS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "MotionControls", 1),
+ MAIN_IR_MODE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "IRMode",
+ InputOverlayPointer.MODE_FOLLOW),
MAIN_DOUBLE_TAP_BUTTON(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID_OVERLAY_BUTTONS,
"DoubleTapButton",
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java
index 7f1e158830..8d94033bf9 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java
@@ -162,6 +162,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mInputOverlay.refreshControls();
}
+ public void refreshOverlayPointer(Settings settings)
+ {
+ if (mInputOverlay != null)
+ mInputOverlay.refreshOverlayPointer(settings);
+ }
+
public void resetInputOverlay()
{
if (mInputOverlay != null)
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
index 5b3b232af4..c58207283a 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
@@ -164,7 +164,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
doubleTapButton = InputOverlayPointer.DOUBLE_TAP_A;
}
- overlayPointer = new InputOverlayPointer(mSurfacePosition, doubleTapButton);
+ overlayPointer = new InputOverlayPointer(mSurfacePosition, doubleTapButton,
+ IntSetting.MAIN_IR_MODE.getIntGlobal());
}
@Override
@@ -769,6 +770,14 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
invalidate();
}
+ public void refreshOverlayPointer(Settings settings)
+ {
+ if (overlayPointer != null)
+ {
+ overlayPointer.setMode(IntSetting.MAIN_IR_MODE.getInt(settings));
+ }
+ }
+
public void resetButtonPlacement()
{
boolean isLandscape =
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java
index 6ad9c29ca3..01e1e3ad57 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayPointer.java
@@ -17,13 +17,23 @@ public class InputOverlayPointer
public static final int DOUBLE_TAP_2 = 2;
public static final int DOUBLE_TAP_CLASSIC_A = 3;
+ public static final int MODE_DISABLED = 0;
+ public static final int MODE_FOLLOW = 1;
+ public static final int MODE_DRAG = 2;
+
private final float[] axes = {0f, 0f};
+ private final float[] oldaxes = {0f, 0f};
private float mGameCenterX;
private float mGameCenterY;
private float mGameWidthHalfInv;
private float mGameHeightHalfInv;
+ private float mTouchStartX;
+ private float mTouchStartY;
+
+ private int mMode;
+
private boolean doubleTap = false;
private int doubleTapButton;
private int trackId = -1;
@@ -38,9 +48,10 @@ public class InputOverlayPointer
DOUBLE_TAP_OPTIONS.add(NativeLibrary.ButtonType.CLASSIC_BUTTON_A);
}
- public InputOverlayPointer(Rect surfacePosition, int button)
+ public InputOverlayPointer(Rect surfacePosition, int button, int mode)
{
doubleTapButton = button;
+ mMode = mode;
mGameCenterX = (surfacePosition.left + surfacePosition.right) / 2.0f;
mGameCenterY = (surfacePosition.top + surfacePosition.bottom) / 2.0f;
@@ -76,38 +87,62 @@ public class InputOverlayPointer
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
trackId = event.getPointerId(pointerIndex);
+ mTouchStartX = event.getX(pointerIndex);
+ mTouchStartY = event.getY(pointerIndex);
touchPress();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
if (trackId == event.getPointerId(pointerIndex))
trackId = -1;
+ if (mMode == MODE_DRAG)
+ updateOldAxes();
break;
}
if (trackId == -1)
return;
- axes[0] = (event.getY(event.findPointerIndex(trackId)) - mGameCenterY) * mGameHeightHalfInv;
- axes[1] = (event.getX(event.findPointerIndex(trackId)) - mGameCenterX) * mGameWidthHalfInv;
+ if (mMode == MODE_FOLLOW)
+ {
+ axes[0] = (event.getY(event.findPointerIndex(trackId)) - mGameCenterY) * mGameHeightHalfInv;
+ axes[1] = (event.getX(event.findPointerIndex(trackId)) - mGameCenterX) * mGameWidthHalfInv;
+ }
+ else if (mMode == MODE_DRAG)
+ {
+ axes[0] = oldaxes[0] +
+ (event.getY(event.findPointerIndex(trackId)) - mTouchStartY) * mGameHeightHalfInv;
+ axes[1] = oldaxes[1] +
+ (event.getX(event.findPointerIndex(trackId)) - mTouchStartX) * mGameWidthHalfInv;
+ }
}
private void touchPress()
{
- if (doubleTap)
- {
- NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
- doubleTapButton, NativeLibrary.ButtonState.PRESSED);
- new Handler().postDelayed(() -> NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
- doubleTapButton, NativeLibrary.ButtonState.RELEASED), 50);
- }
- else
+ if (mMode != MODE_DISABLED)
{
- doubleTap = true;
- new Handler().postDelayed(() -> doubleTap = false, 300);
+ if (doubleTap)
+ {
+ NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
+ doubleTapButton, NativeLibrary.ButtonState.PRESSED);
+ new Handler()
+ .postDelayed(() -> NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
+ doubleTapButton, NativeLibrary.ButtonState.RELEASED), 50);
+ }
+ else
+ {
+ doubleTap = true;
+ new Handler().postDelayed(() -> doubleTap = false, 300);
+ }
}
}
+ private void updateOldAxes()
+ {
+ oldaxes[0] = axes[0];
+ oldaxes[1] = axes[1];
+ }
+
public float[] getAxisValues()
{
float[] iraxes = {0f, 0f, 0f, 0f};
@@ -117,4 +152,11 @@ public class InputOverlayPointer
iraxes[2] = axes[1];
return iraxes;
}
+
+ public void setMode(int mode)
+ {
+ mMode = mode;
+ if (mode == MODE_DRAG)
+ updateOldAxes();
+ }
}