SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_touch.h
1#ifndef SDL3PP_TOUCH_H_
2#define SDL3PP_TOUCH_H_
3
4#include <SDL3/SDL_touch.h>
5#include "SDL3pp_error.h"
6#include "SDL3pp_mouse.h"
7#include "SDL3pp_stdinc.h"
8
9namespace SDL {
10
30using FingerRaw = SDL_Finger;
31
32// Forward decl
33struct Finger;
34
45using TouchID = SDL_TouchID;
46
59using FingerID = SDL_FingerID;
60
66using TouchDeviceType = SDL_TouchDeviceType;
67
69 SDL_TOUCH_DEVICE_INVALID;
70
72 SDL_TOUCH_DEVICE_DIRECT;
73
75 SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
77
79 SDL_TOUCH_DEVICE_INDIRECT_RELATIVE;
81
94{
100 constexpr Finger(const FingerRaw& finger = {})
101 : FingerRaw(finger)
102 {
103 }
104
113 constexpr Finger(SDL_FingerID id, float x, float y, float pressure)
114 : FingerRaw{id, x, y, pressure}
115 {
116 }
117
123 constexpr explicit operator bool() const { return id != 0; }
124
130 constexpr SDL_FingerID GetId() const { return id; }
131
138 constexpr Finger& SetId(SDL_FingerID newId)
139 {
140 id = newId;
141 return *this;
142 }
143
149 constexpr float GetX() const { return x; }
150
157 constexpr Finger& SetX(float newX)
158 {
159 x = newX;
160 return *this;
161 }
162
168 constexpr float GetY() const { return y; }
169
176 constexpr Finger& SetY(float newY)
177 {
178 y = newY;
179 return *this;
180 }
181
187 constexpr float GetPressure() const { return pressure; }
188
195 constexpr Finger& SetPressure(float newPressure)
196 {
197 pressure = newPressure;
198 return *this;
199 }
200};
201
207constexpr MouseID TOUCH_MOUSEID = SDL_TOUCH_MOUSEID;
208
214constexpr TouchID MOUSE_TOUCHID = SDL_MOUSE_TOUCHID;
215
229{
230 int count = 0;
231 auto data = SDL_GetTouchDevices(&count);
232 return OwnArray<TouchID>(data, size_t(count));
233}
234
244inline const char* GetTouchDeviceName(TouchID touchID)
245{
246 return SDL_GetTouchDeviceName(touchID);
247}
248
258{
259 return SDL_GetTouchDeviceType(touchID);
260}
261
272{
273 int count = 0;
274 auto data = reinterpret_cast<Finger**>(SDL_GetTouchFingers(touchID, &count));
275 return OwnArray<Finger*>(data, size_t(count));
276}
277
279
280} // namespace SDL
281
282#endif /* SDL3PP_TOUCH_H_ */
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
SDL_MouseID MouseID
This is a unique ID for a mouse for the time it is connected to the system, and is never reused for t...
Definition: SDL3pp_mouse.h:170
TouchDeviceType GetTouchDeviceType(TouchID touchID)
Get the type of the given touch device.
Definition: SDL3pp_touch.h:257
SDL_TouchID TouchID
A unique ID for a touch device.
Definition: SDL3pp_touch.h:45
SDL_TouchDeviceType TouchDeviceType
An enum that describes the type of a touch device.
Definition: SDL3pp_touch.h:66
OwnArray< Finger * > GetTouchFingers(TouchID touchID)
Get a list of active fingers for a given touch device.
Definition: SDL3pp_touch.h:271
const char * GetTouchDeviceName(TouchID touchID)
Get the touch device name as reported from the driver.
Definition: SDL3pp_touch.h:244
OwnArray< TouchID > GetTouchDevices()
Get a list of registered touch devices.
Definition: SDL3pp_touch.h:228
SDL_FingerID FingerID
A unique ID for a single finger on a touch device.
Definition: SDL3pp_touch.h:59
constexpr MouseID TOUCH_MOUSEID
The MouseID for mouse events simulated with touch input.
Definition: SDL3pp_touch.h:207
constexpr TouchDeviceType TOUCH_DEVICE_INVALID
TOUCH_DEVICE_INVALID.
Definition: SDL3pp_touch.h:68
constexpr TouchID MOUSE_TOUCHID
The TouchID for touch events simulated with mouse input.
Definition: SDL3pp_touch.h:214
SDL_Finger FingerRaw
Alias to raw representation for Finger.
Definition: SDL3pp_touch.h:30
constexpr TouchDeviceType TOUCH_DEVICE_INDIRECT_ABSOLUTE
trackpad with absolute device coordinates
Definition: SDL3pp_touch.h:74
constexpr TouchDeviceType TOUCH_DEVICE_DIRECT
touch screen with window-relative coordinates
Definition: SDL3pp_touch.h:71
constexpr TouchDeviceType TOUCH_DEVICE_INDIRECT_RELATIVE
trackpad with screen cursor-relative coordinates
Definition: SDL3pp_touch.h:78
Main include header for the SDL3pp library.
Data about a single finger in a multitouch event.
Definition: SDL3pp_touch.h:94
constexpr float GetPressure() const
Get the pressure.
Definition: SDL3pp_touch.h:187
constexpr Finger & SetId(SDL_FingerID newId)
Set the id.
Definition: SDL3pp_touch.h:138
constexpr Finger(const FingerRaw &finger={})
Wraps Finger.
Definition: SDL3pp_touch.h:100
constexpr Finger & SetPressure(float newPressure)
Set the pressure.
Definition: SDL3pp_touch.h:195
constexpr SDL_FingerID GetId() const
Get the id.
Definition: SDL3pp_touch.h:130
constexpr float GetX() const
Get the x.
Definition: SDL3pp_touch.h:149
constexpr Finger & SetX(float newX)
Set the x.
Definition: SDL3pp_touch.h:157
constexpr Finger & SetY(float newY)
Set the y.
Definition: SDL3pp_touch.h:176
constexpr float GetY() const
Get the y.
Definition: SDL3pp_touch.h:168
constexpr Finger(SDL_FingerID id, float x, float y, float pressure)
Constructs from its fields.
Definition: SDL3pp_touch.h:113