--- a/hedgewars/uKeys.pas Sat Apr 21 17:55:45 2012 +0200
+++ b/hedgewars/uKeys.pas Sat Apr 21 17:59:14 2012 +0200
@@ -41,7 +41,7 @@
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
{$IFDEF MOBILE}
-procedure setiPhoneBinds;
+procedure setTouchWidgetStates;
{$ENDIF}
implementation
@@ -63,7 +63,7 @@
var i, j, k: LongInt;
s: shortstring;
Trusted: boolean;
-{$IFNDEF MOBILE}pkbd: PByteArray;{$ENDIF}
+ pkbd: PByteArray;
begin
hideAmmoMenu:= false;
Trusted:= (CurrentTeam <> nil)
@@ -74,37 +74,34 @@
// TODO: Scale on screen dimensions and/or axis value (game controller)?
movecursor(5 * CursorMovementX, 5 * CursorMovementY);
-k:= SDL_GetMouseState(nil, nil);
+pkbd:= SDL_GetKeyState(@j);
+for i:= 1 to pred(j) do
+ tkbdn[i]:= pkbd^[i];
-{$IFDEF MOBILE}
-SDL_GetKeyState(@j);
-{$ELSE}
-pkbd:= SDL_GetKeyState(@j);
-for i:= 6 to pred(j) do // first 6 will be overwritten
- tkbdn[i]:= pkbd^[i];
-{$ENDIF}
-
+k:= SDL_GetMouseState(nil, nil);
// mouse buttons
{$IFDEF DARWIN}
-tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
-tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
+tkbdn[SDL_SCANCODE_MOUSEL]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
+tkbdni[SDL_SCANCODE_MOUSER]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
{$ELSE}
-tkbdn[1]:= (k and 1);
-tkbdn[3]:= ((k shr 2) and 1);
+tkbdn[SDL_SCANCODE_MOUSEL]:= (k and 1);
+tkbdn[SDL_SCANCODE_MOUSER]:= ((k shr 2) and 1);
{$ENDIF}
-tkbdn[2]:= ((k shr 1) and 1);
+tkbdn[SDL_SCANCODE_MOUSEM]:= ((k shr 1) and 1);
// mouse wheels
-tkbdn[4]:= ord(wheelDown);
-tkbdn[5]:= ord(wheelUp);
+tkbdn[SDL_SCANCODE_WHEELDOWN]:= ord(wheelDown);
+tkbdn[SDL_SCANCODE_WHEELUP]:= ord(wheelUp);
wheelUp:= false;
wheelDown:= false;
{$IFDEF MOBILE}
-setiPhoneBinds();
-{$ELSE}
+setTouchWidgetStates();
+{$ENDIF}
+
+{$IFNDEF MOBILE}
// Controller(s)
-k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
+k:= SDL_SCANCODE_CONTROLLER; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
for j:= 0 to Pred(ControllerNumControllers) do
begin
for i:= 0 to Pred(ControllerNumAxes[j]) do
@@ -137,12 +134,12 @@
// ctrl/cmd + q to close engine and frontend
{$IFDEF DARWIN}
- if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
+ if ((tkbdn[SDL_SCANCODE_LGUI] = 1) or (tkbdn[SDL_SCANCODE_RGUI] = 1)) then
{$ELSE}
- if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
+ if ((tkbdn[SDL_SCANCODE_LCTRL] = 1) or (tkbdn[SDL_SCANCODE_RCTRL] = 1)) then
{$ENDIF}
begin
- if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true)
+ if tkbdn[SDL_SCANCODE_Q] = 1 then ParseCommand ('halt', true)
end;
// now process strokes
@@ -170,43 +167,41 @@
procedure ResetKbd;
var j, k, t: LongInt;
-{$IFNDEF MOBILE}
i: LongInt;
pkbd: PByteArray;
-{$ENDIF}
begin
k:= SDL_GetMouseState(nil, nil);
-{$IFNDEF MOBILE}pkbd:={$ENDIF}SDL_GetKeyState(@j);
+pkbd:=SDL_GetKeyState(@j);
TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + IntToStr(j) + ')', true);
-{$IFNDEF MOBILE}
for i:= 1 to pred(j) do
tkbdn[i]:= pkbd^[i];
-{$ENDIF}
// mouse buttons
{$IFDEF DARWIN}
-tkbdn[1]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
-tkbdn[3]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
+tkbdn[SDL_SCANCODE_MOUSEL]:= ((k and 1) and not (tkbdn[306] or tkbdn[305]));
+tkbdn[SDL_SCANCODE_MOUSER]:= ((k and 1) and (tkbdn[306] or tkbdn[305])) or (k and 4);
{$ELSE}
-tkbdn[1]:= (k and 1);
-tkbdn[3]:= ((k shr 2) and 1);
+tkbdn[SDL_SCANCODE_MOUSEL]:= (k and 1);
+tkbdn[SDL_SCANCODE_MOUSER]:= ((k shr 2) and 1);
{$ENDIF}
-tkbdn[2]:= ((k shr 1) and 1);
+tkbdn[SDL_SCANCODE_MOUSEM]:= ((k shr 1) and 1);
// mouse wheels
-tkbdn[4]:= ord(wheelDown);
-tkbdn[5]:= ord(wheelUp);
+tkbdn[SDL_SCANCODE_WHEELDOWN]:= ord(wheelDown);
+tkbdn[SDL_SCANCODE_WHEELUP]:= ord(wheelUp);
wheelUp:= false;
wheelDown:= false;
{$IFDEF MOBILE}
-setiPhoneBinds();
-{$ELSE}
+setTouchWidgetStates();
+{$ENDIF}
+
+{$IFNDEF MOBILE}
// Controller(s)
-k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
+k:= SDL_SCANCODE_CONTROLLER; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
for j:= 0 to Pred(ControllerNumControllers) do
begin
for i:= 0 to Pred(ControllerNumAxes[j]) do
@@ -246,16 +241,10 @@
var i, j, k, t: LongInt;
s: string[15];
begin
-KeyNames[1]:= 'mousel';
-KeyNames[2]:= 'mousem';
-KeyNames[3]:= 'mouser';
-KeyNames[4]:= 'wheelup';
-KeyNames[5]:= 'wheeldown';
-
-for i:= 6 to cKeyMaxIndex do
+for i:= 0 to cKeyMaxIndex do
begin
s:= shortstring(sdl_getkeyname(i));
- //writeln(stdout,IntToStr(i) + ': ' + s);
+ //WriteToConsole(IntToStr(i) + ': ' + s);
if s = 'unknown key' then KeyNames[i]:= ''
else
begin
@@ -266,11 +255,14 @@
end;
end;
+KeyNames[SDL_SCANCODE_MOUSEL]:= 'mousel';
+KeyNames[SDL_SCANCODE_MOUSEM]:= 'mousem';
+KeyNames[SDL_SCANCODE_MOUSER]:= 'mouser';
+KeyNames[SDL_SCANCODE_WHEELUP]:= 'wheelup';
+KeyNames[SDL_SCANCODE_WHEELDOWN]:= 'wheeldown';
//for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]);
-// get the size of keyboard array
-SDL_GetKeyState(@k);
-
+k:= SDL_SCANCODE_CONTROLLER;
// Controller(s)
for j:= 0 to Pred(ControllerNumControllers) do
begin
@@ -295,54 +287,59 @@
end;
end;
-DefaultBinds[ 27]:= 'quit';
-DefaultBinds[ 96]:= 'history';
+DefaultBinds[SDL_SCANCODE_ESCAPE]:= 'quit';
+DefaultBinds[SDL_SCANCODE_GRAVE]:= 'history';
DefaultBinds[127]:= 'rotmask';
//numpad
//DefaultBinds[265]:= '+volup';
//DefaultBinds[256]:= '+voldown';
-DefaultBinds[KeyNameToCode('0')]:= '+volup';
-DefaultBinds[KeyNameToCode('9')]:= '+voldown';
-DefaultBinds[KeyNameToCode('c')]:= 'capture';
-DefaultBinds[KeyNameToCode('h')]:= 'findhh';
-DefaultBinds[KeyNameToCode('p')]:= 'pause';
-DefaultBinds[KeyNameToCode('s')]:= '+speedup';
-DefaultBinds[KeyNameToCode('t')]:= 'chat';
-DefaultBinds[KeyNameToCode('y')]:= 'confirm';
+DefaultBinds[SDL_SCANCODE_0]:= '+volup';
+DefaultBinds[SDL_SCANCODE_9]:= '+voldown';
+DefaultBinds[SDL_SCANCODE_C]:= 'capture';
+DefaultBinds[SDL_SCANCODE_H]:= 'findhh';
+DefaultBinds[SDL_SCANCODE_P]:= 'pause';
+DefaultBinds[SDL_SCANCODE_S]:= '+speedup';
+DefaultBinds[SDL_SCANCODE_T]:= 'chat';
+DefaultBinds[SDL_SCANCODE_Y]:= 'confirm';
-DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset';
-DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout';
-DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin';
+DefaultBinds[SDL_SCANCODE_MOUSEM]:= 'zoomreset';
+DefaultBinds[SDL_SCANCODE_WHEELUP]:= 'zoomout';
+DefaultBinds[SDL_SCANCODE_WHEELDOWN]:= 'zoomin';
-DefaultBinds[KeyNameToCode('f12')]:= 'fullscr';
+DefaultBinds[SDL_SCANCODE_F12]:= 'fullscr';
-DefaultBinds[ 1]:= '/put';
-DefaultBinds[ 3]:= 'ammomenu';
-DefaultBinds[ 8]:= 'hjump';
-DefaultBinds[ 9]:= 'switch';
-DefaultBinds[13]:= 'ljump';
-DefaultBinds[32]:= '+attack';
-{$IFDEF MOBILE}
-DefaultBinds[23]:= '+up';
-DefaultBinds[24]:= '+down';
-DefaultBinds[25]:= '+left';
-DefaultBinds[26]:= '+right';
-DefaultBinds[27]:= '+precise';
-DefaultBinds[44]:= 'chat';
-DefaultBinds[55]:= 'pause';
-{$ELSE}
-DefaultBinds[KeyNameToCode('up')]:= '+up';
-DefaultBinds[KeyNameToCode('down')]:= '+down';
-DefaultBinds[KeyNameToCode('left')]:= '+left';
-DefaultBinds[KeyNameToCode('right')]:= '+right';
-DefaultBinds[KeyNameToCode('left_shift')]:= '+precise';
-{$ENDIF}
+DefaultBinds[SDL_SCANCODE_MOUSEL]:= '/put';
+DefaultBinds[SDL_SCANCODE_MOUSER]:= 'ammomenu';
+DefaultBinds[SDL_SCANCODE_BACKSPACE]:= 'hjump';
+DefaultBinds[SDL_SCANCODE_TAB]:= 'switch';
+DefaultBinds[SDL_SCANCODE_RETURN]:= 'ljump';
+DefaultBinds[SDL_SCANCODE_SPACE]:= '+attack';
+
+DefaultBinds[SDL_SCANCODE_UP]:= '+up';
+DefaultBinds[SDL_SCANCODE_DOWN]:= '+down';
+DefaultBinds[SDL_SCANCODE_LEFT]:= '+left';
+DefaultBinds[SDL_SCANCODE_RIGHT]:= '+right';
+DefaultBinds[SDL_SCANCODE_LSHIFT]:= '+precise';
-for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
-for i:= 1 to 5 do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i);
+DefaultBinds[SDL_SCANCODE_F1]:= 'slot 1';
+DefaultBinds[SDL_SCANCODE_F2]:= 'slot 2';
+DefaultBinds[SDL_SCANCODE_F3]:= 'slot 3';
+DefaultBinds[SDL_SCANCODE_F4]:= 'slot 4';
+DefaultBinds[SDL_SCANCODE_F5]:= 'slot 5';
+DefaultBinds[SDL_SCANCODE_F6]:= 'slot 6';
+DefaultBinds[SDL_SCANCODE_F7]:= 'slot 7';
+DefaultBinds[SDL_SCANCODE_F8]:= 'slot 8';
+DefaultBinds[SDL_SCANCODE_F9]:= 'slot 9';
+DefaultBinds[SDL_SCANCODE_F10]:= 'slot 10';
+
+DefaultBinds[SDL_SCANCODE_1]:= 'timer 1';
+DefaultBinds[SDL_SCANCODE_2]:= 'timer 2';
+DefaultBinds[SDL_SCANCODE_3]:= 'timer 3';
+DefaultBinds[SDL_SCANCODE_4]:= 'timer 4';
+DefaultBinds[SDL_SCANCODE_5]:= 'timer 5';
SetDefaultBinds();
end;
@@ -363,25 +360,25 @@
end;
{$IFDEF MOBILE}
-procedure setiPhoneBinds;
+procedure setTouchWidgetStates;
begin
- tkbdn[ 1]:= ord(leftClick);
- tkbdn[ 2]:= ord(middleClick);
- tkbdn[ 3]:= ord(rightClick);
+ tkbdn[SDL_SCANCODE_MOUSEL]:= tkbdn[SDL_SCANCODE_MOUSEL] or ord(leftClick);
+ tkbdn[SDL_SCANCODE_MOUSEM]:= tkbdn[SDL_SCANCODE_MOUSEM] or ord(middleClick);
+ tkbdn[SDL_SCANCODE_MOUSER]:= tkbdn[SDL_SCANCODE_MOUSER] or ord(rightClick);
- tkbdn[23]:= ord(upKey);
- tkbdn[24]:= ord(downKey);
- tkbdn[25]:= ord(leftKey);
- tkbdn[26]:= ord(rightKey);
- tkbdn[27]:= ord(preciseKey);
+ tkbdn[SDL_SCANCODE_UP] := tkbdn[SDL_SCANCODE_UP] or ord(upKey);
+ tkbdn[SDL_SCANCODE_DOWN] := tkbdn[SDL_SCANCODE_DOWN] or ord(downKey);
+ tkbdn[SDL_SCANCODE_LEFT] := tkbdn[SDL_SCANCODE_LEFT] or ord(leftKey);
+ tkbdn[SDL_SCANCODE_RIGHT] := tkbdn[SDL_SCANCODE_RIGHT] or ord(rightKey);
+ tkbdn[SDL_SCANCODE_LSHIFT]:= tkbdn[SDL_SCANCODE_LSHIFT] or ord(preciseKey);
- tkbdn[ 8]:= ord(backspaceKey);
- tkbdn[ 9]:= ord(tabKey);
- tkbdn[13]:= ord(enterKey);
- tkbdn[32]:= ord(spaceKey);
+ tkbdn[SDL_SCANCODE_BACKSPACE]:= tkbdn[SDL_SCANCODE_BACKSPACE] or ord(backspaceKey);
+ tkbdn[SDL_SCANCODE_TAB]:= tkbdn[SDL_SCANCODE_TAB] or ord(tabKey);
+ tkbdn[SDL_SCANCODE_RETURN]:= ord(enterKey);
+ tkbdn[SDL_SCANCODE_SPACE]:= ord(spaceKey);
- tkbdn[44]:= ord(chatAction);
- tkbdn[55]:= ord(pauseAction);
+ tkbdn[SDL_SCANCODE_T]:= tkbdn[SDL_SCANCODE_T] or ord(chatAction);
+ tkbdn[SDL_SCANCODE_PAUSE]:= ord(pauseAction);
// set to false the keys that only need one stoke
leftClick:= false;