SDL 3.0
SDL_touch.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 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 * # CategoryTouch
24 *
25 * SDL touch management.
26 */
27
28#ifndef SDL_touch_h_
29#define SDL_touch_h_
30
31#include <SDL3/SDL_stdinc.h>
32#include <SDL3/SDL_error.h>
33#include <SDL3/SDL_mouse.h>
34
35#include <SDL3/SDL_begin_code.h>
36/* Set up for C function definitions, even when using C++ */
37#ifdef __cplusplus
38extern "C" {
39#endif
40
43
45{
47 SDL_TOUCH_DEVICE_DIRECT, /* touch screen with window-relative coordinates */
48 SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /* trackpad with absolute device coordinates */
49 SDL_TOUCH_DEVICE_INDIRECT_RELATIVE /* trackpad with screen cursor-relative coordinates */
51
52/**
53 * Data about a single finger in a multitouch event.
54 *
55 * Each touch even is a collection of fingers that are simultaneously in
56 * contact with the touch device (so a "touch" can be a "multitouch," in
57 * reality), and this struct reports details of the specific fingers.
58 *
59 * \since This struct is available since SDL 3.1.3.
60 *
61 * \sa SDL_GetTouchFingers
62 */
63typedef struct SDL_Finger
64{
65 SDL_FingerID id; /**< the finger ID */
66 float x; /**< the x-axis location of the touch event, normalized (0...1) */
67 float y; /**< the y-axis location of the touch event, normalized (0...1) */
68 float pressure; /**< the quantity of pressure applied, normalized (0...1) */
70
71/* Used as the device ID for mouse events simulated with touch input */
72#define SDL_TOUCH_MOUSEID ((SDL_MouseID)-1)
73
74/* Used as the SDL_TouchID for touch events simulated with mouse input */
75#define SDL_MOUSE_TOUCHID ((SDL_TouchID)-1)
76
77
78/**
79 * Get a list of registered touch devices.
80 *
81 * On some platforms SDL first sees the touch device if it was actually used.
82 * Therefore the returned list might be empty, although devices are available.
83 * After using all devices at least once the number will be correct.
84 *
85 * \param count a pointer filled in with the number of devices returned, may
86 * be NULL.
87 * \returns a 0 terminated array of touch device IDs or NULL on failure; call
88 * SDL_GetError() for more information. This should be freed with
89 * SDL_free() when it is no longer needed.
90 *
91 * \since This function is available since SDL 3.1.3.
92 */
93extern SDL_DECLSPEC SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count);
94
95/**
96 * Get the touch device name as reported from the driver.
97 *
98 * \param touchID the touch device instance ID.
99 * \returns touch device name, or NULL on failure; call SDL_GetError() for
100 * more information.
101 *
102 * \since This function is available since SDL 3.1.3.
103 */
104extern SDL_DECLSPEC const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID);
105
106/**
107 * Get the type of the given touch device.
108 *
109 * \param touchID the ID of a touch device.
110 * \returns touch device type.
111 *
112 * \since This function is available since SDL 3.1.3.
113 */
114extern SDL_DECLSPEC SDL_TouchDeviceType SDLCALL SDL_GetTouchDeviceType(SDL_TouchID touchID);
115
116/**
117 * Get a list of active fingers for a given touch device.
118 *
119 * \param touchID the ID of a touch device.
120 * \param count a pointer filled in with the number of fingers returned, can
121 * be NULL.
122 * \returns a NULL terminated array of SDL_Finger pointers or NULL on failure;
123 * call SDL_GetError() for more information. This is a single
124 * allocation that should be freed with SDL_free() when it is no
125 * longer needed.
126 *
127 * \since This function is available since SDL 3.1.3.
128 */
129extern SDL_DECLSPEC SDL_Finger ** SDLCALL SDL_GetTouchFingers(SDL_TouchID touchID, int *count);
130
131/* Ends C function definitions when using C++ */
132#ifdef __cplusplus
133}
134#endif
135#include <SDL3/SDL_close_code.h>
136
137#endif /* SDL_touch_h_ */
uint64_t Uint64
Definition: SDL_stdinc.h:392
Uint64 SDL_TouchID
Definition: SDL_touch.h:41
SDL_Finger ** SDL_GetTouchFingers(SDL_TouchID touchID, int *count)
SDL_TouchID * SDL_GetTouchDevices(int *count)
SDL_TouchDeviceType
Definition: SDL_touch.h:45
@ SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE
Definition: SDL_touch.h:48
@ SDL_TOUCH_DEVICE_DIRECT
Definition: SDL_touch.h:47
@ SDL_TOUCH_DEVICE_INDIRECT_RELATIVE
Definition: SDL_touch.h:49
@ SDL_TOUCH_DEVICE_INVALID
Definition: SDL_touch.h:46
SDL_TouchDeviceType SDL_GetTouchDeviceType(SDL_TouchID touchID)
const char * SDL_GetTouchDeviceName(SDL_TouchID touchID)
Uint64 SDL_FingerID
Definition: SDL_touch.h:42
float y
Definition: SDL_touch.h:67
float pressure
Definition: SDL_touch.h:68
SDL_FingerID id
Definition: SDL_touch.h:65
float x
Definition: SDL_touch.h:66