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
57// Forward decl
58struct Joystick;
59
61using JoystickRaw = SDL_Joystick*;
62
63// Forward decl
64struct JoystickRef;
65
68{
70
73 : value(value)
74 {
75 }
76
78 constexpr JoystickParam(std::nullptr_t = nullptr)
79 : value(nullptr)
80 {
81 }
82
84 constexpr explicit operator bool() const { return !!value; }
85
87 constexpr auto operator<=>(const JoystickParam& other) const = default;
88
90 constexpr operator JoystickRaw() const { return value; }
91};
92
94using JoystickIDRaw = SDL_JoystickID;
95
96// Forward decl
97struct JoystickID;
98
99// Forward decl
100struct JoystickApiLock;
101
118using JoystickType = SDL_JoystickType;
119
121 SDL_JOYSTICK_TYPE_UNKNOWN;
122
124 SDL_JOYSTICK_TYPE_GAMEPAD;
125
127 SDL_JOYSTICK_TYPE_WHEEL;
128
130 SDL_JOYSTICK_TYPE_ARCADE_STICK;
131
133 SDL_JOYSTICK_TYPE_FLIGHT_STICK;
134
136 SDL_JOYSTICK_TYPE_DANCE_PAD;
137
139 SDL_JOYSTICK_TYPE_GUITAR;
140
142 SDL_JOYSTICK_TYPE_DRUM_KIT;
143
145 SDL_JOYSTICK_TYPE_ARCADE_PAD;
146
148 SDL_JOYSTICK_TYPE_THROTTLE;
149
151 SDL_JOYSTICK_TYPE_COUNT;
152
164{
165 JoystickIDRaw m_joystickID;
166
167public:
173 constexpr JoystickID(JoystickIDRaw joystickID = {}) noexcept
174 : m_joystickID(joystickID)
175 {
176 }
177
183 constexpr operator JoystickIDRaw() const noexcept { return m_joystickID; }
184
200 const char* GetJoystickNameForID();
201
217 const char* GetJoystickPathForID();
218
234
251
269
287
305
323
340
352
365
375 bool IsJoystickVirtual();
376};
377
386using JoystickConnectionState = SDL_JoystickConnectionState;
387
389 SDL_JOYSTICK_CONNECTION_INVALID;
390
392 SDL_JOYSTICK_CONNECTION_UNKNOWN;
393
395 SDL_JOYSTICK_CONNECTION_WIRED;
396
398 SDL_JOYSTICK_CONNECTION_WIRELESS;
399
405
406constexpr Uint8 HAT_CENTERED = SDL_HAT_CENTERED;
407
408constexpr Uint8 HAT_UP = SDL_HAT_UP;
409
410constexpr Uint8 HAT_RIGHT = SDL_HAT_RIGHT;
411
412constexpr Uint8 HAT_DOWN = SDL_HAT_DOWN;
413
414constexpr Uint8 HAT_LEFT = SDL_HAT_LEFT;
415
416constexpr Uint8 HAT_RIGHTUP = SDL_HAT_RIGHTUP;
417
418constexpr Uint8 HAT_RIGHTDOWN = SDL_HAT_RIGHTDOWN;
419
420constexpr Uint8 HAT_LEFTUP = SDL_HAT_LEFTUP;
421
422constexpr Uint8 HAT_LEFTDOWN = SDL_HAT_LEFTDOWN;
423
434{
435 JoystickRaw m_resource = nullptr;
436
437public:
439 constexpr Joystick(std::nullptr_t = nullptr) noexcept
440 : m_resource(0)
441 {
442 }
443
451 constexpr explicit Joystick(const JoystickRaw resource) noexcept
452 : m_resource(resource)
453 {
454 }
455
456protected:
458 constexpr Joystick(const Joystick& other) noexcept = default;
459
460public:
462 constexpr Joystick(Joystick&& other) noexcept
463 : Joystick(other.release())
464 {
465 }
466
467 constexpr Joystick(const JoystickRef& other) = delete;
468
469 constexpr Joystick(JoystickRef&& other) = delete;
470
486 Joystick(JoystickID instance_id)
487 : m_resource(CheckError(SDL_OpenJoystick(instance_id)))
488 {
489 }
490
492 ~Joystick() { SDL_CloseJoystick(m_resource); }
493
495 constexpr Joystick& operator=(Joystick&& other) noexcept
496 {
497 std::swap(m_resource, other.m_resource);
498 return *this;
499 }
500
501protected:
503 constexpr Joystick& operator=(const Joystick& other) noexcept = default;
504
505public:
507 constexpr JoystickRaw get() const noexcept { return m_resource; }
508
510 constexpr JoystickRaw release() noexcept
511 {
512 auto r = m_resource;
513 m_resource = nullptr;
514 return r;
515 }
516
518 constexpr auto operator<=>(const Joystick& other) const noexcept = default;
519
521 constexpr explicit operator bool() const noexcept { return !!m_resource; }
522
524 constexpr operator JoystickParam() const noexcept { return {m_resource}; }
525
535 void Close();
536
563 void SetVirtualAxis(int axis, Sint16 value);
564
588 void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel);
589
612 void SetVirtualButton(int button, bool down);
613
636 void SetVirtualHat(int hat, Uint8 value);
637
665 void SetVirtualTouchpad(int touchpad,
666 int finger,
667 bool down,
668 const FPointRaw& p,
669 float pressure);
670
697 Uint64 sensor_timestamp,
698 const float* data,
699 int num_values);
700
725
738 const char* GetName();
739
752 const char* GetPath();
753
768 int GetPlayerIndex();
769
783 void SetPlayerIndex(int player_index);
784
801 GUID GetGUID();
802
817
832
847
861
875 const char* GetSerial();
876
889
900 bool Connected();
901
913
933 int GetNumAxes();
934
955 int GetNumBalls();
956
972 int GetNumHats();
973
989 int GetNumButtons();
990
1014 Sint16 GetAxis(int axis);
1015
1031 bool GetAxisInitialState(int axis, Sint16* state);
1032
1052 void GetBall(int ball, int* dx, int* dy);
1053
1068 Uint8 GetHat(int hat);
1069
1083 bool GetButton(int button);
1084
1105 bool Rumble(Uint16 low_frequency_rumble,
1106 Uint16 high_frequency_rumble,
1107 Uint32 duration_ms);
1108
1136 void RumbleTriggers(Uint16 left_rumble,
1137 Uint16 right_rumble,
1138 Uint32 duration_ms);
1139
1158 void SetLED(Uint8 red, Uint8 green, Uint8 blue);
1159
1171 void SendEffect(const void* data, int size);
1172
1184
1205 PowerState GetPowerInfo(int* percent);
1206};
1207
1210{
1211 using Joystick::Joystick;
1212
1220 JoystickRef(JoystickParam resource) noexcept
1221 : Joystick(resource.value)
1222 {
1223 }
1224
1232 JoystickRef(JoystickRaw resource) noexcept
1233 : Joystick(resource)
1234 {
1235 }
1236
1238 constexpr JoystickRef(const JoystickRef& other) noexcept = default;
1239
1242};
1243
1251constexpr int JOYSTICK_AXIS_MAX = SDL_JOYSTICK_AXIS_MAX;
1252
1262constexpr int JOYSTICK_AXIS_MIN = SDL_JOYSTICK_AXIS_MIN;
1263
1276{
1277 bool m_lock;
1278
1279public:
1292
1294 JoystickApiLock(const JoystickApiLock& other) = delete;
1295
1297 constexpr JoystickApiLock(JoystickApiLock&& other) noexcept
1298 : m_lock(other.m_lock)
1299 {
1300 other.m_lock = {};
1301 }
1302
1312
1313 JoystickApiLock& operator=(const JoystickApiLock& other) = delete;
1314
1317 {
1318 std::swap(m_lock, other.m_lock);
1319 return *this;
1320 }
1321
1323 constexpr operator bool() const { return bool(m_lock); }
1324
1333 void reset();
1334
1336 void release() { m_lock = false; }
1337};
1338
1350inline void LockJoysticks() { SDL_LockJoysticks(); }
1351
1353 : m_lock(true)
1354{
1355 LockJoysticks();
1356}
1357
1366inline void UnlockJoysticks() { SDL_UnlockJoysticks(); }
1367
1369{
1370 if (!m_lock) return;
1372 m_lock = false;
1373}
1374
1386inline bool HasJoystick() { return SDL_HasJoystick(); }
1387
1403{
1404 int count;
1405 auto r = reinterpret_cast<JoystickID*>(SDL_GetJoysticks(&count));
1406 return OwnArray<JoystickID>(r, count);
1407}
1408
1425inline const char* GetJoystickNameForID(JoystickID instance_id)
1426{
1427 return SDL_GetJoystickNameForID(instance_id);
1428}
1429
1431{
1432 return SDL::GetJoystickNameForID(m_joystickID);
1433}
1434
1451inline const char* GetJoystickPathForID(JoystickID instance_id)
1452{
1453 return SDL_GetJoystickPathForID(instance_id);
1454}
1455
1457{
1458 return SDL::GetJoystickPathForID(m_joystickID);
1459}
1460
1477{
1478 return SDL_GetJoystickPlayerIndexForID(instance_id);
1479}
1480
1482{
1483 return SDL::GetJoystickPlayerIndexForID(m_joystickID);
1484}
1485
1503{
1504 return SDL_GetJoystickGUIDForID(instance_id);
1505}
1506
1508{
1509 return SDL::GetJoystickGUIDForID(m_joystickID);
1510}
1511
1530{
1531 return SDL_GetJoystickVendorForID(instance_id);
1532}
1533
1535{
1536 return SDL::GetJoystickVendorForID(m_joystickID);
1537}
1538
1557{
1558 return SDL_GetJoystickProductForID(instance_id);
1559}
1560
1562{
1563 return SDL::GetJoystickProductForID(m_joystickID);
1564}
1565
1584{
1585 return SDL_GetJoystickProductVersionForID(instance_id);
1586}
1587
1589{
1590 return SDL::GetJoystickProductVersionForID(m_joystickID);
1591}
1592
1610{
1611 return SDL_GetJoystickTypeForID(instance_id);
1612}
1613
1615{
1616 return SDL::GetJoystickTypeForID(m_joystickID);
1617}
1618
1636{
1637 return Joystick(instance_id);
1638}
1639
1640inline Joystick JoystickID::OpenJoystick() { return Joystick(m_joystickID); }
1641
1654{
1655 return {CheckError(SDL_GetJoystickFromID(instance_id))};
1656}
1657
1659{
1660 return SDL::GetJoystickFromID(m_joystickID);
1661}
1662
1678{
1679 return {CheckError(SDL_GetJoystickFromPlayerIndex(player_index))};
1680}
1681
1689using VirtualJoystickTouchpadDesc = SDL_VirtualJoystickTouchpadDesc;
1690
1698using VirtualJoystickSensorDesc = SDL_VirtualJoystickSensorDesc;
1699
1713using VirtualJoystickDesc = SDL_VirtualJoystickDesc;
1714
1746{
1747 return SDL_AttachVirtualJoystick(&desc);
1748}
1749
1763inline void DetachVirtualJoystick(JoystickID instance_id)
1764{
1765 CheckError(SDL_DetachVirtualJoystick(instance_id));
1766}
1767
1769{
1770 SDL::DetachVirtualJoystick(m_joystickID);
1771}
1772
1783inline bool IsJoystickVirtual(JoystickID instance_id)
1784{
1785 return SDL_IsJoystickVirtual(instance_id);
1786}
1787
1789{
1790 return SDL::IsJoystickVirtual(m_joystickID);
1791}
1792
1821 int axis,
1822 Sint16 value)
1823{
1824 CheckError(SDL_SetJoystickVirtualAxis(joystick, axis, value));
1825}
1826
1827inline void Joystick::SetVirtualAxis(int axis, Sint16 value)
1828{
1829 SDL::SetJoystickVirtualAxis(m_resource, axis, value);
1830}
1831
1857 int ball,
1858 Sint16 xrel,
1859 Sint16 yrel)
1860{
1861 CheckError(SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel));
1862}
1863
1864inline void Joystick::SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
1865{
1866 SDL::SetJoystickVirtualBall(m_resource, ball, xrel, yrel);
1867}
1868
1893 int button,
1894 bool down)
1895{
1896 CheckError(SDL_SetJoystickVirtualButton(joystick, button, down));
1897}
1898
1899inline void Joystick::SetVirtualButton(int button, bool down)
1900{
1901 SDL::SetJoystickVirtualButton(m_resource, button, down);
1902}
1903
1927inline void SetJoystickVirtualHat(JoystickParam joystick, int hat, Uint8 value)
1928{
1929 CheckError(SDL_SetJoystickVirtualHat(joystick, hat, value));
1930}
1931
1932inline void Joystick::SetVirtualHat(int hat, Uint8 value)
1933{
1934 SDL::SetJoystickVirtualHat(m_resource, hat, value);
1935}
1936
1965 int touchpad,
1966 int finger,
1967 bool down,
1968 const FPointRaw& p,
1969 float pressure)
1970{
1971 CheckError(SDL_SetJoystickVirtualTouchpad(
1972 joystick, touchpad, finger, down, p.x, p.y, pressure));
1973}
1974
1975inline void Joystick::SetVirtualTouchpad(int touchpad,
1976 int finger,
1977 bool down,
1978 const FPointRaw& p,
1979 float pressure)
1980{
1982 m_resource, touchpad, finger, down, p, pressure);
1983}
1984
2012 SensorType type,
2013 Uint64 sensor_timestamp,
2014 const float* data,
2015 int num_values)
2016{
2017 CheckError(SDL_SendJoystickVirtualSensorData(
2018 joystick, type, sensor_timestamp, data, num_values));
2019}
2020
2022 Uint64 sensor_timestamp,
2023 const float* data,
2024 int num_values)
2025{
2027 m_resource, type, sensor_timestamp, data, num_values);
2028}
2029
2055{
2056 return {CheckError(SDL_GetJoystickProperties(joystick))};
2057}
2058
2060{
2061 return SDL::GetJoystickProperties(m_resource);
2062}
2063
2064namespace prop::JoystickCap {
2065
2066constexpr auto MONO_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN;
2067
2068constexpr auto RGB_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN;
2069
2070constexpr auto PLAYER_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN;
2071
2072constexpr auto RUMBLE_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN;
2073
2074constexpr auto TRIGGER_RUMBLE_BOOLEAN =
2075 SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN;
2076
2077} // namespace prop::JoystickCap
2078
2092inline const char* GetJoystickName(JoystickParam joystick)
2093{
2094 return SDL_GetJoystickName(joystick);
2095}
2096
2097inline const char* Joystick::GetName()
2098{
2099 return SDL::GetJoystickName(m_resource);
2100}
2101
2115inline const char* GetJoystickPath(JoystickParam joystick)
2116{
2117 return SDL_GetJoystickPath(joystick);
2118}
2119
2120inline const char* Joystick::GetPath()
2121{
2122 return SDL::GetJoystickPath(m_resource);
2123}
2124
2141{
2142 return SDL_GetJoystickPlayerIndex(joystick);
2143}
2144
2146{
2147 return SDL::GetJoystickPlayerIndex(m_resource);
2148}
2149
2164inline void SetJoystickPlayerIndex(JoystickParam joystick, int player_index)
2165{
2166 CheckError(SDL_SetJoystickPlayerIndex(joystick, player_index));
2167}
2168
2169inline void Joystick::SetPlayerIndex(int player_index)
2170{
2171 SDL::SetJoystickPlayerIndex(m_resource, player_index);
2172}
2173
2191{
2192 return SDL_GetJoystickGUID(joystick);
2193}
2194
2195inline GUID Joystick::GetGUID() { return SDL::GetJoystickGUID(m_resource); }
2196
2212{
2213 return SDL_GetJoystickVendor(joystick);
2214}
2215
2217{
2218 return SDL::GetJoystickVendor(m_resource);
2219}
2220
2236{
2237 return SDL_GetJoystickProduct(joystick);
2238}
2239
2241{
2242 return SDL::GetJoystickProduct(m_resource);
2243}
2244
2260{
2261 return SDL_GetJoystickProductVersion(joystick);
2262}
2263
2265{
2266 return SDL::GetJoystickProductVersion(m_resource);
2267}
2268
2282{
2283 return SDL_GetJoystickFirmwareVersion(joystick);
2284}
2285
2287{
2288 return SDL::GetJoystickFirmwareVersion(m_resource);
2289}
2290
2304inline const char* GetJoystickSerial(JoystickParam joystick)
2305{
2306 return SDL_GetJoystickSerial(joystick);
2307}
2308
2309inline const char* Joystick::GetSerial()
2310{
2311 return SDL::GetJoystickSerial(m_resource);
2312}
2313
2327{
2328 return SDL_GetJoystickType(joystick);
2329}
2330
2332{
2333 return SDL::GetJoystickType(m_resource);
2334}
2335
2354inline void GetJoystickGUIDInfo(GUID guid,
2355 Uint16* vendor,
2356 Uint16* product,
2357 Uint16* version,
2358 Uint16* crc16)
2359{
2360 SDL_GetJoystickGUIDInfo(guid, vendor, product, version, crc16);
2361}
2362
2375{
2376 return SDL_JoystickConnected(joystick);
2377}
2378
2379inline bool Joystick::Connected() { return SDL::JoystickConnected(m_resource); }
2380
2393{
2394 return CheckError(SDL_GetJoystickID(joystick));
2395}
2396
2397inline JoystickID Joystick::GetID() { return SDL::GetJoystickID(m_resource); }
2398
2420{
2421 return CheckError(SDL_GetNumJoystickAxes(joystick));
2422}
2423
2425{
2426 return SDL::GetNumJoystickAxes(m_resource);
2427}
2428
2451{
2452 return CheckError(SDL_GetNumJoystickBalls(joystick));
2453}
2454
2456{
2457 return SDL::GetNumJoystickBalls(m_resource);
2458}
2459
2477{
2478 return CheckError(SDL_GetNumJoystickHats(joystick));
2479}
2480
2482{
2483 return SDL::GetNumJoystickHats(m_resource);
2484}
2485
2503{
2504 return CheckError(SDL_GetNumJoystickButtons(joystick));
2505}
2506
2508{
2509 return SDL::GetNumJoystickButtons(m_resource);
2510}
2511
2527inline void SetJoystickEventsEnabled(bool enabled)
2528{
2529 SDL_SetJoystickEventsEnabled(enabled);
2530}
2531
2546inline bool JoystickEventsEnabled() { return SDL_JoystickEventsEnabled(); }
2547
2558inline void UpdateJoysticks() { SDL_UpdateJoysticks(); }
2559
2584inline Sint16 GetJoystickAxis(JoystickParam joystick, int axis)
2585{
2586 return SDL_GetJoystickAxis(joystick, axis);
2587}
2588
2590{
2591 return SDL::GetJoystickAxis(m_resource, axis);
2592}
2593
2611 int axis,
2612 Sint16* state)
2613{
2614 return SDL_GetJoystickAxisInitialState(joystick, axis, state);
2615}
2616
2617inline bool Joystick::GetAxisInitialState(int axis, Sint16* state)
2618{
2619 return SDL::GetJoystickAxisInitialState(m_resource, axis, state);
2620}
2621
2642inline void GetJoystickBall(JoystickParam joystick, int ball, int* dx, int* dy)
2643{
2644 CheckError(SDL_GetJoystickBall(joystick, ball, dx, dy));
2645}
2646
2647inline void Joystick::GetBall(int ball, int* dx, int* dy)
2648{
2649 SDL::GetJoystickBall(m_resource, ball, dx, dy);
2650}
2651
2667inline Uint8 GetJoystickHat(JoystickParam joystick, int hat)
2668{
2669 return SDL_GetJoystickHat(joystick, hat);
2670}
2671
2673{
2674 return SDL::GetJoystickHat(m_resource, hat);
2675}
2676
2691inline bool GetJoystickButton(JoystickParam joystick, int button)
2692{
2693 return SDL_GetJoystickButton(joystick, button);
2694}
2695
2696inline bool Joystick::GetButton(int button)
2697{
2698 return SDL::GetJoystickButton(m_resource, button);
2699}
2700
2722inline bool RumbleJoystick(JoystickParam joystick,
2723 Uint16 low_frequency_rumble,
2724 Uint16 high_frequency_rumble,
2725 Uint32 duration_ms)
2726{
2727 return SDL_RumbleJoystick(
2728 joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
2729}
2730
2731inline bool Joystick::Rumble(Uint16 low_frequency_rumble,
2732 Uint16 high_frequency_rumble,
2733 Uint32 duration_ms)
2734{
2735 return SDL::RumbleJoystick(
2736 m_resource, low_frequency_rumble, high_frequency_rumble, duration_ms);
2737}
2738
2767 Uint16 left_rumble,
2768 Uint16 right_rumble,
2769 Uint32 duration_ms)
2770{
2771 CheckError(SDL_RumbleJoystickTriggers(
2772 joystick, left_rumble, right_rumble, duration_ms));
2773}
2774
2775inline void Joystick::RumbleTriggers(Uint16 left_rumble,
2776 Uint16 right_rumble,
2777 Uint32 duration_ms)
2778{
2780 m_resource, left_rumble, right_rumble, duration_ms);
2781}
2782
2802inline void SetJoystickLED(JoystickParam joystick,
2803 Uint8 red,
2804 Uint8 green,
2805 Uint8 blue)
2806{
2807 CheckError(SDL_SetJoystickLED(joystick, red, green, blue));
2808}
2809
2810inline void Joystick::SetLED(Uint8 red, Uint8 green, Uint8 blue)
2811{
2812 SDL::SetJoystickLED(m_resource, red, green, blue);
2813}
2814
2828 const void* data,
2829 int size)
2830{
2831 CheckError(SDL_SendJoystickEffect(joystick, data, size));
2832}
2833
2834inline void Joystick::SendEffect(const void* data, int size)
2835{
2836 SDL::SendJoystickEffect(m_resource, data, size);
2837}
2838
2850inline void CloseJoystick(JoystickRaw joystick) { SDL_CloseJoystick(joystick); }
2851
2853
2866 JoystickParam joystick)
2867{
2868 return CheckError(SDL_GetJoystickConnectionState(joystick));
2869}
2870
2872{
2873 return SDL::GetJoystickConnectionState(m_resource);
2874}
2875
2896inline PowerState GetJoystickPowerInfo(JoystickParam joystick, int* percent)
2897{
2898 return SDL_GetJoystickPowerInfo(joystick, percent);
2899}
2900
2902{
2903 return SDL::GetJoystickPowerInfo(m_resource, percent);
2904}
2905
2907
2908} // namespace SDL
2909
2910#endif /* SDL3PP_JOYSTICK_H_ */
Locking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1276
~JoystickApiLock()
Unlocking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1311
constexpr JoystickApiLock(JoystickApiLock &&other) noexcept
Move constructor.
Definition: SDL3pp_joystick.h:1297
JoystickApiLock & operator=(JoystickApiLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_joystick.h:1316
JoystickApiLock(const JoystickApiLock &other)=delete
Copy constructor.
void release()
Releases the lock without unlocking.
Definition: SDL3pp_joystick.h:1336
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:164
constexpr JoystickID(JoystickIDRaw joystickID={}) noexcept
Wraps JoystickID.
Definition: SDL3pp_joystick.h:173
The joystick structure used to identify an SDL joystick.
Definition: SDL3pp_joystick.h:434
constexpr Joystick & operator=(const Joystick &other) noexcept=default
Assignment operator.
constexpr Joystick(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_joystick.h:439
constexpr Joystick(const Joystick &other) noexcept=default
Copy constructor.
constexpr Joystick(const JoystickRaw resource) noexcept
Constructs from JoystickParam.
Definition: SDL3pp_joystick.h:451
constexpr auto operator<=>(const Joystick &other) const noexcept=default
Comparison.
~Joystick()
Destructor.
Definition: SDL3pp_joystick.h:492
constexpr JoystickRaw get() const noexcept
Retrieves underlying JoystickRaw.
Definition: SDL3pp_joystick.h:507
constexpr JoystickRaw release() noexcept
Retrieves underlying JoystickRaw and clear this.
Definition: SDL3pp_joystick.h:510
Joystick(JoystickID instance_id)
Open a joystick for use.
Definition: SDL3pp_joystick.h:486
constexpr Joystick & operator=(Joystick &&other) noexcept
Assignment operator.
Definition: SDL3pp_joystick.h:495
constexpr Joystick(Joystick &&other) noexcept
Move constructor.
Definition: SDL3pp_joystick.h:462
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:2054
SDL_Joystick * JoystickRaw
Alias to raw representation for Joystick.
Definition: SDL3pp_joystick.h:61
int GetJoystickPlayerIndexForID(JoystickID instance_id)
Get the player index of a joystick.
Definition: SDL3pp_joystick.h:1476
constexpr JoystickType JOYSTICK_TYPE_COUNT
JOYSTICK_TYPE_COUNT.
Definition: SDL3pp_joystick.h:150
Uint16 GetProductVersion()
Get the product version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2264
constexpr Uint8 HAT_UP
UP.
Definition: SDL3pp_joystick.h:408
int GetJoystickPlayerIndexForID()
Get the player index of a joystick.
Definition: SDL3pp_joystick.h:1481
int GetPlayerIndex()
Get the player index of an opened joystick.
Definition: SDL3pp_joystick.h:2145
void LockJoysticks()
Locking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1350
bool IsJoystickVirtual()
Query whether or not a joystick is virtual.
Definition: SDL3pp_joystick.h:1788
Uint16 GetJoystickVendorForID()
Get the USB vendor ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1534
int GetNumJoystickBalls(JoystickParam joystick)
Get the number of trackballs on a joystick.
Definition: SDL3pp_joystick.h:2450
constexpr JoystickType JOYSTICK_TYPE_ARCADE_STICK
JOYSTICK_TYPE_ARCADE_STICK.
Definition: SDL3pp_joystick.h:129
bool HasJoystick()
Return whether a joystick is currently connected.
Definition: SDL3pp_joystick.h:1386
constexpr Uint8 HAT_LEFT
LEFT.
Definition: SDL3pp_joystick.h:414
Uint16 GetJoystickProductForID(JoystickID instance_id)
Get the USB product ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1556
Uint16 GetProduct()
Get the USB product ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2240
int GetNumBalls()
Get the number of trackballs on a joystick.
Definition: SDL3pp_joystick.h:2455
bool GetButton(int button)
Get the current state of a button on a joystick.
Definition: SDL3pp_joystick.h:2696
JoystickID AttachVirtualJoystick(const VirtualJoystickDesc &desc)
Attach a new virtual joystick.
Definition: SDL3pp_joystick.h:1745
Sint16 GetAxis(int axis)
Get the current state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2589
void SetJoystickLED(JoystickParam joystick, Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition: SDL3pp_joystick.h:2802
Uint16 GetVendor()
Get the USB vendor ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2216
constexpr Uint8 HAT_DOWN
DOWN.
Definition: SDL3pp_joystick.h:412
SDL_VirtualJoystickTouchpadDesc VirtualJoystickTouchpadDesc
The structure that describes a virtual joystick touchpad.
Definition: SDL3pp_joystick.h:1689
constexpr JoystickType JOYSTICK_TYPE_DRUM_KIT
JOYSTICK_TYPE_DRUM_KIT.
Definition: SDL3pp_joystick.h:141
void SetJoystickVirtualHat(JoystickParam joystick, int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1927
void SetJoystickVirtualBall(JoystickParam joystick, int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1856
const char * GetJoystickName(JoystickParam joystick)
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:2092
constexpr JoystickConnectionState JOYSTICK_CONNECTION_INVALID
JOYSTICK_CONNECTION_INVALID.
Definition: SDL3pp_joystick.h:388
constexpr JoystickConnectionState JOYSTICK_CONNECTION_UNKNOWN
JOYSTICK_CONNECTION_UNKNOWN.
Definition: SDL3pp_joystick.h:391
void SetJoystickVirtualAxis(JoystickParam joystick, int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1820
JoystickID GetJoystickID(JoystickParam joystick)
Get the instance ID of an opened joystick.
Definition: SDL3pp_joystick.h:2392
GUID GetGUID()
Get the implementation-dependent GUID for the joystick.
Definition: SDL3pp_joystick.h:2195
Uint16 GetJoystickVendor(JoystickParam joystick)
Get the USB vendor ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2211
int GetNumHats()
Get the number of POV hats on a joystick.
Definition: SDL3pp_joystick.h:2481
JoystickType GetJoystickTypeForID(JoystickID instance_id)
Get the type of a joystick, if available.
Definition: SDL3pp_joystick.h:1609
JoystickRef GetJoystickFromPlayerIndex(int player_index)
Get the Joystick associated with a player index.
Definition: SDL3pp_joystick.h:1677
Uint16 GetJoystickProductVersionForID()
Get the product version of a joystick, if available.
Definition: SDL3pp_joystick.h:1588
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:2011
const char * GetPath()
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:2120
constexpr JoystickType JOYSTICK_TYPE_WHEEL
JOYSTICK_TYPE_WHEEL.
Definition: SDL3pp_joystick.h:126
bool RumbleJoystick(JoystickParam joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition: SDL3pp_joystick.h:2722
constexpr Uint8 HAT_RIGHTDOWN
RIGHTDOWN.
Definition: SDL3pp_joystick.h:418
void GetJoystickBall(JoystickParam joystick, int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition: SDL3pp_joystick.h:2642
void UpdateJoysticks()
Update the current state of the open joysticks.
Definition: SDL3pp_joystick.h:2558
Joystick OpenJoystick()
Open a joystick for use.
Definition: SDL3pp_joystick.h:1640
void SendEffect(const void *data, int size)
Send a joystick specific effect packet.
Definition: SDL3pp_joystick.h:2834
void SetJoystickPlayerIndex(JoystickParam joystick, int player_index)
Set the player index of an opened joystick.
Definition: SDL3pp_joystick.h:2164
void SetVirtualButton(int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1899
int GetNumJoystickAxes(JoystickParam joystick)
Get the number of general axis controls on a joystick.
Definition: SDL3pp_joystick.h:2419
void DetachVirtualJoystick(JoystickID instance_id)
Detach a virtual joystick.
Definition: SDL3pp_joystick.h:1763
SDL_JoystickID JoystickIDRaw
Alias to raw representation for JoystickID.
Definition: SDL3pp_joystick.h:94
constexpr JoystickType JOYSTICK_TYPE_GUITAR
JOYSTICK_TYPE_GUITAR.
Definition: SDL3pp_joystick.h:138
JoystickType GetJoystickTypeForID()
Get the type of a joystick, if available.
Definition: SDL3pp_joystick.h:1614
void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1864
int GetNumAxes()
Get the number of general axis controls on a joystick.
Definition: SDL3pp_joystick.h:2424
constexpr JoystickType JOYSTICK_TYPE_UNKNOWN
JOYSTICK_TYPE_UNKNOWN.
Definition: SDL3pp_joystick.h:120
void DetachVirtualJoystick()
Detach a virtual joystick.
Definition: SDL3pp_joystick.h:1768
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:1975
void SetLED(Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition: SDL3pp_joystick.h:2810
void RumbleTriggers(Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
Start a rumble effect in the joystick's triggers.
Definition: SDL3pp_joystick.h:2775
Uint16 GetJoystickVendorForID(JoystickID instance_id)
Get the USB vendor ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1529
bool GetJoystickButton(JoystickParam joystick, int button)
Get the current state of a button on a joystick.
Definition: SDL3pp_joystick.h:2691
JoystickType GetJoystickType(JoystickParam joystick)
Get the type of an opened joystick.
Definition: SDL3pp_joystick.h:2326
void SetVirtualAxis(int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1827
constexpr Uint8 HAT_RIGHT
RIGHT.
Definition: SDL3pp_joystick.h:410
constexpr JoystickType JOYSTICK_TYPE_FLIGHT_STICK
JOYSTICK_TYPE_FLIGHT_STICK.
Definition: SDL3pp_joystick.h:132
constexpr JoystickType JOYSTICK_TYPE_GAMEPAD
JOYSTICK_TYPE_GAMEPAD.
Definition: SDL3pp_joystick.h:123
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:1964
constexpr JoystickType JOYSTICK_TYPE_DANCE_PAD
JOYSTICK_TYPE_DANCE_PAD.
Definition: SDL3pp_joystick.h:135
void UnlockJoysticks()
Unlocking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1366
PropertiesRef GetProperties()
Get the properties associated with a joystick.
Definition: SDL3pp_joystick.h:2059
GUID GetJoystickGUIDForID()
Get the implementation-dependent GUID of a joystick.
Definition: SDL3pp_joystick.h:1507
Uint16 GetFirmwareVersion()
Get the firmware version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2286
constexpr Uint8 HAT_LEFTUP
LEFTUP.
Definition: SDL3pp_joystick.h:420
GUID GetJoystickGUID(JoystickParam joystick)
Get the implementation-dependent GUID for the joystick.
Definition: SDL3pp_joystick.h:2190
constexpr JoystickType JOYSTICK_TYPE_THROTTLE
JOYSTICK_TYPE_THROTTLE.
Definition: SDL3pp_joystick.h:147
const char * GetSerial()
Get the serial number of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2309
bool Rumble(Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition: SDL3pp_joystick.h:2731
OwnArray< JoystickID > GetJoysticks()
Get a list of currently connected joysticks.
Definition: SDL3pp_joystick.h:1402
constexpr int JOYSTICK_AXIS_MAX
The largest value an Joystick's axis can report.
Definition: SDL3pp_joystick.h:1251
PowerState GetJoystickPowerInfo(JoystickParam joystick, int *percent)
Get the battery state of a joystick.
Definition: SDL3pp_joystick.h:2896
constexpr int JOYSTICK_AXIS_MIN
The smallest value an Joystick's axis can report.
Definition: SDL3pp_joystick.h:1262
int GetJoystickPlayerIndex(JoystickParam joystick)
Get the player index of an opened joystick.
Definition: SDL3pp_joystick.h:2140
Uint16 GetJoystickProductVersionForID(JoystickID instance_id)
Get the product version of a joystick, if available.
Definition: SDL3pp_joystick.h:1583
void SetJoystickEventsEnabled(bool enabled)
Set the state of joystick event processing.
Definition: SDL3pp_joystick.h:2527
constexpr Uint8 HAT_RIGHTUP
RIGHTUP.
Definition: SDL3pp_joystick.h:416
bool Connected()
Get the status of a specified joystick.
Definition: SDL3pp_joystick.h:2379
GUID GetJoystickGUIDForID(JoystickID instance_id)
Get the implementation-dependent GUID of a joystick.
Definition: SDL3pp_joystick.h:1502
void SendJoystickEffect(JoystickParam joystick, const void *data, int size)
Send a joystick specific effect packet.
Definition: SDL3pp_joystick.h:2827
Uint16 GetJoystickFirmwareVersion(JoystickParam joystick)
Get the firmware version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2281
Uint8 GetJoystickHat(JoystickParam joystick, int hat)
Get the current state of a POV hat on a joystick.
Definition: SDL3pp_joystick.h:2667
constexpr Uint8 HAT_CENTERED
CENTERED.
Definition: SDL3pp_joystick.h:406
const char * GetJoystickPath(JoystickParam joystick)
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:2115
Uint16 GetJoystickProduct(JoystickParam joystick)
Get the USB product ID of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2235
const char * GetJoystickSerial(JoystickParam joystick)
Get the serial number of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2304
JoystickType GetType()
Get the type of an opened joystick.
Definition: SDL3pp_joystick.h:2331
int GetNumJoystickButtons(JoystickParam joystick)
Get the number of buttons on a joystick.
Definition: SDL3pp_joystick.h:2502
int GetNumJoystickHats(JoystickParam joystick)
Get the number of POV hats on a joystick.
Definition: SDL3pp_joystick.h:2476
SDL_VirtualJoystickSensorDesc VirtualJoystickSensorDesc
The structure that describes a virtual joystick sensor.
Definition: SDL3pp_joystick.h:1698
SDL_JoystickConnectionState JoystickConnectionState
Possible connection states for a joystick device.
Definition: SDL3pp_joystick.h:386
bool GetJoystickAxisInitialState(JoystickParam joystick, int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2610
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRELESS
JOYSTICK_CONNECTION_WIRELESS.
Definition: SDL3pp_joystick.h:397
bool JoystickConnected(JoystickParam joystick)
Get the status of a specified joystick.
Definition: SDL3pp_joystick.h:2374
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:2021
bool GetAxisInitialState(int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2617
JoystickRef GetJoystickFromID(JoystickID instance_id)
Get the Joystick associated with an instance ID, if it has been opened.
Definition: SDL3pp_joystick.h:1653
JoystickRef GetJoystickFromID()
Get the Joystick associated with an instance ID, if it has been opened.
Definition: SDL3pp_joystick.h:1658
void Close()
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition: SDL3pp_joystick.h:2852
bool JoystickEventsEnabled()
Query the state of joystick event processing.
Definition: SDL3pp_joystick.h:2546
void reset()
Unlocking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1368
void CloseJoystick(JoystickRaw joystick)
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition: SDL3pp_joystick.h:2850
SDL_VirtualJoystickDesc VirtualJoystickDesc
The structure that describes a virtual joystick.
Definition: SDL3pp_joystick.h:1713
const char * GetJoystickPathForID()
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1456
Uint8 HatState
Represents tbe HatState for a Joystick.
Definition: SDL3pp_joystick.h:404
void SetVirtualHat(int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1932
constexpr JoystickType JOYSTICK_TYPE_ARCADE_PAD
JOYSTICK_TYPE_ARCADE_PAD.
Definition: SDL3pp_joystick.h:144
JoystickConnectionState GetConnectionState()
Get the connection state of a joystick.
Definition: SDL3pp_joystick.h:2871
PowerState GetPowerInfo(int *percent)
Get the battery state of a joystick.
Definition: SDL3pp_joystick.h:2901
Sint16 GetJoystickAxis(JoystickParam joystick, int axis)
Get the current state of an axis control on a joystick.
Definition: SDL3pp_joystick.h:2584
bool IsJoystickVirtual(JoystickID instance_id)
Query whether or not a joystick is virtual.
Definition: SDL3pp_joystick.h:1783
JoystickID GetID()
Get the instance ID of an opened joystick.
Definition: SDL3pp_joystick.h:2397
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRED
JOYSTICK_CONNECTION_WIRED.
Definition: SDL3pp_joystick.h:394
const char * GetJoystickNameForID()
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1430
const char * GetJoystickPathForID(JoystickID instance_id)
Get the implementation dependent path of a joystick.
Definition: SDL3pp_joystick.h:1451
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:2354
constexpr Uint8 HAT_LEFTDOWN
LEFTDOWN.
Definition: SDL3pp_joystick.h:422
Joystick OpenJoystick(JoystickID instance_id)
Open a joystick for use.
Definition: SDL3pp_joystick.h:1635
Uint16 GetJoystickProductVersion(JoystickParam joystick)
Get the product version of an opened joystick, if available.
Definition: SDL3pp_joystick.h:2259
const char * GetName()
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:2097
Uint8 GetHat(int hat)
Get the current state of a POV hat on a joystick.
Definition: SDL3pp_joystick.h:2672
void SetPlayerIndex(int player_index)
Set the player index of an opened joystick.
Definition: SDL3pp_joystick.h:2169
JoystickConnectionState GetJoystickConnectionState(JoystickParam joystick)
Get the connection state of a joystick.
Definition: SDL3pp_joystick.h:2865
void GetBall(int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition: SDL3pp_joystick.h:2647
Uint16 GetJoystickProductForID()
Get the USB product ID of a joystick, if available.
Definition: SDL3pp_joystick.h:1561
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:2766
const char * GetJoystickNameForID(JoystickID instance_id)
Get the implementation dependent name of a joystick.
Definition: SDL3pp_joystick.h:1425
void SetJoystickVirtualButton(JoystickParam joystick, int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition: SDL3pp_joystick.h:1892
JoystickApiLock()
Locking for atomic access to the joystick API.
Definition: SDL3pp_joystick.h:1352
int GetNumButtons()
Get the number of buttons on a joystick.
Definition: SDL3pp_joystick.h:2507
SDL_JoystickType JoystickType
An enum of some common joystick types.
Definition: SDL3pp_joystick.h:118
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:2282
::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:68
constexpr JoystickParam(JoystickRaw value)
Constructs from JoystickRaw.
Definition: SDL3pp_joystick.h:72
JoystickRaw value
parameter's JoystickRaw
Definition: SDL3pp_joystick.h:69
constexpr auto operator<=>(const JoystickParam &other) const =default
Comparison.
constexpr JoystickParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_joystick.h:78
Semi-safe reference for Joystick.
Definition: SDL3pp_joystick.h:1210
constexpr JoystickRef(const JoystickRef &other) noexcept=default
Copy constructor.
JoystickRef(JoystickParam resource) noexcept
Constructs from JoystickParam.
Definition: SDL3pp_joystick.h:1220
JoystickRef(JoystickRaw resource) noexcept
Constructs from JoystickParam.
Definition: SDL3pp_joystick.h:1232
~JoystickRef()
Destructor.
Definition: SDL3pp_joystick.h:1241
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716