Update touch code

This commit is contained in:
mittorn 2016-05-04 21:34:15 +00:00
parent cd81aa82ea
commit e33ceda57a

View file

@ -501,27 +501,53 @@ View.OnKeyListener, View.OnTouchListener {
// Touch events // Touch events
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
/* Ref: http://developer.android.com/training/gestures/multi.html */
final int touchDevId = event.getDeviceId(); final int touchDevId = event.getDeviceId();
final int pointerCount = event.getPointerCount(); final int pointerCount = event.getPointerCount();
// touchId, pointerId, action, x, y, pressure
int actionPointerIndex = event.getActionIndex();
int pointerFingerId = event.getPointerId(actionPointerIndex);
int action = event.getActionMasked(); int action = event.getActionMasked();
int pointerFingerId;
float x = event.getX(actionPointerIndex); int mouseButton;
float y = event.getY(actionPointerIndex); int i = -1;
float x,y;
if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) { switch(action) {
// TODO send motion to every pointer if its position has case MotionEvent.ACTION_MOVE:
// changed since prev event. for (i = 0; i < pointerCount; i++) {
for (int i = 0; i < pointerCount; i++) {
pointerFingerId = event.getPointerId(i); pointerFingerId = event.getPointerId(i);
x = event.getX(i); x = event.getX(i);
y = event.getY(i); y = event.getY(i);
XashActivity.nativeTouch(pointerFingerId, action, x, y); XashActivity.nativeTouch(pointerFingerId, action, x, y);
} }
} else { break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_DOWN:
// Primary pointer up/down, the index is always zero
i = 0;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_POINTER_DOWN:
// Non primary pointer up/down
if (i == -1) {
i = event.getActionIndex();
}
pointerFingerId = event.getPointerId(i);
x = event.getX(i);
y = event.getY(i);
XashActivity.nativeTouch(pointerFingerId, action, x, y); XashActivity.nativeTouch(pointerFingerId, action, x, y);
break;
case MotionEvent.ACTION_CANCEL:
for (i = 0; i < pointerCount; i++) {
pointerFingerId = event.getPointerId(i);
x = event.getX(i);
y = event.getY(i);
XashActivity.nativeTouch(pointerFingerId, action, x, y);
}
break;
default:
break;
} }
return true; return true;
} }