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
56
57// Forward decl
58struct JoystickBase;
59
60// Forward decl
61struct Joystick;
62
64using JoystickRaw = SDL_Joystick*;
65
72
74using JoystickIDRaw = SDL_JoystickID;
75
76// Forward decl
77struct JoystickID;
78
79// Forward decl
80struct JoystickApiLock;
81
98using JoystickType = SDL_JoystickType;
99
101 SDL_JOYSTICK_TYPE_UNKNOWN;
102
104 SDL_JOYSTICK_TYPE_GAMEPAD;
105
107 SDL_JOYSTICK_TYPE_WHEEL;
108
110 SDL_JOYSTICK_TYPE_ARCADE_STICK;
111
113 SDL_JOYSTICK_TYPE_FLIGHT_STICK;
114
116 SDL_JOYSTICK_TYPE_DANCE_PAD;
117
119 SDL_JOYSTICK_TYPE_GUITAR;
120
122 SDL_JOYSTICK_TYPE_DRUM_KIT;
123
125 SDL_JOYSTICK_TYPE_ARCADE_PAD;
126
128 SDL_JOYSTICK_TYPE_THROTTLE;
129
131 SDL_JOYSTICK_TYPE_COUNT;
132
144{
145 JoystickIDRaw m_joystickID;
146
147public:
153 constexpr JoystickID(JoystickIDRaw joystickID = {}) noexcept
154 : m_joystickID(joystickID)
155 {
156 }
157
163 constexpr operator JoystickIDRaw() const noexcept { return m_joystickID; }
164
180 const char* GetJoystickNameForID();
181
197 const char* GetJoystickPathForID();
198
214
231
249
267
285
303
320
332
345
355 bool IsJoystickVirtual();
356};
357
366using JoystickConnectionState = SDL_JoystickConnectionState;
367
369 SDL_JOYSTICK_CONNECTION_INVALID;
370
372 SDL_JOYSTICK_CONNECTION_UNKNOWN;
373
375 SDL_JOYSTICK_CONNECTION_WIRED;
376
378 SDL_JOYSTICK_CONNECTION_WIRELESS;
379
385
386constexpr Uint8 HAT_CENTERED = SDL_HAT_CENTERED;
387
388constexpr Uint8 HAT_UP = SDL_HAT_UP;
389
390constexpr Uint8 HAT_RIGHT = SDL_HAT_RIGHT;
391
392constexpr Uint8 HAT_DOWN = SDL_HAT_DOWN;
393
394constexpr Uint8 HAT_LEFT = SDL_HAT_LEFT;
395
396constexpr Uint8 HAT_RIGHTUP = SDL_HAT_RIGHTUP;
397
398constexpr Uint8 HAT_RIGHTDOWN = SDL_HAT_RIGHTDOWN;
399
400constexpr Uint8 HAT_LEFTUP = SDL_HAT_LEFTUP;
401
402constexpr Uint8 HAT_LEFTDOWN = SDL_HAT_LEFTDOWN;
403
409struct JoystickBase : ResourceBaseT<JoystickRaw>
410{
412
422 void Close();
423
450 void SetVirtualAxis(int axis, Sint16 value);
451
475 void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel);
476
499 void SetVirtualButton(int button, bool down);
500
523 void SetVirtualHat(int hat, Uint8 value);
524
552 void SetVirtualTouchpad(int touchpad,
553 int finger,
554 bool down,
555 const FPointRaw& p,
556 float pressure);
557
584 Uint64 sensor_timestamp,
585 const float* data,
586 int num_values);
587
612
625 const char* GetName();
626
639 const char* GetPath();
640
655 int GetPlayerIndex();
656
670 void SetPlayerIndex(int player_index);
671
688 GUID GetGUID();
689
704
719
734
748
762 const char* GetSerial();
763
776
787 bool Connected();
788
800
820 int GetNumAxes();
821
842 int GetNumBalls();
843
859 int GetNumHats();
860
876 int GetNumButtons();
877
901 Sint16 GetAxis(int axis);
902
918 bool GetAxisInitialState(int axis, Sint16* state);
919
939 void GetBall(int ball, int* dx, int* dy);
940
955 Uint8 GetHat(int hat);
956
970 bool GetButton(int button);
971
992 bool Rumble(Uint16 low_frequency_rumble,
993 Uint16 high_frequency_rumble,
994 Uint32 duration_ms);
995
1023 void RumbleTriggers(Uint16 left_rumble,
1024 Uint16 right_rumble,
1025 Uint32 duration_ms);
1026
1045 void SetLED(Uint8 red, Uint8 green, Uint8 blue);
1046
1058 void SendEffect(const void* data, int size);
1059
1071
1092 PowerState GetPowerInfo(int* percent);
1093};
1094
1105{
1106 using JoystickBase::JoystickBase;
1107
1115 constexpr explicit Joystick(JoystickRaw resource) noexcept
1116 : JoystickBase(resource)
1117 {
1118 }
1119
1121 constexpr Joystick(Joystick&& other) noexcept
1122 : Joystick(other.release())
1123 {
1124 }
1125
1141 Joystick(JoystickID instance_id);
1142
1144 ~Joystick() { SDL_CloseJoystick(get()); }
1145
1147 constexpr Joystick& operator=(Joystick&& other) noexcept
1148 {
1149 swap(*this, other);
1150 return *this;
1151 }
1152};
1153
1161constexpr int JOYSTICK_AXIS_MAX = SDL_JOYSTICK_AXIS_MAX;
1162
1172constexpr int JOYSTICK_AXIS_MIN = SDL_JOYSTICK_AXIS_MIN;
1173
1186{
1187 bool m_lock;
1188
1189public:
1202
1204 JoystickApiLock(const JoystickApiLock& other) = delete;
1205
1208 : m_lock(other.m_lock)
1209 {
1210 }
1211
1221
1222 JoystickApiLock& operator=(const JoystickApiLock& other) = delete;
1223
1226 {
1227 std::swap(m_lock, other.m_lock);
1228 return *this;
1229 }
1230
1232 constexpr operator bool() const { return bool(m_lock); }
1233
1242 void reset();
1243
1245 void release() { m_lock = false; }
1246};
1247
1259inline void LockJoysticks() { SDL_LockJoysticks(); }
1260
1262 : m_lock(true)
1263{
1264 LockJoysticks();
1265}
1266
1275inline void UnlockJoysticks() { SDL_UnlockJoysticks(); }
1276
1278{
1279 if (!m_lock) return;
1281 m_lock = false;
1282}
1283
1295inline bool HasJoystick() { return SDL_HasJoystick(); }
1296
1312{
1313 int count;
1314 auto r = reinterpret_cast<JoystickID*>(SDL_GetJoysticks(&count));
1315 return OwnArray<JoystickID>(r, count);
1316}
1317
1334inline const char* GetJoystickNameForID(JoystickID instance_id)
1335{
1336 return SDL_GetJoystickNameForID(instance_id);
1337}
1338
1340{
1341 return SDL::GetJoystickNameForID(m_joystickID);
1342}
1343
1360inline const char* GetJoystickPathForID(JoystickID instance_id)
1361{
1362 return SDL_GetJoystickPathForID(instance_id);
1363}
1364
1366{
1367 return SDL::GetJoystickPathForID(m_joystickID);
1368}
1369
1386{
1387 return SDL_GetJoystickPlayerIndexForID(instance_id);
1388}
1389
1391{
1392 return SDL::GetJoystickPlayerIndexForID(m_joystickID);
1393}
1394
1412{
1413 return SDL_GetJoystickGUIDForID(instance_id);
1414}
1415
1417{
1418 return SDL::GetJoystickGUIDForID(m_joystickID);
1419}
1420
1439{
1440 return SDL_GetJoystickVendorForID(instance_id);
1441}
1442
1444{
1445 return SDL::GetJoystickVendorForID(m_joystickID);
1446}
1447
1466{
1467 return SDL_GetJoystickProductForID(instance_id);
1468}
1469
1471{
1472 return SDL::GetJoystickProductForID(m_joystickID);
1473}
1474
1493{
1494 return SDL_GetJoystickProductVersionForID(instance_id);
1495}
1496
1501
1519{
1520 return SDL_GetJoystickTypeForID(instance_id);
1521}
1522
1524{
1525 return SDL::GetJoystickTypeForID(m_joystickID);
1526}
1527
1545{
1546 return Joystick(instance_id);
1547}
1548
1550 : Joystick(CheckError(SDL_OpenJoystick(instance_id)))
1551{
1552}
1553
1554inline Joystick JoystickID::OpenJoystick() { return Joystick(m_joystickID); }
1555
1568{
1569 return CheckError(SDL_GetJoystickFromID(instance_id));
1570}
1571
1573{
1574 return SDL::GetJoystickFromID(m_joystickID);
1575}
1576
1592{
1593 return CheckError(SDL_GetJoystickFromPlayerIndex(player_index));
1594}
1595
1603using VirtualJoystickTouchpadDesc = SDL_VirtualJoystickTouchpadDesc;
1604
1612using VirtualJoystickSensorDesc = SDL_VirtualJoystickSensorDesc;
1613
1627using VirtualJoystickDesc = SDL_VirtualJoystickDesc;
1628
1660{
1661 return CheckError(SDL_AttachVirtualJoystick(&desc));
1662}
1663
1677inline void DetachVirtualJoystick(JoystickID instance_id)
1678{
1679 CheckError(SDL_DetachVirtualJoystick(instance_id));
1680}
1681
1683{
1684 SDL::DetachVirtualJoystick(m_joystickID);
1685}
1686
1697inline bool IsJoystickVirtual(JoystickID instance_id)
1698{
1699 return SDL_IsJoystickVirtual(instance_id);
1700}
1701
1703{
1704 return SDL::IsJoystickVirtual(m_joystickID);
1705}
1706
1734inline void SetJoystickVirtualAxis(JoystickRef joystick, int axis, Sint16 value)
1735{
1736 CheckError(SDL_SetJoystickVirtualAxis(joystick, axis, value));
1737}
1738
1739inline void JoystickBase::SetVirtualAxis(int axis, Sint16 value)
1740{
1741 SDL::SetJoystickVirtualAxis(get(), axis, value);
1742}
1743
1769 int ball,
1770 Sint16 xrel,
1771 Sint16 yrel)
1772{
1773 CheckError(SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel));
1774}
1775
1776inline void JoystickBase::SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
1777{
1778 SDL::SetJoystickVirtualBall(get(), ball, xrel, yrel);
1779}
1780
1805 int button,
1806 bool down)
1807{
1808 CheckError(SDL_SetJoystickVirtualButton(joystick, button, down));
1809}
1810
1811inline void JoystickBase::SetVirtualButton(int button, bool down)
1812{
1813 SDL::SetJoystickVirtualButton(get(), button, down);
1814}
1815
1839inline void SetJoystickVirtualHat(JoystickRef joystick, int hat, Uint8 value)
1840{
1841 CheckError(SDL_SetJoystickVirtualHat(joystick, hat, value));
1842}
1843
1844inline void JoystickBase::SetVirtualHat(int hat, Uint8 value)
1845{
1846 SDL::SetJoystickVirtualHat(get(), hat, value);
1847}
1848
1877 int touchpad,
1878 int finger,
1879 bool down,
1880 const FPointRaw& p,
1881 float pressure)
1882{
1883 CheckError(SDL_SetJoystickVirtualTouchpad(
1884 joystick, touchpad, finger, down, p.x, p.y, pressure));
1885}
1886
1887inline void JoystickBase::SetVirtualTouchpad(int touchpad,
1888 int finger,
1889 bool down,
1890 const FPointRaw& p,
1891 float pressure)
1892{
1893 SDL::SetJoystickVirtualTouchpad(get(), touchpad, finger, down, p, pressure);
1894}
1895
1923 SensorType type,
1924 Uint64 sensor_timestamp,
1925 const float* data,
1926 int num_values)
1927{
1928 CheckError(SDL_SendJoystickVirtualSensorData(
1929 joystick, type, sensor_timestamp, data, num_values));
1930}
1931
1933 Uint64 sensor_timestamp,
1934 const float* data,
1935 int num_values)
1936{
1938 get(), type, sensor_timestamp, data, num_values);
1939}
1940
1966{
1967 return CheckError(SDL_GetJoystickProperties(joystick));
1968}
1969
1974
1986
1987constexpr auto MONO_LED_BOOLEAN =
1988 SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN;
1989
1990constexpr auto RGB_LED_BOOLEAN =
1991 SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN;
1992
1993constexpr auto PLAYER_LED_BOOLEAN =
1994 SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN;
1995
1996constexpr auto RUMBLE_BOOLEAN =
1997 SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN;
1998
2000 SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN;
2001
2002} // namespace prop::JoystickCap
2003
2017inline const char* GetJoystickName(JoystickRef joystick)
2018{
2019 return SDL_GetJoystickName(joystick);
2020}
2021
2022inline const char* JoystickBase::GetName()
2023{
2024 return SDL::GetJoystickName(get());
2025}
2026
2040inline const char* GetJoystickPath(JoystickRef joystick)
2041{
2042 return SDL_GetJoystickPath(joystick);
2043}
2044
2045inline const char* JoystickBase::GetPath()
2046{
2047 return SDL::GetJoystickPath(get());
2048}
2049
2066{
2067 return SDL_GetJoystickPlayerIndex(joystick);
2068}
2069
2071{
2073}
2074
2089inline void SetJoystickPlayerIndex(JoystickRef joystick, int player_index)
2090{
2091 CheckError(SDL_SetJoystickPlayerIndex(joystick, player_index));
2092}
2093
2094inline void JoystickBase::SetPlayerIndex(int player_index)
2095{
2096 SDL::SetJoystickPlayerIndex(get(), player_index);
2097}
2098
2116{
2117 return SDL_GetJoystickGUID(joystick);
2118}
2119
2121
2137{
2138 return SDL_GetJoystickVendor(joystick);
2139}
2140
2142{
2143 return SDL::GetJoystickVendor(get());
2144}
2145
2161{
2162 return SDL_GetJoystickProduct(joystick);
2163}
2164
2166{
2167 return SDL::GetJoystickProduct(get());
2168}
2169
2185{
2186 return SDL_GetJoystickProductVersion(joystick);
2187}
2188
2193
2207{
2208 return SDL_GetJoystickFirmwareVersion(joystick);
2209}
2210
2215
2229inline const char* GetJoystickSerial(JoystickRef joystick)
2230{
2231 return SDL_GetJoystickSerial(joystick);
2232}
2233
2234inline const char* JoystickBase::GetSerial()
2235{
2236 return SDL::GetJoystickSerial(get());
2237}
2238
2252{
2253 return SDL_GetJoystickType(joystick);
2254}
2255
2257{
2258 return SDL::GetJoystickType(get());
2259}
2260
2279inline void GetJoystickGUIDInfo(GUID guid,
2280 Uint16* vendor,
2281 Uint16* product,
2282 Uint16* version,
2283 Uint16* crc16)
2284{
2285 SDL_GetJoystickGUIDInfo(guid, vendor, product, version, crc16);
2286}
2287
2299inline bool JoystickConnected(JoystickRef joystick)
2300{
2301 return SDL_JoystickConnected(joystick);
2302}
2303
2305
2318{
2319 return CheckError(SDL_GetJoystickID(joystick));
2320}
2321
2323
2345{
2346 return CheckError(SDL_GetNumJoystickAxes(joystick));
2347}
2348
2350
2373{
2374 return CheckError(SDL_GetNumJoystickBalls(joystick));
2375}
2376
2378{
2379 return SDL::GetNumJoystickBalls(get());
2380}
2381
2399{
2400 return CheckError(SDL_GetNumJoystickHats(joystick));
2401}
2402
2404
2422{
2423 return CheckError(SDL_GetNumJoystickButtons(joystick));
2424}
2425
2427{
2429}
2430
2446inline void SetJoystickEventsEnabled(bool enabled)
2447{
2448 SDL_SetJoystickEventsEnabled(enabled);
2449}
2450
2465inline bool JoystickEventsEnabled() { return SDL_JoystickEventsEnabled(); }
2466
2477inline void UpdateJoysticks() { SDL_UpdateJoysticks(); }
2478
2503inline Sint16 GetJoystickAxis(JoystickRef joystick, int axis)
2504{
2505 return SDL_GetJoystickAxis(joystick, axis);
2506}
2507
2509{
2510 return SDL::GetJoystickAxis(get(), axis);
2511}
2512
2530 int axis,
2531 Sint16* state)
2532{
2533 return SDL_GetJoystickAxisInitialState(joystick, axis, state);
2534}
2535
2536inline bool JoystickBase::GetAxisInitialState(int axis, Sint16* state)
2537{
2538 return SDL::GetJoystickAxisInitialState(get(), axis, state);
2539}
2540
2561inline void GetJoystickBall(JoystickRef joystick, int ball, int* dx, int* dy)
2562{
2563 CheckError(SDL_GetJoystickBall(joystick, ball, dx, dy));
2564}
2565
2566inline void JoystickBase::GetBall(int ball, int* dx, int* dy)
2567{
2568 SDL::GetJoystickBall(get(), ball, dx, dy);
2569}
2570
2586inline Uint8 GetJoystickHat(JoystickRef joystick, int hat)
2587{
2588 return SDL_GetJoystickHat(joystick, hat);
2589}
2590
2592{
2593 return SDL::GetJoystickHat(get(), hat);
2594}
2595
2610inline bool GetJoystickButton(JoystickRef joystick, int button)
2611{
2612 return SDL_GetJoystickButton(joystick, button);
2613}
2614
2615inline bool JoystickBase::GetButton(int button)
2616{
2617 return SDL::GetJoystickButton(get(), button);
2618}
2619
2641inline bool RumbleJoystick(JoystickRef joystick,
2642 Uint16 low_frequency_rumble,
2643 Uint16 high_frequency_rumble,
2644 Uint32 duration_ms)
2645{
2646 return SDL_RumbleJoystick(
2647 joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
2648}
2649
2650inline bool JoystickBase::Rumble(Uint16 low_frequency_rumble,
2651 Uint16 high_frequency_rumble,
2652 Uint32 duration_ms)
2653{
2654 return SDL::RumbleJoystick(
2655 get(), low_frequency_rumble, high_frequency_rumble, duration_ms);
2656}
2657
2686 Uint16 left_rumble,
2687 Uint16 right_rumble,
2688 Uint32 duration_ms)
2689{
2690 CheckError(SDL_RumbleJoystickTriggers(
2691 joystick, left_rumble, right_rumble, duration_ms));
2692}
2693
2694inline void JoystickBase::RumbleTriggers(Uint16 left_rumble,
2695 Uint16 right_rumble,
2696 Uint32 duration_ms)
2697{
2698 SDL::RumbleJoystickTriggers(get(), left_rumble, right_rumble, duration_ms);
2699}
2700
2720inline void SetJoystickLED(JoystickRef joystick,
2721 Uint8 red,
2722 Uint8 green,
2723 Uint8 blue)
2724{
2725 CheckError(SDL_SetJoystickLED(joystick, red, green, blue));
2726}
2727
2728inline void JoystickBase::SetLED(Uint8 red, Uint8 green, Uint8 blue)
2729{
2730 SDL::SetJoystickLED(get(), red, green, blue);
2731}
2732
2745inline void SendJoystickEffect(JoystickRef joystick, const void* data, int size)
2746{
2747 CheckError(SDL_SendJoystickEffect(joystick, data, size));
2748}
2749
2750inline void JoystickBase::SendEffect(const void* data, int size)
2751{
2752 SDL::SendJoystickEffect(get(), data, size);
2753}
2754
2766inline void CloseJoystick(JoystickRaw joystick) { SDL_CloseJoystick(joystick); }
2767
2769
2782{
2783 return CheckError(SDL_GetJoystickConnectionState(joystick));
2784}
2785
2790
2811inline PowerState GetJoystickPowerInfo(JoystickRef joystick, int* percent)
2812{
2813 return SDL_GetJoystickPowerInfo(joystick, percent);
2814}
2815
2817{
2818 return SDL::GetJoystickPowerInfo(get(), percent);
2819}
2820
2822
2823} // namespace SDL
2824
2825#endif /* SDL3PP_JOYSTICK_H_ */
Locking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1186
~JoystickApiLock()
Unlocking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1220
JoystickApiLock & operator=(JoystickApiLock &&other) noexcept
Assignment operator.
Definition SDL3pp_joystick.h:1225
JoystickApiLock(const JoystickApiLock &other)=delete
Copy constructor.
void release()
Releases the lock without unlocking.
Definition SDL3pp_joystick.h:1245
JoystickApiLock(JoystickApiLock &&other) noexcept
Move constructor.
Definition SDL3pp_joystick.h:1207
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:144
constexpr JoystickID(JoystickIDRaw joystickID={}) noexcept
Wraps JoystickID.
Definition SDL3pp_joystick.h:153
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
int GetNumJoystickAxes(JoystickRef joystick)
Get the number of general axis controls on a joystick.
Definition SDL3pp_joystick.h:2344
int GetJoystickPlayerIndexForID(JoystickID instance_id)
Get the player index of a joystick.
Definition SDL3pp_joystick.h:1385
constexpr JoystickType JOYSTICK_TYPE_COUNT
JOYSTICK_TYPE_COUNT.
Definition SDL3pp_joystick.h:130
constexpr Uint8 HAT_UP
UP.
Definition SDL3pp_joystick.h:388
void GetBall(int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition SDL3pp_joystick.h:2566
int GetNumJoystickHats(JoystickRef joystick)
Get the number of POV hats on a joystick.
Definition SDL3pp_joystick.h:2398
void SetPlayerIndex(int player_index)
Set the player index of an opened joystick.
Definition SDL3pp_joystick.h:2094
int GetJoystickPlayerIndexForID()
Get the player index of a joystick.
Definition SDL3pp_joystick.h:1390
void LockJoysticks()
Locking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1259
bool IsJoystickVirtual()
Query whether or not a joystick is virtual.
Definition SDL3pp_joystick.h:1702
const char * GetPath()
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:2045
Uint16 GetJoystickVendorForID()
Get the USB vendor ID of a joystick, if available.
Definition SDL3pp_joystick.h:1443
SDL_JoystickConnectionState JoystickConnectionState
Possible connection states for a joystick device.
Definition SDL3pp_joystick.h:366
Uint16 GetProductVersion()
Get the product version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2189
constexpr JoystickType JOYSTICK_TYPE_ARCADE_STICK
JOYSTICK_TYPE_ARCADE_STICK.
Definition SDL3pp_joystick.h:109
bool HasJoystick()
Return whether a joystick is currently connected.
Definition SDL3pp_joystick.h:1295
constexpr Uint8 HAT_LEFT
LEFT.
Definition SDL3pp_joystick.h:394
Uint16 GetJoystickProductForID(JoystickID instance_id)
Get the USB product ID of a joystick, if available.
Definition SDL3pp_joystick.h:1465
void SetJoystickVirtualTouchpad(JoystickRef 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:1876
bool GetJoystickAxisInitialState(JoystickRef joystick, int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2529
Uint16 GetProduct()
Get the USB product ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2165
Uint16 GetJoystickProduct(JoystickRef joystick)
Get the USB product ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2160
JoystickID AttachVirtualJoystick(const VirtualJoystickDesc &desc)
Attach a new virtual joystick.
Definition SDL3pp_joystick.h:1659
bool GetButton(int button)
Get the current state of a button on a joystick.
Definition SDL3pp_joystick.h:2615
SDL_VirtualJoystickSensorDesc VirtualJoystickSensorDesc
The structure that describes a virtual joystick sensor.
Definition SDL3pp_joystick.h:1612
bool GetAxisInitialState(int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2536
void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition SDL3pp_joystick.h:1776
constexpr Uint8 HAT_DOWN
DOWN.
Definition SDL3pp_joystick.h:392
constexpr JoystickType JOYSTICK_TYPE_DRUM_KIT
JOYSTICK_TYPE_DRUM_KIT.
Definition SDL3pp_joystick.h:121
int GetNumAxes()
Get the number of general axis controls on a joystick.
Definition SDL3pp_joystick.h:2349
Uint8 GetHat(int hat)
Get the current state of a POV hat on a joystick.
Definition SDL3pp_joystick.h:2591
JoystickType GetJoystickType(JoystickRef joystick)
Get the type of an opened joystick.
Definition SDL3pp_joystick.h:2251
int GetJoystickPlayerIndex(JoystickRef joystick)
Get the player index of an opened joystick.
Definition SDL3pp_joystick.h:2065
constexpr JoystickConnectionState JOYSTICK_CONNECTION_INVALID
JOYSTICK_CONNECTION_INVALID.
Definition SDL3pp_joystick.h:368
constexpr JoystickConnectionState JOYSTICK_CONNECTION_UNKNOWN
JOYSTICK_CONNECTION_UNKNOWN.
Definition SDL3pp_joystick.h:371
void SendEffect(const void *data, int size)
Send a joystick specific effect packet.
Definition SDL3pp_joystick.h:2750
ResourceRefT< JoystickBase > JoystickRef
Reference for Joystick.
Definition SDL3pp_joystick.h:71
JoystickType GetJoystickTypeForID(JoystickID instance_id)
Get the type of a joystick, if available.
Definition SDL3pp_joystick.h:1518
JoystickRef GetJoystickFromPlayerIndex(int player_index)
Get the Joystick associated with a player index.
Definition SDL3pp_joystick.h:1591
Uint16 GetJoystickProductVersionForID()
Get the product version of a joystick, if available.
Definition SDL3pp_joystick.h:1497
int GetNumBalls()
Get the number of trackballs on a joystick.
Definition SDL3pp_joystick.h:2377
SDL_JoystickType JoystickType
An enum of some common joystick types.
Definition SDL3pp_joystick.h:98
SDL_VirtualJoystickTouchpadDesc VirtualJoystickTouchpadDesc
The structure that describes a virtual joystick touchpad.
Definition SDL3pp_joystick.h:1603
constexpr JoystickType JOYSTICK_TYPE_WHEEL
JOYSTICK_TYPE_WHEEL.
Definition SDL3pp_joystick.h:106
bool GetJoystickButton(JoystickRef joystick, int button)
Get the current state of a button on a joystick.
Definition SDL3pp_joystick.h:2610
PowerState GetJoystickPowerInfo(JoystickRef joystick, int *percent)
Get the battery state of a joystick.
Definition SDL3pp_joystick.h:2811
constexpr Uint8 HAT_RIGHTDOWN
RIGHTDOWN.
Definition SDL3pp_joystick.h:398
void UpdateJoysticks()
Update the current state of the open joysticks.
Definition SDL3pp_joystick.h:2477
void SendJoystickEffect(JoystickRef joystick, const void *data, int size)
Send a joystick specific effect packet.
Definition SDL3pp_joystick.h:2745
Joystick OpenJoystick()
Open a joystick for use.
Definition SDL3pp_joystick.h:1554
int GetPlayerIndex()
Get the player index of an opened joystick.
Definition SDL3pp_joystick.h:2070
SDL_Joystick * JoystickRaw
Alias to raw representation for Joystick.
Definition SDL3pp_joystick.h:64
int GetNumJoystickBalls(JoystickRef joystick)
Get the number of trackballs on a joystick.
Definition SDL3pp_joystick.h:2372
void DetachVirtualJoystick(JoystickID instance_id)
Detach a virtual joystick.
Definition SDL3pp_joystick.h:1677
constexpr JoystickType JOYSTICK_TYPE_GUITAR
JOYSTICK_TYPE_GUITAR.
Definition SDL3pp_joystick.h:118
JoystickType GetJoystickTypeForID()
Get the type of a joystick, if available.
Definition SDL3pp_joystick.h:1523
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:1887
constexpr JoystickType JOYSTICK_TYPE_UNKNOWN
JOYSTICK_TYPE_UNKNOWN.
Definition SDL3pp_joystick.h:100
void DetachVirtualJoystick()
Detach a virtual joystick.
Definition SDL3pp_joystick.h:1682
Uint16 GetJoystickVendorForID(JoystickID instance_id)
Get the USB vendor ID of a joystick, if available.
Definition SDL3pp_joystick.h:1438
void Close()
Close a joystick previously opened with OpenJoystick().
Definition SDL3pp_joystick.h:2768
Uint8 GetJoystickHat(JoystickRef joystick, int hat)
Get the current state of a POV hat on a joystick.
Definition SDL3pp_joystick.h:2586
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:1932
Uint8 HatState
Represents tbe HatState for a Joystick.
Definition SDL3pp_joystick.h:384
constexpr Uint8 HAT_RIGHT
RIGHT.
Definition SDL3pp_joystick.h:390
constexpr JoystickType JOYSTICK_TYPE_FLIGHT_STICK
JOYSTICK_TYPE_FLIGHT_STICK.
Definition SDL3pp_joystick.h:112
constexpr JoystickType JOYSTICK_TYPE_GAMEPAD
JOYSTICK_TYPE_GAMEPAD.
Definition SDL3pp_joystick.h:103
constexpr JoystickType JOYSTICK_TYPE_DANCE_PAD
JOYSTICK_TYPE_DANCE_PAD.
Definition SDL3pp_joystick.h:115
void UnlockJoysticks()
Unlocking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1275
const char * GetJoystickName(JoystickRef joystick)
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:2017
GUID GetJoystickGUIDForID()
Get the implementation-dependent GUID of a joystick.
Definition SDL3pp_joystick.h:1416
GUID GetGUID()
Get the implementation-dependent GUID for the joystick.
Definition SDL3pp_joystick.h:2120
SDL_VirtualJoystickDesc VirtualJoystickDesc
The structure that describes a virtual joystick.
Definition SDL3pp_joystick.h:1627
constexpr Uint8 HAT_LEFTUP
LEFTUP.
Definition SDL3pp_joystick.h:400
constexpr JoystickType JOYSTICK_TYPE_THROTTLE
JOYSTICK_TYPE_THROTTLE.
Definition SDL3pp_joystick.h:127
Sint16 GetJoystickAxis(JoystickRef joystick, int axis)
Get the current state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2503
void SetJoystickVirtualBall(JoystickRef joystick, int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition SDL3pp_joystick.h:1768
bool Rumble(Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition SDL3pp_joystick.h:2650
int GetNumJoystickButtons(JoystickRef joystick)
Get the number of buttons on a joystick.
Definition SDL3pp_joystick.h:2421
Uint16 GetJoystickVendor(JoystickRef joystick)
Get the USB vendor ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2136
OwnArray< JoystickID > GetJoysticks()
Get a list of currently connected joysticks.
Definition SDL3pp_joystick.h:1311
constexpr int JOYSTICK_AXIS_MAX
The largest value an Joystick's axis can report.
Definition SDL3pp_joystick.h:1161
void SetVirtualButton(int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition SDL3pp_joystick.h:1811
constexpr int JOYSTICK_AXIS_MIN
The smallest value an Joystick's axis can report.
Definition SDL3pp_joystick.h:1172
void SetLED(Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition SDL3pp_joystick.h:2728
int GetNumButtons()
Get the number of buttons on a joystick.
Definition SDL3pp_joystick.h:2426
Uint16 GetJoystickProductVersionForID(JoystickID instance_id)
Get the product version of a joystick, if available.
Definition SDL3pp_joystick.h:1492
void SetJoystickEventsEnabled(bool enabled)
Set the state of joystick event processing.
Definition SDL3pp_joystick.h:2446
constexpr Uint8 HAT_RIGHTUP
RIGHTUP.
Definition SDL3pp_joystick.h:396
void SetJoystickVirtualHat(JoystickRef joystick, int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition SDL3pp_joystick.h:1839
GUID GetJoystickGUIDForID(JoystickID instance_id)
Get the implementation-dependent GUID of a joystick.
Definition SDL3pp_joystick.h:1411
const char * GetJoystickPath(JoystickRef joystick)
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:2040
Uint16 GetJoystickFirmwareVersion(JoystickRef joystick)
Get the firmware version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2206
JoystickConnectionState GetConnectionState()
Get the connection state of a joystick.
Definition SDL3pp_joystick.h:2786
constexpr Uint8 HAT_CENTERED
CENTERED.
Definition SDL3pp_joystick.h:386
void SetVirtualAxis(int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition SDL3pp_joystick.h:1739
JoystickID GetID()
Get the instance ID of an opened joystick.
Definition SDL3pp_joystick.h:2322
Uint16 GetJoystickProductVersion(JoystickRef joystick)
Get the product version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2184
Sint16 GetAxis(int axis)
Get the current state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2508
const char * GetJoystickSerial(JoystickRef joystick)
Get the serial number of an opened joystick, if available.
Definition SDL3pp_joystick.h:2229
JoystickConnectionState GetJoystickConnectionState(JoystickRef joystick)
Get the connection state of a joystick.
Definition SDL3pp_joystick.h:2781
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRELESS
JOYSTICK_CONNECTION_WIRELESS.
Definition SDL3pp_joystick.h:377
bool JoystickConnected(JoystickRef joystick)
Get the status of a specified joystick.
Definition SDL3pp_joystick.h:2299
JoystickType GetType()
Get the type of an opened joystick.
Definition SDL3pp_joystick.h:2256
PowerState GetPowerInfo(int *percent)
Get the battery state of a joystick.
Definition SDL3pp_joystick.h:2816
SDL_JoystickID JoystickIDRaw
Alias to raw representation for JoystickID.
Definition SDL3pp_joystick.h:74
int GetNumHats()
Get the number of POV hats on a joystick.
Definition SDL3pp_joystick.h:2403
JoystickRef GetJoystickFromID(JoystickID instance_id)
Get the Joystick associated with an instance ID, if it has been opened.
Definition SDL3pp_joystick.h:1567
JoystickRef GetJoystickFromID()
Get the Joystick associated with an instance ID, if it has been opened.
Definition SDL3pp_joystick.h:1572
bool JoystickEventsEnabled()
Query the state of joystick event processing.
Definition SDL3pp_joystick.h:2465
const char * GetSerial()
Get the serial number of an opened joystick, if available.
Definition SDL3pp_joystick.h:2234
void reset()
Unlocking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1277
bool Connected()
Get the status of a specified joystick.
Definition SDL3pp_joystick.h:2304
void CloseJoystick(JoystickRaw joystick)
Close a joystick previously opened with OpenJoystick().
Definition SDL3pp_joystick.h:2766
void SetJoystickLED(JoystickRef joystick, Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition SDL3pp_joystick.h:2720
const char * GetJoystickPathForID()
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:1365
GUID GetJoystickGUID(JoystickRef joystick)
Get the implementation-dependent GUID for the joystick.
Definition SDL3pp_joystick.h:2115
void SetJoystickVirtualButton(JoystickRef joystick, int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition SDL3pp_joystick.h:1804
void RumbleTriggers(Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
Start a rumble effect in the joystick's triggers.
Definition SDL3pp_joystick.h:2694
void SetJoystickPlayerIndex(JoystickRef joystick, int player_index)
Set the player index of an opened joystick.
Definition SDL3pp_joystick.h:2089
Uint16 GetFirmwareVersion()
Get the firmware version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2211
constexpr JoystickType JOYSTICK_TYPE_ARCADE_PAD
JOYSTICK_TYPE_ARCADE_PAD.
Definition SDL3pp_joystick.h:124
PropertiesRef GetJoystickProperties(JoystickRef joystick)
Get the properties associated with a joystick.
Definition SDL3pp_joystick.h:1965
bool IsJoystickVirtual(JoystickID instance_id)
Query whether or not a joystick is virtual.
Definition SDL3pp_joystick.h:1697
bool RumbleJoystick(JoystickRef joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition SDL3pp_joystick.h:2641
Uint16 GetVendor()
Get the USB vendor ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2141
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRED
JOYSTICK_CONNECTION_WIRED.
Definition SDL3pp_joystick.h:374
const char * GetJoystickNameForID()
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:1339
void SetVirtualHat(int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition SDL3pp_joystick.h:1844
const char * GetJoystickPathForID(JoystickID instance_id)
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:1360
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:2279
constexpr Uint8 HAT_LEFTDOWN
LEFTDOWN.
Definition SDL3pp_joystick.h:402
Joystick OpenJoystick(JoystickID instance_id)
Open a joystick for use.
Definition SDL3pp_joystick.h:1544
void RumbleJoystickTriggers(JoystickRef joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
Start a rumble effect in the joystick's triggers.
Definition SDL3pp_joystick.h:2685
PropertiesRef GetProperties()
Get the properties associated with a joystick.
Definition SDL3pp_joystick.h:1970
Uint16 GetJoystickProductForID()
Get the USB product ID of a joystick, if available.
Definition SDL3pp_joystick.h:1470
const char * GetName()
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:2022
void SendJoystickVirtualSensorData(JoystickRef 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:1922
void GetJoystickBall(JoystickRef joystick, int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition SDL3pp_joystick.h:2561
const char * GetJoystickNameForID(JoystickID instance_id)
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:1334
void SetJoystickVirtualAxis(JoystickRef joystick, int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition SDL3pp_joystick.h:1734
JoystickApiLock()
Locking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1261
JoystickID GetJoystickID(JoystickRef joystick)
Get the instance ID of an opened joystick.
Definition SDL3pp_joystick.h:2317
SDL_PowerState PowerState
The basic state for the system's power supply.
Definition SDL3pp_power.h:38
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:53
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:105
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition SDL3pp_stdinc.h:2182
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:270
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
::Sint16 Sint16
A signed 16-bit integer type.
Definition SDL3pp_stdinc.h:257
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:326
Joystick capability properties.
Definition SDL3pp_joystick.h:1985
constexpr auto TRIGGER_RUMBLE_BOOLEAN
Trigger rumble enabled.
Definition SDL3pp_joystick.h:1999
constexpr auto MONO_LED_BOOLEAN
Mono led enabled.
Definition SDL3pp_joystick.h:1987
constexpr auto PLAYER_LED_BOOLEAN
Player led enabled.
Definition SDL3pp_joystick.h:1993
constexpr auto RGB_LED_BOOLEAN
Rgb led enabled.
Definition SDL3pp_joystick.h:1990
constexpr auto RUMBLE_BOOLEAN
Rumble enabled.
Definition SDL3pp_joystick.h:1996
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
Base class to Joystick.
Definition SDL3pp_joystick.h:410
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The joystick structure used to identify an SDL joystick.
Definition SDL3pp_joystick.h:1105
~Joystick()
Destructor.
Definition SDL3pp_joystick.h:1144
constexpr Joystick & operator=(Joystick &&other) noexcept
Assignment operator.
Definition SDL3pp_joystick.h:1147
constexpr Joystick(Joystick &&other) noexcept
Move constructor.
Definition SDL3pp_joystick.h:1121
constexpr Joystick(JoystickRaw resource) noexcept
Constructs from raw Joystick.
Definition SDL3pp_joystick.h:1115
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93