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
31using FingerRaw = SDL_Finger;
32
43using TouchID = SDL_TouchID;
44
57using FingerID = SDL_FingerID;
58
64using TouchDeviceType = SDL_TouchDeviceType;
65
67 SDL_TOUCH_DEVICE_INVALID;
68
70 SDL_TOUCH_DEVICE_DIRECT;
71
73 SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
75
77 SDL_TOUCH_DEVICE_INDIRECT_RELATIVE;
79
92{
98 constexpr Finger(const FingerRaw& finger = {})
99 : FingerRaw(finger)
100 {
101 }
102
111 constexpr Finger(SDL_FingerID id, float x, float y, float pressure)
112 : FingerRaw{id, x, y, pressure}
113 {
114 }
115
121 constexpr explicit operator bool() const { return id != 0; }
122
128 constexpr SDL_FingerID GetId() const { return id; }
129
136 constexpr Finger& SetId(SDL_FingerID newId)
137 {
138 id = newId;
139 return *this;
140 }
141
147 constexpr float GetX() const { return x; }
148
155 constexpr Finger& SetX(float newX)
156 {
157 x = newX;
158 return *this;
159 }
160
166 constexpr float GetY() const { return y; }
167
174 constexpr Finger& SetY(float newY)
175 {
176 y = newY;
177 return *this;
178 }
179
185 constexpr float GetPressure() const { return pressure; }
186
193 constexpr Finger& SetPressure(float newPressure)
194 {
195 pressure = newPressure;
196 return *this;
197 }
198};
199
205constexpr MouseID TOUCH_MOUSEID = SDL_TOUCH_MOUSEID;
206
212constexpr TouchID MOUSE_TOUCHID = SDL_MOUSE_TOUCHID;
213
227{
228 int count = 0;
229 auto data = SDL_GetTouchDevices(&count);
230 return OwnArray<TouchID>(data, size_t(count));
231}
232
242inline const char* GetTouchDeviceName(TouchID touchID)
243{
244 return SDL_GetTouchDeviceName(touchID);
245}
246
256{
257 return SDL_GetTouchDeviceType(touchID);
258}
259
270{
271 int count = 0;
272 auto data = reinterpret_cast<Finger**>(SDL_GetTouchFingers(touchID, &count));
273 return OwnArray<Finger*>(data, size_t(count));
274}
275
277
278} // namespace SDL
279
280#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:171
TouchDeviceType GetTouchDeviceType(TouchID touchID)
Get the type of the given touch device.
Definition: SDL3pp_touch.h:255
SDL_TouchID TouchID
A unique ID for a touch device.
Definition: SDL3pp_touch.h:43
SDL_TouchDeviceType TouchDeviceType
An enum that describes the type of a touch device.
Definition: SDL3pp_touch.h:64
OwnArray< Finger * > GetTouchFingers(TouchID touchID)
Get a list of active fingers for a given touch device.
Definition: SDL3pp_touch.h:269
const char * GetTouchDeviceName(TouchID touchID)
Get the touch device name as reported from the driver.
Definition: SDL3pp_touch.h:242
OwnArray< TouchID > GetTouchDevices()
Get a list of registered touch devices.
Definition: SDL3pp_touch.h:226
SDL_FingerID FingerID
A unique ID for a single finger on a touch device.
Definition: SDL3pp_touch.h:57
constexpr MouseID TOUCH_MOUSEID
The MouseID for mouse events simulated with touch input.
Definition: SDL3pp_touch.h:205
constexpr TouchDeviceType TOUCH_DEVICE_INVALID
TOUCH_DEVICE_INVALID.
Definition: SDL3pp_touch.h:66
constexpr TouchID MOUSE_TOUCHID
The TouchID for touch events simulated with mouse input.
Definition: SDL3pp_touch.h:212
SDL_Finger FingerRaw
Alias to raw representation for Finger.
Definition: SDL3pp_touch.h:31
constexpr TouchDeviceType TOUCH_DEVICE_INDIRECT_ABSOLUTE
trackpad with absolute device coordinates
Definition: SDL3pp_touch.h:72
constexpr TouchDeviceType TOUCH_DEVICE_DIRECT
touch screen with window-relative coordinates
Definition: SDL3pp_touch.h:69
constexpr TouchDeviceType TOUCH_DEVICE_INDIRECT_RELATIVE
trackpad with screen cursor-relative coordinates
Definition: SDL3pp_touch.h:76
Main include header for the SDL3pp library.
Data about a single finger in a multitouch event.
Definition: SDL3pp_touch.h:92
constexpr float GetPressure() const
Get the pressure.
Definition: SDL3pp_touch.h:185
constexpr Finger & SetId(SDL_FingerID newId)
Set the id.
Definition: SDL3pp_touch.h:136
constexpr Finger(const FingerRaw &finger={})
Wraps Finger.
Definition: SDL3pp_touch.h:98
constexpr Finger & SetPressure(float newPressure)
Set the pressure.
Definition: SDL3pp_touch.h:193
constexpr SDL_FingerID GetId() const
Get the id.
Definition: SDL3pp_touch.h:128
constexpr float GetX() const
Get the x.
Definition: SDL3pp_touch.h:147
constexpr Finger & SetX(float newX)
Set the x.
Definition: SDL3pp_touch.h:155
constexpr Finger & SetY(float newY)
Set the y.
Definition: SDL3pp_touch.h:174
constexpr float GetY() const
Get the y.
Definition: SDL3pp_touch.h:166
constexpr Finger(SDL_FingerID id, float x, float y, float pressure)
Constructs from its fields.
Definition: SDL3pp_touch.h:111