SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_joystick.h
1#ifndef SDL3PP_JOYSTICK_H_
2#define SDL3PP_JOYSTICK_H_
3
4#include <SDL3/SDL_joystick.h>
5#include "SDL3pp_error.h"
6#include "SDL3pp_guid.h"
7#include "SDL3pp_mutex.h"
8#include "SDL3pp_power.h"
9#include "SDL3pp_properties.h"
10#include "SDL3pp_rect.h"
11#include "SDL3pp_sensor.h"
12#include "SDL3pp_stdinc.h"
13
14namespace SDL {
15
49// Forward decl
50struct Joystick;
51
53using JoystickRaw = SDL_Joystick*;
54
55// Forward decl
56struct JoystickRef;
57
60{
62
65 : value(value)
66 {
67 }
68
70 constexpr JoystickParam(std::nullptr_t _ = nullptr)
71 : value(nullptr)
72 {
73 }
74
76 constexpr explicit operator bool() const { return !!value; }
77
79 constexpr auto operator<=>(const JoystickParam& other) const = default;
80
82 constexpr operator JoystickRaw() const { return value; }
83};
84
86using JoystickIDRaw = SDL_JoystickID;
87
100using JoystickType = SDL_JoystickType;
101
103 SDL_JOYSTICK_TYPE_UNKNOWN;
104
106 SDL_JOYSTICK_TYPE_GAMEPAD;
107
109 SDL_JOYSTICK_TYPE_WHEEL;
110
112 SDL_JOYSTICK_TYPE_ARCADE_STICK;
113
115 SDL_JOYSTICK_TYPE_FLIGHT_STICK;
116
118 SDL_JOYSTICK_TYPE_DANCE_PAD;
119
121 SDL_JOYSTICK_TYPE_GUITAR;
122
124 SDL_JOYSTICK_TYPE_DRUM_KIT;
125
127 SDL_JOYSTICK_TYPE_ARCADE_PAD;
128
130 SDL_JOYSTICK_TYPE_THROTTLE;
131
133 SDL_JOYSTICK_TYPE_COUNT;
134
146{
147 JoystickIDRaw m_joystickID;
148
149public:
155 constexpr JoystickID(JoystickIDRaw joystickID = {})
156 : m_joystickID(joystickID)
157 {
158 }
159
165 constexpr operator JoystickIDRaw() const { return m_joystickID; }
166
180 const char* GetJoystickNameForID();
181
195 const char* GetJoystickPathForID();
196
210
225
241
257
273
289
304
314
326
334 bool IsJoystickVirtual();
335};
336
345using JoystickConnectionState = SDL_JoystickConnectionState;
346
348 SDL_JOYSTICK_CONNECTION_INVALID;
349
351 SDL_JOYSTICK_CONNECTION_UNKNOWN;
352
354 SDL_JOYSTICK_CONNECTION_WIRED;
355
357 SDL_JOYSTICK_CONNECTION_WIRELESS;
358
364
365constexpr Uint8 HAT_CENTERED = SDL_HAT_CENTERED;
366
367constexpr Uint8 HAT_UP = SDL_HAT_UP;
368
369constexpr Uint8 HAT_RIGHT = SDL_HAT_RIGHT;
370
371constexpr Uint8 HAT_DOWN = SDL_HAT_DOWN;
372
373constexpr Uint8 HAT_LEFT = SDL_HAT_LEFT;
374
375constexpr Uint8 HAT_RIGHTUP = SDL_HAT_RIGHTUP;
376
377constexpr Uint8 HAT_RIGHTDOWN = SDL_HAT_RIGHTDOWN;
378
379constexpr Uint8 HAT_LEFTUP = SDL_HAT_LEFTUP;
380
381constexpr Uint8 HAT_LEFTDOWN = SDL_HAT_LEFTDOWN;
382
393{
394 JoystickRaw m_resource = nullptr;
395
396public:
398 constexpr Joystick() = default;
399
407 constexpr explicit Joystick(const JoystickRaw resource)
408 : m_resource(resource)
409 {
410 }
411
413 constexpr Joystick(const Joystick& other) = delete;
414
416 constexpr Joystick(Joystick&& other)
417 : Joystick(other.release())
418 {
419 }
420
421 constexpr Joystick(const JoystickRef& other) = delete;
422
423 constexpr Joystick(JoystickRef&& other) = delete;
424
438 Joystick(JoystickID instance_id)
439 : m_resource(CheckError(SDL_OpenJoystick(instance_id)))
440 {
441 }
442
444 ~Joystick() { SDL_CloseJoystick(m_resource); }
445
448 {
449 std::swap(m_resource, other.m_resource);
450 return *this;
451 }
452
454 constexpr JoystickRaw get() const { return m_resource; }
455
458 {
459 auto r = m_resource;
460 m_resource = nullptr;
461 return r;
462 }
463
465 constexpr auto operator<=>(const Joystick& other) const = default;
466
468 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
469
471 constexpr explicit operator bool() const { return !!m_resource; }
472
474 constexpr operator JoystickParam() const { return {m_resource}; }
475
484 void Close();
485
505 void SetVirtualAxis(int axis, Sint16 value);
506
523 void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel);
524
540 void SetVirtualButton(int button, bool down);
541
557 void SetVirtualHat(int hat, Uint8 value);
558
579 void SetVirtualTouchpad(int touchpad,
580 int finger,
581 bool down,
582 const FPointRaw& p,
583 float pressure);
584
604 Uint64 sensor_timestamp,
605 const float* data,
606 int num_values);
607
630
641 const char* GetName();
642
653 const char* GetPath();
654
667 int GetPlayerIndex();
668
680 void SetPlayerIndex(int player_index);
681
696 GUID GetGUID();
697
710
723
736
748
760 const char* GetSerial();
761
772
781 bool Connected();
782
792
810 int GetNumAxes();
811
830 int GetNumBalls();
831
845 int GetNumHats();
846
860 int GetNumButtons();
861
883 Sint16 GetAxis(int axis);
884
898 bool GetAxisInitialState(int axis, Sint16* state);
899
917 void GetBall(int ball, int* dx, int* dy);
918
931 Uint8 GetHat(int hat);
932
944 bool GetButton(int button);
945
964 bool Rumble(Uint16 low_frequency_rumble,
965 Uint16 high_frequency_rumble,
966 Uint32 duration_ms);
967
993 void RumbleTriggers(Uint16 left_rumble,
994 Uint16 right_rumble,
995 Uint32 duration_ms);
996
1013 void SetLED(Uint8 red, Uint8 green, Uint8 blue);
1014
1024 void SendEffect(const void* data, int size);
1025
1035
1054 PowerState GetPowerInfo(int* percent);
1055};
1056
1059{
1068 : Joystick(resource.value)
1069 {
1070 }
1071
1074 : Joystick(other.get())
1075 {
1076 }
1077
1080};
1081
1089constexpr int JOYSTICK_AXIS_MAX = SDL_JOYSTICK_AXIS_MAX;
1090
1100constexpr int JOYSTICK_AXIS_MIN = SDL_JOYSTICK_AXIS_MIN;
1101
1111inline void LockJoysticks(void) { SDL_LockJoysticks(); }
1112
1118inline void UnlockJoysticks(void) { SDL_UnlockJoysticks(); }
1119
1129inline bool HasJoystick() { return SDL_HasJoystick(); }
1130
1144{
1145 int count;
1146 auto r = reinterpret_cast<JoystickID*>(SDL_GetJoysticks(&count));
1147 return OwnArray<JoystickID>(r, count);
1148}
1149
1164inline const char* GetJoystickNameForID(JoystickID instance_id)
1165{
1166 return SDL_GetJoystickNameForID(instance_id);
1167}
1168
1170{
1171 return SDL::GetJoystickNameForID(m_joystickID);
1172}
1173
1188inline const char* GetJoystickPathForID(JoystickID instance_id)
1189{
1190 return SDL_GetJoystickPathForID(instance_id);
1191}
1192
1194{
1195 return SDL::GetJoystickPathForID(m_joystickID);
1196}
1197
1212{
1213 return SDL_GetJoystickPlayerIndexForID(instance_id);
1214}
1215
1217{
1218 return SDL::GetJoystickPlayerIndexForID(m_joystickID);
1219}
1220
1236{
1237 return SDL_GetJoystickGUIDForID(instance_id);
1238}
1239
1241{
1242 return SDL::GetJoystickGUIDForID(m_joystickID);
1243}
1244
1261{
1262 return SDL_GetJoystickVendorForID(instance_id);
1263}
1264
1266{
1267 return SDL::GetJoystickVendorForID(m_joystickID);
1268}
1269
1286{
1287 return SDL_GetJoystickProductForID(instance_id);
1288}
1289
1291{
1292 return SDL::GetJoystickProductForID(m_joystickID);
1293}
1294
1311{
1312 return SDL_GetJoystickProductVersionForID(instance_id);
1313}
1314
1316{
1317 return SDL::GetJoystickProductVersionForID(m_joystickID);
1318}
1319
1336{
1337 return SDL_GetJoystickTypeForID(instance_id);
1338}
1339
1341{
1342 return SDL::GetJoystickTypeForID(m_joystickID);
1343}
1344
1360{
1361 return Joystick(instance_id);
1362}
1363
1364inline Joystick JoystickID::OpenJoystick() { return Joystick(m_joystickID); }
1365
1376{
1377 return {CheckError(SDL_GetJoystickFromID(instance_id))};
1378}
1379
1381{
1382 return SDL::GetJoystickFromID(m_joystickID);
1383}
1384
1398{
1399 return {CheckError(SDL_GetJoystickFromPlayerIndex(player_index))};
1400}
1401
1409using VirtualJoystickTouchpadDesc = SDL_VirtualJoystickTouchpadDesc;
1410
1418using VirtualJoystickSensorDesc = SDL_VirtualJoystickSensorDesc;
1419
1433using VirtualJoystickDesc = SDL_VirtualJoystickDesc;
1434
1447{
1448 return SDL_AttachVirtualJoystick(&desc);
1449}
1450
1462inline void DetachVirtualJoystick(JoystickID instance_id)
1463{
1464 CheckError(SDL_DetachVirtualJoystick(instance_id));
1465}
1466
1468{
1469 SDL::DetachVirtualJoystick(m_joystickID);
1470}
1471
1480inline bool IsJoystickVirtual(JoystickID instance_id)
1481{
1482 return SDL_IsJoystickVirtual(instance_id);
1483}
1484
1486{
1487 return SDL::IsJoystickVirtual(m_joystickID);
1488}
1489
1511 int axis,
1512 Sint16 value)
1513{
1514 CheckError(SDL_SetJoystickVirtualAxis(joystick, axis, value));
1515}
1516
1517inline void Joystick::SetVirtualAxis(int axis, Sint16 value)
1518{
1519 SDL::SetJoystickVirtualAxis(m_resource, axis, value);
1520}
1521
1540 int ball,
1541 Sint16 xrel,
1542 Sint16 yrel)
1543{
1544 CheckError(SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel));
1545}
1546
1547inline void Joystick::SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
1548{
1549 SDL::SetJoystickVirtualBall(m_resource, ball, xrel, yrel);
1550}
1551
1569 int button,
1570 bool down)
1571{
1572 CheckError(SDL_SetJoystickVirtualButton(joystick, button, down));
1573}
1574
1575inline void Joystick::SetVirtualButton(int button, bool down)
1576{
1577 SDL::SetJoystickVirtualButton(m_resource, button, down);
1578}
1579
1596inline void SetJoystickVirtualHat(JoystickParam joystick, int hat, Uint8 value)
1597{
1598 CheckError(SDL_SetJoystickVirtualHat(joystick, hat, value));
1599}
1600
1601inline void Joystick::SetVirtualHat(int hat, Uint8 value)
1602{
1603 SDL::SetJoystickVirtualHat(m_resource, hat, value);
1604}
1605
1628 int touchpad,
1629 int finger,
1630 bool down,
1631 const FPointRaw& p,
1632 float pressure)
1633{
1634 CheckError(SDL_SetJoystickVirtualTouchpad(
1635 joystick, touchpad, finger, down, p.x, p.y, pressure));
1636}
1637
1638inline void Joystick::SetVirtualTouchpad(int touchpad,
1639 int finger,
1640 bool down,
1641 const FPointRaw& p,
1642 float pressure)
1643{
1645 m_resource, touchpad, finger, down, p, pressure);
1646}
1647
1668 SensorType type,
1669 Uint64 sensor_timestamp,
1670 const float* data,
1671 int num_values)
1672{
1673 CheckError(SDL_SendJoystickVirtualSensorData(
1674 joystick, type, sensor_timestamp, data, num_values));
1675}
1676
1678 Uint64 sensor_timestamp,
1679 const float* data,
1680 int num_values)
1681{
1683 m_resource, type, sensor_timestamp, data, num_values);
1684}
1685
1709{
1710 return {CheckError(SDL_GetJoystickProperties(joystick))};
1711}
1712
1714{
1715 return SDL::GetJoystickProperties(m_resource);
1716}
1717
1718namespace prop::JoystickCap {
1719
1720constexpr auto MONO_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN;
1721
1722constexpr auto RGB_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN;
1723
1724constexpr auto PLAYER_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN;
1725
1726constexpr auto RUMBLE_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN;
1727
1728constexpr auto TRIGGER_RUMBLE_BOOLEAN =
1729 SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN;
1730
1731} // namespace prop::JoystickCap
1732
1744inline const char* GetJoystickName(JoystickParam joystick)
1745{
1746 return SDL_GetJoystickName(joystick);
1747}
1748
1749inline const char* Joystick::GetName()
1750{
1751 return SDL::GetJoystickName(m_resource);
1752}
1753
1765inline const char* GetJoystickPath(JoystickParam joystick)
1766{
1767 return SDL_GetJoystickPath(joystick);
1768}
1769
1770inline const char* Joystick::GetPath()
1771{
1772 return SDL::GetJoystickPath(m_resource);
1773}
1774
1789{
1790 return SDL_GetJoystickPlayerIndex(joystick);
1791}
1792
1794{
1795 return SDL::GetJoystickPlayerIndex(m_resource);
1796}
1797
1810inline void SetJoystickPlayerIndex(JoystickParam joystick, int player_index)
1811{
1812 CheckError(SDL_SetJoystickPlayerIndex(joystick, player_index));
1813}
1814
1815inline void Joystick::SetPlayerIndex(int player_index)
1816{
1817 SDL::SetJoystickPlayerIndex(m_resource, player_index);
1818}
1819
1836{
1837 return SDL_GetJoystickGUID(joystick);
1838}
1839
1840inline GUID Joystick::GetGUID() { return SDL::GetJoystickGUID(m_resource); }
1841
1855{
1856 return SDL_GetJoystickVendor(joystick);
1857}
1858
1860{
1861 return SDL::GetJoystickVendor(m_resource);
1862}
1863
1877{
1878 return SDL_GetJoystickProduct(joystick);
1879}
1880
1882{
1883 return SDL::GetJoystickProduct(m_resource);
1884}
1885
1899{
1900 return SDL_GetJoystickProductVersion(joystick);
1901}
1902
1904{
1905 return SDL::GetJoystickProductVersion(m_resource);
1906}
1907
1920{
1921 return SDL_GetJoystickFirmwareVersion(joystick);
1922}
1923
1925{
1926 return SDL::GetJoystickFirmwareVersion(m_resource);
1927}
1928
1940inline const char* GetJoystickSerial(JoystickParam joystick)
1941{
1942 return SDL_GetJoystickSerial(joystick);
1943}
1944
1945inline const char* Joystick::GetSerial()
1946{
1947 return SDL::GetJoystickSerial(m_resource);
1948}
1949
1961{
1962 return SDL_GetJoystickType(joystick);
1963}
1964
1966{
1967 return SDL::GetJoystickType(m_resource);
1968}
1969
1987inline void GetJoystickGUIDInfo(GUID guid,
1988 Uint16* vendor,
1989 Uint16* product,
1990 Uint16* version,
1991 Uint16* crc16)
1992{
1993 SDL_GetJoystickGUIDInfo(guid, vendor, product, version, crc16);
1994}
1995
2006{
2007 return SDL_JoystickConnected(joystick);
2008}
2009
2010inline bool Joystick::Connected() { return SDL::JoystickConnected(m_resource); }
2011
2022{
2023 return CheckError(SDL_GetJoystickID(joystick));
2024}
2025
2026inline JoystickID Joystick::GetID() { return SDL::GetJoystickID(m_resource); }
2027
2047{
2048 return CheckError(SDL_GetNumJoystickAxes(joystick));
2049}
2050
2052{
2053 return SDL::GetNumJoystickAxes(m_resource);
2054}
2055
2076{
2077 return CheckError(SDL_GetNumJoystickBalls(joystick));
2078}
2079
2081{
2082 return SDL::GetNumJoystickBalls(m_resource);
2083}
2084
2100{
2101 return CheckError(SDL_GetNumJoystickHats(joystick));
2102}
2103
2105{
2106 return SDL::GetNumJoystickHats(m_resource);
2107}
2108
2124{
2125 return CheckError(SDL_GetNumJoystickButtons(joystick));
2126}
2127
2129{
2130 return SDL::GetNumJoystickButtons(m_resource);
2131}
2132
2147inline void SetJoystickEventsEnabled(bool enabled)
2148{
2149 SDL_SetJoystickEventsEnabled(enabled);
2150}
2151
2165inline bool JoystickEventsEnabled() { return SDL_JoystickEventsEnabled(); }
2166
2175inline void UpdateJoysticks() { SDL_UpdateJoysticks(); }
2176
2199inline Sint16 GetJoystickAxis(JoystickParam joystick, int axis)
2200{
2201 return SDL_GetJoystickAxis(joystick, axis);
2202}
2203
2205{
2206 return SDL::GetJoystickAxis(m_resource, axis);
2207}
2208
2224 int axis,
2225 Sint16* state)
2226{
2227 return SDL_GetJoystickAxisInitialState(joystick, axis, state);
2228}
2229
2230inline bool Joystick::GetAxisInitialState(int axis, Sint16* state)
2231{
2232 return SDL::GetJoystickAxisInitialState(m_resource, axis, state);
2233}
2234
2253inline void GetJoystickBall(JoystickParam joystick, int ball, int* dx, int* dy)
2254{
2255 CheckError(SDL_GetJoystickBall(joystick, ball, dx, dy));
2256}
2257
2258inline void Joystick::GetBall(int ball, int* dx, int* dy)
2259{
2260 SDL::GetJoystickBall(m_resource, ball, dx, dy);
2261}
2262
2276inline Uint8 GetJoystickHat(JoystickParam joystick, int hat)
2277{
2278 return SDL_GetJoystickHat(joystick, hat);
2279}
2280
2282{
2283 return SDL::GetJoystickHat(m_resource, hat);
2284}
2285
2298inline bool GetJoystickButton(JoystickParam joystick, int button)
2299{
2300 return SDL_GetJoystickButton(joystick, button);
2301}
2302
2303inline bool Joystick::GetButton(int button)
2304{
2305 return SDL::GetJoystickButton(m_resource, button);
2306}
2307
2327inline bool RumbleJoystick(JoystickParam joystick,
2328 Uint16 low_frequency_rumble,
2329 Uint16 high_frequency_rumble,
2330 Uint32 duration_ms)
2331{
2332 return SDL_RumbleJoystick(
2333 joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
2334}
2335
2336inline bool Joystick::Rumble(Uint16 low_frequency_rumble,
2337 Uint16 high_frequency_rumble,
2338 Uint32 duration_ms)
2339{
2340 return SDL::RumbleJoystick(
2341 m_resource, low_frequency_rumble, high_frequency_rumble, duration_ms);
2342}
2343
2371 Uint16 left_rumble,
2372 Uint16 right_rumble,
2373 Uint32 duration_ms)
2374{
2375 CheckError(SDL_RumbleJoystickTriggers(
2376 joystick, left_rumble, right_rumble, duration_ms));
2377}
2378
2379inline void Joystick::RumbleTriggers(Uint16 left_rumble,
2380 Uint16 right_rumble,
2381 Uint32 duration_ms)
2382{
2384 m_resource, left_rumble, right_rumble, duration_ms);
2385}
2386
2404inline void SetJoystickLED(JoystickParam joystick,
2405 Uint8 red,
2406 Uint8 green,
2407 Uint8 blue)
2408{
2409 CheckError(SDL_SetJoystickLED(joystick, red, green, blue));
2410}
2411
2412inline void Joystick::SetLED(Uint8 red, Uint8 green, Uint8 blue)
2413{
2414 SDL::SetJoystickLED(m_resource, red, green, blue);
2415}
2416
2428 const void* data,
2429 int size)
2430{
2431 CheckError(SDL_SendJoystickEffect(joystick, data, size));
2432}
2433
2434inline void Joystick::SendEffect(const void* data, int size)
2435{
2436 SDL::SendJoystickEffect(m_resource, data, size);
2437}
2438
2448inline void CloseJoystick(JoystickRaw joystick) { SDL_CloseJoystick(joystick); }
2449
2451
2462 JoystickParam joystick)
2463{
2464 return CheckError(SDL_GetJoystickConnectionState(joystick));
2465}
2466
2468{
2469 return SDL::GetJoystickConnectionState(m_resource);
2470}
2471
2491inline PowerState GetJoystickPowerInfo(JoystickParam joystick, int* percent)
2492{
2493 return SDL_GetJoystickPowerInfo(joystick, percent);
2494}
2495
2497{
2498 return SDL::GetJoystickPowerInfo(m_resource, percent);
2499}
2500
2502
2503} // namespace SDL
2504
2505#endif /* SDL3PP_JOYSTICK_H_ */
This is a unique ID for a joystick for the time it is connected to the system, and is never reused fo...
Definition: SDL3pp_joystick.h:146
constexpr JoystickID(JoystickIDRaw joystickID={})
Wraps JoystickID.
Definition: SDL3pp_joystick.h:155
The joystick structure used to identify an SDL joystick.
Definition: SDL3pp_joystick.h:393
Joystick & operator=(Joystick other)
Assignment operator.
Definition: SDL3pp_joystick.h:447
constexpr auto operator<=>(const Joystick &other) const =default
Comparison.
constexpr JoystickRaw get() const
Retrieves underlying JoystickRaw.
Definition: SDL3pp_joystick.h:454
constexpr Joystick(const Joystick &other)=delete
Copy constructor.
~Joystick()
Destructor.
Definition: SDL3pp_joystick.h:444
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_joystick.h:468
constexpr Joystick()=default
Default ctor.
Joystick(JoystickID instance_id)
Open a joystick for use.
Definition: SDL3pp_joystick.h:438
constexpr Joystick(Joystick &&other)
Move constructor.
Definition: SDL3pp_joystick.h:416
constexpr JoystickRaw release()
Retrieves underlying JoystickRaw and clear this.
Definition: SDL3pp_joystick.h:457
constexpr Joystick(const JoystickRaw resource)
Constructs from JoystickParam.
Definition: SDL3pp_joystick.h:407
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
PropertiesRef GetJoystickProperties(JoystickParam joystick)
Get the properties associated with a joystick.
Definition: SDL3pp_joystick.h:1708
SDL_Joystick * JoystickRaw
Alias to raw representation for Joystick.
Definition: SDL3pp_joystick.h:53
int GetJoystickPlayerIndexForID(JoystickID instance_id)
Get the player index of a joystick.
Definition: SDL3pp_joystick.h:1211
constexpr JoystickType JOYSTICK_TYPE_COUNT
JOYSTICK_TYPE_COUNT.
Definition: SDL3pp_joystick.h:132
Uint16 GetProductVersion()
Get the product version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1903
constexpr Uint8 HAT_UP
UP.
Definition: SDL3pp_joystick.h:367
int GetJoystickPlayerIndexForID()
Get the player index of a joystick.
Definition: SDL3pp_joystick.h:1216
int GetPlayerIndex()
Get the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1793
bool IsJoystickVirtual()
Query whether or not a joystick is virtual.
Definition: SDL3pp_joystick.h:1485
Uint16 GetJoystickVendorForID()
Get the USB vendor ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1265
int GetNumJoystickBalls(JoystickParam joystick)
Get the number of trackballs on a joystick.
Definition: SDL3pp_joystick.h:2075
constexpr JoystickType JOYSTICK_TYPE_ARCADE_STICK
JOYSTICK_TYPE_ARCADE_STICK.
Definition: SDL3pp_joystick.h:111
bool HasJoystick()
Return whether a joystick is currently connected.
Definition: SDL3pp_joystick.h:1129
constexpr Uint8 HAT_LEFT
LEFT.
Definition: SDL3pp_joystick.h:373
Uint16 GetJoystickProductForID(JoystickID instance_id)
Get the USB product ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1285
Uint16 GetProduct()
Get the USB product ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1881
int GetNumBalls()
Get the number of trackballs on a joystick.
Definition: SDL3pp_joystick.h:2080
bool GetButton(int button)
Get the current state of a button on a joystick.
Definition: SDL3pp_joystick.h:2303
JoystickID AttachVirtualJoystick(const VirtualJoystickDesc &desc)
Attach a new virtual joystick.
Definition: SDL3pp_joystick.h:1446
Sint16 GetAxis(int axis)
Get the current state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2204
void SetJoystickLED(JoystickParam joystick, Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition: SDL3pp_joystick.h:2404
Uint16 GetVendor()
Get the USB vendor ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1859
constexpr Uint8 HAT_DOWN
DOWN.
Definition: SDL3pp_joystick.h:371
SDL_VirtualJoystickTouchpadDesc VirtualJoystickTouchpadDesc
The structure that describes a virtual joystick touchpad.
Definition: SDL3pp_joystick.h:1409
constexpr JoystickType JOYSTICK_TYPE_DRUM_KIT
JOYSTICK_TYPE_DRUM_KIT.
Definition: SDL3pp_joystick.h:123
void SetJoystickVirtualHat(JoystickParam joystick, int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1596
void SetJoystickVirtualBall(JoystickParam joystick, int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1539
const char * GetJoystickName(JoystickParam joystick)
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1744
constexpr JoystickConnectionState JOYSTICK_CONNECTION_INVALID
JOYSTICK_CONNECTION_INVALID.
Definition: SDL3pp_joystick.h:347
constexpr JoystickConnectionState JOYSTICK_CONNECTION_UNKNOWN
JOYSTICK_CONNECTION_UNKNOWN.
Definition: SDL3pp_joystick.h:350
void SetJoystickVirtualAxis(JoystickParam joystick, int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1510
JoystickID GetJoystickID(JoystickParam joystick)
Get the instance ID of an opened joystick.
Definition: SDL3pp_joystick.h:2021
GUID GetGUID()
Get the implementation-dependent GUID for the joystick.
Definition: SDL3pp_joystick.h:1840
Uint16 GetJoystickVendor(JoystickParam joystick)
Get the USB vendor ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1854
int GetNumHats()
Get the number of POV hats on a joystick.
Definition: SDL3pp_joystick.h:2104
JoystickType GetJoystickTypeForID(JoystickID instance_id)
Get the type of a joystick, if available.
Definition: SDL3pp_joystick.h:1335
JoystickRef GetJoystickFromPlayerIndex(int player_index)
Get the Joystick associated with a player index.
Definition: SDL3pp_joystick.h:1397
Uint16 GetJoystickProductVersionForID()
Get the product version of a joystick, if available.
Definition: SDL3pp_joystick.h:1315
void SendJoystickVirtualSensorData(JoystickParam joystick, SensorType type, Uint64 sensor_timestamp, const float *data, int num_values)
Send a sensor update for an opened virtual joystick.
Definition: SDL3pp_joystick.h:1667
const char * GetPath()
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1770
constexpr JoystickType JOYSTICK_TYPE_WHEEL
JOYSTICK_TYPE_WHEEL.
Definition: SDL3pp_joystick.h:108
bool RumbleJoystick(JoystickParam joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition: SDL3pp_joystick.h:2327
constexpr Uint8 HAT_RIGHTDOWN
RIGHTDOWN.
Definition: SDL3pp_joystick.h:377
void GetJoystickBall(JoystickParam joystick, int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition: SDL3pp_joystick.h:2253
void UpdateJoysticks()
Update the current state of the open joysticks.
Definition: SDL3pp_joystick.h:2175
Joystick OpenJoystick()
Open a joystick for use.
Definition: SDL3pp_joystick.h:1364
void SendEffect(const void *data, int size)
Send a joystick specific effect packet.
Definition: SDL3pp_joystick.h:2434
void SetJoystickPlayerIndex(JoystickParam joystick, int player_index)
Set the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1810
void UnlockJoysticks(void)
Unlocking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1118
void SetVirtualButton(int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1575
int GetNumJoystickAxes(JoystickParam joystick)
Get the number of general axis controls on a joystick.
Definition: SDL3pp_joystick.h:2046
void DetachVirtualJoystick(JoystickID instance_id)
Detach a virtual joystick.
Definition: SDL3pp_joystick.h:1462
SDL_JoystickID JoystickIDRaw
Alias to raw representation for JoystickID.
Definition: SDL3pp_joystick.h:86
constexpr JoystickType JOYSTICK_TYPE_GUITAR
JOYSTICK_TYPE_GUITAR.
Definition: SDL3pp_joystick.h:120
JoystickType GetJoystickTypeForID()
Get the type of a joystick, if available.
Definition: SDL3pp_joystick.h:1340
void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1547
int GetNumAxes()
Get the number of general axis controls on a joystick.
Definition: SDL3pp_joystick.h:2051
constexpr JoystickType JOYSTICK_TYPE_UNKNOWN
JOYSTICK_TYPE_UNKNOWN.
Definition: SDL3pp_joystick.h:102
void DetachVirtualJoystick()
Detach a virtual joystick.
Definition: SDL3pp_joystick.h:1467
void SetVirtualTouchpad(int touchpad, int finger, bool down, const FPointRaw &p, float pressure)
Set touchpad finger state on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1638
void SetLED(Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition: SDL3pp_joystick.h:2412
void RumbleTriggers(Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
Start a rumble effect in the joystick's triggers.
Definition: SDL3pp_joystick.h:2379
Uint16 GetJoystickVendorForID(JoystickID instance_id)
Get the USB vendor ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1260
bool GetJoystickButton(JoystickParam joystick, int button)
Get the current state of a button on a joystick.
Definition: SDL3pp_joystick.h:2298
JoystickType GetJoystickType(JoystickParam joystick)
Get the type of an opened joystick.
Definition: SDL3pp_joystick.h:1960
void SetVirtualAxis(int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1517
constexpr Uint8 HAT_RIGHT
RIGHT.
Definition: SDL3pp_joystick.h:369
constexpr JoystickType JOYSTICK_TYPE_FLIGHT_STICK
JOYSTICK_TYPE_FLIGHT_STICK.
Definition: SDL3pp_joystick.h:114
constexpr JoystickType JOYSTICK_TYPE_GAMEPAD
JOYSTICK_TYPE_GAMEPAD.
Definition: SDL3pp_joystick.h:105
void SetJoystickVirtualTouchpad(JoystickParam joystick, int touchpad, int finger, bool down, const FPointRaw &p, float pressure)
Set touchpad finger state on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1627
constexpr JoystickType JOYSTICK_TYPE_DANCE_PAD
JOYSTICK_TYPE_DANCE_PAD.
Definition: SDL3pp_joystick.h:117
PropertiesRef GetProperties()
Get the properties associated with a joystick.
Definition: SDL3pp_joystick.h:1713
GUID GetJoystickGUIDForID()
Get the implementation-dependent GUID of a joystick.
Definition: SDL3pp_joystick.h:1240
Uint16 GetFirmwareVersion()
Get the firmware version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1924
constexpr Uint8 HAT_LEFTUP
LEFTUP.
Definition: SDL3pp_joystick.h:379
GUID GetJoystickGUID(JoystickParam joystick)
Get the implementation-dependent GUID for the joystick.
Definition: SDL3pp_joystick.h:1835
constexpr JoystickType JOYSTICK_TYPE_THROTTLE
JOYSTICK_TYPE_THROTTLE.
Definition: SDL3pp_joystick.h:129
const char * GetSerial()
Get the serial number of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1945
bool Rumble(Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition: SDL3pp_joystick.h:2336
void LockJoysticks(void)
Locking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1111
OwnArray< JoystickID > GetJoysticks()
Get a list of currently connected joysticks.
Definition: SDL3pp_joystick.h:1143
constexpr int JOYSTICK_AXIS_MAX
The largest value an Joystick's axis can report.
Definition: SDL3pp_joystick.h:1089
PowerState GetJoystickPowerInfo(JoystickParam joystick, int *percent)
Get the battery state of a joystick.
Definition: SDL3pp_joystick.h:2491
constexpr int JOYSTICK_AXIS_MIN
The smallest value an Joystick's axis can report.
Definition: SDL3pp_joystick.h:1100
int GetJoystickPlayerIndex(JoystickParam joystick)
Get the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1788
Uint16 GetJoystickProductVersionForID(JoystickID instance_id)
Get the product version of a joystick, if available.
Definition: SDL3pp_joystick.h:1310
void SetJoystickEventsEnabled(bool enabled)
Set the state of joystick event processing.
Definition: SDL3pp_joystick.h:2147
constexpr Uint8 HAT_RIGHTUP
RIGHTUP.
Definition: SDL3pp_joystick.h:375
bool Connected()
Get the status of a specified joystick.
Definition: SDL3pp_joystick.h:2010
GUID GetJoystickGUIDForID(JoystickID instance_id)
Get the implementation-dependent GUID of a joystick.
Definition: SDL3pp_joystick.h:1235
void SendJoystickEffect(JoystickParam joystick, const void *data, int size)
Send a joystick specific effect packet.
Definition: SDL3pp_joystick.h:2427
Uint16 GetJoystickFirmwareVersion(JoystickParam joystick)
Get the firmware version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1919
Uint8 GetJoystickHat(JoystickParam joystick, int hat)
Get the current state of a POV hat on a joystick.
Definition: SDL3pp_joystick.h:2276
constexpr Uint8 HAT_CENTERED
CENTERED.
Definition: SDL3pp_joystick.h:365
const char * GetJoystickPath(JoystickParam joystick)
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1765
Uint16 GetJoystickProduct(JoystickParam joystick)
Get the USB product ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1876
const char * GetJoystickSerial(JoystickParam joystick)
Get the serial number of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1940
JoystickType GetType()
Get the type of an opened joystick.
Definition: SDL3pp_joystick.h:1965
int GetNumJoystickButtons(JoystickParam joystick)
Get the number of buttons on a joystick.
Definition: SDL3pp_joystick.h:2123
int GetNumJoystickHats(JoystickParam joystick)
Get the number of POV hats on a joystick.
Definition: SDL3pp_joystick.h:2099
SDL_VirtualJoystickSensorDesc VirtualJoystickSensorDesc
The structure that describes a virtual joystick sensor.
Definition: SDL3pp_joystick.h:1418
SDL_JoystickConnectionState JoystickConnectionState
Possible connection states for a joystick device.
Definition: SDL3pp_joystick.h:345
bool GetJoystickAxisInitialState(JoystickParam joystick, int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2223
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRELESS
JOYSTICK_CONNECTION_WIRELESS.
Definition: SDL3pp_joystick.h:356
bool JoystickConnected(JoystickParam joystick)
Get the status of a specified joystick.
Definition: SDL3pp_joystick.h:2005
void SendVirtualSensorData(SensorType type, Uint64 sensor_timestamp, const float *data, int num_values)
Send a sensor update for an opened virtual joystick.
Definition: SDL3pp_joystick.h:1677
bool GetAxisInitialState(int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2230
JoystickRef GetJoystickFromID(JoystickID instance_id)
Get the Joystick associated with an instance ID, if it has been opened.
Definition: SDL3pp_joystick.h:1375
JoystickRef GetJoystickFromID()
Get the Joystick associated with an instance ID, if it has been opened.
Definition: SDL3pp_joystick.h:1380
void Close()
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition: SDL3pp_joystick.h:2450
bool JoystickEventsEnabled()
Query the state of joystick event processing.
Definition: SDL3pp_joystick.h:2165
void CloseJoystick(JoystickRaw joystick)
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition: SDL3pp_joystick.h:2448
SDL_VirtualJoystickDesc VirtualJoystickDesc
The structure that describes a virtual joystick.
Definition: SDL3pp_joystick.h:1433
const char * GetJoystickPathForID()
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1193
Uint8 HatState
Represents tbe HatState for a Joystick.
Definition: SDL3pp_joystick.h:363
void SetVirtualHat(int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1601
constexpr JoystickType JOYSTICK_TYPE_ARCADE_PAD
JOYSTICK_TYPE_ARCADE_PAD.
Definition: SDL3pp_joystick.h:126
JoystickConnectionState GetConnectionState()
Get the connection state of a joystick.
Definition: SDL3pp_joystick.h:2467
PowerState GetPowerInfo(int *percent)
Get the battery state of a joystick.
Definition: SDL3pp_joystick.h:2496
Sint16 GetJoystickAxis(JoystickParam joystick, int axis)
Get the current state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2199
bool IsJoystickVirtual(JoystickID instance_id)
Query whether or not a joystick is virtual.
Definition: SDL3pp_joystick.h:1480
JoystickID GetID()
Get the instance ID of an opened joystick.
Definition: SDL3pp_joystick.h:2026
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRED
JOYSTICK_CONNECTION_WIRED.
Definition: SDL3pp_joystick.h:353
const char * GetJoystickNameForID()
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1169
const char * GetJoystickPathForID(JoystickID instance_id)
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1188
void GetJoystickGUIDInfo(GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16)
Get the device information encoded in a GUID structure.
Definition: SDL3pp_joystick.h:1987
constexpr Uint8 HAT_LEFTDOWN
LEFTDOWN.
Definition: SDL3pp_joystick.h:381
Joystick OpenJoystick(JoystickID instance_id)
Open a joystick for use.
Definition: SDL3pp_joystick.h:1359
Uint16 GetJoystickProductVersion(JoystickParam joystick)
Get the product version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1898
const char * GetName()
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1749
Uint8 GetHat(int hat)
Get the current state of a POV hat on a joystick.
Definition: SDL3pp_joystick.h:2281
void SetPlayerIndex(int player_index)
Set the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1815
JoystickConnectionState GetJoystickConnectionState(JoystickParam joystick)
Get the connection state of a joystick.
Definition: SDL3pp_joystick.h:2461
void GetBall(int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition: SDL3pp_joystick.h:2258
Uint16 GetJoystickProductForID()
Get the USB product ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1290
void RumbleJoystickTriggers(JoystickParam joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
Start a rumble effect in the joystick's triggers.
Definition: SDL3pp_joystick.h:2370
const char * GetJoystickNameForID(JoystickID instance_id)
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1164
void SetJoystickVirtualButton(JoystickParam joystick, int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1568
int GetNumButtons()
Get the number of buttons on a joystick.
Definition: SDL3pp_joystick.h:2128
SDL_JoystickType JoystickType
An enum of some common joystick types.
Definition: SDL3pp_joystick.h:100
SDL_PowerState PowerState
The basic state for the system's power supply.
Definition: SDL3pp_power.h:38
SDL_FPoint FPointRaw
Alias to raw representation for FPoint.
Definition: SDL3pp_rect.h:25
SDL_SensorType SensorType
The different sensors defined by SDL.
Definition: SDL3pp_sensor.h:125
Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:291
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition: SDL3pp_stdinc.h:2258
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:325
Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:363
Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:257
Sint16 Sint16
A signed 16-bit integer type.
Definition: SDL3pp_stdinc.h:274
Main include header for the SDL3pp library.
An GUID is a 128-bit identifier for an input device that identifies that device across runs of SDL pr...
Definition: SDL3pp_guid.h:41
Safely wrap Joystick for non owning parameters.
Definition: SDL3pp_joystick.h:60
constexpr JoystickParam(JoystickRaw value)
Constructs from JoystickRaw.
Definition: SDL3pp_joystick.h:64
JoystickRaw value
parameter's JoystickRaw
Definition: SDL3pp_joystick.h:61
constexpr auto operator<=>(const JoystickParam &other) const =default
Comparison.
constexpr JoystickParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_joystick.h:70
Semi-safe reference for Joystick.
Definition: SDL3pp_joystick.h:1059
JoystickRef(const JoystickRef &other)
Copy constructor.
Definition: SDL3pp_joystick.h:1073
JoystickRef(JoystickParam resource)
Constructs from JoystickParam.
Definition: SDL3pp_joystick.h:1067
~JoystickRef()
Destructor.
Definition: SDL3pp_joystick.h:1079
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:569