SDL 3.0
SDL_pen.h
Go to the documentation of this file.
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/**
23 * # CategoryPen
24 *
25 * SDL pen event handling.
26 *
27 * SDL provides an API for pressure-sensitive pen (stylus and/or eraser)
28 * handling, e.g., for input and drawing tablets or suitably equipped mobile /
29 * tablet devices.
30 *
31 * To get started with pens, simply handle pen events:
32 *
33 * - SDL_EVENT_PEN_PROXIMITY_IN, SDL_EVENT_PEN_PROXIMITY_OUT
34 * (SDL_PenProximityEvent)
35 * - SDL_EVENT_PEN_DOWN, SDL_EVENT_PEN_UP (SDL_PenTouchEvent)
36 * - SDL_EVENT_PEN_MOTION (SDL_PenMotionEvent)
37 * - SDL_EVENT_PEN_BUTTON_DOWN, SDL_EVENT_PEN_BUTTON_UP (SDL_PenButtonEvent)
38 * - SDL_EVENT_PEN_AXIS (SDL_PenAxisEvent)
39 *
40 * When a pen starts providing input, SDL will assign it a unique SDL_PenID,
41 * which will remain for the life of the process, as long as the pen stays
42 * connected.
43 *
44 * Pens may provide more than simple touch input; they might have other axes,
45 * such as pressure, tilt, rotation, etc.
46 */
47
48#ifndef SDL_pen_h_
49#define SDL_pen_h_
50
51#include <SDL3/SDL_stdinc.h>
52#include <SDL3/SDL_mouse.h>
53#include <SDL3/SDL_touch.h>
54
55#include <SDL3/SDL_begin_code.h>
56/* Set up for C function definitions, even when using C++ */
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61/**
62 * SDL pen instance IDs.
63 *
64 * Zero is used to signify an invalid/null device.
65 *
66 * These show up in pen events when SDL sees input from them. They remain
67 * consistent as long as SDL can recognize a tool to be the same pen; but if a
68 * pen physically leaves the area and returns, it might get a new ID.
69 *
70 * \since This datatype is available since SDL 3.2.0.
71 */
73
74/**
75 * The SDL_MouseID for mouse events simulated with pen input.
76 *
77 * \since This macro is available since SDL 3.2.0.
78 */
79#define SDL_PEN_MOUSEID ((SDL_MouseID)-2)
80
81/**
82 * The SDL_TouchID for touch events simulated with pen input.
83 *
84 * \since This macro is available since SDL 3.2.0.
85 */
86#define SDL_PEN_TOUCHID ((SDL_TouchID)-2)
87
88/**
89 * Pen input flags, as reported by various pen events' `pen_state` field.
90 *
91 * \since This datatype is available since SDL 3.2.0.
92 */
94
95#define SDL_PEN_INPUT_DOWN (1u << 0) /**< pen is pressed down */
96#define SDL_PEN_INPUT_BUTTON_1 (1u << 1) /**< button 1 is pressed */
97#define SDL_PEN_INPUT_BUTTON_2 (1u << 2) /**< button 2 is pressed */
98#define SDL_PEN_INPUT_BUTTON_3 (1u << 3) /**< button 3 is pressed */
99#define SDL_PEN_INPUT_BUTTON_4 (1u << 4) /**< button 4 is pressed */
100#define SDL_PEN_INPUT_BUTTON_5 (1u << 5) /**< button 5 is pressed */
101#define SDL_PEN_INPUT_ERASER_TIP (1u << 30) /**< eraser tip is used */
102
103/**
104 * Pen axis indices.
105 *
106 * These are the valid values for the `axis` field in SDL_PenAxisEvent. All
107 * axes are either normalised to 0..1 or report a (positive or negative) angle
108 * in degrees, with 0.0 representing the centre. Not all pens/backends support
109 * all axes: unsupported axes are always zero.
110 *
111 * To convert angles for tilt and rotation into vector representation, use
112 * SDL_sinf on the XTILT, YTILT, or ROTATION component, for example:
113 *
114 * `SDL_sinf(xtilt * SDL_PI_F / 180.0)`.
115 *
116 * \since This enum is available since SDL 3.2.0.
117 */
118typedef enum SDL_PenAxis
119{
120 SDL_PEN_AXIS_PRESSURE, /**< Pen pressure. Unidirectional: 0 to 1.0 */
121 SDL_PEN_AXIS_XTILT, /**< Pen horizontal tilt angle. Bidirectional: -90.0 to 90.0 (left-to-right). */
122 SDL_PEN_AXIS_YTILT, /**< Pen vertical tilt angle. Bidirectional: -90.0 to 90.0 (top-to-down). */
123 SDL_PEN_AXIS_DISTANCE, /**< Pen distance to drawing surface. Unidirectional: 0.0 to 1.0 */
124 SDL_PEN_AXIS_ROTATION, /**< Pen barrel rotation. Bidirectional: -180 to 179.9 (clockwise, 0 is facing up, -180.0 is facing down). */
125 SDL_PEN_AXIS_SLIDER, /**< Pen finger wheel or slider (e.g., Airbrush Pen). Unidirectional: 0 to 1.0 */
126 SDL_PEN_AXIS_TANGENTIAL_PRESSURE, /**< Pressure from squeezing the pen ("barrel pressure"). */
127 SDL_PEN_AXIS_COUNT /**< Total known pen axis types in this version of SDL. This number may grow in future releases! */
129
130/**
131 * An enum that describes the type of a pen device.
132 *
133 * A "direct" device is a pen that touches a graphic display (like an Apple
134 * Pencil on an iPad's screen). "Indirect" devices touch an external tablet
135 * surface that is connected to the machine but is not a display (like a
136 * lower-end Wacom tablet connected over USB).
137 *
138 * Apps may use this information to decide if they should draw a cursor; if
139 * the pen is touching the screen directly, a cursor doesn't make sense and
140 * can be in the way, but becomes necessary for indirect devices to know where
141 * on the display they are interacting.
142 *
143 * \since This enum is available since SDL 3.4.0.
144 */
146{
147 SDL_PEN_DEVICE_TYPE_INVALID = -1, /**< Not a valid pen device. */
148 SDL_PEN_DEVICE_TYPE_UNKNOWN, /**< Don't know specifics of this pen. */
149 SDL_PEN_DEVICE_TYPE_DIRECT, /**< Pen touches display. */
150 SDL_PEN_DEVICE_TYPE_INDIRECT /**< Pen touches something that isn't the display. */
152
153/**
154 * Get the device type of the given pen.
155 *
156 * Many platforms do not supply this information, so an app must always be
157 * prepared to get an SDL_PEN_DEVICE_TYPE_UNKNOWN result.
158 *
159 * \param instance_id the pen instance ID.
160 * \returns the device type of the given pen, or SDL_PEN_DEVICE_TYPE_INVALID
161 * on failure; call SDL_GetError() for more information.
162 *
163 * \threadsafety It is safe to call this function from any thread.
164 *
165 * \since This function is available since SDL 3.4.0.
166 */
167extern SDL_DECLSPEC SDL_PenDeviceType SDLCALL SDL_GetPenDeviceType(SDL_PenID instance_id);
168
169/* Ends C function definitions when using C++ */
170#ifdef __cplusplus
171}
172#endif
173#include <SDL3/SDL_close_code.h>
174
175#endif /* SDL_pen_h_ */
176
Uint32 SDL_PenID
Definition SDL_pen.h:72
SDL_PenAxis
Definition SDL_pen.h:119
@ SDL_PEN_AXIS_PRESSURE
Definition SDL_pen.h:120
@ SDL_PEN_AXIS_XTILT
Definition SDL_pen.h:121
@ SDL_PEN_AXIS_SLIDER
Definition SDL_pen.h:125
@ SDL_PEN_AXIS_DISTANCE
Definition SDL_pen.h:123
@ SDL_PEN_AXIS_YTILT
Definition SDL_pen.h:122
@ SDL_PEN_AXIS_ROTATION
Definition SDL_pen.h:124
@ SDL_PEN_AXIS_TANGENTIAL_PRESSURE
Definition SDL_pen.h:126
@ SDL_PEN_AXIS_COUNT
Definition SDL_pen.h:127
SDL_PenDeviceType
Definition SDL_pen.h:146
@ SDL_PEN_DEVICE_TYPE_INVALID
Definition SDL_pen.h:147
@ SDL_PEN_DEVICE_TYPE_UNKNOWN
Definition SDL_pen.h:148
@ SDL_PEN_DEVICE_TYPE_DIRECT
Definition SDL_pen.h:149
@ SDL_PEN_DEVICE_TYPE_INDIRECT
Definition SDL_pen.h:150
SDL_PenDeviceType SDL_GetPenDeviceType(SDL_PenID instance_id)
Uint32 SDL_PenInputFlags
Definition SDL_pen.h:93
uint32_t Uint32
Definition SDL_stdinc.h:488