Atlas - SDL_androidpen.c
Home / ext / SDL / src / video / android Lines: 1 | Size: 3706 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 "SDL_androidpen.h" 26#include "../../events/SDL_pen_c.h" 27#include "../../core/android/SDL_android.h" 28 29#define ACTION_DOWN 0 30#define ACTION_UP 1 31#define ACTION_CANCEL 3 32#define ACTION_POINTER_DOWN 5 33#define ACTION_POINTER_UP 6 34#define ACTION_HOVER_ENTER 9 35#define ACTION_HOVER_EXIT 10 36 37void Android_OnPen(SDL_Window *window, int pen_id_in, SDL_PenDeviceType device_type, int button, int action, float x, float y, float p) 38{ 39 if (!window) { 40 return; 41 } 42 43 // pointer index starts from zero. 44 pen_id_in++; 45 46 SDL_PenID pen = SDL_FindPenByHandle((void *) (size_t) pen_id_in); 47 if (!pen) { 48 // TODO: Query JNI for pen device info 49 SDL_PenInfo peninfo; 50 SDL_zero(peninfo); 51 peninfo.capabilities = SDL_PEN_CAPABILITY_PRESSURE | SDL_PEN_CAPABILITY_ERASER; 52 peninfo.num_buttons = 2; 53 peninfo.subtype = SDL_PEN_TYPE_PEN; 54 peninfo.device_type = device_type; 55 pen = SDL_AddPenDevice(0, NULL, window, &peninfo, (void *) (size_t) pen_id_in, true); 56 if (!pen) { 57 SDL_Log("error: can't add a pen device %d", pen_id_in); 58 return; 59 } 60 } 61 62 SDL_SendPenMotion(0, pen, window, x, y); 63 SDL_SendPenAxis(0, pen, window, SDL_PEN_AXIS_PRESSURE, p); 64 // TODO: add more axis 65 66 SDL_PenInputFlags current = SDL_GetPenStatus(pen, NULL, 0); 67 int diff = current ^ button; 68 if (diff != 0) { 69 // Android only exposes BUTTON_STYLUS_PRIMARY and BUTTON_STYLUS_SECONDARY 70 if (diff & SDL_PEN_INPUT_BUTTON_1) 71 SDL_SendPenButton(0, pen, window, 1, (button & SDL_PEN_INPUT_BUTTON_1) != 0); 72 73 if (diff & SDL_PEN_INPUT_BUTTON_2) 74 SDL_SendPenButton(0, pen, window, 2, (button & SDL_PEN_INPUT_BUTTON_2) != 0); 75 } 76 77 // button contains DOWN/ERASER_TIP on DOWN/UP regardless of pressed state, use action to distinguish 78 // we don't compare tip flags above because MotionEvent.getButtonState doesn't return stylus tip/eraser state. 79 switch (action) { 80 case ACTION_HOVER_ENTER: 81 SDL_SendPenProximity(0, pen, window, true); 82 break; 83 84 case ACTION_CANCEL: 85 case ACTION_HOVER_EXIT: // strictly speaking, this can mean both "proximity out" and "left the View" but close enough. 86 SDL_SendPenProximity(0, pen, window, false); 87 break; 88 89 case ACTION_DOWN: 90 case ACTION_POINTER_DOWN: 91 SDL_SendPenTouch(0, pen, window, (button & SDL_PEN_INPUT_ERASER_TIP) != 0, true); 92 break; 93 94 case ACTION_UP: 95 case ACTION_POINTER_UP: 96 SDL_SendPenTouch(0, pen, window, (button & SDL_PEN_INPUT_ERASER_TIP) != 0, false); 97 break; 98 99 default: 100 break; 101 } 102} 103 104#endif // SDL_VIDEO_DRIVER_ANDROID 105[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.