| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 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 | |
| 22 | #include "../SDL_internal.h" |
| 23 | |
| 24 | #ifndef SDL_pen_c_h_ |
| 25 | #define SDL_pen_c_h_ |
| 26 | |
| 27 | #include "SDL_mouse_c.h" |
| 28 | |
| 29 | typedef Uint32 SDL_PenCapabilityFlags; |
| 30 | #define SDL_PEN_CAPABILITY_PRESSURE (1u << 0) /**< Provides pressure information on SDL_PEN_AXIS_PRESSURE. */ |
| 31 | #define SDL_PEN_CAPABILITY_XTILT (1u << 1) /**< Provides horizontal tilt information on SDL_PEN_AXIS_XTILT. */ |
| 32 | #define SDL_PEN_CAPABILITY_YTILT (1u << 2) /**< Provides vertical tilt information on SDL_PEN_AXIS_YTILT. */ |
| 33 | #define SDL_PEN_CAPABILITY_DISTANCE (1u << 3) /**< Provides distance to drawing tablet on SDL_PEN_AXIS_DISTANCE. */ |
| 34 | #define SDL_PEN_CAPABILITY_ROTATION (1u << 4) /**< Provides barrel rotation info on SDL_PEN_AXIS_ROTATION. */ |
| 35 | #define SDL_PEN_CAPABILITY_SLIDER (1u << 5) /**< Provides slider/finger wheel/etc on SDL_PEN_AXIS_SLIDER. */ |
| 36 | #define SDL_PEN_CAPABILITY_TANGENTIAL_PRESSURE (1u << 6) /**< Provides barrel pressure on SDL_PEN_AXIS_TANGENTIAL_PRESSURE. */ |
| 37 | #define SDL_PEN_CAPABILITY_ERASER (1u << 7) /**< Pen also has an eraser tip. */ |
| 38 | |
| 39 | typedef enum SDL_PenSubtype |
| 40 | { |
| 41 | SDL_PEN_TYPE_UNKNOWN, /**< Unknown pen device */ |
| 42 | SDL_PEN_TYPE_ERASER, /**< Eraser */ |
| 43 | SDL_PEN_TYPE_PEN, /**< Generic pen; this is the default. */ |
| 44 | SDL_PEN_TYPE_PENCIL, /**< Pencil */ |
| 45 | SDL_PEN_TYPE_BRUSH, /**< Brush-like device */ |
| 46 | SDL_PEN_TYPE_AIRBRUSH /**< Airbrush device that "sprays" ink */ |
| 47 | } SDL_PenSubtype; |
| 48 | |
| 49 | typedef struct SDL_PenInfo |
| 50 | { |
| 51 | SDL_PenCapabilityFlags capabilities; /**< bitflags of device capabilities */ |
| 52 | float max_tilt; /**< Physical maximum tilt angle, for XTILT and YTILT, or -1.0f if unknown. Pens cannot typically tilt all the way to 90 degrees, so this value is usually less than 90.0. */ |
| 53 | Uint32 wacom_id; /**< For Wacom devices: wacom tool type ID, otherwise 0 (useful e.g. with libwacom) */ |
| 54 | int num_buttons; /**< Number of pen buttons (not counting the pen tip), or -1 if unknown. */ |
| 55 | SDL_PenSubtype subtype; /**< type of pen device */ |
| 56 | } SDL_PenInfo; |
| 57 | |
| 58 | // Backend calls this when a new pen device is hotplugged, plus once for each pen already connected at startup. |
| 59 | // Note that name and info are copied but currently unused; this is placeholder for a potentially more robust API later. |
| 60 | // Both are allowed to be NULL. |
| 61 | extern SDL_PenID SDL_AddPenDevice(Uint64 timestamp, const char *name, const SDL_PenInfo *info, void *handle); |
| 62 | |
| 63 | // Backend calls this when an existing pen device is disconnected during runtime. They must free their own stuff separately. |
| 64 | extern void SDL_RemovePenDevice(Uint64 timestamp, SDL_PenID instance_id); |
| 65 | |
| 66 | // Backend can call this to remove all pens, probably during shutdown, with a callback to let them free their own handle. |
| 67 | extern void SDL_RemoveAllPenDevices(void (*callback)(SDL_PenID instance_id, void *handle, void *userdata), void *userdata); |
| 68 | |
| 69 | // Backend calls this when a pen's button changes, to generate events and update state. |
| 70 | extern void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *window, bool eraser, bool down); |
| 71 | |
| 72 | // Backend calls this when a pen moves on the tablet, to generate events and update state. |
| 73 | extern void SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *window, float x, float y); |
| 74 | |
| 75 | // Backend calls this when a pen's axis changes, to generate events and update state. |
| 76 | extern void SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *window, SDL_PenAxis axis, float value); |
| 77 | |
| 78 | // Backend calls this when a pen's button changes, to generate events and update state. |
| 79 | extern void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *window, Uint8 button, bool down); |
| 80 | |
| 81 | // Backend can optionally use this to find the SDL_PenID for the `handle` that was passed to SDL_AddPenDevice. |
| 82 | extern SDL_PenID SDL_FindPenByHandle(void *handle); |
| 83 | |
| 84 | // Backend can optionally use this to find a SDL_PenID, selected by a callback examining all devices. Zero if not found. |
| 85 | extern SDL_PenID SDL_FindPenByCallback(bool (*callback)(void *handle, void *userdata), void *userdata); |
| 86 | |
| 87 | // Backend can use this to query current pen status. |
| 88 | SDL_PenInputFlags SDL_GetPenStatus(SDL_PenID instance_id, float *axes, int num_axes); |
| 89 | |
| 90 | // Backend can use this to map an axis to a capability bit. |
| 91 | SDL_PenCapabilityFlags SDL_GetPenCapabilityFromAxis(SDL_PenAxis axis); |
| 92 | |
| 93 | // Higher-level SDL video subsystem code calls this when starting up. Backends shouldn't. |
| 94 | extern bool SDL_InitPen(void); |
| 95 | |
| 96 | // Higher-level SDL video subsystem code calls this when shutting down. Backends shouldn't. |
| 97 | extern void SDL_QuitPen(void); |
| 98 | |
| 99 | #endif // SDL_pen_c_h_ |
| 100 | |