| 1 | /* |
| 2 | Copyright (c) 2015, Cong Xu |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are met: |
| 6 | |
| 7 | Redistributions of source code must retain the above copyright notice, this |
| 8 | list of conditions and the following disclaimer. |
| 9 | Redistributions in binary form must reproduce the above copyright notice, |
| 10 | this list of conditions and the following disclaimer in the documentation |
| 11 | and/or other materials provided with the distribution. |
| 12 | |
| 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 17 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 23 | POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | #ifndef _SDL_joystickbuttonnames_h |
| 26 | #define _SDL_joystickbuttonnames_h |
| 27 | |
| 28 | #include <SDL_gamecontroller.h> |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | /** |
| 35 | * \return -1 on error; 0 on success |
| 36 | */ |
| 37 | int SDLJBN_Init(void); |
| 38 | |
| 39 | void SDLJBN_Quit(void); |
| 40 | |
| 41 | /** |
| 42 | * Load a set of mappings from a file |
| 43 | * |
| 44 | * \return number of mappings added, -1 on error |
| 45 | */ |
| 46 | int SDLJBN_AddMappingsFromFile(const char *file); |
| 47 | |
| 48 | /** |
| 49 | * Load a set of mappings from a SDL_RWops object |
| 50 | * |
| 51 | * \return number of mappings added, -1 on error |
| 52 | */ |
| 53 | int SDLJBN_AddMappingsFromRW(SDL_RWops *rw, int freerw); |
| 54 | |
| 55 | /** |
| 56 | * Get the button name and color for an SDL_GameControllerButton |
| 57 | * Arguments can be set to NULL if they are not required |
| 58 | * Use SDLJBN_GetError to get the error reason |
| 59 | * |
| 60 | * \return -1 on error; 0 on success |
| 61 | */ |
| 62 | int SDLJBN_GetButtonNameAndColor(SDL_Joystick *joystick, |
| 63 | SDL_GameControllerButton button, |
| 64 | char *s, Uint8 *r, Uint8 *g, Uint8 *b); |
| 65 | /** |
| 66 | * Get the axis name and color for an SDL_GameControllerAxis |
| 67 | * Arguments can be set to NULL if they are not required |
| 68 | * Use SDLJBN_GetError to get the error reason |
| 69 | * |
| 70 | * \return -1 on error; 0 on success |
| 71 | */ |
| 72 | int SDLJBN_GetAxisNameAndColor(SDL_Joystick *joystick, |
| 73 | SDL_GameControllerAxis axis, |
| 74 | char *s, Uint8 *r, Uint8 *g, Uint8 *b); |
| 75 | |
| 76 | /* Convenience macros */ |
| 77 | #define SDLJBN_GetButtonName(joystick, button, s)\ |
| 78 | SDLJBN_GetButtonNameAndColor(joystick, button, s, NULL, NULL, NULL); |
| 79 | #define SDLJBN_GetButtonColor(joystick, button, r, g, b)\ |
| 80 | SDLJBN_GetButtonNameAndColor(joystick, button, NULL, r, g, b); |
| 81 | #define SDLJBN_GetAxisName(joystick, axis, s)\ |
| 82 | SDLJBN_GetAxisNameAndColor(joystick, axis, s, NULL, NULL, NULL); |
| 83 | #define SDLJBN_GetAxisColor(joystick, axis, r, g, b)\ |
| 84 | SDLJBN_GetAxisNameAndColor(joystick, axis, NULL, r, g, b); |
| 85 | |
| 86 | const char *SDLJBN_GetError(void); |
| 87 | |
| 88 | #ifdef __cplusplus |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | #endif |