SDL standard library
SDL_joystick.h@0:dda4f4550403, 2016-09-07 (annotated)
- Committer:
- miruga27
- Date:
- Wed Sep 07 18:46:53 2016 +0000
- Revision:
- 0:dda4f4550403
7/09/2016;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
miruga27 | 0:dda4f4550403 | 1 | /* |
miruga27 | 0:dda4f4550403 | 2 | Simple DirectMedia Layer |
miruga27 | 0:dda4f4550403 | 3 | Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> |
miruga27 | 0:dda4f4550403 | 4 | |
miruga27 | 0:dda4f4550403 | 5 | This software is provided 'as-is', without any express or implied |
miruga27 | 0:dda4f4550403 | 6 | warranty. In no event will the authors be held liable for any damages |
miruga27 | 0:dda4f4550403 | 7 | arising from the use of this software. |
miruga27 | 0:dda4f4550403 | 8 | |
miruga27 | 0:dda4f4550403 | 9 | Permission is granted to anyone to use this software for any purpose, |
miruga27 | 0:dda4f4550403 | 10 | including commercial applications, and to alter it and redistribute it |
miruga27 | 0:dda4f4550403 | 11 | freely, subject to the following restrictions: |
miruga27 | 0:dda4f4550403 | 12 | |
miruga27 | 0:dda4f4550403 | 13 | 1. The origin of this software must not be misrepresented; you must not |
miruga27 | 0:dda4f4550403 | 14 | claim that you wrote the original software. If you use this software |
miruga27 | 0:dda4f4550403 | 15 | in a product, an acknowledgment in the product documentation would be |
miruga27 | 0:dda4f4550403 | 16 | appreciated but is not required. |
miruga27 | 0:dda4f4550403 | 17 | 2. Altered source versions must be plainly marked as such, and must not be |
miruga27 | 0:dda4f4550403 | 18 | misrepresented as being the original software. |
miruga27 | 0:dda4f4550403 | 19 | 3. This notice may not be removed or altered from any source distribution. |
miruga27 | 0:dda4f4550403 | 20 | */ |
miruga27 | 0:dda4f4550403 | 21 | |
miruga27 | 0:dda4f4550403 | 22 | /** |
miruga27 | 0:dda4f4550403 | 23 | * \file SDL_joystick.h |
miruga27 | 0:dda4f4550403 | 24 | * |
miruga27 | 0:dda4f4550403 | 25 | * Include file for SDL joystick event handling |
miruga27 | 0:dda4f4550403 | 26 | * |
miruga27 | 0:dda4f4550403 | 27 | * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks, with the exact joystick |
miruga27 | 0:dda4f4550403 | 28 | * behind a device_index changing as joysticks are plugged and unplugged. |
miruga27 | 0:dda4f4550403 | 29 | * |
miruga27 | 0:dda4f4550403 | 30 | * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted |
miruga27 | 0:dda4f4550403 | 31 | * then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in. |
miruga27 | 0:dda4f4550403 | 32 | * |
miruga27 | 0:dda4f4550403 | 33 | * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of |
miruga27 | 0:dda4f4550403 | 34 | * the device (a X360 wired controller for example). This identifier is platform dependent. |
miruga27 | 0:dda4f4550403 | 35 | * |
miruga27 | 0:dda4f4550403 | 36 | * |
miruga27 | 0:dda4f4550403 | 37 | */ |
miruga27 | 0:dda4f4550403 | 38 | |
miruga27 | 0:dda4f4550403 | 39 | #ifndef _SDL_joystick_h |
miruga27 | 0:dda4f4550403 | 40 | #define _SDL_joystick_h |
miruga27 | 0:dda4f4550403 | 41 | |
miruga27 | 0:dda4f4550403 | 42 | #include "SDL_stdinc.h" |
miruga27 | 0:dda4f4550403 | 43 | #include "SDL_error.h" |
miruga27 | 0:dda4f4550403 | 44 | |
miruga27 | 0:dda4f4550403 | 45 | #include "begin_code.h" |
miruga27 | 0:dda4f4550403 | 46 | /* Set up for C function definitions, even when using C++ */ |
miruga27 | 0:dda4f4550403 | 47 | #ifdef __cplusplus |
miruga27 | 0:dda4f4550403 | 48 | extern "C" { |
miruga27 | 0:dda4f4550403 | 49 | #endif |
miruga27 | 0:dda4f4550403 | 50 | |
miruga27 | 0:dda4f4550403 | 51 | /** |
miruga27 | 0:dda4f4550403 | 52 | * \file SDL_joystick.h |
miruga27 | 0:dda4f4550403 | 53 | * |
miruga27 | 0:dda4f4550403 | 54 | * In order to use these functions, SDL_Init() must have been called |
miruga27 | 0:dda4f4550403 | 55 | * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system |
miruga27 | 0:dda4f4550403 | 56 | * for joysticks, and load appropriate drivers. |
miruga27 | 0:dda4f4550403 | 57 | * |
miruga27 | 0:dda4f4550403 | 58 | * If you would like to receive joystick updates while the application |
miruga27 | 0:dda4f4550403 | 59 | * is in the background, you should set the following hint before calling |
miruga27 | 0:dda4f4550403 | 60 | * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS |
miruga27 | 0:dda4f4550403 | 61 | */ |
miruga27 | 0:dda4f4550403 | 62 | |
miruga27 | 0:dda4f4550403 | 63 | /* The joystick structure used to identify an SDL joystick */ |
miruga27 | 0:dda4f4550403 | 64 | struct _SDL_Joystick; |
miruga27 | 0:dda4f4550403 | 65 | typedef struct _SDL_Joystick SDL_Joystick; |
miruga27 | 0:dda4f4550403 | 66 | |
miruga27 | 0:dda4f4550403 | 67 | /* A structure that encodes the stable unique id for a joystick device */ |
miruga27 | 0:dda4f4550403 | 68 | typedef struct { |
miruga27 | 0:dda4f4550403 | 69 | Uint8 data[16]; |
miruga27 | 0:dda4f4550403 | 70 | } SDL_JoystickGUID; |
miruga27 | 0:dda4f4550403 | 71 | |
miruga27 | 0:dda4f4550403 | 72 | typedef Sint32 SDL_JoystickID; |
miruga27 | 0:dda4f4550403 | 73 | |
miruga27 | 0:dda4f4550403 | 74 | |
miruga27 | 0:dda4f4550403 | 75 | /* Function prototypes */ |
miruga27 | 0:dda4f4550403 | 76 | /** |
miruga27 | 0:dda4f4550403 | 77 | * Count the number of joysticks attached to the system right now |
miruga27 | 0:dda4f4550403 | 78 | */ |
miruga27 | 0:dda4f4550403 | 79 | extern DECLSPEC int SDLCALL SDL_NumJoysticks(void); |
miruga27 | 0:dda4f4550403 | 80 | |
miruga27 | 0:dda4f4550403 | 81 | /** |
miruga27 | 0:dda4f4550403 | 82 | * Get the implementation dependent name of a joystick. |
miruga27 | 0:dda4f4550403 | 83 | * This can be called before any joysticks are opened. |
miruga27 | 0:dda4f4550403 | 84 | * If no name can be found, this function returns NULL. |
miruga27 | 0:dda4f4550403 | 85 | */ |
miruga27 | 0:dda4f4550403 | 86 | extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index); |
miruga27 | 0:dda4f4550403 | 87 | |
miruga27 | 0:dda4f4550403 | 88 | /** |
miruga27 | 0:dda4f4550403 | 89 | * Open a joystick for use. |
miruga27 | 0:dda4f4550403 | 90 | * The index passed as an argument refers tothe N'th joystick on the system. |
miruga27 | 0:dda4f4550403 | 91 | * This index is the value which will identify this joystick in future joystick |
miruga27 | 0:dda4f4550403 | 92 | * events. |
miruga27 | 0:dda4f4550403 | 93 | * |
miruga27 | 0:dda4f4550403 | 94 | * \return A joystick identifier, or NULL if an error occurred. |
miruga27 | 0:dda4f4550403 | 95 | */ |
miruga27 | 0:dda4f4550403 | 96 | extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index); |
miruga27 | 0:dda4f4550403 | 97 | |
miruga27 | 0:dda4f4550403 | 98 | /** |
miruga27 | 0:dda4f4550403 | 99 | * Return the name for this currently opened joystick. |
miruga27 | 0:dda4f4550403 | 100 | * If no name can be found, this function returns NULL. |
miruga27 | 0:dda4f4550403 | 101 | */ |
miruga27 | 0:dda4f4550403 | 102 | extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 103 | |
miruga27 | 0:dda4f4550403 | 104 | /** |
miruga27 | 0:dda4f4550403 | 105 | * Return the GUID for the joystick at this index |
miruga27 | 0:dda4f4550403 | 106 | */ |
miruga27 | 0:dda4f4550403 | 107 | extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index); |
miruga27 | 0:dda4f4550403 | 108 | |
miruga27 | 0:dda4f4550403 | 109 | /** |
miruga27 | 0:dda4f4550403 | 110 | * Return the GUID for this opened joystick |
miruga27 | 0:dda4f4550403 | 111 | */ |
miruga27 | 0:dda4f4550403 | 112 | extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 113 | |
miruga27 | 0:dda4f4550403 | 114 | /** |
miruga27 | 0:dda4f4550403 | 115 | * Return a string representation for this guid. pszGUID must point to at least 33 bytes |
miruga27 | 0:dda4f4550403 | 116 | * (32 for the string plus a NULL terminator). |
miruga27 | 0:dda4f4550403 | 117 | */ |
miruga27 | 0:dda4f4550403 | 118 | extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID); |
miruga27 | 0:dda4f4550403 | 119 | |
miruga27 | 0:dda4f4550403 | 120 | /** |
miruga27 | 0:dda4f4550403 | 121 | * convert a string into a joystick formatted guid |
miruga27 | 0:dda4f4550403 | 122 | */ |
miruga27 | 0:dda4f4550403 | 123 | extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID); |
miruga27 | 0:dda4f4550403 | 124 | |
miruga27 | 0:dda4f4550403 | 125 | /** |
miruga27 | 0:dda4f4550403 | 126 | * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not. |
miruga27 | 0:dda4f4550403 | 127 | */ |
miruga27 | 0:dda4f4550403 | 128 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 129 | |
miruga27 | 0:dda4f4550403 | 130 | /** |
miruga27 | 0:dda4f4550403 | 131 | * Get the instance ID of an opened joystick or -1 if the joystick is invalid. |
miruga27 | 0:dda4f4550403 | 132 | */ |
miruga27 | 0:dda4f4550403 | 133 | extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 134 | |
miruga27 | 0:dda4f4550403 | 135 | /** |
miruga27 | 0:dda4f4550403 | 136 | * Get the number of general axis controls on a joystick. |
miruga27 | 0:dda4f4550403 | 137 | */ |
miruga27 | 0:dda4f4550403 | 138 | extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 139 | |
miruga27 | 0:dda4f4550403 | 140 | /** |
miruga27 | 0:dda4f4550403 | 141 | * Get the number of trackballs on a joystick. |
miruga27 | 0:dda4f4550403 | 142 | * |
miruga27 | 0:dda4f4550403 | 143 | * Joystick trackballs have only relative motion events associated |
miruga27 | 0:dda4f4550403 | 144 | * with them and their state cannot be polled. |
miruga27 | 0:dda4f4550403 | 145 | */ |
miruga27 | 0:dda4f4550403 | 146 | extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 147 | |
miruga27 | 0:dda4f4550403 | 148 | /** |
miruga27 | 0:dda4f4550403 | 149 | * Get the number of POV hats on a joystick. |
miruga27 | 0:dda4f4550403 | 150 | */ |
miruga27 | 0:dda4f4550403 | 151 | extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 152 | |
miruga27 | 0:dda4f4550403 | 153 | /** |
miruga27 | 0:dda4f4550403 | 154 | * Get the number of buttons on a joystick. |
miruga27 | 0:dda4f4550403 | 155 | */ |
miruga27 | 0:dda4f4550403 | 156 | extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 157 | |
miruga27 | 0:dda4f4550403 | 158 | /** |
miruga27 | 0:dda4f4550403 | 159 | * Update the current state of the open joysticks. |
miruga27 | 0:dda4f4550403 | 160 | * |
miruga27 | 0:dda4f4550403 | 161 | * This is called automatically by the event loop if any joystick |
miruga27 | 0:dda4f4550403 | 162 | * events are enabled. |
miruga27 | 0:dda4f4550403 | 163 | */ |
miruga27 | 0:dda4f4550403 | 164 | extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void); |
miruga27 | 0:dda4f4550403 | 165 | |
miruga27 | 0:dda4f4550403 | 166 | /** |
miruga27 | 0:dda4f4550403 | 167 | * Enable/disable joystick event polling. |
miruga27 | 0:dda4f4550403 | 168 | * |
miruga27 | 0:dda4f4550403 | 169 | * If joystick events are disabled, you must call SDL_JoystickUpdate() |
miruga27 | 0:dda4f4550403 | 170 | * yourself and check the state of the joystick when you want joystick |
miruga27 | 0:dda4f4550403 | 171 | * information. |
miruga27 | 0:dda4f4550403 | 172 | * |
miruga27 | 0:dda4f4550403 | 173 | * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE. |
miruga27 | 0:dda4f4550403 | 174 | */ |
miruga27 | 0:dda4f4550403 | 175 | extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state); |
miruga27 | 0:dda4f4550403 | 176 | |
miruga27 | 0:dda4f4550403 | 177 | /** |
miruga27 | 0:dda4f4550403 | 178 | * Get the current state of an axis control on a joystick. |
miruga27 | 0:dda4f4550403 | 179 | * |
miruga27 | 0:dda4f4550403 | 180 | * The state is a value ranging from -32768 to 32767. |
miruga27 | 0:dda4f4550403 | 181 | * |
miruga27 | 0:dda4f4550403 | 182 | * The axis indices start at index 0. |
miruga27 | 0:dda4f4550403 | 183 | */ |
miruga27 | 0:dda4f4550403 | 184 | extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick, |
miruga27 | 0:dda4f4550403 | 185 | int axis); |
miruga27 | 0:dda4f4550403 | 186 | |
miruga27 | 0:dda4f4550403 | 187 | /** |
miruga27 | 0:dda4f4550403 | 188 | * \name Hat positions |
miruga27 | 0:dda4f4550403 | 189 | */ |
miruga27 | 0:dda4f4550403 | 190 | /* @{ */ |
miruga27 | 0:dda4f4550403 | 191 | #define SDL_HAT_CENTERED 0x00 |
miruga27 | 0:dda4f4550403 | 192 | #define SDL_HAT_UP 0x01 |
miruga27 | 0:dda4f4550403 | 193 | #define SDL_HAT_RIGHT 0x02 |
miruga27 | 0:dda4f4550403 | 194 | #define SDL_HAT_DOWN 0x04 |
miruga27 | 0:dda4f4550403 | 195 | #define SDL_HAT_LEFT 0x08 |
miruga27 | 0:dda4f4550403 | 196 | #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP) |
miruga27 | 0:dda4f4550403 | 197 | #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN) |
miruga27 | 0:dda4f4550403 | 198 | #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP) |
miruga27 | 0:dda4f4550403 | 199 | #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN) |
miruga27 | 0:dda4f4550403 | 200 | /* @} */ |
miruga27 | 0:dda4f4550403 | 201 | |
miruga27 | 0:dda4f4550403 | 202 | /** |
miruga27 | 0:dda4f4550403 | 203 | * Get the current state of a POV hat on a joystick. |
miruga27 | 0:dda4f4550403 | 204 | * |
miruga27 | 0:dda4f4550403 | 205 | * The hat indices start at index 0. |
miruga27 | 0:dda4f4550403 | 206 | * |
miruga27 | 0:dda4f4550403 | 207 | * \return The return value is one of the following positions: |
miruga27 | 0:dda4f4550403 | 208 | * - ::SDL_HAT_CENTERED |
miruga27 | 0:dda4f4550403 | 209 | * - ::SDL_HAT_UP |
miruga27 | 0:dda4f4550403 | 210 | * - ::SDL_HAT_RIGHT |
miruga27 | 0:dda4f4550403 | 211 | * - ::SDL_HAT_DOWN |
miruga27 | 0:dda4f4550403 | 212 | * - ::SDL_HAT_LEFT |
miruga27 | 0:dda4f4550403 | 213 | * - ::SDL_HAT_RIGHTUP |
miruga27 | 0:dda4f4550403 | 214 | * - ::SDL_HAT_RIGHTDOWN |
miruga27 | 0:dda4f4550403 | 215 | * - ::SDL_HAT_LEFTUP |
miruga27 | 0:dda4f4550403 | 216 | * - ::SDL_HAT_LEFTDOWN |
miruga27 | 0:dda4f4550403 | 217 | */ |
miruga27 | 0:dda4f4550403 | 218 | extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick, |
miruga27 | 0:dda4f4550403 | 219 | int hat); |
miruga27 | 0:dda4f4550403 | 220 | |
miruga27 | 0:dda4f4550403 | 221 | /** |
miruga27 | 0:dda4f4550403 | 222 | * Get the ball axis change since the last poll. |
miruga27 | 0:dda4f4550403 | 223 | * |
miruga27 | 0:dda4f4550403 | 224 | * \return 0, or -1 if you passed it invalid parameters. |
miruga27 | 0:dda4f4550403 | 225 | * |
miruga27 | 0:dda4f4550403 | 226 | * The ball indices start at index 0. |
miruga27 | 0:dda4f4550403 | 227 | */ |
miruga27 | 0:dda4f4550403 | 228 | extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick, |
miruga27 | 0:dda4f4550403 | 229 | int ball, int *dx, int *dy); |
miruga27 | 0:dda4f4550403 | 230 | |
miruga27 | 0:dda4f4550403 | 231 | /** |
miruga27 | 0:dda4f4550403 | 232 | * Get the current state of a button on a joystick. |
miruga27 | 0:dda4f4550403 | 233 | * |
miruga27 | 0:dda4f4550403 | 234 | * The button indices start at index 0. |
miruga27 | 0:dda4f4550403 | 235 | */ |
miruga27 | 0:dda4f4550403 | 236 | extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick, |
miruga27 | 0:dda4f4550403 | 237 | int button); |
miruga27 | 0:dda4f4550403 | 238 | |
miruga27 | 0:dda4f4550403 | 239 | /** |
miruga27 | 0:dda4f4550403 | 240 | * Close a joystick previously opened with SDL_JoystickOpen(). |
miruga27 | 0:dda4f4550403 | 241 | */ |
miruga27 | 0:dda4f4550403 | 242 | extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick); |
miruga27 | 0:dda4f4550403 | 243 | |
miruga27 | 0:dda4f4550403 | 244 | |
miruga27 | 0:dda4f4550403 | 245 | /* Ends C function definitions when using C++ */ |
miruga27 | 0:dda4f4550403 | 246 | #ifdef __cplusplus |
miruga27 | 0:dda4f4550403 | 247 | } |
miruga27 | 0:dda4f4550403 | 248 | #endif |
miruga27 | 0:dda4f4550403 | 249 | #include "close_code.h" |
miruga27 | 0:dda4f4550403 | 250 | |
miruga27 | 0:dda4f4550403 | 251 | #endif /* _SDL_joystick_h */ |
miruga27 | 0:dda4f4550403 | 252 | |
miruga27 | 0:dda4f4550403 | 253 | /* vi: set ts=4 sw=4 expandtab: */ |