mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 15:31:17 +01:00
Android: Normalize pointer touches based on rendered aspect ratio
This allows the defaults to be actual defaults across devices with different screen sizes
This commit is contained in:
parent
ec557eb3a2
commit
e8739156e4
@ -492,4 +492,19 @@ public final class NativeLibrary
|
|||||||
|
|
||||||
sEmulationActivity.clear();
|
sEmulationActivity.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateTouchPointer()
|
||||||
|
{
|
||||||
|
final EmulationActivity emulationActivity = sEmulationActivity.get();
|
||||||
|
if (emulationActivity == null)
|
||||||
|
{
|
||||||
|
Log.warning("[NativeLibrary] EmulationActivity is null.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emulationActivity.runOnUiThread(emulationActivity::initInputPointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static native float GetGameAspectRatio();
|
||||||
}
|
}
|
||||||
|
@ -757,7 +757,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
|
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
|
||||||
{
|
{
|
||||||
editor.commit();
|
editor.commit();
|
||||||
mEmulationFragment.refreshInputOverlay();
|
mEmulationFragment.initInputPointer();
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog alertDialog = builder.create();
|
AlertDialog alertDialog = builder.create();
|
||||||
@ -1064,4 +1064,9 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
{
|
{
|
||||||
return mSettings;
|
return mSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initInputPointer()
|
||||||
|
{
|
||||||
|
mEmulationFragment.initInputPointer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,11 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
mInputOverlay.refreshControls();
|
mInputOverlay.refreshControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initInputPointer()
|
||||||
|
{
|
||||||
|
mInputOverlay.initTouchPointer();
|
||||||
|
}
|
||||||
|
|
||||||
public void refreshInputOverlay()
|
public void refreshInputOverlay()
|
||||||
{
|
{
|
||||||
mInputOverlay.refreshControls();
|
mInputOverlay.refreshControls();
|
||||||
|
@ -92,6 +92,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
if (!mPreferences.getBoolean("OverlayInitV2", false))
|
if (!mPreferences.getBoolean("OverlayInitV2", false))
|
||||||
defaultOverlay();
|
defaultOverlay();
|
||||||
|
|
||||||
// Load the controls.
|
// Load the controls.
|
||||||
refreshControls();
|
refreshControls();
|
||||||
|
|
||||||
@ -105,6 +106,27 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
requestFocus();
|
requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initTouchPointer()
|
||||||
|
{
|
||||||
|
// Refresh before starting the pointer
|
||||||
|
refreshControls();
|
||||||
|
|
||||||
|
if (!EmulationActivity.isGameCubeGame())
|
||||||
|
{
|
||||||
|
int doubleTapButton = mPreferences.getInt("doubleTapButton",
|
||||||
|
InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(InputOverlayPointer.DOUBLE_TAP_A));
|
||||||
|
|
||||||
|
if (mPreferences.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUCK) !=
|
||||||
|
InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
|
||||||
|
doubleTapButton == InputOverlayPointer.DOUBLE_TAP_CLASSIC_A)
|
||||||
|
{
|
||||||
|
doubleTapButton = InputOverlayPointer.DOUBLE_TAP_A;
|
||||||
|
}
|
||||||
|
|
||||||
|
overlayPointer = new InputOverlayPointer(this.getContext(), doubleTapButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas)
|
public void draw(Canvas canvas)
|
||||||
{
|
{
|
||||||
@ -201,15 +223,22 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
|
|
||||||
// Release the buttons first, then press
|
// Release the buttons first, then press
|
||||||
for (int i = 0; i < dpadPressed.length; i++)
|
for (int i = 0; i < dpadPressed.length; i++)
|
||||||
|
{
|
||||||
if (!dpadPressed[i])
|
if (!dpadPressed[i])
|
||||||
|
{
|
||||||
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i),
|
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i),
|
||||||
ButtonState.RELEASED);
|
ButtonState.RELEASED);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Press buttons
|
// Press buttons
|
||||||
for (int i = 0; i < dpadPressed.length; i++)
|
for (int i = 0; i < dpadPressed.length; i++)
|
||||||
|
{
|
||||||
if (dpadPressed[i])
|
if (dpadPressed[i])
|
||||||
|
{
|
||||||
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i),
|
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i),
|
||||||
ButtonState.PRESSED);
|
ButtonState.PRESSED);
|
||||||
|
}
|
||||||
|
}
|
||||||
setDpadState(dpad, dpadPressed[0], dpadPressed[1], dpadPressed[2], dpadPressed[3]);
|
setDpadState(dpad, dpadPressed[0], dpadPressed[1], dpadPressed[2], dpadPressed[3]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -671,19 +700,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EmulationActivity.isGameCubeGame())
|
|
||||||
{
|
|
||||||
int doubleTapButton = mPreferences.getInt("doubleTapButton",
|
|
||||||
InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(InputOverlayPointer.DOUBLE_TAP_A));
|
|
||||||
|
|
||||||
if (mPreferences.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUCK) !=
|
|
||||||
InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
|
|
||||||
doubleTapButton == InputOverlayPointer.DOUBLE_TAP_CLASSIC_A)
|
|
||||||
doubleTapButton = InputOverlayPointer.DOUBLE_TAP_A;
|
|
||||||
|
|
||||||
overlayPointer = new InputOverlayPointer(this.getContext(), doubleTapButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,11 @@ public class InputOverlayPointer
|
|||||||
public static final int DOUBLE_TAP_CLASSIC_A = 3;
|
public static final int DOUBLE_TAP_CLASSIC_A = 3;
|
||||||
|
|
||||||
private final float[] axes = {0f, 0f};
|
private final float[] axes = {0f, 0f};
|
||||||
|
|
||||||
private float maxHeight;
|
private float maxHeight;
|
||||||
private float maxWidth;
|
private float maxWidth;
|
||||||
|
private float aspectAdjusted;
|
||||||
|
private boolean xAdjusted;
|
||||||
private boolean doubleTap = false;
|
private boolean doubleTap = false;
|
||||||
private int doubleTapButton;
|
private int doubleTapButton;
|
||||||
private int trackId = -1;
|
private int trackId = -1;
|
||||||
@ -41,8 +44,33 @@ public class InputOverlayPointer
|
|||||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||||
display.getMetrics(outMetrics);
|
display.getMetrics(outMetrics);
|
||||||
doubleTapButton = button;
|
doubleTapButton = button;
|
||||||
maxWidth = outMetrics.widthPixels / 2;
|
|
||||||
maxHeight = outMetrics.heightPixels / 2;
|
Integer y = outMetrics.heightPixels;
|
||||||
|
Integer x = outMetrics.widthPixels;
|
||||||
|
|
||||||
|
// Adjusting for device's black bars.
|
||||||
|
Float deviceAR = (float) x / y;
|
||||||
|
Float gameAR = NativeLibrary.GetGameAspectRatio();
|
||||||
|
aspectAdjusted = gameAR / deviceAR;
|
||||||
|
|
||||||
|
if (gameAR < deviceAR) // Black bars on left/right
|
||||||
|
{
|
||||||
|
xAdjusted = true;
|
||||||
|
Integer gameX = Math.round((float) y * gameAR);
|
||||||
|
Integer buffer = (x - gameX);
|
||||||
|
|
||||||
|
maxWidth = (float) (x - buffer) / 2;
|
||||||
|
maxHeight = (float) y / 2;
|
||||||
|
}
|
||||||
|
else // Bars on top/bottom
|
||||||
|
{
|
||||||
|
xAdjusted = false;
|
||||||
|
Integer gameY = Math.round((float) x * gameAR);
|
||||||
|
Integer buffer = (y - gameY);
|
||||||
|
|
||||||
|
maxWidth = (float) x / 2;
|
||||||
|
maxHeight = (float) (y - buffer) / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onTouch(MotionEvent event)
|
public boolean onTouch(MotionEvent event)
|
||||||
@ -68,9 +96,16 @@ public class InputOverlayPointer
|
|||||||
|
|
||||||
int x = (int) event.getX(event.findPointerIndex(trackId));
|
int x = (int) event.getX(event.findPointerIndex(trackId));
|
||||||
int y = (int) event.getY(event.findPointerIndex(trackId));
|
int y = (int) event.getY(event.findPointerIndex(trackId));
|
||||||
|
if (xAdjusted)
|
||||||
|
{
|
||||||
axes[0] = (y - maxHeight) / maxHeight;
|
axes[0] = (y - maxHeight) / maxHeight;
|
||||||
|
axes[1] = ((x * aspectAdjusted) - maxWidth) / maxWidth;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
axes[0] = ((y * aspectAdjusted) - maxHeight) / maxHeight;
|
||||||
axes[1] = (x - maxWidth) / maxWidth;
|
axes[1] = (x - maxWidth) / maxWidth;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ static JavaVM* s_java_vm;
|
|||||||
|
|
||||||
static jclass s_native_library_class;
|
static jclass s_native_library_class;
|
||||||
static jmethodID s_display_alert_msg;
|
static jmethodID s_display_alert_msg;
|
||||||
|
static jmethodID s_get_update_touch_pointer;
|
||||||
|
|
||||||
static jclass s_game_file_class;
|
static jclass s_game_file_class;
|
||||||
static jfieldID s_game_file_pointer;
|
static jfieldID s_game_file_pointer;
|
||||||
@ -41,6 +42,11 @@ jmethodID GetDisplayAlertMsg()
|
|||||||
return s_display_alert_msg;
|
return s_display_alert_msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jmethodID GetUpdateTouchPointer()
|
||||||
|
{
|
||||||
|
return s_get_update_touch_pointer;
|
||||||
|
}
|
||||||
|
|
||||||
jclass GetAnalyticsClass()
|
jclass GetAnalyticsClass()
|
||||||
{
|
{
|
||||||
return s_analytics_class;
|
return s_analytics_class;
|
||||||
@ -98,6 +104,8 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
|||||||
s_native_library_class = reinterpret_cast<jclass>(env->NewGlobalRef(native_library_class));
|
s_native_library_class = reinterpret_cast<jclass>(env->NewGlobalRef(native_library_class));
|
||||||
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
|
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
|
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
|
||||||
|
s_get_update_touch_pointer =
|
||||||
|
env->GetStaticMethodID(IDCache::GetNativeLibraryClass(), "updateTouchPointer", "()V");
|
||||||
|
|
||||||
const jclass game_file_class = env->FindClass("org/dolphinemu/dolphinemu/model/GameFile");
|
const jclass game_file_class = env->FindClass("org/dolphinemu/dolphinemu/model/GameFile");
|
||||||
s_game_file_class = reinterpret_cast<jclass>(env->NewGlobalRef(game_file_class));
|
s_game_file_class = reinterpret_cast<jclass>(env->NewGlobalRef(game_file_class));
|
||||||
|
@ -14,6 +14,7 @@ JavaVM* GetJavaVM();
|
|||||||
|
|
||||||
jclass GetNativeLibraryClass();
|
jclass GetNativeLibraryClass();
|
||||||
jmethodID GetDisplayAlertMsg();
|
jmethodID GetDisplayAlertMsg();
|
||||||
|
jmethodID GetUpdateTouchPointer();
|
||||||
|
|
||||||
jclass GetAnalyticsClass();
|
jclass GetAnalyticsClass();
|
||||||
jmethodID GetSendAnalyticsReport();
|
jmethodID GetSendAnalyticsReport();
|
||||||
|
@ -107,6 +107,11 @@ void Host_UpdateMainFrame()
|
|||||||
|
|
||||||
void Host_RequestRenderWindowSize(int width, int height)
|
void Host_RequestRenderWindowSize(int width, int height)
|
||||||
{
|
{
|
||||||
|
// Update touch pointer
|
||||||
|
JNIEnv* env;
|
||||||
|
IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr);
|
||||||
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetUpdateTouchPointer());
|
||||||
|
IDCache::GetJavaVM()->DetachCurrentThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Host_UINeedsControllerState()
|
bool Host_UINeedsControllerState()
|
||||||
@ -564,6 +569,13 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestr
|
|||||||
s_surf = nullptr;
|
s_surf = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jfloat JNICALL
|
||||||
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameAspectRatio(JNIEnv* env, jobject obj)
|
||||||
|
{
|
||||||
|
return g_renderer->CalculateDrawAspectRatio();
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv* env,
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv* env,
|
||||||
jobject obj)
|
jobject obj)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user