Merge pull request #15440 from volzhs/fix-android-touch
Fix Android multi touch
This commit is contained in:
commit
06bb4acae0
3 changed files with 19 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -110,7 +110,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
|||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
||||
super.onTouchEvent(event);
|
||||
return activity.gotTouchEvent(event);
|
||||
};
|
||||
|
||||
|
|
|
@ -444,25 +444,27 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
|
|||
}
|
||||
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<InputEventScreenTouch> ev;
|
||||
ev.instance();
|
||||
|
||||
Ref<InputEventScreenTouch> 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<TouchPos>
|
|||
ev->set_position(touch[i].pos);
|
||||
input->parse_input_event(ev);
|
||||
touch.remove(i);
|
||||
i--;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue