Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

409 строки
14 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2018 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 joyid);
  170. /**
  171. * Return the name for this currently opened joystick.
  172. * If no name can be found, this function returns NULL.
  173. */
  174. extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
  175. /**
  176. * Get the player index of an opened joystick, or -1 if it's not available
  177. *
  178. * For XInput controllers this returns the XInput user index.
  179. */
  180. extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick * joystick);
  181. /**
  182. * Return the GUID for this opened joystick
  183. */
  184. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
  185. /**
  186. * Get the USB vendor ID of an opened joystick, if available.
  187. * If the vendor ID isn't available this function returns 0.
  188. */
  189. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick * joystick);
  190. /**
  191. * Get the USB product ID of an opened joystick, if available.
  192. * If the product ID isn't available this function returns 0.
  193. */
  194. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick * joystick);
  195. /**
  196. * Get the product version of an opened joystick, if available.
  197. * If the product version isn't available this function returns 0.
  198. */
  199. extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick * joystick);
  200. /**
  201. * Get the type of an opened joystick.
  202. */
  203. extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick * joystick);
  204. /**
  205. * Return a string representation for this guid. pszGUID must point to at least 33 bytes
  206. * (32 for the string plus a NULL terminator).
  207. */
  208. extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
  209. /**
  210. * Convert a string into a joystick guid
  211. */
  212. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
  213. /**
  214. * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
  215. */
  216. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
  217. /**
  218. * Get the instance ID of an opened joystick or -1 if the joystick is invalid.
  219. */
  220. extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
  221. /**
  222. * Get the number of general axis controls on a joystick.
  223. */
  224. extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
  225. /**
  226. * Get the number of trackballs on a joystick.
  227. *
  228. * Joystick trackballs have only relative motion events associated
  229. * with them and their state cannot be polled.
  230. */
  231. extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
  232. /**
  233. * Get the number of POV hats on a joystick.
  234. */
  235. extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
  236. /**
  237. * Get the number of buttons on a joystick.
  238. */
  239. extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
  240. /**
  241. * Update the current state of the open joysticks.
  242. *
  243. * This is called automatically by the event loop if any joystick
  244. * events are enabled.
  245. */
  246. extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
  247. /**
  248. * Enable/disable joystick event polling.
  249. *
  250. * If joystick events are disabled, you must call SDL_JoystickUpdate()
  251. * yourself and check the state of the joystick when you want joystick
  252. * information.
  253. *
  254. * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
  255. */
  256. extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
  257. #define SDL_JOYSTICK_AXIS_MAX 32767
  258. #define SDL_JOYSTICK_AXIS_MIN -32768
  259. /**
  260. * Get the current state of an axis control on a joystick.
  261. *
  262. * The state is a value ranging from -32768 to 32767.
  263. *
  264. * The axis indices start at index 0.
  265. */
  266. extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
  267. int axis);
  268. /**
  269. * Get the initial state of an axis control on a joystick.
  270. *
  271. * The state is a value ranging from -32768 to 32767.
  272. *
  273. * The axis indices start at index 0.
  274. *
  275. * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
  276. */
  277. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick * joystick,
  278. int axis, Sint16 *state);
  279. /**
  280. * \name Hat positions
  281. */
  282. /* @{ */
  283. #define SDL_HAT_CENTERED 0x00
  284. #define SDL_HAT_UP 0x01
  285. #define SDL_HAT_RIGHT 0x02
  286. #define SDL_HAT_DOWN 0x04
  287. #define SDL_HAT_LEFT 0x08
  288. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  289. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  290. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  291. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  292. /* @} */
  293. /**
  294. * Get the current state of a POV hat on a joystick.
  295. *
  296. * The hat indices start at index 0.
  297. *
  298. * \return The return value is one of the following positions:
  299. * - ::SDL_HAT_CENTERED
  300. * - ::SDL_HAT_UP
  301. * - ::SDL_HAT_RIGHT
  302. * - ::SDL_HAT_DOWN
  303. * - ::SDL_HAT_LEFT
  304. * - ::SDL_HAT_RIGHTUP
  305. * - ::SDL_HAT_RIGHTDOWN
  306. * - ::SDL_HAT_LEFTUP
  307. * - ::SDL_HAT_LEFTDOWN
  308. */
  309. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
  310. int hat);
  311. /**
  312. * Get the ball axis change since the last poll.
  313. *
  314. * \return 0, or -1 if you passed it invalid parameters.
  315. *
  316. * The ball indices start at index 0.
  317. */
  318. extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
  319. int ball, int *dx, int *dy);
  320. /**
  321. * Get the current state of a button on a joystick.
  322. *
  323. * The button indices start at index 0.
  324. */
  325. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
  326. int button);
  327. /**
  328. * Trigger a rumble effect
  329. * Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling.
  330. *
  331. * \param joystick The joystick to vibrate
  332. * \param low_frequency_rumble The intensity of the low frequency (left) rumble motor, from 0 to 0xFFFF
  333. * \param high_frequency_rumble The intensity of the high frequency (right) rumble motor, from 0 to 0xFFFF
  334. * \param duration_ms The duration of the rumble effect, in milliseconds
  335. *
  336. * \return 0, or -1 if rumble isn't supported on this joystick
  337. */
  338. extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  339. /**
  340. * Close a joystick previously opened with SDL_JoystickOpen().
  341. */
  342. extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
  343. /**
  344. * Return the battery level of this joystick
  345. */
  346. extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
  347. /* Ends C function definitions when using C++ */
  348. #ifdef __cplusplus
  349. }
  350. #endif
  351. #include "close_code.h"
  352. #endif /* SDL_joystick_h_ */
  353. /* vi: set ts=4 sw=4 expandtab: */