src/video/android/SDL_androidtouch.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 15 Oct 2019 22:36:08 -0400
changeset 13130 502bb7d04f0a
parent 13041 6ea2f4ed7014
permissions -rw-r--r--
x11: On macOS, look for X11 install in /opt/X11 instead of /usr/X11R6.

This is where Apple installs XQuartz now (and apparently, the compatibility
symlink at /usr/X11R6 can be missing).

Fixes Bugzilla #4706.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "../../SDL_internal.h"
    22 
    23 #if SDL_VIDEO_DRIVER_ANDROID
    24 
    25 #include <android/log.h>
    26 
    27 #include "SDL_hints.h"
    28 #include "SDL_events.h"
    29 #include "SDL_log.h"
    30 #include "SDL_androidtouch.h"
    31 #include "../../events/SDL_mouse_c.h"
    32 #include "../../events/SDL_touch_c.h"
    33 #include "../../core/android/SDL_android.h"
    34 
    35 #define ACTION_DOWN 0
    36 #define ACTION_UP 1
    37 #define ACTION_MOVE 2
    38 /* #define ACTION_CANCEL 3 */
    39 /* #define ACTION_OUTSIDE 4 */
    40 #define ACTION_POINTER_DOWN 5
    41 #define ACTION_POINTER_UP 6
    42 
    43 void Android_InitTouch(void)
    44 {
    45     /* Add all touch devices */
    46     Android_JNI_InitTouch();
    47 }
    48 
    49 void Android_QuitTouch(void)
    50 {
    51     return;
    52 }
    53 
    54 void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
    55 {
    56     SDL_TouchID touchDeviceId = 0;
    57     SDL_FingerID fingerId = 0;
    58 
    59     if (!window) {
    60         return;
    61     }
    62 
    63     touchDeviceId = (SDL_TouchID)touch_device_id_in;
    64     if (SDL_AddTouch(touchDeviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
    65         SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
    66     }
    67 
    68     fingerId = (SDL_FingerID)pointer_finger_id_in;
    69     switch (action) {
    70         case ACTION_DOWN:
    71         case ACTION_POINTER_DOWN:
    72             SDL_SendTouch(touchDeviceId, fingerId, window, SDL_TRUE, x, y, p);
    73             break;
    74 
    75         case ACTION_MOVE:
    76             SDL_SendTouchMotion(touchDeviceId, fingerId, window, x, y, p);
    77             break;
    78 
    79         case ACTION_UP:
    80         case ACTION_POINTER_UP:
    81             SDL_SendTouch(touchDeviceId, fingerId, window, SDL_FALSE, x, y, p);
    82             break;
    83 
    84         default:
    85             break;
    86     }
    87 }
    88 
    89 #endif /* SDL_VIDEO_DRIVER_ANDROID */
    90 
    91 /* vi: set ts=4 sw=4 expandtab: */