SDL_joystick.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 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. /* The joystick structure used to identify an SDL joystick */
  55. struct _SDL_Joystick;
  56. typedef struct _SDL_Joystick SDL_Joystick;
  57. /* A structure that encodes the stable unique id for a joystick device */
  58. typedef struct {
  59. Uint8 data[16];
  60. } SDL_JoystickGUID;
  61. typedef Sint32 SDL_JoystickID;
  62. /* Function prototypes */
  63. /**
  64. * Count the number of joysticks attached to the system right now
  65. */
  66. extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
  67. /**
  68. * Get the implementation dependent name of a joystick.
  69. * This can be called before any joysticks are opened.
  70. * If no name can be found, this function returns NULL.
  71. */
  72. extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
  73. /**
  74. * Open a joystick for use.
  75. * The index passed as an argument refers tothe N'th joystick on the system.
  76. * This index is the value which will identify this joystick in future joystick
  77. * events.
  78. *
  79. * \return A joystick identifier, or NULL if an error occurred.
  80. */
  81. extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
  82. /**
  83. * Return the name for this currently opened joystick.
  84. * If no name can be found, this function returns NULL.
  85. */
  86. extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
  87. /**
  88. * Return the GUID for the joystick at this index
  89. */
  90. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
  91. /**
  92. * Return the GUID for this opened joystick
  93. */
  94. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
  95. /**
  96. * Return a string representation for this guid. pszGUID must point to at least 33 bytes
  97. * (32 for the string plus a NULL terminator).
  98. */
  99. extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
  100. /**
  101. * convert a string into a joystick formatted guid
  102. */
  103. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
  104. /**
  105. * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
  106. */
  107. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
  108. /**
  109. * Get the instance ID of an opened joystick or -1 if the joystick is invalid.
  110. */
  111. extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
  112. /**
  113. * Get the number of general axis controls on a joystick.
  114. */
  115. extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
  116. /**
  117. * Get the number of trackballs on a joystick.
  118. *
  119. * Joystick trackballs have only relative motion events associated
  120. * with them and their state cannot be polled.
  121. */
  122. extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
  123. /**
  124. * Get the number of POV hats on a joystick.
  125. */
  126. extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
  127. /**
  128. * Get the number of buttons on a joystick.
  129. */
  130. extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
  131. /**
  132. * Update the current state of the open joysticks.
  133. *
  134. * This is called automatically by the event loop if any joystick
  135. * events are enabled.
  136. */
  137. extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
  138. /**
  139. * Enable/disable joystick event polling.
  140. *
  141. * If joystick events are disabled, you must call SDL_JoystickUpdate()
  142. * yourself and check the state of the joystick when you want joystick
  143. * information.
  144. *
  145. * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
  146. */
  147. extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
  148. /**
  149. * Get the current state of an axis control on a joystick.
  150. *
  151. * The state is a value ranging from -32768 to 32767.
  152. *
  153. * The axis indices start at index 0.
  154. */
  155. extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
  156. int axis);
  157. /**
  158. * \name Hat positions
  159. */
  160. /* @{ */
  161. #define SDL_HAT_CENTERED 0x00
  162. #define SDL_HAT_UP 0x01
  163. #define SDL_HAT_RIGHT 0x02
  164. #define SDL_HAT_DOWN 0x04
  165. #define SDL_HAT_LEFT 0x08
  166. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  167. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  168. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  169. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  170. /* @} */
  171. /**
  172. * Get the current state of a POV hat on a joystick.
  173. *
  174. * The hat indices start at index 0.
  175. *
  176. * \return The return value is one of the following positions:
  177. * - ::SDL_HAT_CENTERED
  178. * - ::SDL_HAT_UP
  179. * - ::SDL_HAT_RIGHT
  180. * - ::SDL_HAT_DOWN
  181. * - ::SDL_HAT_LEFT
  182. * - ::SDL_HAT_RIGHTUP
  183. * - ::SDL_HAT_RIGHTDOWN
  184. * - ::SDL_HAT_LEFTUP
  185. * - ::SDL_HAT_LEFTDOWN
  186. */
  187. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
  188. int hat);
  189. /**
  190. * Get the ball axis change since the last poll.
  191. *
  192. * \return 0, or -1 if you passed it invalid parameters.
  193. *
  194. * The ball indices start at index 0.
  195. */
  196. extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
  197. int ball, int *dx, int *dy);
  198. /**
  199. * Get the current state of a button on a joystick.
  200. *
  201. * The button indices start at index 0.
  202. */
  203. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
  204. int button);
  205. /**
  206. * Close a joystick previously opened with SDL_JoystickOpen().
  207. */
  208. extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
  209. /* Ends C function definitions when using C++ */
  210. #ifdef __cplusplus
  211. }
  212. #endif
  213. #include "close_code.h"
  214. #endif /* _SDL_joystick_h */
  215. /* vi: set ts=4 sw=4 expandtab: */