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 Joystick;
59
61using JoystickRaw = SDL_Joystick*;
62
69
71using JoystickIDRaw = SDL_JoystickID;
72
73// Forward decl
74struct JoystickID;
75
76// Forward decl
77struct JoystickApiLock;
78
95using JoystickType = SDL_JoystickType;
96
98 SDL_JOYSTICK_TYPE_UNKNOWN;
99
101 SDL_JOYSTICK_TYPE_GAMEPAD;
102
104 SDL_JOYSTICK_TYPE_WHEEL;
105
107 SDL_JOYSTICK_TYPE_ARCADE_STICK;
108
110 SDL_JOYSTICK_TYPE_FLIGHT_STICK;
111
113 SDL_JOYSTICK_TYPE_DANCE_PAD;
114
116 SDL_JOYSTICK_TYPE_GUITAR;
117
119 SDL_JOYSTICK_TYPE_DRUM_KIT;
120
122 SDL_JOYSTICK_TYPE_ARCADE_PAD;
123
125 SDL_JOYSTICK_TYPE_THROTTLE;
126
128 SDL_JOYSTICK_TYPE_COUNT;
129
141{
142 JoystickIDRaw m_joystickID;
143
144public:
150 constexpr JoystickID(JoystickIDRaw joystickID = {}) noexcept
151 : m_joystickID(joystickID)
152 {
153 }
154
160 constexpr operator JoystickIDRaw() const noexcept { return m_joystickID; }
161
177 const char* GetJoystickNameForID();
178
194 const char* GetJoystickPathForID();
195
211
228
246
264
282
300
317
329
342
352 bool IsJoystickVirtual();
353};
354
363using JoystickConnectionState = SDL_JoystickConnectionState;
364
366 SDL_JOYSTICK_CONNECTION_INVALID;
367
369 SDL_JOYSTICK_CONNECTION_UNKNOWN;
370
372 SDL_JOYSTICK_CONNECTION_WIRED;
373
375 SDL_JOYSTICK_CONNECTION_WIRELESS;
376
382
383constexpr Uint8 HAT_CENTERED = SDL_HAT_CENTERED;
384
385constexpr Uint8 HAT_UP = SDL_HAT_UP;
386
387constexpr Uint8 HAT_RIGHT = SDL_HAT_RIGHT;
388
389constexpr Uint8 HAT_DOWN = SDL_HAT_DOWN;
390
391constexpr Uint8 HAT_LEFT = SDL_HAT_LEFT;
392
393constexpr Uint8 HAT_RIGHTUP = SDL_HAT_RIGHTUP;
394
395constexpr Uint8 HAT_RIGHTDOWN = SDL_HAT_RIGHTDOWN;
396
397constexpr Uint8 HAT_LEFTUP = SDL_HAT_LEFTUP;
398
399constexpr Uint8 HAT_LEFTDOWN = SDL_HAT_LEFTDOWN;
400
410struct Joystick : ResourceBase<JoystickRaw>
411{
413
421 constexpr explicit Joystick(JoystickRaw resource) noexcept
422 : ResourceBase(resource)
423 {
424 }
425
427 constexpr Joystick(const Joystick& other) = delete;
428
430 constexpr Joystick(Joystick&& other) noexcept
431 : Joystick(other.release())
432 {
433 }
434
435 constexpr Joystick(const JoystickRef& other) = delete;
436
437 constexpr Joystick(JoystickRef&& other) = delete;
438
454 Joystick(JoystickID instance_id);
455
457 ~Joystick() { SDL_CloseJoystick(get()); }
458
460 constexpr Joystick& operator=(Joystick&& other) noexcept
461 {
462 swap(*this, other);
463 return *this;
464 }
465
467 Joystick& operator=(const Joystick& other) = delete;
468
478 void Close();
479
506 void SetVirtualAxis(int axis, Sint16 value);
507
531 void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel);
532
555 void SetVirtualButton(int button, bool down);
556
579 void SetVirtualHat(int hat, Uint8 value);
580
608 void SetVirtualTouchpad(int touchpad,
609 int finger,
610 bool down,
611 const FPointRaw& p,
612 float pressure);
613
640 Uint64 sensor_timestamp,
641 const float* data,
642 int num_values);
643
668
681 const char* GetName();
682
695 const char* GetPath();
696
711 int GetPlayerIndex();
712
726 void SetPlayerIndex(int player_index);
727
744 GUID GetGUID();
745
760
775
790
804
818 const char* GetSerial();
819
832
843 bool Connected();
844
856
876 int GetNumAxes();
877
898 int GetNumBalls();
899
915 int GetNumHats();
916
932 int GetNumButtons();
933
957 Sint16 GetAxis(int axis);
958
974 bool GetAxisInitialState(int axis, Sint16* state);
975
995 void GetBall(int ball, int* dx, int* dy);
996
1011 Uint8 GetHat(int hat);
1012
1026 bool GetButton(int button);
1027
1048 bool Rumble(Uint16 low_frequency_rumble,
1049 Uint16 high_frequency_rumble,
1050 Uint32 duration_ms);
1051
1079 void RumbleTriggers(Uint16 left_rumble,
1080 Uint16 right_rumble,
1081 Uint32 duration_ms);
1082
1101 void SetLED(Uint8 red, Uint8 green, Uint8 blue);
1102
1114 void SendEffect(const void* data, int size);
1115
1127
1148 PowerState GetPowerInfo(int* percent);
1149};
1150
1158constexpr int JOYSTICK_AXIS_MAX = SDL_JOYSTICK_AXIS_MAX;
1159
1169constexpr int JOYSTICK_AXIS_MIN = SDL_JOYSTICK_AXIS_MIN;
1170
1183{
1184 bool m_lock;
1185
1186public:
1199
1201 JoystickApiLock(const JoystickApiLock& other) = delete;
1202
1205 : m_lock(other.m_lock)
1206 {
1207 }
1208
1218
1219 JoystickApiLock& operator=(const JoystickApiLock& other) = delete;
1220
1223 {
1224 std::swap(m_lock, other.m_lock);
1225 return *this;
1226 }
1227
1229 constexpr operator bool() const { return bool(m_lock); }
1230
1239 void reset();
1240
1242 void release() { m_lock = false; }
1243};
1244
1256inline void LockJoysticks() { SDL_LockJoysticks(); }
1257
1259 : m_lock(true)
1260{
1261 LockJoysticks();
1262}
1263
1272inline void UnlockJoysticks() { SDL_UnlockJoysticks(); }
1273
1275{
1276 if (!m_lock) return;
1278 m_lock = false;
1279}
1280
1292inline bool HasJoystick() { return SDL_HasJoystick(); }
1293
1309{
1310 int count;
1311 auto r = reinterpret_cast<JoystickID*>(SDL_GetJoysticks(&count));
1312 return OwnArray<JoystickID>(r, count);
1313}
1314
1331inline const char* GetJoystickNameForID(JoystickID instance_id)
1332{
1333 return SDL_GetJoystickNameForID(instance_id);
1334}
1335
1337{
1338 return SDL::GetJoystickNameForID(m_joystickID);
1339}
1340
1357inline const char* GetJoystickPathForID(JoystickID instance_id)
1358{
1359 return SDL_GetJoystickPathForID(instance_id);
1360}
1361
1363{
1364 return SDL::GetJoystickPathForID(m_joystickID);
1365}
1366
1383{
1384 return SDL_GetJoystickPlayerIndexForID(instance_id);
1385}
1386
1388{
1389 return SDL::GetJoystickPlayerIndexForID(m_joystickID);
1390}
1391
1409{
1410 return SDL_GetJoystickGUIDForID(instance_id);
1411}
1412
1414{
1415 return SDL::GetJoystickGUIDForID(m_joystickID);
1416}
1417
1436{
1437 return SDL_GetJoystickVendorForID(instance_id);
1438}
1439
1441{
1442 return SDL::GetJoystickVendorForID(m_joystickID);
1443}
1444
1463{
1464 return SDL_GetJoystickProductForID(instance_id);
1465}
1466
1468{
1469 return SDL::GetJoystickProductForID(m_joystickID);
1470}
1471
1490{
1491 return SDL_GetJoystickProductVersionForID(instance_id);
1492}
1493
1498
1516{
1517 return SDL_GetJoystickTypeForID(instance_id);
1518}
1519
1521{
1522 return SDL::GetJoystickTypeForID(m_joystickID);
1523}
1524
1542{
1543 return Joystick(instance_id);
1544}
1545
1547 : Joystick(CheckError(SDL_OpenJoystick(instance_id)))
1548{
1549}
1550
1551inline Joystick JoystickID::OpenJoystick() { return Joystick(m_joystickID); }
1552
1565{
1566 return {CheckError(SDL_GetJoystickFromID(instance_id))};
1567}
1568
1570{
1571 return SDL::GetJoystickFromID(m_joystickID);
1572}
1573
1589{
1590 return {CheckError(SDL_GetJoystickFromPlayerIndex(player_index))};
1591}
1592
1600using VirtualJoystickTouchpadDesc = SDL_VirtualJoystickTouchpadDesc;
1601
1609using VirtualJoystickSensorDesc = SDL_VirtualJoystickSensorDesc;
1610
1624using VirtualJoystickDesc = SDL_VirtualJoystickDesc;
1625
1657{
1658 return CheckError(SDL_AttachVirtualJoystick(&desc));
1659}
1660
1674inline void DetachVirtualJoystick(JoystickID instance_id)
1675{
1676 CheckError(SDL_DetachVirtualJoystick(instance_id));
1677}
1678
1680{
1681 SDL::DetachVirtualJoystick(m_joystickID);
1682}
1683
1694inline bool IsJoystickVirtual(JoystickID instance_id)
1695{
1696 return SDL_IsJoystickVirtual(instance_id);
1697}
1698
1700{
1701 return SDL::IsJoystickVirtual(m_joystickID);
1702}
1703
1731inline void SetJoystickVirtualAxis(JoystickRef joystick, int axis, Sint16 value)
1732{
1733 CheckError(SDL_SetJoystickVirtualAxis(joystick, axis, value));
1734}
1735
1736inline void Joystick::SetVirtualAxis(int axis, Sint16 value)
1737{
1738 SDL::SetJoystickVirtualAxis(get(), axis, value);
1739}
1740
1766 int ball,
1767 Sint16 xrel,
1768 Sint16 yrel)
1769{
1770 CheckError(SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel));
1771}
1772
1773inline void Joystick::SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
1774{
1775 SDL::SetJoystickVirtualBall(get(), ball, xrel, yrel);
1776}
1777
1802 int button,
1803 bool down)
1804{
1805 CheckError(SDL_SetJoystickVirtualButton(joystick, button, down));
1806}
1807
1808inline void Joystick::SetVirtualButton(int button, bool down)
1809{
1810 SDL::SetJoystickVirtualButton(get(), button, down);
1811}
1812
1836inline void SetJoystickVirtualHat(JoystickRef joystick, int hat, Uint8 value)
1837{
1838 CheckError(SDL_SetJoystickVirtualHat(joystick, hat, value));
1839}
1840
1841inline void Joystick::SetVirtualHat(int hat, Uint8 value)
1842{
1843 SDL::SetJoystickVirtualHat(get(), hat, value);
1844}
1845
1874 int touchpad,
1875 int finger,
1876 bool down,
1877 const FPointRaw& p,
1878 float pressure)
1879{
1880 CheckError(SDL_SetJoystickVirtualTouchpad(
1881 joystick, touchpad, finger, down, p.x, p.y, pressure));
1882}
1883
1884inline void Joystick::SetVirtualTouchpad(int touchpad,
1885 int finger,
1886 bool down,
1887 const FPointRaw& p,
1888 float pressure)
1889{
1890 SDL::SetJoystickVirtualTouchpad(get(), touchpad, finger, down, p, pressure);
1891}
1892
1920 SensorType type,
1921 Uint64 sensor_timestamp,
1922 const float* data,
1923 int num_values)
1924{
1925 CheckError(SDL_SendJoystickVirtualSensorData(
1926 joystick, type, sensor_timestamp, data, num_values));
1927}
1928
1930 Uint64 sensor_timestamp,
1931 const float* data,
1932 int num_values)
1933{
1935 get(), type, sensor_timestamp, data, num_values);
1936}
1937
1963{
1964 return {CheckError(SDL_GetJoystickProperties(joystick))};
1965}
1966
1971
1983
1984constexpr auto MONO_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN;
1985
1986constexpr auto RGB_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN;
1987
1988constexpr auto PLAYER_LED_BOOLEAN = SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN;
1989
1990constexpr auto RUMBLE_BOOLEAN = SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN;
1991
1992constexpr auto TRIGGER_RUMBLE_BOOLEAN =
1993 SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN;
1994
1995} // namespace prop::JoystickCap
1996
2010inline const char* GetJoystickName(JoystickRef joystick)
2011{
2012 return SDL_GetJoystickName(joystick);
2013}
2014
2015inline const char* Joystick::GetName() { return SDL::GetJoystickName(get()); }
2016
2030inline const char* GetJoystickPath(JoystickRef joystick)
2031{
2032 return SDL_GetJoystickPath(joystick);
2033}
2034
2035inline const char* Joystick::GetPath() { return SDL::GetJoystickPath(get()); }
2036
2053{
2054 return SDL_GetJoystickPlayerIndex(joystick);
2055}
2056
2058{
2060}
2061
2076inline void SetJoystickPlayerIndex(JoystickRef joystick, int player_index)
2077{
2078 CheckError(SDL_SetJoystickPlayerIndex(joystick, player_index));
2079}
2080
2081inline void Joystick::SetPlayerIndex(int player_index)
2082{
2083 SDL::SetJoystickPlayerIndex(get(), player_index);
2084}
2085
2103{
2104 return SDL_GetJoystickGUID(joystick);
2105}
2106
2108
2124{
2125 return SDL_GetJoystickVendor(joystick);
2126}
2127
2129
2145{
2146 return SDL_GetJoystickProduct(joystick);
2147}
2148
2150
2166{
2167 return SDL_GetJoystickProductVersion(joystick);
2168}
2169
2174
2188{
2189 return SDL_GetJoystickFirmwareVersion(joystick);
2190}
2191
2196
2210inline const char* GetJoystickSerial(JoystickRef joystick)
2211{
2212 return SDL_GetJoystickSerial(joystick);
2213}
2214
2215inline const char* Joystick::GetSerial()
2216{
2217 return SDL::GetJoystickSerial(get());
2218}
2219
2233{
2234 return SDL_GetJoystickType(joystick);
2235}
2236
2238
2257inline void GetJoystickGUIDInfo(GUID guid,
2258 Uint16* vendor,
2259 Uint16* product,
2260 Uint16* version,
2261 Uint16* crc16)
2262{
2263 SDL_GetJoystickGUIDInfo(guid, vendor, product, version, crc16);
2264}
2265
2277inline bool JoystickConnected(JoystickRef joystick)
2278{
2279 return SDL_JoystickConnected(joystick);
2280}
2281
2283
2296{
2297 return CheckError(SDL_GetJoystickID(joystick));
2298}
2299
2301
2323{
2324 return CheckError(SDL_GetNumJoystickAxes(joystick));
2325}
2326
2328
2351{
2352 return CheckError(SDL_GetNumJoystickBalls(joystick));
2353}
2354
2356
2374{
2375 return CheckError(SDL_GetNumJoystickHats(joystick));
2376}
2377
2379
2397{
2398 return CheckError(SDL_GetNumJoystickButtons(joystick));
2399}
2400
2402{
2404}
2405
2421inline void SetJoystickEventsEnabled(bool enabled)
2422{
2423 SDL_SetJoystickEventsEnabled(enabled);
2424}
2425
2440inline bool JoystickEventsEnabled() { return SDL_JoystickEventsEnabled(); }
2441
2452inline void UpdateJoysticks() { SDL_UpdateJoysticks(); }
2453
2478inline Sint16 GetJoystickAxis(JoystickRef joystick, int axis)
2479{
2480 return SDL_GetJoystickAxis(joystick, axis);
2481}
2482
2484{
2485 return SDL::GetJoystickAxis(get(), axis);
2486}
2487
2505 int axis,
2506 Sint16* state)
2507{
2508 return SDL_GetJoystickAxisInitialState(joystick, axis, state);
2509}
2510
2511inline bool Joystick::GetAxisInitialState(int axis, Sint16* state)
2512{
2513 return SDL::GetJoystickAxisInitialState(get(), axis, state);
2514}
2515
2536inline void GetJoystickBall(JoystickRef joystick, int ball, int* dx, int* dy)
2537{
2538 CheckError(SDL_GetJoystickBall(joystick, ball, dx, dy));
2539}
2540
2541inline void Joystick::GetBall(int ball, int* dx, int* dy)
2542{
2543 SDL::GetJoystickBall(get(), ball, dx, dy);
2544}
2545
2561inline Uint8 GetJoystickHat(JoystickRef joystick, int hat)
2562{
2563 return SDL_GetJoystickHat(joystick, hat);
2564}
2565
2567{
2568 return SDL::GetJoystickHat(get(), hat);
2569}
2570
2585inline bool GetJoystickButton(JoystickRef joystick, int button)
2586{
2587 return SDL_GetJoystickButton(joystick, button);
2588}
2589
2590inline bool Joystick::GetButton(int button)
2591{
2592 return SDL::GetJoystickButton(get(), button);
2593}
2594
2616inline bool RumbleJoystick(JoystickRef joystick,
2617 Uint16 low_frequency_rumble,
2618 Uint16 high_frequency_rumble,
2619 Uint32 duration_ms)
2620{
2621 return SDL_RumbleJoystick(
2622 joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
2623}
2624
2625inline bool Joystick::Rumble(Uint16 low_frequency_rumble,
2626 Uint16 high_frequency_rumble,
2627 Uint32 duration_ms)
2628{
2629 return SDL::RumbleJoystick(
2630 get(), low_frequency_rumble, high_frequency_rumble, duration_ms);
2631}
2632
2661 Uint16 left_rumble,
2662 Uint16 right_rumble,
2663 Uint32 duration_ms)
2664{
2665 CheckError(SDL_RumbleJoystickTriggers(
2666 joystick, left_rumble, right_rumble, duration_ms));
2667}
2668
2669inline void Joystick::RumbleTriggers(Uint16 left_rumble,
2670 Uint16 right_rumble,
2671 Uint32 duration_ms)
2672{
2673 SDL::RumbleJoystickTriggers(get(), left_rumble, right_rumble, duration_ms);
2674}
2675
2695inline void SetJoystickLED(JoystickRef joystick,
2696 Uint8 red,
2697 Uint8 green,
2698 Uint8 blue)
2699{
2700 CheckError(SDL_SetJoystickLED(joystick, red, green, blue));
2701}
2702
2703inline void Joystick::SetLED(Uint8 red, Uint8 green, Uint8 blue)
2704{
2705 SDL::SetJoystickLED(get(), red, green, blue);
2706}
2707
2720inline void SendJoystickEffect(JoystickRef joystick, const void* data, int size)
2721{
2722 CheckError(SDL_SendJoystickEffect(joystick, data, size));
2723}
2724
2725inline void Joystick::SendEffect(const void* data, int size)
2726{
2727 SDL::SendJoystickEffect(get(), data, size);
2728}
2729
2741inline void CloseJoystick(JoystickRaw joystick) { SDL_CloseJoystick(joystick); }
2742
2744
2757{
2758 return CheckError(SDL_GetJoystickConnectionState(joystick));
2759}
2760
2765
2786inline PowerState GetJoystickPowerInfo(JoystickRef joystick, int* percent)
2787{
2788 return SDL_GetJoystickPowerInfo(joystick, percent);
2789}
2790
2792{
2793 return SDL::GetJoystickPowerInfo(get(), percent);
2794}
2795
2797
2798} // namespace SDL
2799
2800#endif /* SDL3PP_JOYSTICK_H_ */
Locking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1183
~JoystickApiLock()
Unlocking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1217
JoystickApiLock & operator=(JoystickApiLock &&other) noexcept
Assignment operator.
Definition SDL3pp_joystick.h:1222
JoystickApiLock(const JoystickApiLock &other)=delete
Copy constructor.
void release()
Releases the lock without unlocking.
Definition SDL3pp_joystick.h:1242
JoystickApiLock(JoystickApiLock &&other) noexcept
Move constructor.
Definition SDL3pp_joystick.h:1204
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:141
constexpr JoystickID(JoystickIDRaw joystickID={}) noexcept
Wraps JoystickID.
Definition SDL3pp_joystick.h:150
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
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:2322
int GetJoystickPlayerIndexForID(JoystickID instance_id)
Get the player index of a joystick.
Definition SDL3pp_joystick.h:1382
constexpr JoystickType JOYSTICK_TYPE_COUNT
JOYSTICK_TYPE_COUNT.
Definition SDL3pp_joystick.h:127
Uint16 GetProductVersion()
Get the product version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2170
constexpr Uint8 HAT_UP
UP.
Definition SDL3pp_joystick.h:385
int GetNumJoystickHats(JoystickRef joystick)
Get the number of POV hats on a joystick.
Definition SDL3pp_joystick.h:2373
int GetJoystickPlayerIndexForID()
Get the player index of a joystick.
Definition SDL3pp_joystick.h:1387
int GetPlayerIndex()
Get the player index of an opened joystick.
Definition SDL3pp_joystick.h:2057
void LockJoysticks()
Locking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1256
bool IsJoystickVirtual()
Query whether or not a joystick is virtual.
Definition SDL3pp_joystick.h:1699
Uint16 GetJoystickVendorForID()
Get the USB vendor ID of a joystick, if available.
Definition SDL3pp_joystick.h:1440
SDL_JoystickConnectionState JoystickConnectionState
Possible connection states for a joystick device.
Definition SDL3pp_joystick.h:363
constexpr JoystickType JOYSTICK_TYPE_ARCADE_STICK
JOYSTICK_TYPE_ARCADE_STICK.
Definition SDL3pp_joystick.h:106
bool HasJoystick()
Return whether a joystick is currently connected.
Definition SDL3pp_joystick.h:1292
constexpr Uint8 HAT_LEFT
LEFT.
Definition SDL3pp_joystick.h:391
Uint16 GetJoystickProductForID(JoystickID instance_id)
Get the USB product ID of a joystick, if available.
Definition SDL3pp_joystick.h:1462
Uint16 GetProduct()
Get the USB product ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2149
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:1873
bool GetJoystickAxisInitialState(JoystickRef joystick, int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2504
int GetNumBalls()
Get the number of trackballs on a joystick.
Definition SDL3pp_joystick.h:2355
bool GetButton(int button)
Get the current state of a button on a joystick.
Definition SDL3pp_joystick.h:2590
Uint16 GetJoystickProduct(JoystickRef joystick)
Get the USB product ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2144
JoystickID AttachVirtualJoystick(const VirtualJoystickDesc &desc)
Attach a new virtual joystick.
Definition SDL3pp_joystick.h:1656
Sint16 GetAxis(int axis)
Get the current state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2483
SDL_VirtualJoystickSensorDesc VirtualJoystickSensorDesc
The structure that describes a virtual joystick sensor.
Definition SDL3pp_joystick.h:1609
Uint16 GetVendor()
Get the USB vendor ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2128
constexpr Uint8 HAT_DOWN
DOWN.
Definition SDL3pp_joystick.h:389
constexpr JoystickType JOYSTICK_TYPE_DRUM_KIT
JOYSTICK_TYPE_DRUM_KIT.
Definition SDL3pp_joystick.h:118
JoystickType GetJoystickType(JoystickRef joystick)
Get the type of an opened joystick.
Definition SDL3pp_joystick.h:2232
int GetJoystickPlayerIndex(JoystickRef joystick)
Get the player index of an opened joystick.
Definition SDL3pp_joystick.h:2052
constexpr JoystickConnectionState JOYSTICK_CONNECTION_INVALID
JOYSTICK_CONNECTION_INVALID.
Definition SDL3pp_joystick.h:365
constexpr JoystickConnectionState JOYSTICK_CONNECTION_UNKNOWN
JOYSTICK_CONNECTION_UNKNOWN.
Definition SDL3pp_joystick.h:368
GUID GetGUID()
Get the implementation-dependent GUID for the joystick.
Definition SDL3pp_joystick.h:2107
int GetNumHats()
Get the number of POV hats on a joystick.
Definition SDL3pp_joystick.h:2378
JoystickType GetJoystickTypeForID(JoystickID instance_id)
Get the type of a joystick, if available.
Definition SDL3pp_joystick.h:1515
JoystickRef GetJoystickFromPlayerIndex(int player_index)
Get the Joystick associated with a player index.
Definition SDL3pp_joystick.h:1588
Uint16 GetJoystickProductVersionForID()
Get the product version of a joystick, if available.
Definition SDL3pp_joystick.h:1494
SDL_JoystickType JoystickType
An enum of some common joystick types.
Definition SDL3pp_joystick.h:95
const char * GetPath()
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:2035
SDL_VirtualJoystickTouchpadDesc VirtualJoystickTouchpadDesc
The structure that describes a virtual joystick touchpad.
Definition SDL3pp_joystick.h:1600
constexpr JoystickType JOYSTICK_TYPE_WHEEL
JOYSTICK_TYPE_WHEEL.
Definition SDL3pp_joystick.h:103
bool GetJoystickButton(JoystickRef joystick, int button)
Get the current state of a button on a joystick.
Definition SDL3pp_joystick.h:2585
PowerState GetJoystickPowerInfo(JoystickRef joystick, int *percent)
Get the battery state of a joystick.
Definition SDL3pp_joystick.h:2786
constexpr Uint8 HAT_RIGHTDOWN
RIGHTDOWN.
Definition SDL3pp_joystick.h:395
void UpdateJoysticks()
Update the current state of the open joysticks.
Definition SDL3pp_joystick.h:2452
void SendJoystickEffect(JoystickRef joystick, const void *data, int size)
Send a joystick specific effect packet.
Definition SDL3pp_joystick.h:2720
Joystick OpenJoystick()
Open a joystick for use.
Definition SDL3pp_joystick.h:1551
void SendEffect(const void *data, int size)
Send a joystick specific effect packet.
Definition SDL3pp_joystick.h:2725
ResourceRef< Joystick > JoystickRef
Reference for Joystick.
Definition SDL3pp_joystick.h:68
void SetVirtualButton(int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition SDL3pp_joystick.h:1808
SDL_Joystick * JoystickRaw
Alias to raw representation for Joystick.
Definition SDL3pp_joystick.h:61
int GetNumJoystickBalls(JoystickRef joystick)
Get the number of trackballs on a joystick.
Definition SDL3pp_joystick.h:2350
void DetachVirtualJoystick(JoystickID instance_id)
Detach a virtual joystick.
Definition SDL3pp_joystick.h:1674
constexpr JoystickType JOYSTICK_TYPE_GUITAR
JOYSTICK_TYPE_GUITAR.
Definition SDL3pp_joystick.h:115
JoystickType GetJoystickTypeForID()
Get the type of a joystick, if available.
Definition SDL3pp_joystick.h:1520
void SetVirtualBall(int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition SDL3pp_joystick.h:1773
int GetNumAxes()
Get the number of general axis controls on a joystick.
Definition SDL3pp_joystick.h:2327
constexpr JoystickType JOYSTICK_TYPE_UNKNOWN
JOYSTICK_TYPE_UNKNOWN.
Definition SDL3pp_joystick.h:97
void DetachVirtualJoystick()
Detach a virtual joystick.
Definition SDL3pp_joystick.h:1679
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:1884
void SetLED(Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition SDL3pp_joystick.h:2703
void RumbleTriggers(Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
Start a rumble effect in the joystick's triggers.
Definition SDL3pp_joystick.h:2669
Uint16 GetJoystickVendorForID(JoystickID instance_id)
Get the USB vendor ID of a joystick, if available.
Definition SDL3pp_joystick.h:1435
Uint8 GetJoystickHat(JoystickRef joystick, int hat)
Get the current state of a POV hat on a joystick.
Definition SDL3pp_joystick.h:2561
void SetVirtualAxis(int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition SDL3pp_joystick.h:1736
Uint8 HatState
Represents tbe HatState for a Joystick.
Definition SDL3pp_joystick.h:381
constexpr Uint8 HAT_RIGHT
RIGHT.
Definition SDL3pp_joystick.h:387
constexpr JoystickType JOYSTICK_TYPE_FLIGHT_STICK
JOYSTICK_TYPE_FLIGHT_STICK.
Definition SDL3pp_joystick.h:109
constexpr JoystickType JOYSTICK_TYPE_GAMEPAD
JOYSTICK_TYPE_GAMEPAD.
Definition SDL3pp_joystick.h:100
constexpr JoystickType JOYSTICK_TYPE_DANCE_PAD
JOYSTICK_TYPE_DANCE_PAD.
Definition SDL3pp_joystick.h:112
void UnlockJoysticks()
Unlocking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1272
PropertiesRef GetProperties()
Get the properties associated with a joystick.
Definition SDL3pp_joystick.h:1967
const char * GetJoystickName(JoystickRef joystick)
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:2010
GUID GetJoystickGUIDForID()
Get the implementation-dependent GUID of a joystick.
Definition SDL3pp_joystick.h:1413
SDL_VirtualJoystickDesc VirtualJoystickDesc
The structure that describes a virtual joystick.
Definition SDL3pp_joystick.h:1624
Uint16 GetFirmwareVersion()
Get the firmware version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2192
constexpr Uint8 HAT_LEFTUP
LEFTUP.
Definition SDL3pp_joystick.h:397
constexpr JoystickType JOYSTICK_TYPE_THROTTLE
JOYSTICK_TYPE_THROTTLE.
Definition SDL3pp_joystick.h:124
Sint16 GetJoystickAxis(JoystickRef joystick, int axis)
Get the current state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2478
void SetJoystickVirtualBall(JoystickRef joystick, int ball, Sint16 xrel, Sint16 yrel)
Generate ball motion on an opened virtual joystick.
Definition SDL3pp_joystick.h:1765
const char * GetSerial()
Get the serial number of an opened joystick, if available.
Definition SDL3pp_joystick.h:2215
int GetNumJoystickButtons(JoystickRef joystick)
Get the number of buttons on a joystick.
Definition SDL3pp_joystick.h:2396
bool Rumble(Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition SDL3pp_joystick.h:2625
Uint16 GetJoystickVendor(JoystickRef joystick)
Get the USB vendor ID of an opened joystick, if available.
Definition SDL3pp_joystick.h:2123
OwnArray< JoystickID > GetJoysticks()
Get a list of currently connected joysticks.
Definition SDL3pp_joystick.h:1308
constexpr int JOYSTICK_AXIS_MAX
The largest value an Joystick's axis can report.
Definition SDL3pp_joystick.h:1158
constexpr int JOYSTICK_AXIS_MIN
The smallest value an Joystick's axis can report.
Definition SDL3pp_joystick.h:1169
Uint16 GetJoystickProductVersionForID(JoystickID instance_id)
Get the product version of a joystick, if available.
Definition SDL3pp_joystick.h:1489
void SetJoystickEventsEnabled(bool enabled)
Set the state of joystick event processing.
Definition SDL3pp_joystick.h:2421
constexpr Uint8 HAT_RIGHTUP
RIGHTUP.
Definition SDL3pp_joystick.h:393
void SetJoystickVirtualHat(JoystickRef joystick, int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition SDL3pp_joystick.h:1836
bool Connected()
Get the status of a specified joystick.
Definition SDL3pp_joystick.h:2282
GUID GetJoystickGUIDForID(JoystickID instance_id)
Get the implementation-dependent GUID of a joystick.
Definition SDL3pp_joystick.h:1408
const char * GetJoystickPath(JoystickRef joystick)
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:2030
Uint16 GetJoystickFirmwareVersion(JoystickRef joystick)
Get the firmware version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2187
constexpr Uint8 HAT_CENTERED
CENTERED.
Definition SDL3pp_joystick.h:383
JoystickType GetType()
Get the type of an opened joystick.
Definition SDL3pp_joystick.h:2237
Uint16 GetJoystickProductVersion(JoystickRef joystick)
Get the product version of an opened joystick, if available.
Definition SDL3pp_joystick.h:2165
const char * GetJoystickSerial(JoystickRef joystick)
Get the serial number of an opened joystick, if available.
Definition SDL3pp_joystick.h:2210
JoystickConnectionState GetJoystickConnectionState(JoystickRef joystick)
Get the connection state of a joystick.
Definition SDL3pp_joystick.h:2756
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRELESS
JOYSTICK_CONNECTION_WIRELESS.
Definition SDL3pp_joystick.h:374
bool JoystickConnected(JoystickRef joystick)
Get the status of a specified joystick.
Definition SDL3pp_joystick.h:2277
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:1929
bool GetAxisInitialState(int axis, Sint16 *state)
Get the initial state of an axis control on a joystick.
Definition SDL3pp_joystick.h:2511
SDL_JoystickID JoystickIDRaw
Alias to raw representation for JoystickID.
Definition SDL3pp_joystick.h:71
JoystickRef GetJoystickFromID(JoystickID instance_id)
Get the Joystick associated with an instance ID, if it has been opened.
Definition SDL3pp_joystick.h:1564
JoystickRef GetJoystickFromID()
Get the Joystick associated with an instance ID, if it has been opened.
Definition SDL3pp_joystick.h:1569
void Close()
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition SDL3pp_joystick.h:2743
bool JoystickEventsEnabled()
Query the state of joystick event processing.
Definition SDL3pp_joystick.h:2440
void reset()
Unlocking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1274
void CloseJoystick(JoystickRaw joystick)
Close a joystick previously opened with JoystickID.OpenJoystick().
Definition SDL3pp_joystick.h:2741
void SetJoystickLED(JoystickRef joystick, Uint8 red, Uint8 green, Uint8 blue)
Update a joystick's LED color.
Definition SDL3pp_joystick.h:2695
const char * GetJoystickPathForID()
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:1362
GUID GetJoystickGUID(JoystickRef joystick)
Get the implementation-dependent GUID for the joystick.
Definition SDL3pp_joystick.h:2102
void SetJoystickVirtualButton(JoystickRef joystick, int button, bool down)
Set the state of a button on an opened virtual joystick.
Definition SDL3pp_joystick.h:1801
void SetVirtualHat(int hat, Uint8 value)
Set the state of a hat on an opened virtual joystick.
Definition SDL3pp_joystick.h:1841
void SetJoystickPlayerIndex(JoystickRef joystick, int player_index)
Set the player index of an opened joystick.
Definition SDL3pp_joystick.h:2076
constexpr JoystickType JOYSTICK_TYPE_ARCADE_PAD
JOYSTICK_TYPE_ARCADE_PAD.
Definition SDL3pp_joystick.h:121
JoystickConnectionState GetConnectionState()
Get the connection state of a joystick.
Definition SDL3pp_joystick.h:2761
PowerState GetPowerInfo(int *percent)
Get the battery state of a joystick.
Definition SDL3pp_joystick.h:2791
PropertiesRef GetJoystickProperties(JoystickRef joystick)
Get the properties associated with a joystick.
Definition SDL3pp_joystick.h:1962
bool IsJoystickVirtual(JoystickID instance_id)
Query whether or not a joystick is virtual.
Definition SDL3pp_joystick.h:1694
bool RumbleJoystick(JoystickRef joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Start a rumble effect.
Definition SDL3pp_joystick.h:2616
JoystickID GetID()
Get the instance ID of an opened joystick.
Definition SDL3pp_joystick.h:2300
constexpr JoystickConnectionState JOYSTICK_CONNECTION_WIRED
JOYSTICK_CONNECTION_WIRED.
Definition SDL3pp_joystick.h:371
const char * GetJoystickNameForID()
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:1336
const char * GetJoystickPathForID(JoystickID instance_id)
Get the implementation dependent path of a joystick.
Definition SDL3pp_joystick.h:1357
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:2257
constexpr Uint8 HAT_LEFTDOWN
LEFTDOWN.
Definition SDL3pp_joystick.h:399
Joystick OpenJoystick(JoystickID instance_id)
Open a joystick for use.
Definition SDL3pp_joystick.h:1541
const char * GetName()
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:2015
Uint8 GetHat(int hat)
Get the current state of a POV hat on a joystick.
Definition SDL3pp_joystick.h:2566
void SetPlayerIndex(int player_index)
Set the player index of an opened joystick.
Definition SDL3pp_joystick.h:2081
void GetBall(int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition SDL3pp_joystick.h:2541
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:2660
Uint16 GetJoystickProductForID()
Get the USB product ID of a joystick, if available.
Definition SDL3pp_joystick.h:1467
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:1919
void GetJoystickBall(JoystickRef joystick, int ball, int *dx, int *dy)
Get the ball axis change since the last poll.
Definition SDL3pp_joystick.h:2536
const char * GetJoystickNameForID(JoystickID instance_id)
Get the implementation dependent name of a joystick.
Definition SDL3pp_joystick.h:1331
void SetJoystickVirtualAxis(JoystickRef joystick, int axis, Sint16 value)
Set the state of an axis on an opened virtual joystick.
Definition SDL3pp_joystick.h:1731
JoystickApiLock()
Locking for atomic access to the joystick API.
Definition SDL3pp_joystick.h:1258
int GetNumButtons()
Get the number of buttons on a joystick.
Definition SDL3pp_joystick.h:2401
JoystickID GetJoystickID(JoystickRef joystick)
Get the instance ID of an opened joystick.
Definition SDL3pp_joystick.h:2295
SDL_PowerState PowerState
The basic state for the system's power supply.
Definition SDL3pp_power.h:38
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
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:102
Uint16 crc16(Uint16 crc, const void *data, size_t len)
Calculate a CRC-16 value.
Definition SDL3pp_stdinc.h:2176
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:264
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:290
::Sint16 Sint16
A signed 16-bit integer type.
Definition SDL3pp_stdinc.h:251
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:238
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:320
Joystick capability properties.
Definition SDL3pp_joystick.h:1982
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
The joystick structure used to identify an SDL joystick.
Definition SDL3pp_joystick.h:411
Joystick & operator=(const Joystick &other)=delete
Assignment operator.
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr Joystick(const Joystick &other)=delete
Copy constructor.
~Joystick()
Destructor.
Definition SDL3pp_joystick.h:457
constexpr Joystick & operator=(Joystick &&other) noexcept
Assignment operator.
Definition SDL3pp_joystick.h:460
constexpr Joystick(Joystick &&other) noexcept
Move constructor.
Definition SDL3pp_joystick.h:430
constexpr Joystick(JoystickRaw resource) noexcept
Constructs from raw Joystick.
Definition SDL3pp_joystick.h:421
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156