🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

453 lines
15 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_joystick.h
  20. *
  21. * Include file for SDL joystick event handling
  22. *
  23. * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick
  24. * behind a device_index changing as joysticks are plugged and unplugged.
  25. *
  26. * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
  27. * then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
  28. *
  29. * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of
  30. * the device (a X360 wired controller for example). This identifier is platform dependent.
  31. *
  32. *
  33. */
  34. #ifndef SDL_joystick_h_
  35. #define SDL_joystick_h_
  36. #include "SDL_stdinc.h"
  37. #include "SDL_error.h"
  38. #include "begin_code.h"
  39. /* Set up for C function definitions, even when using C++ */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. * \file SDL_joystick.h
  45. *
  46. * In order to use these functions, SDL_Init() must have been called
  47. * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
  48. * for joysticks, and load appropriate drivers.
  49. *
  50. * If you would like to receive joystick updates while the application
  51. * is in the background, you should set the following hint before calling
  52. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  53. */
  54. /**
  55. * The joystick structure used to identify an SDL joystick
  56. */
  57. struct _SDL_Joystick;
  58. typedef struct _SDL_Joystick SDL_Joystick;
  59. /* A structure that encodes the stable unique id for a joystick device */
  60. typedef struct {
  61. Uint8 data[16];
  62. } SDL_JoystickGUID;
  63. /**
  64. * This is a unique ID for a joystick for the time it is connected to the system,
  65. * and is never reused for the lifetime of the application. If the joystick is
  66. * disconnected and reconnected, it will get a new ID.
  67. *
  68. * The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
  69. */
  70. typedef Sint32 SDL_JoystickID;
  71. typedef enum
  72. {
  73. SDL_JOYSTICK_TYPE_UNKNOWN,
  74. SDL_JOYSTICK_TYPE_GAMECONTROLLER,
  75. SDL_JOYSTICK_TYPE_WHEEL,
  76. SDL_JOYSTICK_TYPE_ARCADE_STICK,
  77. SDL_JOYSTICK_TYPE_FLIGHT_STICK,
  78. SDL_JOYSTICK_TYPE_DANCE_PAD,
  79. SDL_JOYSTICK_TYPE_GUITAR,
  80. SDL_JOYSTICK_TYPE_DRUM_KIT,
  81. SDL_JOYSTICK_TYPE_ARCADE_PAD,
  82. SDL_JOYSTICK_TYPE_THROTTLE
  83. } SDL_JoystickType;
  84. typedef enum
  85. {
  86. SDL_JOYSTICK_POWER_UNKNOWN = -1,
  87. SDL_JOYSTICK_POWER_EMPTY, /* <= 5% */
  88. SDL_JOYSTICK_POWER_LOW, /* <= 20% */
  89. SDL_JOYSTICK_POWER_MEDIUM, /* <= 70% */
  90. SDL_JOYSTICK_POWER_FULL, /* <= 100% */
  91. SDL_JOYSTICK_POWER_WIRED,
  92. SDL_JOYSTICK_POWER_MAX
  93. } SDL_JoystickPowerLevel;
  94. /* Function prototypes */
  95. /**
  96. * Locking for multi-threaded access to the joystick API
  97. *
  98. * If you are using the joystick API or handling events from multiple threads
  99. * you should use these locking functions to protect access to the joysticks.
  100. *
  101. * In particular, you are guaranteed that the joystick list won't change, so
  102. * the API functions that take a joystick index will be valid, and joystick
  103. * and game controller events will not be delivered.
  104. */
  105. extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);
  106. extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void);
  107. /**
  108. * Count the number of joysticks attached to the system right now
  109. */
  110. extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
  111. /**
  112. * Get the implementation dependent name of a joystick.
  113. * This can be called before any joysticks are opened.
  114. * If no name can be found, this function returns NULL.
  115. */
  116. extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
  117. /**
  118. * Get the player index of a joystick, or -1 if it's not available
  119. * This can be called before any joysticks are opened.
  120. */
  121. extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index);
  122. /**
  123. * Return the GUID for the joystick at this index
  124. * This can be called before any joysticks are opened.
  125. */
  126. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
  127. /**
  128. * Get the USB vendor ID of a joystick, if available.
  129. * This can be called before any joysticks are opened.
  130. * If the vendor ID isn't available this function returns 0.
  131. */
  132. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
  133. /**
  134. * Get the USB product ID of a joystick, if available.
  135. * This can be called before any joysticks are opened.
  136. * If the product ID isn't available this function returns 0.
  137. */
  138. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
  139. /**
  140. * Get the product version of a joystick, if available.
  141. * This can be called before any joysticks are opened.
  142. * If the product version isn't available this function returns 0.
  143. */
  144. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
  145. /**
  146. * Get the type of a joystick, if available.
  147. * This can be called before any joysticks are opened.
  148. */
  149. extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
  150. /**
  151. * Get the instance ID of a joystick.
  152. * This can be called before any joysticks are opened.
  153. * If the index is out of range, this function will return -1.
  154. */
  155. extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index);
  156. /**
  157. * Open a joystick for use.
  158. * The index passed as an argument refers to the N'th joystick on the system.
  159. * This index is not the value which will identify this joystick in future
  160. * joystick events. The joystick's instance id (::SDL_JoystickID) will be used
  161. * there instead.
  162. *
  163. * \return A joystick identifier, or NULL if an error occurred.
  164. */
  165. extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
  166. /**
  167. * Return the SDL_Joystick associated with an instance id.
  168. */
  169. extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID instance_id);
  170. /**
  171. * Return the SDL_Joystick associated with a player index.
  172. */
  173. extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromPlayerIndex(int player_index);
  174. /**
  175. * Attaches a new virtual joystick.
  176. * Returns the joystick's device index, or -1 if an error occurred.
  177. */
  178. extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type,
  179. int naxes,
  180. int nbuttons,
  181. int nhats);
  182. /**
  183. * Detaches a virtual joystick
  184. * Returns 0 on success, or -1 if an error occurred.
  185. */
  186. extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);
  187. /**
  188. * Indicates whether or not a virtual-joystick is at a given device index.
  189. */
  190. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);
  191. /**
  192. * Set values on an opened, virtual-joystick's controls.
  193. * Please note that values set here will not be applied until the next
  194. * call to SDL_JoystickUpdate, which can either be called directly,
  195. * or can be called indirectly through various other SDL APIS,
  196. * including, but not limited to the following: SDL_PollEvent,
  197. * SDL_PumpEvents, SDL_WaitEventTimeout, SDL_WaitEvent.
  198. *
  199. * Returns 0 on success, -1 on error.
  200. */
  201. extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick * joystick, int axis, Sint16 value);
  202. extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick * joystick, int button, Uint8 value);
  203. extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick * joystick, int hat, Uint8 value);
  204. /**
  205. * Return the name for this currently opened joystick.
  206. * If no name can be found, this function returns NULL.
  207. */
  208. extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
  209. /**
  210. * Get the player index of an opened joystick, or -1 if it's not available
  211. *
  212. * For XInput controllers this returns the XInput user index.
  213. */
  214. extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick * joystick);
  215. /**
  216. * Set the player index of an opened joystick
  217. */
  218. extern DECLSPEC void SDLCALL SDL_JoystickSetPlayerIndex(SDL_Joystick * joystick, int player_index);
  219. /**
  220. * Return the GUID for this opened joystick
  221. */
  222. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
  223. /**
  224. * Get the USB vendor ID of an opened joystick, if available.
  225. * If the vendor ID isn't available this function returns 0.
  226. */
  227. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick * joystick);
  228. /**
  229. * Get the USB product ID of an opened joystick, if available.
  230. * If the product ID isn't available this function returns 0.
  231. */
  232. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick * joystick);
  233. /**
  234. * Get the product version of an opened joystick, if available.
  235. * If the product version isn't available this function returns 0.
  236. */
  237. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick * joystick);
  238. /**
  239. * Get the type of an opened joystick.
  240. */
  241. extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick * joystick);
  242. /**
  243. * Return a string representation for this guid. pszGUID must point to at least 33 bytes
  244. * (32 for the string plus a NULL terminator).
  245. */
  246. extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
  247. /**
  248. * Convert a string into a joystick guid
  249. */
  250. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
  251. /**
  252. * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
  253. */
  254. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
  255. /**
  256. * Get the instance ID of an opened joystick or -1 if the joystick is invalid.
  257. */
  258. extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
  259. /**
  260. * Get the number of general axis controls on a joystick.
  261. */
  262. extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
  263. /**
  264. * Get the number of trackballs on a joystick.
  265. *
  266. * Joystick trackballs have only relative motion events associated
  267. * with them and their state cannot be polled.
  268. */
  269. extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
  270. /**
  271. * Get the number of POV hats on a joystick.
  272. */
  273. extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
  274. /**
  275. * Get the number of buttons on a joystick.
  276. */
  277. extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
  278. /**
  279. * Update the current state of the open joysticks.
  280. *
  281. * This is called automatically by the event loop if any joystick
  282. * events are enabled.
  283. */
  284. extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
  285. /**
  286. * Enable/disable joystick event polling.
  287. *
  288. * If joystick events are disabled, you must call SDL_JoystickUpdate()
  289. * yourself and check the state of the joystick when you want joystick
  290. * information.
  291. *
  292. * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
  293. */
  294. extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
  295. #define SDL_JOYSTICK_AXIS_MAX 32767
  296. #define SDL_JOYSTICK_AXIS_MIN -32768
  297. /**
  298. * Get the current state of an axis control on a joystick.
  299. *
  300. * The state is a value ranging from -32768 to 32767.
  301. *
  302. * The axis indices start at index 0.
  303. */
  304. extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
  305. int axis);
  306. /**
  307. * Get the initial state of an axis control on a joystick.
  308. *
  309. * The state is a value ranging from -32768 to 32767.
  310. *
  311. * The axis indices start at index 0.
  312. *
  313. * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
  314. */
  315. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick * joystick,
  316. int axis, Sint16 *state);
  317. /**
  318. * \name Hat positions
  319. */
  320. /* @{ */
  321. #define SDL_HAT_CENTERED 0x00
  322. #define SDL_HAT_UP 0x01
  323. #define SDL_HAT_RIGHT 0x02
  324. #define SDL_HAT_DOWN 0x04
  325. #define SDL_HAT_LEFT 0x08
  326. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  327. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  328. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  329. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  330. /* @} */
  331. /**
  332. * Get the current state of a POV hat on a joystick.
  333. *
  334. * The hat indices start at index 0.
  335. *
  336. * \return The return value is one of the following positions:
  337. * - ::SDL_HAT_CENTERED
  338. * - ::SDL_HAT_UP
  339. * - ::SDL_HAT_RIGHT
  340. * - ::SDL_HAT_DOWN
  341. * - ::SDL_HAT_LEFT
  342. * - ::SDL_HAT_RIGHTUP
  343. * - ::SDL_HAT_RIGHTDOWN
  344. * - ::SDL_HAT_LEFTUP
  345. * - ::SDL_HAT_LEFTDOWN
  346. */
  347. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
  348. int hat);
  349. /**
  350. * Get the ball axis change since the last poll.
  351. *
  352. * \return 0, or -1 if you passed it invalid parameters.
  353. *
  354. * The ball indices start at index 0.
  355. */
  356. extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
  357. int ball, int *dx, int *dy);
  358. /**
  359. * Get the current state of a button on a joystick.
  360. *
  361. * The button indices start at index 0.
  362. */
  363. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
  364. int button);
  365. /**
  366. * Trigger a rumble effect
  367. * Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling.
  368. *
  369. * \param joystick The joystick to vibrate
  370. * \param low_frequency_rumble The intensity of the low frequency (left) rumble motor, from 0 to 0xFFFF
  371. * \param high_frequency_rumble The intensity of the high frequency (right) rumble motor, from 0 to 0xFFFF
  372. * \param duration_ms The duration of the rumble effect, in milliseconds
  373. *
  374. * \return 0, or -1 if rumble isn't supported on this joystick
  375. */
  376. extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  377. /**
  378. * Close a joystick previously opened with SDL_JoystickOpen().
  379. */
  380. extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
  381. /**
  382. * Return the battery level of this joystick
  383. */
  384. extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
  385. /* Ends C function definitions when using C++ */
  386. #ifdef __cplusplus
  387. }
  388. #endif
  389. #include "close_code.h"
  390. #endif /* SDL_joystick_h_ */
  391. /* vi: set ts=4 sw=4 expandtab: */