DEADSOFTWARE

f7583101539b4faa2e1ac8a1f56af7ae781503cd
[d2df-sdl.git] / src / lib / sdl2 / sdlgamecontroller.inc
1 //from sdl_gamecontroller.h
3 {**
4 * SDL_gamecontroller.h
5 *
6 * In order to use these functions, SDL_Init() must have been called
7 * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
8 * for game controllers, and load appropriate drivers.
9 *
10 * If you would like to receive controller updates while the application
11 * is in the background, you should set the following hint before calling
12 * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
13 *}
15 {* The gamecontroller structure used to identify an SDL game controller *}
16 type
17 PSDL_GameController = ^TSDL_GameController;
18 TSDL_GameController = Pointer; //todo
20 TSDL_GameControllerBindType = (SDL_CONTROLLER_BINDTYPE_NONE,
21 SDL_CONTROLLER_BINDTYPE_BUTTON,
22 SDL_CONTROLLER_BINDTYPE_AXIS,
23 SDL_CONTROLLER_BINDTYPE_HAT);
25 {**
26 * Get the SDL joystick layer binding for this controller button/axis mapping
27 *}
28 THat = record
29 hat: Integer;
30 hat_mask: Integer;
31 end;
33 TSDL_GameControllerButtonBind = record
34 bindType: TSDL_GameControllerBindType;
35 case Integer of
36 0: ( button: Integer; );
37 1: ( axis: Integer; );
38 2: ( hat: THat; );
39 end;
41 {**
42 * To count the number of game controllers in the system for the following:
43 * int nJoysticks = SDL_NumJoysticks();
44 * int nGameControllers = 0;
45 * for ( int i = 0; i < nJoysticks; i++ ) {
46 * if ( SDL_IsGameController(i) ) {
47 * nGameControllers++;
48 *
49 *
50 *
51 * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
52 * guid,name,mappings
53 *
54 * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
55 * Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
56 * The mapping format for joystick is:
57 * bX - a joystick button, index X
58 * hX.Y - hat X with value Y
59 * aX - axis X of the joystick
60 * Buttons can be used as a controller axis and vice versa.
61 *
62 * This string shows an example of a valid mapping for a controller
63 * "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7",
64 *
65 *}
67 {**
68 * Add or update an existing mapping configuration
69 *
70 * 1 if mapping is added, 0 if updated, -1 on error
71 *}
72 function SDL_GameControllerAddMapping( mappingString: PAnsiChar ): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerAddMapping' {$ENDIF} {$ENDIF};
74 {**
75 * Load a set of mappings from a seekable SDL data stream (memory or file), filtered by the current SDL_GetPlatform()
76 * A community sourced database of controllers is available at https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt
77 *
78 * If freerw is non-zero, the stream will be closed after being read.
79 *
80 * Returns number of mappings added, -1 on error
81 *}
82 function SDL_GameControllerAddMappingsFromRW(rw: PSDL_RWops; freerw: SInt32):SInt32;
83 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerAddMappingsFromRW' {$ENDIF} {$ENDIF};
85 {**
86 * Get a mapping string for a GUID
87 *
88 * the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available
89 *}
90 function SDL_GameControllerMappingForGUID( guid: TSDL_JoystickGUID ): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerMappingForGUID' {$ENDIF} {$ENDIF};
92 {**
93 * Get a mapping string for an open GameController
94 *
95 * the mapping string. Must be freed with SDL_free. Returns NULL if no mapping is available
96 *}
97 function SDL_GameControllerMapping( gamecontroller: PSDL_GameController ): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerMapping' {$ENDIF} {$ENDIF};
99 {**
100 * Is the joystick on this index supported by the game controller interface?
101 *}
102 function SDL_IsGameController(joystick_index: Integer): TSDL_Bool cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_IsGameController' {$ENDIF} {$ENDIF};
104 {**
105 * Get the implementation dependent name of a game controller.
106 * This can be called before any controllers are opened.
107 * If no name can be found, this function returns NULL.
108 *}
109 function SDL_GameControllerNameForIndex(joystick_index: Integer): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerNameForIndex' {$ENDIF} {$ENDIF};
111 {**
112 * Open a game controller for use.
113 * The index passed as an argument refers to the N'th game controller on the system.
114 * This index is the value which will identify this controller in future controller
115 * events.
117 * A controller identifier, or NULL if an error occurred.
118 *}
119 function SDL_GameControllerOpen(joystick_index: Integer): PSDL_GameController cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerOpen' {$ENDIF} {$ENDIF};
121 {**
122 * Return the name for this currently opened controller
123 *}
124 function SDL_GameControllerName(gamecontroller: PSDL_GameController): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerName' {$ENDIF} {$ENDIF};
126 {**
127 * Returns SDL_TRUE if the controller has been opened and currently connected,
128 * or SDL_FALSE if it has not.
129 *}
130 function SDL_GameControllerGetAttached(gamecontroller: PSDL_GameController): TSDL_Bool cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetAttached' {$ENDIF} {$ENDIF};
132 {**
133 * Get the underlying joystick object used by a controller
134 *}
135 function SDL_GameControllerGetJoystick(gamecontroller: PSDL_GameController): PSDL_Joystick cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetJoystick' {$ENDIF} {$ENDIF};
137 {**
138 * Enable/disable controller event polling.
140 * If controller events are disabled, you must call SDL_GameControllerUpdate()
141 * yourself and check the state of the controller when you want controller
142 * information.
144 * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
145 *}
146 function SDL_GameControllerEventState(state: Integer): Integer cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerEventState' {$ENDIF} {$ENDIF};
148 {**
149 * Update the current state of the open game controllers.
151 * This is called automatically by the event loop if any game controller
152 * events are enabled.
153 *}
154 procedure SDL_GameControllerUpdate() cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerUpdate' {$ENDIF} {$ENDIF};
156 {**
157 * The list of axes available from a controller
158 *}
160 const
161 SDL_CONTROLLER_AXIS_INVALID = -1;
162 SDL_CONTROLLER_AXIS_LEFTX = 0;
163 SDL_CONTROLLER_AXIS_LEFTY = 1;
164 SDL_CONTROLLER_AXIS_RIGHTX = 2;
165 SDL_CONTROLLER_AXIS_RIGHTY = 3;
166 SDL_CONTROLLER_AXIS_TRIGGERLEFT = 4;
167 SDL_CONTROLLER_AXIS_TRIGGERRIGHT = 5;
168 SDL_CONTROLLER_AXIS_MAX = 6;
169 type
170 TSDL_GameControllerAxis = Byte;
172 {**
173 * turn this string into a axis mapping
174 *}
175 function SDL_GameControllerGetAxisFromString(pchString: PAnsiChar): TSDL_GameControllerAxis cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetAxisFromString' {$ENDIF} {$ENDIF};
177 {**
178 * turn this axis enum into a string mapping
179 *}
180 function SDL_GameControllerGetStringForAxis(axis: TSDL_GameControllerAxis): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetStringForAxis' {$ENDIF} {$ENDIF};
182 {**
183 * Get the SDL joystick layer binding for this controller button mapping
184 *}
185 function SDL_GameControllerGetBindForAxis(gamecontroller: PSDL_GameController; axis: TSDL_GameControllerAxis): TSDL_GameControllerButtonBind cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetBindForAxis' {$ENDIF} {$ENDIF};
187 {**
188 * Get the current state of an axis control on a game controller.
190 * The state is a value ranging from -32768 to 32767.
192 * The axis indices start at index 0.
193 *}
194 function SDL_GameControllerGetAxis(gamecontroller: PSDL_GameController; axis: TSDL_GameControllerAxis): SInt16 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetAxis' {$ENDIF} {$ENDIF};
196 {**
197 * The list of buttons available from a controller
198 *}
199 const
200 SDL_CONTROLLER_BUTTON_INVALID = -1;
201 SDL_CONTROLLER_BUTTON_A = 0;
202 SDL_CONTROLLER_BUTTON_B = 1;
203 SDL_CONTROLLER_BUTTON_X = 2;
204 SDL_CONTROLLER_BUTTON_Y = 3;
205 SDL_CONTROLLER_BUTTON_BACK = 4;
206 SDL_CONTROLLER_BUTTON_GUIDE = 5;
207 SDL_CONTROLLER_BUTTON_START = 6;
208 SDL_CONTROLLER_BUTTON_LEFTSTICK = 7;
209 SDL_CONTROLLER_BUTTON_RIGHTSTICK = 8;
210 SDL_CONTROLLER_BUTTON_LEFTSHOULDER = 9;
211 SDL_CONTROLLER_BUTTON_RIGHTSHOULDER = 10;
212 SDL_CONTROLLER_BUTTON_DPAD_UP = 11;
213 SDL_CONTROLLER_BUTTON_DPAD_DOWN = 12;
214 SDL_CONTROLLER_BUTTON_DPAD_LEFT = 13;
215 SDL_CONTROLLER_BUTTON_DPAD_RIGHT = 14;
216 SDL_CONTROLLER_BUTTON_MAX = 15;
217 type
218 TSDL_GameControllerButton = Byte;
220 {**
221 * turn this string into a button mapping
222 *}
223 function SDL_GameControllerGetButtonFromString(pchString: PAnsiChar): TSDL_GameControllerButton cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetButtonFromString' {$ENDIF} {$ENDIF};
225 {**
226 * turn this button enum into a string mapping
227 *}
228 function SDL_GameControllerGetStringForButton(button: TSDL_GameControllerButton): PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetStringForButton' {$ENDIF} {$ENDIF};
230 {**
231 * Get the SDL joystick layer binding for this controller button mapping
232 *}
233 function SDL_GameControllerGetBindForButton(gamecontroller: PSDL_GameController; button: TSDL_GameControllerButton): TSDL_GameControllerButtonBind cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetBindForButton' {$ENDIF} {$ENDIF};
236 {**
237 * Get the current state of a button on a game controller.
239 * The button indices start at index 0.
240 *}
241 function SDL_GameControllerGetButton(gamecontroller: PSDL_GameController; button: TSDL_GameControllerButton): UInt8 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerGetButton' {$ENDIF} {$ENDIF};
243 {**
244 * Close a controller previously opened with SDL_GameControllerOpen().
245 *}
246 procedure SDL_GameControllerClose(gamecontroller: PSDL_GameController) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GameControllerClose' {$ENDIF} {$ENDIF};
249 function SDL_GameControllerAddMappingsFromFile(Const FilePath:PAnsiChar):SInt32;