Key returned 0 for arrows under linux. Sym works, clearer anyway.
authornemo
Sun, 17 Mar 2013 10:13:14 -0400
changeset 8742 b7b8bd398c1b
parent 8741 c98ec6865631
child 8743 0097855532f6
Key returned 0 for arrows under linux. Sym works, clearer anyway.
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uChat.pas
--- a/hedgewars/SDLh.pas	Sun Mar 17 01:36:04 2013 +0100
+++ b/hedgewars/SDLh.pas	Sun Mar 17 10:13:14 2013 -0400
@@ -312,6 +312,13 @@
     IMG_INIT_PNG = $00000002;
     IMG_INIT_TIF = $00000004;
 
+    {* SDL_keysym *}
+    SDLK_BACKSPACE = 8;
+    SDLK_RETURN    = 13;
+    SDLK_ESCAPE    = 27;
+    SDLK_UP        = 273;
+    SDLK_DOWN      = 274;
+
 
 /////////////////////////////////////////////////////////////////
 ///////////////////////  TYPE DEFINITIONS ///////////////////////
--- a/hedgewars/hwengine.pas	Sun Mar 17 01:36:04 2013 +0100
+++ b/hedgewars/hwengine.pas	Sun Mar 17 10:13:14 2013 -0400
@@ -167,8 +167,10 @@
 {$IFDEF SDL13}
                 SDL_KEYDOWN:
                     if GameState = gsChat then
+                        begin
                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
-                        KeyPressChat(SDL_GetKeyFromScancode(event.key.keysym.sym))//TODO correct for keymodifiers
+                        KeyPressChat(SDL_GetKeyFromScancode(event.key.keysym.sym, event.key.keysym.sym)//TODO correct for keymodifiers
+                        end
                     else
                         ProcessKey(event.key);
                 SDL_KEYUP:
@@ -212,7 +214,7 @@
 {$ELSE}
                 SDL_KEYDOWN:
                     if GameState = gsChat then
-                        KeyPressChat(event.key.keysym.unicode)
+                        KeyPressChat(event.key.keysym.unicode, event.key.keysym.sym)
                     else
                         ProcessKey(event.key);
                 SDL_KEYUP:
--- a/hedgewars/uChat.pas	Sun Mar 17 01:36:04 2013 +0100
+++ b/hedgewars/uChat.pas	Sun Mar 17 10:13:14 2013 -0400
@@ -28,7 +28,7 @@
 procedure CleanupInput;
 procedure AddChatString(s: shortstring);
 procedure DrawChat;
-procedure KeyPressChat(Key: Longword);
+procedure KeyPressChat(Key, Sym: Longword);
 
 implementation
 uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO;
@@ -303,72 +303,78 @@
     ResetKbd;
 end;
 
-procedure KeyPressChat(Key: Longword);
+procedure KeyPressChat(Key, Sym: Longword);
 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0);
 var i, btw, index: integer;
     utf8: shortstring;
+    action: boolean;
 begin
-    if Key <> 0 then
-    case Key of
-        {Backspace}
-        8, 127: if Length(InputStr.s) > 0 then
+    action:= false;
+    if Sym <> 0 then
+        case Sym of
+            SDLK_BACKSPACE:
                 begin
-                InputStr.s[0]:= InputStrL[byte(InputStr.s[0])];
-                SetLine(InputStr, InputStr.s, true)
+                action:= true;
+                if Length(InputStr.s) > 0 then
+                    begin
+                    InputStr.s[0]:= InputStrL[byte(InputStr.s[0])];
+                    SetLine(InputStr, InputStr.s, true)
+                    end
+                end;
+            SDLK_ESCAPE: 
+                begin
+                action:= true;
+                if Length(InputStr.s) > 0 then 
+                    SetLine(InputStr, '', true)
+                else CleanupInput
                 end;
-        {Esc}
-        27: if Length(InputStr.s) > 0 then SetLine(InputStr, '', true)
-            else CleanupInput;
-        {Return}
-        3, 13, 271: begin
-            if Length(InputStr.s) > 0 then
+            SDLK_RETURN:
                 begin
-                AcceptChatString(InputStr.s);
-                SetLine(InputStr, '', false)
+                action:= true;
+                if Length(InputStr.s) > 0 then
+                    begin
+                    AcceptChatString(InputStr.s);
+                    SetLine(InputStr, '', false)
+                    end;
+                CleanupInput
                 end;
-            CleanupInput;
-            end;
-        {arrow keys (up, down)}
-        111, 116,     //linux
-        63232, 63233: //osx
-            begin
-
-            if ((Key = 63232) or (Key = 111)) and (history < localLastStr) then inc(history);
-            if ((Key = 63233) or (Key = 116)) and (history > 0) then dec(history);
+            SDLK_UP, SDLK_DOWN:
+                begin
+                action:= true;
+                if (Sym = SDLK_UP) and (history < localLastStr) then inc(history);
+                if (Sym = SDLK_DOWN) and (history > 0) then dec(history);
+                index:= localLastStr - history + 1;
+                if (index > localLastStr) then
+                     SetLine(InputStr, '', true)
+                else SetLine(InputStr, LocalStrs[index], true)
+                end
+        end;
+    if not action and (Key <> 0) then
+        begin
+        if (Key < $80) then
+            btw:= 1
+        else if (Key < $800) then
+            btw:= 2
+        else if (Key < $10000) then
+            btw:= 3
+        else
+            btw:= 4;
 
-            index:= localLastStr - history + 1;
-            if (index > localLastStr) then
-                SetLine(InputStr, '', true)
-            else
-                SetLine(InputStr, LocalStrs[index], true);
+        utf8:= '';
+
+        for i:= btw downto 2 do
+            begin
+            utf8:= char((Key or $80) and $BF) + utf8;
+            Key:= Key shr 6
             end;
-        {arrow keys (left, right)}
-        63234, 63235: begin end;
-        else
-            if (Key < $80) then
-                btw:= 1
-            else if (Key < $800) then
-                btw:= 2
-            else if (Key < $10000) then
-                btw:= 3
-            else
-                btw:= 4;
 
-            utf8:= '';
+        utf8:= char(Key or firstByteMark[Pred(btw)]) + utf8;
 
-            for i:= btw downto 2 do
-                begin
-                utf8:= char((Key or $80) and $BF) + utf8;
-                Key:= Key shr 6
-                end;
+        if byte(InputStr.s[0]) + btw > 240 then
+            exit;
 
-            utf8:= char(Key or firstByteMark[Pred(btw)]) + utf8;
-
-            if byte(InputStr.s[0]) + btw > 240 then
-                exit;
-
-            InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0];
-            SetLine(InputStr, InputStr.s + utf8, true)
+        InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0];
+        SetLine(InputStr, InputStr.s + utf8, true)
         end
 end;