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
88// Forward decl
89struct JoystickID;
90
103using JoystickType = SDL_JoystickType;
104
106 SDL_JOYSTICK_TYPE_UNKNOWN;
107
109 SDL_JOYSTICK_TYPE_GAMEPAD;
110
112 SDL_JOYSTICK_TYPE_WHEEL;
113
115 SDL_JOYSTICK_TYPE_ARCADE_STICK;
116
118 SDL_JOYSTICK_TYPE_FLIGHT_STICK;
119
121 SDL_JOYSTICK_TYPE_DANCE_PAD;
122
124 SDL_JOYSTICK_TYPE_GUITAR;
125
127 SDL_JOYSTICK_TYPE_DRUM_KIT;
128
130 SDL_JOYSTICK_TYPE_ARCADE_PAD;
131
133 SDL_JOYSTICK_TYPE_THROTTLE;
134
136 SDL_JOYSTICK_TYPE_COUNT;
137
149{
150 JoystickIDRaw m_joystickID;
151
152public:
158 constexpr JoystickID(JoystickIDRaw joystickID = {})
159 : m_joystickID(joystickID)
160 {
161 }
162
168 constexpr operator JoystickIDRaw() const { return m_joystickID; }
169
183 const char* GetJoystickNameForID();
184
198 const char* GetJoystickPathForID();
199
213
228
244
260
276
292
307
317
328
336 bool IsJoystickVirtual();
337};
338
347using JoystickConnectionState = SDL_JoystickConnectionState;
348
350 SDL_JOYSTICK_CONNECTION_INVALID;
351
353 SDL_JOYSTICK_CONNECTION_UNKNOWN;
354
356 SDL_JOYSTICK_CONNECTION_WIRED;
357
359 SDL_JOYSTICK_CONNECTION_WIRELESS;
360
366
367constexpr Uint8 HAT_CENTERED = SDL_HAT_CENTERED;
368
369constexpr Uint8 HAT_UP = SDL_HAT_UP;
370
371constexpr Uint8 HAT_RIGHT = SDL_HAT_RIGHT;
372
373constexpr Uint8 HAT_DOWN = SDL_HAT_DOWN;
374
375constexpr Uint8 HAT_LEFT = SDL_HAT_LEFT;
376
377constexpr Uint8 HAT_RIGHTUP = SDL_HAT_RIGHTUP;
378
379constexpr Uint8 HAT_RIGHTDOWN = SDL_HAT_RIGHTDOWN;
380
381constexpr Uint8 HAT_LEFTUP = SDL_HAT_LEFTUP;
382
383constexpr Uint8 HAT_LEFTDOWN = SDL_HAT_LEFTDOWN;
384
395{
396 JoystickRaw m_resource = nullptr;
397
398public:
400 constexpr Joystick() = default;
401
409 constexpr explicit Joystick(const JoystickRaw resource)
410 : m_resource(resource)
411 {
412 }
413
415 constexpr Joystick(const Joystick& other) = delete;
416
418 constexpr Joystick(Joystick&& other)
419 : Joystick(other.release())
420 {
421 }
422
423 constexpr Joystick(const JoystickRef& other) = delete;
424
425 constexpr Joystick(JoystickRef&& other) = delete;
426
440 Joystick(JoystickID instance_id)
441 : m_resource(CheckError(SDL_OpenJoystick(instance_id)))
442 {
443 }
444
446 ~Joystick() { SDL_CloseJoystick(m_resource); }
447
450 {
451 std::swap(m_resource, other.m_resource);
452 return *this;
453 }
454
456 constexpr JoystickRaw get() const { return m_resource; }
457
460 {
461 auto r = m_resource;
462 m_resource = nullptr;
463 return r;
464 }
465
467 constexpr auto operator<=>(const Joystick& other) const = default;
468
470 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
471
473 constexpr explicit operator bool() const { return !!m_resource; }
474
476 constexpr operator JoystickParam() const { return {m_resource}; }
477
485 void Close();
486
505 void SetVirtualAxis(int axis, Sint16 value);
506
522 void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel);
523
538 void SetVirtualButton(int button, bool down);
539
554 void SetVirtualHat(int hat, Uint8 value);
555
575 void SetVirtualTouchpad(int touchpad,
576 int finger,
577 bool down,
578 const FPointRaw& p,
579 float pressure);
580
599 Uint64 sensor_timestamp,
600 const float* data,
601 int num_values);
602
625
636 const char* GetName();
637
648 const char* GetPath();
649
662 int GetPlayerIndex();
663
675 void SetPlayerIndex(int player_index);
676
691 GUID GetGUID();
692
705
718
731
743
755 const char* GetSerial();
756
767
776 bool Connected();
777
787
805 int GetNumAxes();
806
825 int GetNumBalls();
826
840 int GetNumHats();
841
855 int GetNumButtons();
856
878 Sint16 GetAxis(int axis);
879
893 bool GetAxisInitialState(int axis, Sint16* state);
894
912 void GetBall(int ball, int* dx, int* dy);
913
926 Uint8 GetHat(int hat);
927
939 bool GetButton(int button);
940
959 bool Rumble(Uint16 low_frequency_rumble,
960 Uint16 high_frequency_rumble,
961 Uint32 duration_ms);
962
988 void RumbleTriggers(Uint16 left_rumble,
989 Uint16 right_rumble,
990 Uint32 duration_ms);
991
1008 void SetLED(Uint8 red, Uint8 green, Uint8 blue);
1009
1019 void SendEffect(const void* data, int size);
1020
1030
1049 PowerState GetPowerInfo(int* percent);
1050};
1051
1054{
1063 : Joystick(resource.value)
1064 {
1065 }
1066
1069 : Joystick(other.get())
1070 {
1071 }
1072
1075};
1076
1084constexpr int JOYSTICK_AXIS_MAX = SDL_JOYSTICK_AXIS_MAX;
1085
1095constexpr int JOYSTICK_AXIS_MIN = SDL_JOYSTICK_AXIS_MIN;
1096
1106inline void LockJoysticks() { SDL_LockJoysticks(); }
1107
1113inline void UnlockJoysticks() { SDL_UnlockJoysticks(); }
1114
1124inline bool HasJoystick() { return SDL_HasJoystick(); }
1125
1139{
1140 int count;
1141 auto r = reinterpret_cast<JoystickID*>(SDL_GetJoysticks(&count));
1142 return OwnArray<JoystickID>(r, count);
1143}
1144
1159inline const char* GetJoystickNameForID(JoystickID instance_id)
1160{
1161 return SDL_GetJoystickNameForID(instance_id);
1162}
1163
1165{
1166 return SDL::GetJoystickNameForID(m_joystickID);
1167}
1168
1183inline const char* GetJoystickPathForID(JoystickID instance_id)
1184{
1185 return SDL_GetJoystickPathForID(instance_id);
1186}
1187
1189{
1190 return SDL::GetJoystickPathForID(m_joystickID);
1191}
1192
1207{
1208 return SDL_GetJoystickPlayerIndexForID(instance_id);
1209}
1210
1212{
1213 return SDL::GetJoystickPlayerIndexForID(m_joystickID);
1214}
1215
1231{
1232 return SDL_GetJoystickGUIDForID(instance_id);
1233}
1234
1236{
1237 return SDL::GetJoystickGUIDForID(m_joystickID);
1238}
1239
1256{
1257 return SDL_GetJoystickVendorForID(instance_id);
1258}
1259
1261{
1262 return SDL::GetJoystickVendorForID(m_joystickID);
1263}
1264
1281{
1282 return SDL_GetJoystickProductForID(instance_id);
1283}
1284
1286{
1287 return SDL::GetJoystickProductForID(m_joystickID);
1288}
1289
1306{
1307 return SDL_GetJoystickProductVersionForID(instance_id);
1308}
1309
1311{
1312 return SDL::GetJoystickProductVersionForID(m_joystickID);
1313}
1314
1330{
1331 return SDL_GetJoystickTypeForID(instance_id);
1332}
1333
1335{
1336 return SDL::GetJoystickTypeForID(m_joystickID);
1337}
1338
1354{
1355 return Joystick(instance_id);
1356}
1357
1358inline Joystick JoystickID::OpenJoystick() { return Joystick(m_joystickID); }
1359
1370{
1371 return {CheckError(SDL_GetJoystickFromID(instance_id))};
1372}
1373
1375{
1376 return SDL::GetJoystickFromID(m_joystickID);
1377}
1378
1392{
1393 return {CheckError(SDL_GetJoystickFromPlayerIndex(player_index))};
1394}
1395
1403using VirtualJoystickTouchpadDesc = SDL_VirtualJoystickTouchpadDesc;
1404
1412using VirtualJoystickSensorDesc = SDL_VirtualJoystickSensorDesc;
1413
1427using VirtualJoystickDesc = SDL_VirtualJoystickDesc;
1428
1441{
1442 return SDL_AttachVirtualJoystick(&desc);
1443}
1444
1456inline void DetachVirtualJoystick(JoystickID instance_id)
1457{
1458 CheckError(SDL_DetachVirtualJoystick(instance_id));
1459}
1460
1462{
1463 SDL::DetachVirtualJoystick(m_joystickID);
1464}
1465
1474inline bool IsJoystickVirtual(JoystickID instance_id)
1475{
1476 return SDL_IsJoystickVirtual(instance_id);
1477}
1478
1480{
1481 return SDL::IsJoystickVirtual(m_joystickID);
1482}
1483
1504 int axis,
1505 Sint16 value)
1506{
1507 CheckError(SDL_SetJoystickVirtualAxis(joystick, axis, value));
1508}
1509
1510inline void Joystick::SetVirtualAxis(int axis, Sint16 value)
1511{
1512 SDL::SetJoystickVirtualAxis(m_resource, axis, value);
1513}
1514
1532 int ball,
1533 Sint16 xrel,
1534 Sint16 yrel)
1535{
1536 CheckError(SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel));
1537}
1538
1539inline void Joystick::SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
1540{
1541 SDL::SetJoystickVirtualBall(m_resource, ball, xrel, yrel);
1542}
1543
1560 int button,
1561 bool down)
1562{
1563 CheckError(SDL_SetJoystickVirtualButton(joystick, button, down));
1564}
1565
1566inline void Joystick::SetVirtualButton(int button, bool down)
1567{
1568 SDL::SetJoystickVirtualButton(m_resource, button, down);
1569}
1570
1586inline void SetJoystickVirtualHat(JoystickParam joystick, int hat, Uint8 value)
1587{
1588 CheckError(SDL_SetJoystickVirtualHat(joystick, hat, value));
1589}
1590
1591inline void Joystick::SetVirtualHat(int hat, Uint8 value)
1592{
1593 SDL::SetJoystickVirtualHat(m_resource, hat, value);
1594}
1595
1616 int touchpad,
1617 int finger,
1618 bool down,
1619 const FPointRaw& p,
1620 float pressure)
1621{
1622 CheckError(SDL_SetJoystickVirtualTouchpad(
1623 joystick, touchpad, finger, down, p.x, p.y, pressure));
1624}
1625
1626inline void Joystick::SetVirtualTouchpad(int touchpad,
1627 int finger,
1628 bool down,
1629 const FPointRaw& p,
1630 float pressure)
1631{
1633 m_resource, touchpad, finger, down, p, pressure);
1634}
1635
1655 SensorType type,
1656 Uint64 sensor_timestamp,
1657 const float* data,
1658 int num_values)
1659{
1660 CheckError(SDL_SendJoystickVirtualSensorData(
1661 joystick, type, sensor_timestamp, data, num_values));
1662}
1663
1665 Uint64 sensor_timestamp,
1666 const float* data,
1667 int num_values)
1668{
1670 m_resource, type, sensor_timestamp, data, num_values);
1671}
1672
1696{
1697 return {CheckError(SDL_GetJoystickProperties(joystick))};
1698}
1699
1701{
1702 return SDL::GetJoystickProperties(m_resource);
1703}
1704
1705namespace prop::JoystickCap {
1706
1707constexpr auto MONO_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN;
1708
1709constexpr auto RGB_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN;
1710
1711constexpr auto PLAYER_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN;
1712
1713constexpr auto RUMBLE_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN;
1714
1715constexpr auto TRIGGER_RUMBLE_BOOLEAN =
1716 SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN;
1717
1718} // namespace prop::JoystickCap
1719
1731inline const char* GetJoystickName(JoystickParam joystick)
1732{
1733 return SDL_GetJoystickName(joystick);
1734}
1735
1736inline const char* Joystick::GetName()
1737{
1738 return SDL::GetJoystickName(m_resource);
1739}
1740
1752inline const char* GetJoystickPath(JoystickParam joystick)
1753{
1754 return SDL_GetJoystickPath(joystick);
1755}
1756
1757inline const char* Joystick::GetPath()
1758{
1759 return SDL::GetJoystickPath(m_resource);
1760}
1761
1776{
1777 return SDL_GetJoystickPlayerIndex(joystick);
1778}
1779
1781{
1782 return SDL::GetJoystickPlayerIndex(m_resource);
1783}
1784
1797inline void SetJoystickPlayerIndex(JoystickParam joystick, int player_index)
1798{
1799 CheckError(SDL_SetJoystickPlayerIndex(joystick, player_index));
1800}
1801
1802inline void Joystick::SetPlayerIndex(int player_index)
1803{
1804 SDL::SetJoystickPlayerIndex(m_resource, player_index);
1805}
1806
1822{
1823 return SDL_GetJoystickGUID(joystick);
1824}
1825
1826inline GUID Joystick::GetGUID() { return SDL::GetJoystickGUID(m_resource); }
1827
1841{
1842 return SDL_GetJoystickVendor(joystick);
1843}
1844
1846{
1847 return SDL::GetJoystickVendor(m_resource);
1848}
1849
1863{
1864 return SDL_GetJoystickProduct(joystick);
1865}
1866
1868{
1869 return SDL::GetJoystickProduct(m_resource);
1870}
1871
1885{
1886 return SDL_GetJoystickProductVersion(joystick);
1887}
1888
1890{
1891 return SDL::GetJoystickProductVersion(m_resource);
1892}
1893
1905{
1906 return SDL_GetJoystickFirmwareVersion(joystick);
1907}
1908
1910{
1911 return SDL::GetJoystickFirmwareVersion(m_resource);
1912}
1913
1925inline const char* GetJoystickSerial(JoystickParam joystick)
1926{
1927 return SDL_GetJoystickSerial(joystick);
1928}
1929
1930inline const char* Joystick::GetSerial()
1931{
1932 return SDL::GetJoystickSerial(m_resource);
1933}
1934
1946{
1947 return SDL_GetJoystickType(joystick);
1948}
1949
1951{
1952 return SDL::GetJoystickType(m_resource);
1953}
1954
1971inline void GetJoystickGUIDInfo(GUID guid,
1972 Uint16* vendor,
1973 Uint16* product,
1974 Uint16* version,
1975 Uint16* crc16)
1976{
1977 SDL_GetJoystickGUIDInfo(guid, vendor, product, version, crc16);
1978}
1979
1990{
1991 return SDL_JoystickConnected(joystick);
1992}
1993
1994inline bool Joystick::Connected() { return SDL::JoystickConnected(m_resource); }
1995
2006{
2007 return CheckError(SDL_GetJoystickID(joystick));
2008}
2009
2010inline JoystickID Joystick::GetID() { return SDL::GetJoystickID(m_resource); }
2011
2031{
2032 return CheckError(SDL_GetNumJoystickAxes(joystick));
2033}
2034
2036{
2037 return SDL::GetNumJoystickAxes(m_resource);
2038}
2039
2060{
2061 return CheckError(SDL_GetNumJoystickBalls(joystick));
2062}
2063
2065{
2066 return SDL::GetNumJoystickBalls(m_resource);
2067}
2068
2084{
2085 return CheckError(SDL_GetNumJoystickHats(joystick));
2086}
2087
2089{
2090 return SDL::GetNumJoystickHats(m_resource);
2091}
2092
2108{
2109 return CheckError(SDL_GetNumJoystickButtons(joystick));
2110}
2111
2113{
2114 return SDL::GetNumJoystickButtons(m_resource);
2115}
2116
2130inline void SetJoystickEventsEnabled(bool enabled)
2131{
2132 SDL_SetJoystickEventsEnabled(enabled);
2133}
2134
2147inline bool JoystickEventsEnabled() { return SDL_JoystickEventsEnabled(); }
2148
2157inline void UpdateJoysticks() { SDL_UpdateJoysticks(); }
2158
2181inline Sint16 GetJoystickAxis(JoystickParam joystick, int axis)
2182{
2183 return SDL_GetJoystickAxis(joystick, axis);
2184}
2185
2187{
2188 return SDL::GetJoystickAxis(m_resource, axis);
2189}
2190
2206 int axis,
2207 Sint16* state)
2208{
2209 return SDL_GetJoystickAxisInitialState(joystick, axis, state);
2210}
2211
2212inline bool Joystick::GetAxisInitialState(int axis, Sint16* state)
2213{
2214 return SDL::GetJoystickAxisInitialState(m_resource, axis, state);
2215}
2216
2235inline void GetJoystickBall(JoystickParam joystick, int ball, int* dx, int* dy)
2236{
2237 CheckError(SDL_GetJoystickBall(joystick, ball, dx, dy));
2238}
2239
2240inline void Joystick::GetBall(int ball, int* dx, int* dy)
2241{
2242 SDL::GetJoystickBall(m_resource, ball, dx, dy);
2243}
2244
2258inline Uint8 GetJoystickHat(JoystickParam joystick, int hat)
2259{
2260 return SDL_GetJoystickHat(joystick, hat);
2261}
2262
2264{
2265 return SDL::GetJoystickHat(m_resource, hat);
2266}
2267
2280inline bool GetJoystickButton(JoystickParam joystick, int button)
2281{
2282 return SDL_GetJoystickButton(joystick, button);
2283}
2284
2285inline bool Joystick::GetButton(int button)
2286{
2287 return SDL::GetJoystickButton(m_resource, button);
2288}
2289
2309inline bool RumbleJoystick(JoystickParam joystick,
2310 Uint16 low_frequency_rumble,
2311 Uint16 high_frequency_rumble,
2312 Uint32 duration_ms)
2313{
2314 return SDL_RumbleJoystick(
2315 joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
2316}
2317
2318inline bool Joystick::Rumble(Uint16 low_frequency_rumble,
2319 Uint16 high_frequency_rumble,
2320 Uint32 duration_ms)
2321{
2322 return SDL::RumbleJoystick(
2323 m_resource, low_frequency_rumble, high_frequency_rumble, duration_ms);
2324}
2325
2352 Uint16 left_rumble,
2353 Uint16 right_rumble,
2354 Uint32 duration_ms)
2355{
2356 CheckError(SDL_RumbleJoystickTriggers(
2357 joystick, left_rumble, right_rumble, duration_ms));
2358}
2359
2360inline void Joystick::RumbleTriggers(Uint16 left_rumble,
2361 Uint16 right_rumble,
2362 Uint32 duration_ms)
2363{
2365 m_resource, left_rumble, right_rumble, duration_ms);
2366}
2367
2385inline void SetJoystickLED(JoystickParam joystick,
2386 Uint8 red,
2387 Uint8 green,
2388 Uint8 blue)
2389{
2390 CheckError(SDL_SetJoystickLED(joystick, red, green, blue));
2391}
2392
2393inline void Joystick::SetLED(Uint8 red, Uint8 green, Uint8 blue)
2394{
2395 SDL::SetJoystickLED(m_resource, red, green, blue);
2396}
2397
2409 const void* data,
2410 int size)
2411{
2412 CheckError(SDL_SendJoystickEffect(joystick, data, size));
2413}
2414
2415inline void Joystick::SendEffect(const void* data, int size)
2416{
2417 SDL::SendJoystickEffect(m_resource, data, size);
2418}
2419
2429inline void CloseJoystick(JoystickRaw joystick) { SDL_CloseJoystick(joystick); }
2430
2432
2443 JoystickParam joystick)
2444{
2445 return CheckError(SDL_GetJoystickConnectionState(joystick));
2446}
2447
2449{
2450 return SDL::GetJoystickConnectionState(m_resource);
2451}
2452
2471inline PowerState GetJoystickPowerInfo(JoystickParam joystick, int* percent)
2472{
2473 return SDL_GetJoystickPowerInfo(joystick, percent);
2474}
2475
2477{
2478 return SDL::GetJoystickPowerInfo(m_resource, percent);
2479}
2480
2482
2483} // namespace SDL
2484
2485#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:149
constexpr JoystickID(JoystickIDRaw joystickID={})
Wraps JoystickID.
Definition: SDL3pp_joystick.h:158
The joystick structure used to identify an SDL joystick.
Definition: SDL3pp_joystick.h:395
Joystick & operator=(Joystick other)
Assignment operator.
Definition: SDL3pp_joystick.h:449
constexpr auto operator<=>(const Joystick &other) const =default
Comparison.
constexpr JoystickRaw get() const
Retrieves underlying JoystickRaw.
Definition: SDL3pp_joystick.h:456
constexpr Joystick(const Joystick &other)=delete
Copy constructor.
~Joystick()
Destructor.
Definition: SDL3pp_joystick.h:446
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_joystick.h:470
constexpr Joystick()=default
Default ctor.
Joystick(JoystickID instance_id)
Open a joystick for use.
Definition: SDL3pp_joystick.h:440
constexpr Joystick(Joystick &&other)
Move constructor.
Definition: SDL3pp_joystick.h:418
constexpr JoystickRaw release()
Retrieves underlying JoystickRaw and clear this.
Definition: SDL3pp_joystick.h:459
constexpr Joystick(const JoystickRaw resource)
Constructs from JoystickParam.
Definition: SDL3pp_joystick.h:409
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:197
PropertiesRef GetJoystickProperties(JoystickParam joystick)
Get the properties associated with a joystick.
Definition: SDL3pp_joystick.h:1695
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:1206
constexpr JoystickType JOYSTICK_TYPE_COUNT
JOYSTICK_TYPE_COUNT.
Definition: SDL3pp_joystick.h:135
Uint16 GetProductVersion()
Get the product version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1889
constexpr Uint8 HAT_UP
UP.
Definition: SDL3pp_joystick.h:369
int GetJoystickPlayerIndexForID()
Get the player index of a joystick.
Definition: SDL3pp_joystick.h:1211
int GetPlayerIndex()
Get the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1780
void LockJoysticks()
Locking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1106
bool IsJoystickVirtual()
Query whether or not a joystick is virtual.
Definition: SDL3pp_joystick.h:1479
Uint16 GetJoystickVendorForID()
Get the USB vendor ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1260
int GetNumJoystickBalls(JoystickParam joystick)
Get the number of trackballs on a joystick.
Definition: SDL3pp_joystick.h:2059
constexpr JoystickType JOYSTICK_TYPE_ARCADE_STICK
JOYSTICK_TYPE_ARCADE_STICK.
Definition: SDL3pp_joystick.h:114
bool HasJoystick()
Return whether a joystick is currently connected.
Definition: SDL3pp_joystick.h:1124
constexpr Uint8 HAT_LEFT
LEFT.
Definition: SDL3pp_joystick.h:375
Uint16 GetJoystickProductForID(JoystickID instance_id)
Get the USB product ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1280
Uint16 GetProduct()
Get the USB product ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1867
int GetNumBalls()
Get the number of trackballs on a joystick.
Definition: SDL3pp_joystick.h:2064
bool GetButton(int button)
Get the current state of a button on a joystick.
Definition: SDL3pp_joystick.h:2285
JoystickID AttachVirtualJoystick(const VirtualJoystickDesc &desc)
Attach a new virtual joystick.
Definition: SDL3pp_joystick.h:1440
Sint16 GetAxis(int axis)
Get the current state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2186
void SetJoystickLED(JoystickParam joystick, Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition: SDL3pp_joystick.h:2385
Uint16 GetVendor()
Get the USB vendor ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1845
constexpr Uint8 HAT_DOWN
DOWN.
Definition: SDL3pp_joystick.h:373
SDL_VirtualJoystickTouchpadDesc VirtualJoystickTouchpadDesc
The structure that describes a virtual joystick touchpad.
Definition: SDL3pp_joystick.h:1403
constexpr JoystickType JOYSTICK_TYPE_DRUM_KIT
JOYSTICK_TYPE_DRUM_KIT.
Definition: SDL3pp_joystick.h:126
void SetJoystickVirtualHat(JoystickParam joystick, int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1586
void SetJoystickVirtualBall(JoystickParam joystick, int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1531
const char * GetJoystickName(JoystickParam joystick)
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1731
constexpr JoystickConnectionState JOYSTICK_CONNECTION_INVALID
JOYSTICK_CONNECTION_INVALID.
Definition: SDL3pp_joystick.h:349
constexpr JoystickConnectionState JOYSTICK_CONNECTION_UNKNOWN
JOYSTICK_CONNECTION_UNKNOWN.
Definition: SDL3pp_joystick.h:352
void SetJoystickVirtualAxis(JoystickParam joystick, int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1503
JoystickID GetJoystickID(JoystickParam joystick)
Get the instance ID of an opened joystick.
Definition: SDL3pp_joystick.h:2005
GUID GetGUID()
Get the implementation-dependent GUID for the joystick.
Definition: SDL3pp_joystick.h:1826
Uint16 GetJoystickVendor(JoystickParam joystick)
Get the USB vendor ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1840
int GetNumHats()
Get the number of POV hats on a joystick.
Definition: SDL3pp_joystick.h:2088
JoystickType GetJoystickTypeForID(JoystickID instance_id)
Get the type of a joystick, if available.
Definition: SDL3pp_joystick.h:1329
JoystickRef GetJoystickFromPlayerIndex(int player_index)
Get the Joystick associated with a player index.
Definition: SDL3pp_joystick.h:1391
Uint16 GetJoystickProductVersionForID()
Get the product version of a joystick, if available.
Definition: SDL3pp_joystick.h:1310
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:1654
const char * GetPath()
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1757
constexpr JoystickType JOYSTICK_TYPE_WHEEL
JOYSTICK_TYPE_WHEEL.
Definition: SDL3pp_joystick.h:111
bool RumbleJoystick(JoystickParam joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition: SDL3pp_joystick.h:2309
constexpr Uint8 HAT_RIGHTDOWN
RIGHTDOWN.
Definition: SDL3pp_joystick.h:379
void GetJoystickBall(JoystickParam joystick, int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition: SDL3pp_joystick.h:2235
void UpdateJoysticks()
Update the current state of the open joysticks.
Definition: SDL3pp_joystick.h:2157
Joystick OpenJoystick()
Open a joystick for use.
Definition: SDL3pp_joystick.h:1358
void SendEffect(const void *data, int size)
Send a joystick specific effect packet.
Definition: SDL3pp_joystick.h:2415
void SetJoystickPlayerIndex(JoystickParam joystick, int player_index)
Set the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1797
void SetVirtualButton(int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1566
int GetNumJoystickAxes(JoystickParam joystick)
Get the number of general axis controls on a joystick.
Definition: SDL3pp_joystick.h:2030
void DetachVirtualJoystick(JoystickID instance_id)
Detach a virtual joystick.
Definition: SDL3pp_joystick.h:1456
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:123
JoystickType GetJoystickTypeForID()
Get the type of a joystick, if available.
Definition: SDL3pp_joystick.h:1334
void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1539
int GetNumAxes()
Get the number of general axis controls on a joystick.
Definition: SDL3pp_joystick.h:2035
constexpr JoystickType JOYSTICK_TYPE_UNKNOWN
JOYSTICK_TYPE_UNKNOWN.
Definition: SDL3pp_joystick.h:105
void DetachVirtualJoystick()
Detach a virtual joystick.
Definition: SDL3pp_joystick.h:1461
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:1626
void SetLED(Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition: SDL3pp_joystick.h:2393
void RumbleTriggers(Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
Start a rumble effect in the joystick's triggers.
Definition: SDL3pp_joystick.h:2360
Uint16 GetJoystickVendorForID(JoystickID instance_id)
Get the USB vendor ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1255
bool GetJoystickButton(JoystickParam joystick, int button)
Get the current state of a button on a joystick.
Definition: SDL3pp_joystick.h:2280
JoystickType GetJoystickType(JoystickParam joystick)
Get the type of an opened joystick.
Definition: SDL3pp_joystick.h:1945
void SetVirtualAxis(int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1510
constexpr Uint8 HAT_RIGHT
RIGHT.
Definition: SDL3pp_joystick.h:371
constexpr JoystickType JOYSTICK_TYPE_FLIGHT_STICK
JOYSTICK_TYPE_FLIGHT_STICK.
Definition: SDL3pp_joystick.h:117
constexpr JoystickType JOYSTICK_TYPE_GAMEPAD
JOYSTICK_TYPE_GAMEPAD.
Definition: SDL3pp_joystick.h:108
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:1615
constexpr JoystickType JOYSTICK_TYPE_DANCE_PAD
JOYSTICK_TYPE_DANCE_PAD.
Definition: SDL3pp_joystick.h:120
void UnlockJoysticks()
Unlocking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1113
PropertiesRef GetProperties()
Get the properties associated with a joystick.
Definition: SDL3pp_joystick.h:1700
GUID GetJoystickGUIDForID()
Get the implementation-dependent GUID of a joystick.
Definition: SDL3pp_joystick.h:1235
Uint16 GetFirmwareVersion()
Get the firmware version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1909
constexpr Uint8 HAT_LEFTUP
LEFTUP.
Definition: SDL3pp_joystick.h:381
GUID GetJoystickGUID(JoystickParam joystick)
Get the implementation-dependent GUID for the joystick.
Definition: SDL3pp_joystick.h:1821
constexpr JoystickType JOYSTICK_TYPE_THROTTLE
JOYSTICK_TYPE_THROTTLE.
Definition: SDL3pp_joystick.h:132
const char * GetSerial()
Get the serial number of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1930
bool Rumble(Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition: SDL3pp_joystick.h:2318
OwnArray< JoystickID > GetJoysticks()
Get a list of currently connected joysticks.
Definition: SDL3pp_joystick.h:1138
constexpr int JOYSTICK_AXIS_MAX
The largest value an Joystick's axis can report.
Definition: SDL3pp_joystick.h:1084
PowerState GetJoystickPowerInfo(JoystickParam joystick, int *percent)
Get the battery state of a joystick.
Definition: SDL3pp_joystick.h:2471
constexpr int JOYSTICK_AXIS_MIN
The smallest value an Joystick's axis can report.
Definition: SDL3pp_joystick.h:1095
int GetJoystickPlayerIndex(JoystickParam joystick)
Get the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1775
Uint16 GetJoystickProductVersionForID(JoystickID instance_id)
Get the product version of a joystick, if available.
Definition: SDL3pp_joystick.h:1305
void SetJoystickEventsEnabled(bool enabled)
Set the state of joystick event processing.
Definition: SDL3pp_joystick.h:2130
constexpr Uint8 HAT_RIGHTUP
RIGHTUP.
Definition: SDL3pp_joystick.h:377
bool Connected()
Get the status of a specified joystick.
Definition: SDL3pp_joystick.h:1994
GUID GetJoystickGUIDForID(JoystickID instance_id)
Get the implementation-dependent GUID of a joystick.
Definition: SDL3pp_joystick.h:1230
void SendJoystickEffect(JoystickParam joystick, const void *data, int size)
Send a joystick specific effect packet.
Definition: SDL3pp_joystick.h:2408
Uint16 GetJoystickFirmwareVersion(JoystickParam joystick)
Get the firmware version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1904
Uint8 GetJoystickHat(JoystickParam joystick, int hat)
Get the current state of a POV hat on a joystick.
Definition: SDL3pp_joystick.h:2258
constexpr Uint8 HAT_CENTERED
CENTERED.
Definition: SDL3pp_joystick.h:367
const char * GetJoystickPath(JoystickParam joystick)
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1752
Uint16 GetJoystickProduct(JoystickParam joystick)
Get the USB product ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1862
const char * GetJoystickSerial(JoystickParam joystick)
Get the serial number of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1925
JoystickType GetType()
Get the type of an opened joystick.
Definition: SDL3pp_joystick.h:1950
int GetNumJoystickButtons(JoystickParam joystick)
Get the number of buttons on a joystick.
Definition: SDL3pp_joystick.h:2107
int GetNumJoystickHats(JoystickParam joystick)
Get the number of POV hats on a joystick.
Definition: SDL3pp_joystick.h:2083
SDL_VirtualJoystickSensorDesc VirtualJoystickSensorDesc
The structure that describes a virtual joystick sensor.
Definition: SDL3pp_joystick.h:1412
SDL_JoystickConnectionState JoystickConnectionState
Possible connection states for a joystick device.
Definition: SDL3pp_joystick.h:347
bool GetJoystickAxisInitialState(JoystickParam joystick, int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2205
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRELESS
JOYSTICK_CONNECTION_WIRELESS.
Definition: SDL3pp_joystick.h:358
bool JoystickConnected(JoystickParam joystick)
Get the status of a specified joystick.
Definition: SDL3pp_joystick.h:1989
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:1664
bool GetAxisInitialState(int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2212
JoystickRef GetJoystickFromID(JoystickID instance_id)
Get the Joystick associated with an instance ID, if it has been opened.
Definition: SDL3pp_joystick.h:1369
JoystickRef GetJoystickFromID()
Get the Joystick associated with an instance ID, if it has been opened.
Definition: SDL3pp_joystick.h:1374
void Close()
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition: SDL3pp_joystick.h:2431
bool JoystickEventsEnabled()
Query the state of joystick event processing.
Definition: SDL3pp_joystick.h:2147
void CloseJoystick(JoystickRaw joystick)
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition: SDL3pp_joystick.h:2429
SDL_VirtualJoystickDesc VirtualJoystickDesc
The structure that describes a virtual joystick.
Definition: SDL3pp_joystick.h:1427
const char * GetJoystickPathForID()
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1188
Uint8 HatState
Represents tbe HatState for a Joystick.
Definition: SDL3pp_joystick.h:365
void SetVirtualHat(int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1591
constexpr JoystickType JOYSTICK_TYPE_ARCADE_PAD
JOYSTICK_TYPE_ARCADE_PAD.
Definition: SDL3pp_joystick.h:129
JoystickConnectionState GetConnectionState()
Get the connection state of a joystick.
Definition: SDL3pp_joystick.h:2448
PowerState GetPowerInfo(int *percent)
Get the battery state of a joystick.
Definition: SDL3pp_joystick.h:2476
Sint16 GetJoystickAxis(JoystickParam joystick, int axis)
Get the current state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2181
bool IsJoystickVirtual(JoystickID instance_id)
Query whether or not a joystick is virtual.
Definition: SDL3pp_joystick.h:1474
JoystickID GetID()
Get the instance ID of an opened joystick.
Definition: SDL3pp_joystick.h:2010
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRED
JOYSTICK_CONNECTION_WIRED.
Definition: SDL3pp_joystick.h:355
const char * GetJoystickNameForID()
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1164
const char * GetJoystickPathForID(JoystickID instance_id)
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1183
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:1971
constexpr Uint8 HAT_LEFTDOWN
LEFTDOWN.
Definition: SDL3pp_joystick.h:383
Joystick OpenJoystick(JoystickID instance_id)
Open a joystick for use.
Definition: SDL3pp_joystick.h:1353
Uint16 GetJoystickProductVersion(JoystickParam joystick)
Get the product version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:1884
const char * GetName()
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1736
Uint8 GetHat(int hat)
Get the current state of a POV hat on a joystick.
Definition: SDL3pp_joystick.h:2263
void SetPlayerIndex(int player_index)
Set the player index of an opened joystick.
Definition: SDL3pp_joystick.h:1802
JoystickConnectionState GetJoystickConnectionState(JoystickParam joystick)
Get the connection state of a joystick.
Definition: SDL3pp_joystick.h:2442
void GetBall(int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition: SDL3pp_joystick.h:2240
Uint16 GetJoystickProductForID()
Get the USB product ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1285
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:2351
const char * GetJoystickNameForID(JoystickID instance_id)
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1159
void SetJoystickVirtualButton(JoystickParam joystick, int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1559
int GetNumButtons()
Get the number of buttons on a joystick.
Definition: SDL3pp_joystick.h:2112
SDL_JoystickType JoystickType
An enum of some common joystick types.
Definition: SDL3pp_joystick.h:103
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:28
SDL_SensorType SensorType
The different sensors defined by SDL.
Definition: SDL3pp_sensor.h:125
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition: SDL3pp_stdinc.h:2262
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:371
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:289
::Sint16 Sint16
A signed 16-bit integer type.
Definition: SDL3pp_stdinc.h:302
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:315
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:44
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:1054
JoystickRef(const JoystickRef &other)
Copy constructor.
Definition: SDL3pp_joystick.h:1068
JoystickRef(JoystickParam resource)
Constructs from JoystickParam.
Definition: SDL3pp_joystick.h:1062
~JoystickRef()
Destructor.
Definition: SDL3pp_joystick.h:1074
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:701