DEADSOFTWARE

SDL2: set window position properly; always center when going fullscreen->windowed
[d2df-sdl.git] / src / engine / e_input_sdl2.inc
1 interface
3 uses
4 SDL2, SysUtils;
6 const
7 e_MaxKbdKeys = SDL_NUM_SCANCODES;
8 e_MaxJoys = 4;
9 e_MaxJoyBtns = 32;
10 e_MaxJoyAxes = 8;
11 e_MaxJoyHats = 8;
12 e_MaxVirtKeys = 48;
14 e_MaxJoyKeys = e_MaxJoyBtns + e_MaxJoyAxes*2 + e_MaxJoyHats*4;
16 e_MaxInputKeys = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1;
17 // $$$..$$$ - 321 Keyboard buttons/keys
18 // $$$..$$$ - 4*32 Joystick buttons
19 // $$$..$$$ - 8*2 Joystick axes (- and +)
20 // $$$..$$$ - 4*4 Joystick hats (L U R D)
21 // $$$..$$$ - 48 Virtual buttons/keys
23 KBRD_END = e_MaxKbdKeys;
24 JOYK_BEG = KBRD_END;
25 JOYK_END = JOYK_BEG + e_MaxJoyBtns*e_MaxJoys;
26 JOYA_BEG = JOYK_END;
27 JOYA_END = JOYA_BEG + e_MaxJoyAxes*2*e_MaxJoys;
28 JOYH_BEG = JOYA_END;
29 JOYH_END = JOYH_BEG + e_MaxJoyHats*4*e_MaxJoys;
30 VIRT_BEG = JOYH_END;
31 VIRT_END = VIRT_BEG + e_MaxVirtKeys;
33 // these are apparently used in g_gui and g_game and elsewhere
34 IK_INVALID = 0;
35 IK_ESCAPE = SDL_SCANCODE_ESCAPE;
36 IK_RETURN = SDL_SCANCODE_RETURN;
37 IK_KPRETURN= SDL_SCANCODE_KP_ENTER;
38 IK_ENTER = SDL_SCANCODE_RETURN;
39 IK_KPINSERT = SDL_SCANCODE_KP_0;
40 IK_UP = SDL_SCANCODE_UP;
41 IK_KPUP = SDL_SCANCODE_KP_8;
42 IK_DOWN = SDL_SCANCODE_DOWN;
43 IK_KPDOWN = SDL_SCANCODE_KP_2;
44 IK_LEFT = SDL_SCANCODE_LEFT;
45 IK_KPLEFT = SDL_SCANCODE_KP_4;
46 IK_RIGHT = SDL_SCANCODE_RIGHT;
47 IK_KPRIGHT = SDL_SCANCODE_KP_6;
48 IK_DELETE = SDL_SCANCODE_DELETE;
49 IK_HOME = SDL_SCANCODE_HOME;
50 IK_KPHOME = SDL_SCANCODE_KP_7;
51 IK_INSERT = SDL_SCANCODE_INSERT;
52 IK_SPACE = SDL_SCANCODE_SPACE;
53 IK_CONTROL = SDL_SCANCODE_LCTRL;
54 IK_SHIFT = SDL_SCANCODE_LSHIFT;
55 IK_ALT = SDL_SCANCODE_LALT;
56 IK_TAB = SDL_SCANCODE_TAB;
57 IK_PAGEUP = SDL_SCANCODE_PAGEUP;
58 IK_KPPAGEUP= SDL_SCANCODE_KP_9;
59 IK_PAGEDN = SDL_SCANCODE_PAGEDOWN;
60 IK_KPPAGEDN= SDL_SCANCODE_KP_3;
61 IK_KP5 = SDL_SCANCODE_KP_5;
62 IK_NUMLOCK = SDL_SCANCODE_NUMLOCKCLEAR;
63 IK_KPDIVIDE= SDL_SCANCODE_KP_DIVIDE;
64 IK_KPMULTIPLE= SDL_SCANCODE_KP_MULTIPLY;
65 IK_KPMINUS = SDL_SCANCODE_KP_MINUS;
66 IK_KPPLUS = SDL_SCANCODE_KP_PLUS;
67 IK_KPENTER = SDL_SCANCODE_KP_ENTER;
68 IK_KPDOT = SDL_SCANCODE_KP_PERIOD;
69 IK_CAPSLOCK= SDL_SCANCODE_CAPSLOCK;
70 IK_RSHIFT = SDL_SCANCODE_RSHIFT;
71 IK_CTRL = SDL_SCANCODE_LCTRL;
72 IK_RCTRL = SDL_SCANCODE_RCTRL;
73 IK_RALT = SDL_SCANCODE_RALT;
74 IK_WIN = SDL_SCANCODE_LGUI;
75 IK_RWIN = SDL_SCANCODE_RGUI;
76 IK_MENU = SDL_SCANCODE_MENU;
77 IK_PRINTSCR= SDL_SCANCODE_PRINTSCREEN;
78 IK_SCROLLLOCK= SDL_SCANCODE_SCROLLLOCK;
79 IK_LBRACKET= SDL_SCANCODE_LEFTBRACKET;
80 IK_RBRACKET= SDL_SCANCODE_RIGHTBRACKET;
81 IK_SEMICOLON= SDL_SCANCODE_SEMICOLON;
82 IK_QUOTE = SDL_SCANCODE_APOSTROPHE;
83 IK_BACKSLASH= SDL_SCANCODE_BACKSLASH;
84 IK_SLASH = SDL_SCANCODE_SLASH;
85 IK_COMMA = SDL_SCANCODE_COMMA;
86 IK_DOT = SDL_SCANCODE_PERIOD;
87 IK_EQUALS = SDL_SCANCODE_EQUALS;
88 IK_0 = SDL_SCANCODE_0;
89 IK_1 = SDL_SCANCODE_1;
90 IK_2 = SDL_SCANCODE_2;
91 IK_3 = SDL_SCANCODE_3;
92 IK_4 = SDL_SCANCODE_4;
93 IK_5 = SDL_SCANCODE_5;
94 IK_6 = SDL_SCANCODE_6;
95 IK_7 = SDL_SCANCODE_7;
96 IK_8 = SDL_SCANCODE_8;
97 IK_9 = SDL_SCANCODE_9;
98 IK_F1 = SDL_SCANCODE_F1;
99 IK_F2 = SDL_SCANCODE_F2;
100 IK_F3 = SDL_SCANCODE_F3;
101 IK_F4 = SDL_SCANCODE_F4;
102 IK_F5 = SDL_SCANCODE_F5;
103 IK_F6 = SDL_SCANCODE_F6;
104 IK_F7 = SDL_SCANCODE_F7;
105 IK_F8 = SDL_SCANCODE_F8;
106 IK_F9 = SDL_SCANCODE_F9;
107 IK_F10 = SDL_SCANCODE_F10;
108 IK_F11 = SDL_SCANCODE_F11;
109 IK_F12 = SDL_SCANCODE_F12;
110 IK_END = SDL_SCANCODE_END;
111 IK_KPEND = SDL_SCANCODE_KP_1;
112 IK_BACKSPACE = SDL_SCANCODE_BACKSPACE;
113 IK_BACKQUOTE = SDL_SCANCODE_GRAVE;
114 IK_GRAVE = SDL_SCANCODE_GRAVE;
115 IK_PAUSE = SDL_SCANCODE_PAUSE;
116 IK_Y = SDL_SCANCODE_Y;
117 IK_N = SDL_SCANCODE_N;
118 IK_W = SDL_SCANCODE_W;
119 IK_A = SDL_SCANCODE_A;
120 IK_S = SDL_SCANCODE_S;
121 IK_D = SDL_SCANCODE_D;
122 IK_Q = SDL_SCANCODE_Q;
123 IK_E = SDL_SCANCODE_E;
124 IK_H = SDL_SCANCODE_H;
125 IK_J = SDL_SCANCODE_J;
126 IK_T = SDL_SCANCODE_T;
127 IK_Z = SDL_SCANCODE_Z;
128 IK_MINUS = SDL_SCANCODE_MINUS;
129 // TODO: think of something better than this shit
130 IK_LASTKEY = SDL_NUM_SCANCODES-1;
132 VK_FIRSTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys;
133 VK_LEFT = VK_FIRSTKEY + 0;
134 VK_RIGHT = VK_FIRSTKEY + 1;
135 VK_UP = VK_FIRSTKEY + 2;
136 VK_DOWN = VK_FIRSTKEY + 3;
137 VK_FIRE = VK_FIRSTKEY + 4;
138 VK_OPEN = VK_FIRSTKEY + 5;
139 VK_JUMP = VK_FIRSTKEY + 6;
140 VK_CHAT = VK_FIRSTKEY + 7;
141 VK_ESCAPE = VK_FIRSTKEY + 8;
142 VK_0 = VK_FIRSTKEY + 9;
143 VK_1 = VK_FIRSTKEY + 10;
144 VK_2 = VK_FIRSTKEY + 11;
145 VK_3 = VK_FIRSTKEY + 12;
146 VK_4 = VK_FIRSTKEY + 13;
147 VK_5 = VK_FIRSTKEY + 14;
148 VK_6 = VK_FIRSTKEY + 15;
149 VK_7 = VK_FIRSTKEY + 16;
150 VK_8 = VK_FIRSTKEY + 17;
151 VK_9 = VK_FIRSTKEY + 18;
152 VK_A = VK_FIRSTKEY + 19;
153 VK_B = VK_FIRSTKEY + 20;
154 VK_C = VK_FIRSTKEY + 21;
155 VK_D = VK_FIRSTKEY + 22;
156 VK_E = VK_FIRSTKEY + 23;
157 VK_F = VK_FIRSTKEY + 24;
158 VK_CONSOLE = VK_FIRSTKEY + 25;
159 VK_STATUS = VK_FIRSTKEY + 26;
160 VK_TEAM = VK_FIRSTKEY + 27;
161 VK_PREV = VK_FIRSTKEY + 28;
162 VK_NEXT = VK_FIRSTKEY + 29;
163 VK_STRAFE = VK_FIRSTKEY + 30;
164 VK_LSTRAFE = VK_FIRSTKEY + 31;
165 VK_RSTRAFE = VK_FIRSTKEY + 32;
166 VK_PRINTSCR = VK_FIRSTKEY + 33;
167 VK_SHOWKBD = VK_FIRSTKEY + 34;
168 VK_HIDEKBD = VK_FIRSTKEY + 35;
169 VK_LASTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1;
171 AX_MINUS = 0;
172 AX_PLUS = 1;
173 HAT_LEFT = 0;
174 HAT_UP = 1;
175 HAT_RIGHT = 2;
176 HAT_DOWN = 3;
178 JOY0_ATTACK = JOYK_BEG + 0*e_MaxJoyBtns + 0;
179 JOY1_ATTACK = JOYK_BEG + 1*e_MaxJoyBtns + 0;
180 JOY2_ATTACK = JOYK_BEG + 2*e_MaxJoyBtns + 0;
181 JOY3_ATTACK = JOYK_BEG + 3*e_MaxJoyBtns + 0;
182 JOY0_NEXT = JOYK_BEG + 0*e_MaxJoyBtns + 1;
183 JOY1_NEXT = JOYK_BEG + 1*e_MaxJoyBtns + 1;
184 JOY2_NEXT = JOYK_BEG + 2*e_MaxJoyBtns + 1;
185 JOY3_NEXT = JOYK_BEG + 3*e_MaxJoyBtns + 1;
186 JOY0_JUMP = JOYK_BEG + 0*e_MaxJoyBtns + 2;
187 JOY1_JUMP = JOYK_BEG + 1*e_MaxJoyBtns + 2;
188 JOY2_JUMP = JOYK_BEG + 2*e_MaxJoyBtns + 2;
189 JOY3_JUMP = JOYK_BEG + 3*e_MaxJoyBtns + 2;
190 JOY0_ACTIVATE = JOYK_BEG + 0*e_MaxJoyBtns + 3;
191 JOY1_ACTIVATE = JOYK_BEG + 1*e_MaxJoyBtns + 3;
192 JOY2_ACTIVATE = JOYK_BEG + 2*e_MaxJoyBtns + 3;
193 JOY3_ACTIVATE = JOYK_BEG + 3*e_MaxJoyBtns + 3;
194 JOY0_PREV = JOYK_BEG + 0*e_MaxJoyBtns + 4;
195 JOY1_PREV = JOYK_BEG + 1*e_MaxJoyBtns + 4;
196 JOY2_PREV = JOYK_BEG + 2*e_MaxJoyBtns + 4;
197 JOY3_PREV = JOYK_BEG + 3*e_MaxJoyBtns + 4;
199 JOY0_LEFT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
200 JOY1_LEFT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
201 JOY2_LEFT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
202 JOY3_LEFT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
203 JOY0_RIGHT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
204 JOY1_RIGHT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
205 JOY2_RIGHT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
206 JOY3_RIGHT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
207 JOY0_UP = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_UP;
208 JOY1_UP = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_UP;
209 JOY2_UP = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_UP;
210 JOY3_UP = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_UP;
211 JOY0_DOWN = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
212 JOY1_DOWN = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
213 JOY2_DOWN = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
214 JOY3_DOWN = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
216 function e_InitInput: Boolean;
217 procedure e_ReleaseInput;
218 procedure e_UnpressAllKeys;
219 procedure e_KeyUpDown (key: Integer; down: Boolean);
221 function e_KeyPressed (key: Integer): Boolean;
222 function e_AnyKeyPressed: Boolean;
223 function e_GetFirstKeyPressed: Integer;
224 function e_HasJoysticks: Boolean;
226 function e_JoyButtonToKey (id, btn: Integer): Integer;
227 function e_JoyAxisToKey (id, ax, dir: Integer): Integer;
228 function e_JoyHatToKey (id, hat, dir: Integer): Integer;
230 var
231 e_JoystickAvailable: array [0..e_MaxJoys - 1] of Boolean;
232 e_JoystickDeadzones: array [0..e_MaxJoys - 1] of Integer = (8192, 8192, 8192, 8192);
233 e_KeyNames: array [0..e_MaxInputKeys] of String;
235 implementation
237 var
238 InputBuffer: array [0..e_MaxInputKeys - 1] of Boolean;
240 procedure e_UnpressAllKeys;
241 var i: Integer;
242 begin
243 for i := 0 to High(InputBuffer) do
244 InputBuffer[i] := False
245 end;
247 procedure e_KeyUpDown (key: Integer; down: Boolean);
248 begin
249 ASSERT(key >= 0);
250 ASSERT(key < e_MaxInputKeys);
251 if key > 0 then
252 InputBuffer[key] := down
253 end;
255 procedure GenerateKeyNames;
256 var i, j, k: Integer;
257 begin
258 // keyboard key names
259 e_KeyNames[IK_0] := '0';
260 e_KeyNames[IK_1] := '1';
261 e_KeyNames[IK_2] := '2';
262 e_KeyNames[IK_3] := '3';
263 e_KeyNames[IK_4] := '4';
264 e_KeyNames[IK_5] := '5';
265 e_KeyNames[IK_6] := '6';
266 e_KeyNames[IK_7] := '7';
267 e_KeyNames[IK_8] := '8';
268 e_KeyNames[IK_9] := '9';
270 for i := IK_A to IK_Z do
271 e_KeyNames[i] := '' + chr(ord('a') + (i - IK_a));
273 e_KeyNames[IK_ESCAPE] := 'ESCAPE';
274 e_KeyNames[IK_ENTER] := 'ENTER';
275 e_KeyNames[IK_TAB] := 'TAB';
276 e_KeyNames[IK_BACKSPACE] := 'BACKSPACE';
277 e_KeyNames[IK_SPACE] := 'SPACE';
278 e_KeyNames[IK_UP] := 'UP';
279 e_KeyNames[IK_LEFT] := 'LEFT';
280 e_KeyNames[IK_RIGHT] := 'RIGHT';
281 e_KeyNames[IK_DOWN] := 'DOWN';
282 e_KeyNames[IK_INSERT] := 'INSERT';
283 e_KeyNames[IK_DELETE] := 'DELETE';
284 e_KeyNames[IK_HOME] := 'HOME';
285 e_KeyNames[IK_END] := 'END';
286 e_KeyNames[IK_PAGEUP] := 'PGUP';
287 e_KeyNames[IK_PAGEDN] := 'PGDOWN';
288 e_KeyNames[IK_KPINSERT] := 'PAD0';
289 e_KeyNames[IK_KPEND] := 'PAD1';
290 e_KeyNames[IK_KPDOWN] := 'PAD2';
291 e_KeyNames[IK_KPPAGEDN] := 'PAD3';
292 e_KeyNames[IK_KPLEFT] := 'PAD4';
293 e_KeyNames[IK_KP5] := 'PAD5';
294 e_KeyNames[IK_KPRIGHT] := 'PAD6';
295 e_KeyNames[IK_KPHOME] := 'PAD7';
296 e_KeyNames[IK_KPUP] := 'PAD8';
297 e_KeyNames[IK_KPPAGEUP] := 'PAD9';
298 e_KeyNames[IK_NUMLOCK] := 'NUM';
299 e_KeyNames[IK_KPDIVIDE] := 'PAD/';
300 e_KeyNames[IK_KPMULTIPLE] := 'PAD*';
301 e_KeyNames[IK_KPMINUS] := 'PAD-';
302 e_KeyNames[IK_KPPLUS] := 'PAD+';
303 e_KeyNames[IK_KPENTER] := 'PADENTER';
304 e_KeyNames[IK_KPDOT] := 'PAD.';
305 e_KeyNames[IK_CAPSLOCK] := 'CAPS';
306 e_KeyNames[IK_BACKQUOTE] := 'BACKQUOTE';
307 e_KeyNames[IK_F1] := 'F1';
308 e_KeyNames[IK_F2] := 'F2';
309 e_KeyNames[IK_F3] := 'F3';
310 e_KeyNames[IK_F4] := 'F4';
311 e_KeyNames[IK_F5] := 'F5';
312 e_KeyNames[IK_F6] := 'F6';
313 e_KeyNames[IK_F7] := 'F7';
314 e_KeyNames[IK_F8] := 'F8';
315 e_KeyNames[IK_F9] := 'F9';
316 e_KeyNames[IK_F10] := 'F10';
317 e_KeyNames[IK_F11] := 'F11';
318 e_KeyNames[IK_F12] := 'F12';
319 e_KeyNames[IK_SHIFT] := 'LSHIFT';
320 e_KeyNames[IK_RSHIFT] := 'RSHIFT';
321 e_KeyNames[IK_CTRL] := 'LCTRL';
322 e_KeyNames[IK_RCTRL] := 'RCTRL';
323 e_KeyNames[IK_ALT] := 'LALT';
324 e_KeyNames[IK_RALT] := 'RALT';
325 e_KeyNames[IK_WIN] := 'LWIN';
326 e_KeyNames[IK_RWIN] := 'RWIN';
327 e_KeyNames[IK_MENU] := 'MENU';
328 e_KeyNames[IK_PRINTSCR] := 'PSCRN';
329 e_KeyNames[IK_SCROLLLOCK] := 'SCROLL';
330 e_KeyNames[IK_PAUSE] := 'PAUSE';
331 e_KeyNames[IK_LBRACKET] := '[';
332 e_KeyNames[IK_RBRACKET] := ']';
333 e_KeyNames[IK_SEMICOLON] := ';';
334 e_KeyNames[IK_QUOTE] := '''';
335 e_KeyNames[IK_BACKSLASH] := '\';
336 e_KeyNames[IK_SLASH] := '/';
337 e_KeyNames[IK_COMMA] := ',';
338 e_KeyNames[IK_DOT] := '.';
339 e_KeyNames[IK_MINUS] := '-';
340 e_KeyNames[IK_EQUALS] := '=';
342 // joysticks
343 for j := 0 to e_MaxJoys-1 do
344 begin
345 k := JOYK_BEG + j * e_MaxJoyBtns;
346 // buttons
347 for i := 0 to e_MaxJoyBtns-1 do
348 e_KeyNames[k + i] := Format('JOY%dB%d', [j, i]);
349 k := JOYA_BEG + j * e_MaxJoyAxes * 2;
350 // axes
351 for i := 0 to e_MaxJoyAxes-1 do
352 begin
353 e_KeyNames[k + i*2 ] := Format('JOY%dA%d+', [j, i]);
354 e_KeyNames[k + i*2 + 1] := Format('JOY%dA%d-', [j, i]);
355 end;
356 k := JOYH_BEG + j * e_MaxJoyHats * 4;
357 // hats
358 for i := 0 to e_MaxJoyHats-1 do
359 begin
360 e_KeyNames[k + i*4 ] := Format('JOY%dD%dL', [j, i]);
361 e_KeyNames[k + i*4 + 1] := Format('JOY%dD%dU', [j, i]);
362 e_KeyNames[k + i*4 + 2] := Format('JOY%dD%dR', [j, i]);
363 e_KeyNames[k + i*4 + 3] := Format('JOY%dD%dD', [j, i]);
364 end;
365 end;
367 // vitrual keys
368 for i := 0 to e_MaxVirtKeys-1 do
369 e_KeyNames[VIRT_BEG + i] := 'VIRTUAL' + IntToStr(i);
370 end;
372 function e_HasJoysticks: Boolean;
373 var i: Integer;
374 begin
375 i := 0;
376 while (i < e_MaxJoys) and (e_JoystickAvailable[i] = False) do inc(i);
377 result := i < e_MaxJoys
378 end;
380 function e_InitInput: Boolean;
381 var i: Integer;
382 begin
383 for i := 0 to e_MaxJoys - 1 do
384 e_JoystickAvailable[i] := False;
385 GenerateKeyNames;
386 result := True
387 end;
389 procedure e_ReleaseInput;
390 var i: Integer;
391 begin
392 for i := 0 to e_MaxJoys - 1 do
393 e_JoystickAvailable[i] := False
394 end;
396 function e_KeyPressed (key: Integer): Boolean;
397 begin
398 ASSERT(key >= 0);
399 ASSERT(key < e_MaxInputKeys);
400 result := InputBuffer[key]
401 end;
403 function e_AnyKeyPressed: Boolean;
404 begin
405 result := e_GetFirstKeyPressed <> IK_INVALID;
406 end;
408 function e_GetFirstKeyPressed: Integer;
409 var i: Integer;
410 begin
411 i := 1;
412 while (i < e_MaxInputKeys) and (InputBuffer[i] = False) do inc(i);
413 if i < e_MaxInputKeys then
414 result := i
415 else
416 result := IK_INVALID
417 end;
419 function e_JoyButtonToKey (id, btn: Integer): Integer;
420 begin
421 ASSERT(id >= 0);
422 ASSERT(id < e_MaxJoys);
423 ASSERT(btn >= 0);
424 ASSERT(btn < e_MaxJoyBtns);
425 result := JOYK_BEG + id*e_MaxJoyBtns + btn
426 end;
428 function e_JoyAxisToKey (id, ax, dir: Integer): Integer;
429 begin
430 ASSERT(id >= 0);
431 ASSERT(id < e_MaxJoys);
432 ASSERT(ax >= 0);
433 ASSERT(ax < e_MaxJoyAxes);
434 ASSERT(dir in [AX_MINUS, AX_PLUS]);
435 result := JOYA_BEG + id*e_MaxJoyAxes*2 + ax*2 + dir
436 end;
438 function e_JoyHatToKey (id, hat, dir: Integer): Integer;
439 begin
440 ASSERT(id >= 0);
441 ASSERT(id < e_MaxJoys);
442 ASSERT(hat >= 0);
443 ASSERT(hat < e_MaxJoyHats);
444 ASSERT(dir in [HAT_LEFT, HAT_UP, HAT_RIGHT, HAT_DOWN]);
445 result := JOYH_BEG + id*e_MaxJoyHats*4 + hat*4 + dir
446 end;