src/video/android/SDL_androidtouch.c
changeset 8030 7b0d28c202d2
parent 7786 cfc1285375e1
child 8093 b43765095a6f
equal deleted inserted replaced
8029:cf81e6709b3d 8030:7b0d28c202d2
    36 #define ACTION_DOWN 0
    36 #define ACTION_DOWN 0
    37 #define ACTION_UP 1
    37 #define ACTION_UP 1
    38 #define ACTION_MOVE 2
    38 #define ACTION_MOVE 2
    39 #define ACTION_CANCEL 3
    39 #define ACTION_CANCEL 3
    40 #define ACTION_OUTSIDE 4
    40 #define ACTION_OUTSIDE 4
    41 /* The following two are deprecated but it seems they are still emitted (instead the corresponding ACTION_UP/DOWN) as of Android 3.2 */
    41 #define ACTION_POINTER_DOWN 5
    42 #define ACTION_POINTER_1_DOWN 5
    42 #define ACTION_POINTER_UP 6
    43 #define ACTION_POINTER_1_UP 6
       
    44 
       
    45 static SDL_FingerID leftFingerDown = 0;
       
    46 
    43 
    47 static void Android_GetWindowCoordinates(float x, float y,
    44 static void Android_GetWindowCoordinates(float x, float y,
    48                                          int *window_x, int *window_y)
    45                                          int *window_x, int *window_y)
    49 {
    46 {
    50     int window_w, window_h;
    47     int window_w, window_h;
    70 void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
    67 void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
    71 {
    68 {
    72     SDL_TouchID touchDeviceId = 0;
    69     SDL_TouchID touchDeviceId = 0;
    73     SDL_FingerID fingerId = 0;
    70     SDL_FingerID fingerId = 0;
    74     int window_x, window_y;
    71     int window_x, window_y;
       
    72     static SDL_FingerID pointerFingerID = 0;
    75 
    73 
    76     if (!Android_Window) {
    74     if (!Android_Window) {
    77         return;
    75         return;
    78     }
    76     }
    79 
    77 
    83     }
    81     }
    84 
    82 
    85     fingerId = (SDL_FingerID)pointer_finger_id_in;
    83     fingerId = (SDL_FingerID)pointer_finger_id_in;
    86     switch (action) {
    84     switch (action) {
    87         case ACTION_DOWN:
    85         case ACTION_DOWN:
    88         case ACTION_POINTER_1_DOWN:
    86             /* Primary pointer down */
    89             if (!leftFingerDown) {
    87             Android_GetWindowCoordinates(x, y, &window_x, &window_y);
    90                 Android_GetWindowCoordinates(x, y, &window_x, &window_y);
    88             /* send moved event */
    91 
    89             SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    92                 /* send moved event */
    90             /* send mouse down event */
    93                 SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    91             SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    94 
    92             pointerFingerID = fingerId;
    95                 /* send mouse down event */
    93         case ACTION_POINTER_DOWN:
    96                 SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    94             /* Non primary pointer down */
    97 
       
    98                 leftFingerDown = fingerId;
       
    99             }
       
   100             SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
    95             SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
   101             break;
    96             break;
       
    97             
   102         case ACTION_MOVE:
    98         case ACTION_MOVE:
   103             if (!leftFingerDown) {
    99             if (!pointerFingerID) {
   104                 Android_GetWindowCoordinates(x, y, &window_x, &window_y);
   100                 Android_GetWindowCoordinates(x, y, &window_x, &window_y);
   105 
   101 
   106                 /* send moved event */
   102                 /* send moved event */
   107                 SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
   103                 SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
   108             }
   104             }
   109             SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
   105             SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
   110             break;
   106             break;
       
   107             
   111         case ACTION_UP:
   108         case ACTION_UP:
   112         case ACTION_POINTER_1_UP:
   109             /* Primary pointer up */
   113             if (fingerId == leftFingerDown) {
   110             /* send mouse up */
   114                 /* send mouse up */
   111             pointerFingerID = (SDL_FingerID) 0;
   115                 SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
   112             SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
   116                 leftFingerDown = 0;
   113         case ACTION_POINTER_UP:
   117             }
   114             /* Non primary pointer up */
   118             SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
   115             SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
   119             break;
   116             break;
       
   117             
   120         default:
   118         default:
   121             break;
   119             break;
   122     }
   120     }
   123 }
   121 }
   124 
   122