From 8fbb82719e6d1f4e29980d66380474b6a0c45e1d Mon Sep 17 00:00:00 2001 From: volzhs Date: Sun, 7 Jan 2018 23:11:58 +0900 Subject: [PATCH] Fix Android multi touch Fix #11798 --- .../java/src/org/godotengine/godot/Godot.java | 5 +-- .../src/org/godotengine/godot/GodotView.java | 2 +- platform/android/os_android.cpp | 32 ++++++++++--------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index 37f25cc839d..b5b0afb9e0e 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -828,7 +828,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC //@Override public boolean dispatchTouchEvent (MotionEvent event) { public boolean gotTouchEvent(final MotionEvent event) { - super.onTouchEvent(event); final int evcount = event.getPointerCount(); if (evcount == 0) return true; @@ -842,6 +841,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC arr[i * 3 + 1] = (int)event.getX(i); arr[i * 3 + 2] = (int)event.getY(i); } + final int pointer_idx = event.getPointerId(event.getActionIndex()); //System.out.printf("gaction: %d\n",event.getAction()); final int action = event.getAction() & MotionEvent.ACTION_MASK; @@ -862,13 +862,10 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC */ } break; case MotionEvent.ACTION_POINTER_UP: { - final int indexPointUp = event.getActionIndex(); - final int pointer_idx = event.getPointerId(indexPointUp); GodotLib.touch(4, pointer_idx, evcount, arr); //System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx)); } break; case MotionEvent.ACTION_POINTER_DOWN: { - int pointer_idx = event.getActionIndex(); GodotLib.touch(3, pointer_idx, evcount, arr); //System.out.printf("%d - s.down at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx)); } break; diff --git a/platform/android/java/src/org/godotengine/godot/GodotView.java b/platform/android/java/src/org/godotengine/godot/GodotView.java index ca4895a2be6..0222758c2b0 100644 --- a/platform/android/java/src/org/godotengine/godot/GodotView.java +++ b/platform/android/java/src/org/godotengine/godot/GodotView.java @@ -110,7 +110,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener { @Override public boolean onTouchEvent(MotionEvent event) { - + super.onTouchEvent(event); return activity.gotTouchEvent(event); }; diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 93272a10005..23811f963ab 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -444,25 +444,27 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector } touch.clear(); } - } break; - case 3: { // add tuchi + case 3: { // add touch - ERR_FAIL_INDEX(p_pointer, p_points.size()); + for (int i = 0; i < p_points.size(); i++) { + if (p_points[i].id == p_pointer) { + TouchPos tp = p_points[i]; + touch.push_back(tp); - TouchPos tp = p_points[p_pointer]; - touch.push_back(tp); + Ref ev; + ev.instance(); - Ref ev; - ev.instance(); - - ev->set_index(tp.id); - ev->set_pressed(true); - ev->set_position(tp.pos); - input->parse_input_event(ev); + ev->set_index(tp.id); + ev->set_pressed(true); + ev->set_position(tp.pos); + input->parse_input_event(ev); + break; + } + } } break; - case 4: { + case 4: { // remove touch for (int i = 0; i < touch.size(); i++) { if (touch[i].id == p_pointer) { @@ -474,10 +476,10 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector ev->set_position(touch[i].pos); input->parse_input_event(ev); touch.remove(i); - i--; + + break; } } - } break; } }