android : Fix touchscreen for reals

Adds proper multitouch tracking for touchscreen
This commit is contained in:
SachinVin 2020-05-30 19:18:23 +05:30 committed by xperia64
parent 68c343f522
commit 17645fabb3
6 changed files with 31 additions and 16 deletions

View File

@ -96,8 +96,9 @@ public final class NativeLibrary {
* @param x_axis The value of the x-axis.
* @param y_axis The value of the y-axis
* @param pressed To identify if the touch held down or released.
* @return true if the pointer is within the touchscreen
*/
public static native void onTouchEvent(float x_axis, float y_axis, boolean pressed);
public static native boolean onTouchEvent(float x_axis, float y_axis, boolean pressed);
/**
* Handles touch movement.

View File

@ -50,6 +50,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
private SharedPreferences mPreferences;
// Stores the ID of the pointer that interacted with the 3DS touchscreen.
private int mTouchscreenPointerId = -1;
/**
* Constructor
*
@ -64,6 +66,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
defaultOverlay();
}
// Reset 3ds touchscreen pointer ID
mTouchscreenPointerId = -1;
// Load the controls.
refreshControls();
@ -343,18 +348,26 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
NativeLibrary.onTouchEvent(event.getX(pointerIndex), event.getY(pointerIndex), true);
break;
case MotionEvent.ACTION_MOVE:
NativeLibrary.onTouchMoved(event.getX(), event.getY());
if (NativeLibrary.onTouchEvent(event.getX(pointerIndex), event.getY(pointerIndex), true)) {
mTouchscreenPointerId = event.getPointerId(pointerIndex);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
// We dont really care where the touch has been released. We only care whether it has been
// released or not.
NativeLibrary.onTouchEvent(0, 0, false);
if (mTouchscreenPointerId == event.getPointerId(pointerIndex)) {
// We don't really care where the touch has been released. We only care whether it has been
// released or not.
NativeLibrary.onTouchEvent(0, 0, false);
mTouchscreenPointerId = -1;
}
break;
}
for (int i = 0; i < event.getPointerCount(); i++) {
if (mTouchscreenPointerId == event.getPointerId(i)) {
NativeLibrary.onTouchMoved(event.getX(i), event.getY(i));
}
}
}
for (InputOverlayDrawableButton button : overlayButtons) {

View File

@ -81,12 +81,13 @@ void EmuWindow_Android::OnSurfaceChanged(ANativeWindow* surface) {
render_window = surface;
}
void EmuWindow_Android::OnTouchEvent(int x, int y, bool pressed) {
bool EmuWindow_Android::OnTouchEvent(int x, int y, bool pressed) {
if (pressed) {
TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
} else {
TouchReleased();
return TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
}
TouchReleased();
return true;
}
void EmuWindow_Android::OnTouchMoved(int x, int y) {

View File

@ -42,7 +42,7 @@ public:
void OnSurfaceChanged(ANativeWindow* surface);
/// Handles touch event that occur.(Touched or released)
void OnTouchEvent(int x, int y, bool pressed);
bool OnTouchEvent(int x, int y, bool pressed);
/// Handles movement of touch pointer
void OnTouchMoved(int x, int y);

View File

@ -351,10 +351,10 @@ jboolean Java_org_citra_citra_1emu_NativeLibrary_onGamePadAxisEvent(JNIEnv* env,
InputManager::ButtonHandler()->AnalogButtonEvent(axis_id, axis_val));
}
void Java_org_citra_citra_1emu_NativeLibrary_onTouchEvent(JNIEnv* env,
jboolean Java_org_citra_citra_1emu_NativeLibrary_onTouchEvent(JNIEnv* env,
[[maybe_unused]] jclass clazz, jfloat x,
jfloat y, jboolean pressed) {
window->OnTouchEvent((int)x, (int)y, (bool)pressed);
return static_cast<jboolean>(window->OnTouchEvent(static_cast<int>(x + 0.5), static_cast<int>(y + 0.5), pressed));
}
void Java_org_citra_citra_1emu_NativeLibrary_onTouchMoved(JNIEnv* env,

View File

@ -32,7 +32,7 @@ JNIEXPORT jboolean JNICALL Java_org_citra_citra_1emu_NativeLibrary_onGamePadMove
JNIEXPORT jboolean JNICALL Java_org_citra_citra_1emu_NativeLibrary_onGamePadAxisEvent(
JNIEnv* env, jclass clazz, jstring j_device, jint axis_id, jfloat axis_val);
JNIEXPORT void JNICALL Java_org_citra_citra_1emu_NativeLibrary_onTouchEvent(JNIEnv* env,
JNIEXPORT jboolean JNICALL Java_org_citra_citra_1emu_NativeLibrary_onTouchEvent(JNIEnv* env,
jclass clazz, jfloat x,
jfloat y,
jboolean pressed);