1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java Sat Nov 23 23:38:16 2013 +0100
1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Mon Nov 25 12:28:09 2013 -0300
1.3 @@ -666,31 +666,48 @@
1.4 // Touch events
1.5 @Override
1.6 public boolean onTouch(View v, MotionEvent event) {
1.7 - final int touchDevId = event.getDeviceId();
1.8 - final int pointerCount = event.getPointerCount();
1.9 - // touchId, pointerId, action, x, y, pressure
1.10 - int actionPointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; /* API 8: event.getActionIndex(); */
1.11 - int pointerFingerId = event.getPointerId(actionPointerIndex);
1.12 - int action = (event.getAction() & MotionEvent.ACTION_MASK); /* API 8: event.getActionMasked(); */
1.13 -
1.14 - float x = event.getX(actionPointerIndex) / mWidth;
1.15 - float y = event.getY(actionPointerIndex) / mHeight;
1.16 - float p = event.getPressure(actionPointerIndex);
1.17 -
1.18 - if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) {
1.19 - // TODO send motion to every pointer if its position has
1.20 - // changed since prev event.
1.21 - for (int i = 0; i < pointerCount; i++) {
1.22 + /* Ref: http://developer.android.com/training/gestures/multi.html */
1.23 + final int touchDevId = event.getDeviceId();
1.24 + final int pointerCount = event.getPointerCount();
1.25 + int action = event.getActionMasked();
1.26 + int pointerFingerId;
1.27 + int i = -1;
1.28 + float x,y,p;
1.29 +
1.30 + switch(action) {
1.31 + case MotionEvent.ACTION_MOVE:
1.32 + for (i = 0; i < pointerCount; i++) {
1.33 pointerFingerId = event.getPointerId(i);
1.34 x = event.getX(i) / mWidth;
1.35 y = event.getY(i) / mHeight;
1.36 p = event.getPressure(i);
1.37 SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
1.38 }
1.39 - } else {
1.40 + break;
1.41 +
1.42 + case MotionEvent.ACTION_UP:
1.43 + case MotionEvent.ACTION_DOWN:
1.44 + // Primary pointer up/down, the index is always zero
1.45 + i = 0;
1.46 + case MotionEvent.ACTION_POINTER_UP:
1.47 + case MotionEvent.ACTION_POINTER_DOWN:
1.48 + // Non primary pointer up/down
1.49 + if (i == -1) {
1.50 + i = event.getActionIndex();
1.51 + }
1.52 +
1.53 + pointerFingerId = event.getPointerId(i);
1.54 + x = event.getX(i) / mWidth;
1.55 + y = event.getY(i) / mHeight;
1.56 + p = event.getPressure(i);
1.57 SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p);
1.58 - }
1.59 - return true;
1.60 + break;
1.61 +
1.62 + default:
1.63 + break;
1.64 + }
1.65 +
1.66 + return true;
1.67 }
1.68
1.69 // Sensor events
2.1 --- a/src/video/android/SDL_androidtouch.c Sat Nov 23 23:38:16 2013 +0100
2.2 +++ b/src/video/android/SDL_androidtouch.c Mon Nov 25 12:28:09 2013 -0300
2.3 @@ -38,11 +38,8 @@
2.4 #define ACTION_MOVE 2
2.5 #define ACTION_CANCEL 3
2.6 #define ACTION_OUTSIDE 4
2.7 -/* The following two are deprecated but it seems they are still emitted (instead the corresponding ACTION_UP/DOWN) as of Android 3.2 */
2.8 -#define ACTION_POINTER_1_DOWN 5
2.9 -#define ACTION_POINTER_1_UP 6
2.10 -
2.11 -static SDL_FingerID leftFingerDown = 0;
2.12 +#define ACTION_POINTER_DOWN 5
2.13 +#define ACTION_POINTER_UP 6
2.14
2.15 static void Android_GetWindowCoordinates(float x, float y,
2.16 int *window_x, int *window_y)
2.17 @@ -72,6 +69,7 @@
2.18 SDL_TouchID touchDeviceId = 0;
2.19 SDL_FingerID fingerId = 0;
2.20 int window_x, window_y;
2.21 + static SDL_FingerID pointerFingerID = 0;
2.22
2.23 if (!Android_Window) {
2.24 return;
2.25 @@ -85,22 +83,20 @@
2.26 fingerId = (SDL_FingerID)pointer_finger_id_in;
2.27 switch (action) {
2.28 case ACTION_DOWN:
2.29 - case ACTION_POINTER_1_DOWN:
2.30 - if (!leftFingerDown) {
2.31 - Android_GetWindowCoordinates(x, y, &window_x, &window_y);
2.32 -
2.33 - /* send moved event */
2.34 - SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
2.35 -
2.36 - /* send mouse down event */
2.37 - SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
2.38 -
2.39 - leftFingerDown = fingerId;
2.40 - }
2.41 + /* Primary pointer down */
2.42 + Android_GetWindowCoordinates(x, y, &window_x, &window_y);
2.43 + /* send moved event */
2.44 + SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
2.45 + /* send mouse down event */
2.46 + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
2.47 + pointerFingerID = fingerId;
2.48 + case ACTION_POINTER_DOWN:
2.49 + /* Non primary pointer down */
2.50 SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
2.51 break;
2.52 +
2.53 case ACTION_MOVE:
2.54 - if (!leftFingerDown) {
2.55 + if (!pointerFingerID) {
2.56 Android_GetWindowCoordinates(x, y, &window_x, &window_y);
2.57
2.58 /* send moved event */
2.59 @@ -108,15 +104,17 @@
2.60 }
2.61 SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
2.62 break;
2.63 +
2.64 case ACTION_UP:
2.65 - case ACTION_POINTER_1_UP:
2.66 - if (fingerId == leftFingerDown) {
2.67 - /* send mouse up */
2.68 - SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
2.69 - leftFingerDown = 0;
2.70 - }
2.71 + /* Primary pointer up */
2.72 + /* send mouse up */
2.73 + pointerFingerID = (SDL_FingerID) 0;
2.74 + SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
2.75 + case ACTION_POINTER_UP:
2.76 + /* Non primary pointer up */
2.77 SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
2.78 break;
2.79 +
2.80 default:
2.81 break;
2.82 }