Added support for multitouch on Android.

Fixes Bugzilla #1294.

Thanks to Gabriel Jacobo for the patch!
This commit is contained in:
Ryan C. Gordon 2011-10-13 01:21:35 -04:00
parent bc13816375
commit 62176df129
4 changed files with 72 additions and 23 deletions

View file

@ -93,7 +93,8 @@ public class SDLActivity extends Activity {
public static native void onNativeResize(int x, int y, int format);
public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode);
public static native void onNativeTouch(int action, float x,
public static native void onNativeTouch(int touchDevId, int pointerFingerId,
int action, float x,
float y, float p);
public static native void onNativeAccel(float x, float y, float z);
public static native void nativeRunAudioThread();
@ -459,16 +460,34 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// Touch events
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
float x = event.getX();
float y = event.getY();
float p = event.getPressure();
{
final int touchDevId = event.getDeviceId();
final int pointerCount = event.getPointerCount();
// touchId, pointerId, action, x, y, pressure
int actionPointerIndex = event.getActionIndex();
int pointerFingerId = event.getPointerId(actionPointerIndex);
int action = event.getActionMasked();
// TODO: Anything else we need to pass?
SDLActivity.onNativeTouch(action, x, y, p);
return true;
}
float x = event.getX(actionPointerIndex);
float y = event.getY(actionPointerIndex);
float p = event.getPressure(actionPointerIndex);
if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) {
// TODO send motion to every pointer if its position has
// changed since prev event.
for (int i = 0; i < pointerCount; i++) {
pointerFingerId = event.getPointerId(i);
x = event.getX(i);
y = event.getY(i);
p = event.getPressure(i);
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
}
} else {
SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
}
}
return true;
}
// Sensor events
public void enableSensor(int sensortype, boolean enabled) {