Atlas - SDL_androidtouch.c
Home / ext / SDL / src / video / android Lines: 1 | Size: 3139 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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#ifdef SDL_VIDEO_DRIVER_ANDROID 24 25#include <android/log.h> 26 27#include "SDL_androidtouch.h" 28#include "../../events/SDL_mouse_c.h" 29#include "../../events/SDL_touch_c.h" 30#include "../../core/android/SDL_android.h" 31 32#define ACTION_DOWN 0 33#define ACTION_UP 1 34#define ACTION_MOVE 2 35#define ACTION_CANCEL 3 36// #define ACTION_OUTSIDE 4 37#define ACTION_POINTER_DOWN 5 38#define ACTION_POINTER_UP 6 39 40void Android_InitTouch(void) 41{ 42 // Add all touch devices 43 Android_JNI_InitTouch(); 44} 45 46void Android_QuitTouch(void) 47{ 48} 49 50 51SDL_TouchID Android_ConvertJavaTouchID(int touchID) 52{ 53 SDL_TouchID retval = touchID; 54 55 if (touchID < 0) { 56 // Touch ID -1 appears when using Android emulator, eg: 57 // adb shell input mouse tap 100 100 58 // adb shell input touchscreen tap 100 100 59 // 60 // Prevent the values -1 and -2, since they're used in SDL internal for synthetic events: 61 retval -= 2; 62 } else { 63 // Touch ID 0 is invalid 64 retval += 1; 65 } 66 return retval; 67} 68 69void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p) 70{ 71 SDL_TouchID touchDeviceId = 0; 72 SDL_FingerID fingerId = 0; 73 74 if (!window) { 75 return; 76 } 77 78 touchDeviceId = Android_ConvertJavaTouchID(touch_device_id_in); 79 80 // Finger ID should be greater than 0 81 fingerId = (SDL_FingerID)(pointer_finger_id_in + 1); 82 83 if (SDL_AddTouch(touchDeviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) { 84 return; 85 } 86 87 switch (action) { 88 case ACTION_DOWN: 89 case ACTION_POINTER_DOWN: 90 SDL_SendTouch(0, touchDeviceId, fingerId, window, SDL_EVENT_FINGER_DOWN, x, y, p); 91 break; 92 93 case ACTION_MOVE: 94 SDL_SendTouchMotion(0, touchDeviceId, fingerId, window, x, y, p); 95 break; 96 97 case ACTION_UP: 98 case ACTION_POINTER_UP: 99 SDL_SendTouch(0, touchDeviceId, fingerId, window, SDL_EVENT_FINGER_UP, x, y, p); 100 break; 101 102 case ACTION_CANCEL: 103 SDL_SendTouch(0, touchDeviceId, fingerId, window, SDL_EVENT_FINGER_CANCELED, x, y, p); 104 break; 105 106 default: 107 break; 108 } 109} 110 111#endif // SDL_VIDEO_DRIVER_ANDROID 112[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.