00001 /* 00002 SDL - Simple DirectMedia Layer 00003 Copyright (C) 1997-2009 Sam Lantinga 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 Sam Lantinga 00020 slouken@libsdl.org 00021 */ 00022 00029 #ifndef _SDL_joystick_h 00030 #define _SDL_joystick_h 00031 00032 #include "SDL_stdinc.h" 00033 #include "SDL_error.h" 00034 00035 #include "begin_code.h" 00036 /* Set up for C function definitions, even when using C++ */ 00037 #ifdef __cplusplus 00038 /* *INDENT-OFF* */ 00039 extern "C" { 00040 /* *INDENT-ON* */ 00041 #endif 00042 00043 /* In order to use these functions, SDL_Init() must have been called 00044 with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system 00045 for joysticks, and load appropriate drivers. 00046 */ 00047 00048 /* The joystick structure used to identify an SDL joystick */ 00049 struct _SDL_Joystick; 00050 typedef struct _SDL_Joystick SDL_Joystick; 00051 00052 00053 /* Function prototypes */ 00054 /* 00055 * Count the number of joysticks attached to the system 00056 */ 00057 extern DECLSPEC int SDLCALL SDL_NumJoysticks(void); 00058 00059 /* 00060 * Get the implementation dependent name of a joystick. 00061 * This can be called before any joysticks are opened. 00062 * If no name can be found, this function returns NULL. 00063 */ 00064 extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index); 00065 00066 /* 00067 * Open a joystick for use - the index passed as an argument refers to 00068 * the N'th joystick on the system. This index is the value which will 00069 * identify this joystick in future joystick events. 00070 * 00071 * This function returns a joystick identifier, or NULL if an error occurred. 00072 */ 00073 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index); 00074 00075 /* 00076 * Returns 1 if the joystick has been opened, or 0 if it has not. 00077 */ 00078 extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index); 00079 00080 /* 00081 * Get the device index of an opened joystick. 00082 */ 00083 extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick); 00084 00085 /* 00086 * Get the number of general axis controls on a joystick 00087 */ 00088 extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick); 00089 00090 /* 00091 * Get the number of trackballs on a joystick 00092 * Joystick trackballs have only relative motion events associated 00093 * with them and their state cannot be polled. 00094 */ 00095 extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick); 00096 00097 /* 00098 * Get the number of POV hats on a joystick 00099 */ 00100 extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick); 00101 00102 /* 00103 * Get the number of buttons on a joystick 00104 */ 00105 extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick); 00106 00107 /* 00108 * Update the current state of the open joysticks. 00109 * This is called automatically by the event loop if any joystick 00110 * events are enabled. 00111 */ 00112 extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void); 00113 00114 /* 00115 * Enable/disable joystick event polling. 00116 * If joystick events are disabled, you must call SDL_JoystickUpdate() 00117 * yourself and check the state of the joystick when you want joystick 00118 * information. 00119 * The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE. 00120 */ 00121 extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state); 00122 00123 /* 00124 * Get the current state of an axis control on a joystick 00125 * The state is a value ranging from -32768 to 32767. 00126 * The axis indices start at index 0. 00127 */ 00128 extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick, 00129 int axis); 00130 00131 /* 00132 * Get the current state of a POV hat on a joystick 00133 * The return value is one of the following positions: 00134 */ 00135 #define SDL_HAT_CENTERED 0x00 00136 #define SDL_HAT_UP 0x01 00137 #define SDL_HAT_RIGHT 0x02 00138 #define SDL_HAT_DOWN 0x04 00139 #define SDL_HAT_LEFT 0x08 00140 #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP) 00141 #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN) 00142 #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP) 00143 #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN) 00144 /* 00145 * The hat indices start at index 0. 00146 */ 00147 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick, 00148 int hat); 00149 00150 /* 00151 * Get the ball axis change since the last poll 00152 * This returns 0, or -1 if you passed it invalid parameters. 00153 * The ball indices start at index 0. 00154 */ 00155 extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick, 00156 int ball, int *dx, int *dy); 00157 00158 /* 00159 * Get the current state of a button on a joystick 00160 * The button indices start at index 0. 00161 */ 00162 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick, 00163 int button); 00164 00165 /* 00166 * Close a joystick previously opened with SDL_JoystickOpen() 00167 */ 00168 extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick); 00169 00170 00171 /* Ends C function definitions when using C++ */ 00172 #ifdef __cplusplus 00173 /* *INDENT-OFF* */ 00174 } 00175 /* *INDENT-ON* */ 00176 #endif 00177 #include "close_code.h" 00178 00179 #endif /* _SDL_joystick_h */ 00180 00181 /* vi: set ts=4 sw=4 expandtab: */