author | koda |
Thu, 22 Oct 2009 18:59:35 +0000 | |
changeset 2575 | d06e0e829828 |
parent 2567 | 02ff5f9510b5 |
child 2579 | e5e4ebf528b5 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uKeys; |
|
20 |
interface |
|
345 | 21 |
uses uConsts; |
4 | 22 |
{$INCLUDE options.inc} |
167 | 23 |
|
24 |
type TBinds = array[0..cKeyMaxIndex] of shortstring; |
|
2567 | 25 |
type TKeyboardState = array[0..cKeyMaxIndex] of Byte; |
4 | 26 |
|
2567 | 27 |
function KeyNameToCode(name: string): word; |
4 | 28 |
procedure ProcessKbd; |
29 |
procedure ResetKbd; |
|
948 | 30 |
procedure FreezeEnterKey; |
4 | 31 |
procedure InitKbdKeyTable; |
32 |
||
167 | 33 |
procedure SetBinds(var binds: TBinds); |
34 |
procedure SetDefaultBinds; |
|
35 |
||
2428 | 36 |
procedure ControllerInit; |
37 |
procedure ControllerClose; |
|
38 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
39 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
40 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
41 |
||
42 |
var hideAmmoMenu: boolean; |
|
2379 | 43 |
wheelUp: boolean = false; |
44 |
wheelDown: boolean = false; |
|
2567 | 45 |
{$IFDEF IPHONEOS} |
46 |
leftClick: boolean = false; |
|
47 |
middleClick: boolean = false; |
|
48 |
rightClick: boolean = false; |
|
161 | 49 |
|
2567 | 50 |
upKey: boolean = false; |
51 |
downKey: boolean = false; |
|
52 |
rightKey: boolean = false; |
|
53 |
leftKey: boolean = false; |
|
54 |
||
55 |
spaceKey: boolean = false; |
|
56 |
enterKey: boolean = false; |
|
57 |
{$ENDIF} |
|
2428 | 58 |
ControllerNumControllers: Integer; |
59 |
ControllerEnabled: Integer; |
|
60 |
ControllerNumAxes: array[0..5] of Integer; |
|
61 |
//ControllerNumBalls: array[0..5] of Integer; |
|
62 |
ControllerNumHats: array[0..5] of Integer; |
|
63 |
ControllerNumButtons: array[0..5] of Integer; |
|
64 |
ControllerAxes: array[0..5] of array[0..19] of Integer; |
|
65 |
//ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer; |
|
66 |
ControllerHats: array[0..5] of array[0..19] of Byte; |
|
67 |
ControllerButtons: array[0..5] of array[0..19] of Byte; |
|
68 |
||
4 | 69 |
implementation |
2222 | 70 |
uses SDLh, uTeams, uConsole, uMisc, uStore; |
109 | 71 |
const KeyNumber = 1024; |
167 | 72 |
|
2436 | 73 |
var tkbd, tkbdn: TKeyboardState; |
4 | 74 |
KeyNames: array [0..cKeyMaxIndex] of string[15]; |
167 | 75 |
DefaultBinds, CurrentBinds: TBinds; |
4 | 76 |
|
77 |
function KeyNameToCode(name: string): word; |
|
351 | 78 |
var Result: Word; |
4 | 79 |
begin |
80 |
Result:= cKeyMaxIndex; |
|
351 | 81 |
while (Result > 0) and (KeyNames[Result] <> name) do dec(Result); |
82 |
KeyNameToCode:= Result |
|
4 | 83 |
end; |
84 |
||
85 |
procedure ProcessKbd; |
|
2428 | 86 |
var i, j, k: LongInt; |
2436 | 87 |
s: shortstring; |
4 | 88 |
pkbd: PByteArray; |
167 | 89 |
Trusted: boolean; |
4 | 90 |
begin |
2428 | 91 |
hideAmmoMenu:= false; |
167 | 92 |
Trusted:= (CurrentTeam <> nil) |
351 | 93 |
and (not CurrentTeam^.ExtDriven) |
846 | 94 |
and (CurrentHedgehog^.BotLevel = 0); |
161 | 95 |
|
2428 | 96 |
// move cursor/camera |
97 |
// TODO: Scale on screen dimensions and/or axis value (game controller)? |
|
98 |
movecursor(5 * CursorMovementX, 5 * CursorMovementY); |
|
2436 | 99 |
|
2152 | 100 |
{$IFDEF SDL13} |
2436 | 101 |
pkbd := SDL_GetKeyboardState(@j); |
102 |
k := SDL_GetMouseState(0, nil, nil); |
|
2152 | 103 |
{$ELSE} |
2436 | 104 |
pkbd := SDL_GetKeyState(@j); |
105 |
k := SDL_GetMouseState(nil, nil); |
|
2152 | 106 |
{$ENDIF} |
2436 | 107 |
|
108 |
for i:= 6 to pred(j) do // first 6 will be overwritten |
|
109 |
tkbdn[i]:= pkbd^[i]; |
|
110 |
||
2379 | 111 |
// mouse buttons |
2152 | 112 |
{$IFDEF DARWIN} |
2436 | 113 |
tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305])); |
114 |
tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4); |
|
2152 | 115 |
{$ELSE} |
2436 | 116 |
tkbdn[1]:= (k and 1); |
117 |
tkbdn[3]:= ((k shr 2) and 1); |
|
2152 | 118 |
{$ENDIF} |
2436 | 119 |
tkbdn[2]:= ((k shr 1) and 1); |
2328 | 120 |
|
2379 | 121 |
// mouse wheels (see event loop in project file) |
2436 | 122 |
tkbdn[4]:= ord(wheelDown); |
123 |
tkbdn[5]:= ord(wheelUp); |
|
2379 | 124 |
wheelUp:= false; |
125 |
wheelDown:= false; |
|
2567 | 126 |
{$IFDEF IPHONEOS} |
127 |
tkbdn[1]:= ord(leftClick); |
|
128 |
tkbdn[2]:= ord(middleClick); |
|
129 |
tkbdn[3]:= ord(rightClick); |
|
130 |
leftClick:= false; |
|
131 |
middleClick:= false; |
|
132 |
rightClick:= false; |
|
133 |
||
134 |
{* |
|
135 |
//sdl1.3 for these keys is messed up |
|
136 |
tkbdn[273]:= ord(upKey); |
|
137 |
tkbdn[274]:= ord(downKey); |
|
138 |
tkbdn[275]:= ord(rightKey); |
|
139 |
tkbdn[276]:= ord(leftKey); |
|
140 |
||
141 |
tkbdn[32]:= ord(spaceKey); |
|
142 |
tkbdn[13]:= ord(enterKey); |
|
143 |
||
144 |
upKey:= false; |
|
145 |
downKey:= false; |
|
146 |
rightKey:= false; |
|
147 |
leftKey:= false; |
|
148 |
||
149 |
spaceKey:= false; |
|
150 |
enterKey:= false; |
|
151 |
*} |
|
152 |
{$ENDIF} |
|
2152 | 153 |
|
2428 | 154 |
// Controller(s) |
2436 | 155 |
k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
2428 | 156 |
for j:= 0 to Pred(ControllerNumControllers) do |
157 |
begin |
|
158 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
159 |
begin |
|
2436 | 160 |
if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
161 |
if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
|
2428 | 162 |
inc(k, 2); |
163 |
end; |
|
164 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
165 |
begin |
|
2436 | 166 |
tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
167 |
tkbdn[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT; |
|
168 |
tkbdn[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN; |
|
169 |
tkbdn[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT; |
|
2428 | 170 |
inc(k, 4); |
171 |
end; |
|
172 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
173 |
begin |
|
2436 | 174 |
tkbdn[k]:= ControllerButtons[j][i]; |
2428 | 175 |
inc(k, 1); |
176 |
end; |
|
177 |
end; |
|
178 |
||
2379 | 179 |
// now process strokes |
2436 | 180 |
for i:= 0 to cKeyMaxIndex do |
947 | 181 |
if CurrentBinds[i][0] <> #0 then |
182 |
begin |
|
2436 | 183 |
if (i > 3) and (tkbdn[i] <> 0) and not ((CurrentBinds[i] = 'put') or (CurrentBinds[i] = 'ammomenu') or (CurrentBinds[i] = '+cur_u') or (CurrentBinds[i] = '+cur_d') or (CurrentBinds[i] = '+cur_l') or (CurrentBinds[i] = '+cur_r')) then hideAmmoMenu:= true; |
184 |
if (tkbd[i] = 0) and (tkbdn[i] <> 0) then ParseCommand(CurrentBinds[i], Trusted) |
|
947 | 185 |
else if (CurrentBinds[i][1] = '+') |
2436 | 186 |
and (tkbdn[i] = 0) |
948 | 187 |
and (tkbd[i] <> 0) then |
947 | 188 |
begin |
189 |
s:= CurrentBinds[i]; |
|
190 |
s[1]:= '-'; |
|
191 |
ParseCommand(s, Trusted) |
|
192 |
end; |
|
2436 | 193 |
tkbd[i]:= tkbdn[i] |
194 |
end |
|
4 | 195 |
end; |
196 |
||
197 |
procedure ResetKbd; |
|
2428 | 198 |
var i, j, k, t: LongInt; |
4 | 199 |
pkbd: PByteArray; |
200 |
begin |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
201 |
|
2152 | 202 |
{$IFDEF SDL13} |
2436 | 203 |
pkbd:= SDL_GetKeyboardState(@j); |
2567 | 204 |
k:= SDL_GetMouseState(0, nil, nil); |
2152 | 205 |
{$ELSE} |
2436 | 206 |
pkbd:= SDL_GetKeyState(@j); |
2567 | 207 |
k:= SDL_GetMouseState(nil, nil); |
2152 | 208 |
{$ENDIF} |
2436 | 209 |
TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true); |
210 |
||
211 |
for i:= 1 to pred(j) do |
|
212 |
tkbdn[i]:= pkbd^[i]; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2163
diff
changeset
|
213 |
|
2436 | 214 |
// mouse buttons |
215 |
{$IFDEF DARWIN} |
|
216 |
tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305])); |
|
217 |
tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4); |
|
218 |
{$ELSE} |
|
219 |
tkbdn[1]:= (k and 1); |
|
220 |
tkbdn[3]:= ((k shr 2) and 1); |
|
221 |
{$ENDIF} |
|
222 |
tkbdn[2]:= ((k shr 1) and 1); |
|
223 |
||
224 |
// mouse wheels (see event loop in project file) |
|
225 |
tkbdn[4]:= ord(wheelDown); |
|
226 |
tkbdn[5]:= ord(wheelUp); |
|
227 |
wheelUp:= false; |
|
228 |
wheelDown:= false; |
|
2567 | 229 |
{$IFDEF IPHONEOS} |
230 |
tkbdn[1]:= ord(leftClick); |
|
231 |
tkbdn[2]:= ord(middleClick); |
|
232 |
tkbdn[3]:= ord(rightClick); |
|
233 |
leftClick:= false; |
|
234 |
middleClick:= false; |
|
235 |
rightClick:= false; |
|
236 |
||
237 |
{* |
|
238 |
tkbdn[273]:= ord(upKey); |
|
239 |
tkbdn[274]:= ord(downKey); |
|
240 |
tkbdn[275]:= ord(rightKey); |
|
241 |
tkbdn[276]:= ord(leftKey); |
|
242 |
||
243 |
tkbdn[32]:= ord(spaceKey); |
|
244 |
tkbdn[13]:= ord(enterKey); |
|
245 |
||
246 |
upKey:= false; |
|
247 |
downKey:= false; |
|
248 |
rightKey:= false; |
|
249 |
leftKey:= false; |
|
250 |
||
251 |
spaceKey:= false; |
|
252 |
enterKey:= false; |
|
253 |
*} |
|
254 |
{$ENDIF} |
|
2436 | 255 |
|
256 |
// Controller(s) |
|
257 |
k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it |
|
2428 | 258 |
for j:= 0 to Pred(ControllerNumControllers) do |
259 |
begin |
|
260 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
261 |
begin |
|
2436 | 262 |
if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; |
263 |
if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; |
|
2428 | 264 |
inc(k, 2); |
265 |
end; |
|
266 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
267 |
begin |
|
2436 | 268 |
tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP; |
269 |
tkbdn[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT; |
|
270 |
tkbdn[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN; |
|
271 |
tkbdn[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT; |
|
2428 | 272 |
inc(k, 4); |
273 |
end; |
|
274 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
275 |
begin |
|
2436 | 276 |
tkbdn[k]:= ControllerButtons[j][i]; |
2428 | 277 |
inc(k, 1); |
278 |
end; |
|
279 |
end; |
|
2436 | 280 |
|
281 |
for t:= 0 to cKeyMaxIndex do |
|
282 |
tkbd[i]:= tkbdn[i] |
|
4 | 283 |
end; |
284 |
||
285 |
procedure InitKbdKeyTable; |
|
2428 | 286 |
var i, j, k, t: LongInt; |
4 | 287 |
s: string[15]; |
288 |
begin |
|
289 |
KeyNames[1]:= 'mousel'; |
|
290 |
KeyNames[2]:= 'mousem'; |
|
291 |
KeyNames[3]:= 'mouser'; |
|
2379 | 292 |
KeyNames[4]:= 'wheelup'; |
293 |
KeyNames[5]:= 'wheeldown'; |
|
294 |
||
295 |
for i:= 6 to cKeyMaxIndex do |
|
4 | 296 |
begin |
297 |
s:= SDL_GetKeyName(i); |
|
2379 | 298 |
//addfilelog(inttostr(i) + ' ' + s); |
4 | 299 |
if s = 'unknown key' then KeyNames[i]:= '' |
300 |
else begin |
|
301 |
for t:= 1 to Length(s) do |
|
302 |
if s[t] = ' ' then s[t]:= '_'; |
|
303 |
KeyNames[i]:= s |
|
304 |
end; |
|
167 | 305 |
end; |
306 |
||
2436 | 307 |
{$IFDEF SDL13} |
2438 | 308 |
PByteArray(SDL_GetKeyboardState(@i)); |
2436 | 309 |
{$ELSE} |
310 |
SDL_GetKeyState(@i); |
|
311 |
{$ENDIF} |
|
312 |
||
2428 | 313 |
// Controller(s) |
2436 | 314 |
k:= i; |
2428 | 315 |
for j:= 0 to Pred(ControllerNumControllers) do |
316 |
begin |
|
317 |
for i:= 0 to Pred(ControllerNumAxes[j]) do |
|
318 |
begin |
|
319 |
keynames[k + 0]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'u'; |
|
320 |
keynames[k + 1]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'd'; |
|
321 |
inc(k, 2); |
|
322 |
end; |
|
323 |
for i:= 0 to Pred(ControllerNumHats[j]) do |
|
324 |
begin |
|
325 |
keynames[k + 0]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'u'; |
|
326 |
keynames[k + 1]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'r'; |
|
327 |
keynames[k + 2]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'd'; |
|
328 |
keynames[k + 3]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'l'; |
|
329 |
inc(k, 4); |
|
330 |
end; |
|
331 |
for i:= 0 to Pred(ControllerNumButtons[j]) do |
|
332 |
begin |
|
333 |
keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i); |
|
334 |
inc(k, 1); |
|
335 |
end; |
|
336 |
end; |
|
337 |
||
2379 | 338 |
DefaultBinds[ 27]:= 'quit'; |
339 |
DefaultBinds[ 96]:= 'history'; |
|
340 |
DefaultBinds[127]:= 'rotmask'; |
|
341 |
||
342 |
DefaultBinds[KeyNameToCode('0')]:= '+volup'; |
|
343 |
DefaultBinds[KeyNameToCode('9')]:= '+voldown'; |
|
344 |
DefaultBinds[KeyNameToCode('c')]:= 'capture'; |
|
345 |
DefaultBinds[KeyNameToCode('h')]:= 'findhh'; |
|
346 |
DefaultBinds[KeyNameToCode('p')]:= 'pause'; |
|
347 |
DefaultBinds[KeyNameToCode('s')]:= '+speedup'; |
|
348 |
DefaultBinds[KeyNameToCode('t')]:= 'chat'; |
|
349 |
DefaultBinds[KeyNameToCode('y')]:= 'confirm'; |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
350 |
|
2407
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
351 |
DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
352 |
DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
353 |
DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin'; |
9f413bd5150e
- Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents:
2379
diff
changeset
|
354 |
|
1051
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
355 |
DefaultBinds[KeyNameToCode('f12')]:= 'fullscr'; |
dfdd5dfe97d4
Enable fullscreen switching back, now it's bound on F12
unc0rr
parents:
1022
diff
changeset
|
356 |
|
167 | 357 |
SetDefaultBinds |
4 | 358 |
end; |
359 |
||
167 | 360 |
procedure SetBinds(var binds: TBinds); |
361 |
begin |
|
362 |
CurrentBinds:= binds |
|
363 |
end; |
|
364 |
||
365 |
procedure SetDefaultBinds; |
|
366 |
begin |
|
367 |
CurrentBinds:= DefaultBinds |
|
368 |
end; |
|
369 |
||
948 | 370 |
procedure FreezeEnterKey; |
371 |
begin |
|
372 |
tkbd[13]:= 1; |
|
2567 | 373 |
tkbd[271]:= 1; |
948 | 374 |
end; |
167 | 375 |
|
2428 | 376 |
var Controller: array [0..5] of PSDLJoystick; |
377 |
||
378 |
procedure ControllerInit; |
|
379 |
var i, j: Integer; |
|
380 |
begin |
|
381 |
ControllerEnabled:= 0; |
|
382 |
ControllerNumControllers:= SDL_NumJoysticks; |
|
383 |
||
384 |
if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
|
385 |
||
386 |
WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers)); |
|
387 |
||
388 |
if ControllerNumControllers > 0 then |
|
389 |
begin |
|
390 |
for j:= 0 to pred(ControllerNumControllers) do |
|
391 |
begin |
|
392 |
WriteLnToConsole('Using game controller: ' + SDL_JoystickName(j)); |
|
393 |
Controller[j]:= SDL_JoystickOpen(j); |
|
394 |
if Controller[j] = nil then |
|
395 |
WriteLnToConsole('* Failed to open game controller!') |
|
396 |
else |
|
397 |
begin |
|
398 |
ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
|
399 |
//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
|
400 |
ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
|
401 |
ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
|
402 |
WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j])); |
|
403 |
//WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j])); |
|
404 |
WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j])); |
|
405 |
WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j])); |
|
406 |
ControllerEnabled:= 1; |
|
407 |
||
408 |
if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
|
409 |
//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
|
410 |
if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |
|
411 |
if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20; |
|
412 |
||
413 |
// reset all buttons/axes |
|
414 |
for i:= 0 to pred(ControllerNumAxes[j]) do |
|
415 |
ControllerAxes[j][i]:= 0; |
|
416 |
(*for i:= 0 to pred(ControllerNumBalls[j]) do |
|
417 |
begin |
|
418 |
ControllerBalls[j][i][0]:= 0; |
|
419 |
ControllerBalls[j][i][1]:= 0; |
|
420 |
end;*) |
|
421 |
for i:= 0 to pred(ControllerNumHats[j]) do |
|
422 |
ControllerHats[j][i]:= SDL_HAT_CENTERED; |
|
423 |
for i:= 0 to pred(ControllerNumButtons[j]) do |
|
424 |
ControllerButtons[j][i]:= 0; |
|
425 |
end; |
|
426 |
end; |
|
427 |
// enable event generation/controller updating |
|
428 |
SDL_JoystickEventState(1); |
|
429 |
end |
|
430 |
else |
|
431 |
WriteLnToConsole('Not using any game controller'); |
|
432 |
end; |
|
433 |
||
434 |
procedure ControllerClose; |
|
435 |
var j: Integer; |
|
436 |
begin |
|
437 |
if ControllerEnabled > 0 then |
|
438 |
for j:= 0 to pred(ControllerNumControllers) do |
|
439 |
SDL_JoystickClose(Controller[j]); |
|
440 |
end; |
|
441 |
||
442 |
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer); |
|
443 |
begin |
|
444 |
ControllerAxes[joy][axis]:= value; |
|
445 |
end; |
|
446 |
||
447 |
procedure ControllerHatEvent(joy, hat, value: Byte); |
|
448 |
begin |
|
449 |
ControllerHats[joy][hat]:= value; |
|
450 |
end; |
|
451 |
||
452 |
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
|
453 |
begin |
|
454 |
if pressed then ControllerButtons[joy][button]:= 1 else ControllerButtons[joy][button]:= 0; |
|
455 |
end; |
|
456 |
||
4 | 457 |
initialization |
458 |
||
459 |
end. |