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