- Keyboard bindings seem to work fully sdl2transition
authorunc0rr
Fri, 08 Nov 2013 17:53:02 +0400
branchsdl2transition
changeset 9694 e8d0fe885169
parent 9691 a312103af4b1
child 9697 198c3ed28fe8
- Keyboard bindings seem to work fully - Catch mouse wheel event (bindings don't work for unknown reason)
hedgewars/hwengine.pas
hedgewars/uInputHandler.pas
--- a/hedgewars/hwengine.pas	Fri Nov 08 14:22:22 2013 +0400
+++ b/hedgewars/hwengine.pas	Fri Nov 08 17:53:02 2013 +0400
@@ -165,6 +165,18 @@
                     if (GameState <> gsChat) and (GameState >= gsGame) then
                         ProcessKey(event.key);
 
+                SDL_MOUSEBUTTONDOWN:
+                    if GameState = gsConfirm then
+                        ParseCommand('quit', true)
+                    else
+                        if (GameState >= gsGame) then ProcessMouse(event.button, true);
+
+                SDL_MOUSEBUTTONUP:
+                    if (GameState >= gsGame) then ProcessMouse(event.button, false);
+
+                SDL_MOUSEWHEEL:
+                    ProcessMouseWheel(event.wheel.x, event.wheel.y);
+
                 SDL_WINDOWEVENT:
                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
                     begin
--- a/hedgewars/uInputHandler.pas	Fri Nov 08 14:22:22 2013 +0400
+++ b/hedgewars/uInputHandler.pas	Fri Nov 08 17:53:02 2013 +0400
@@ -30,6 +30,7 @@
 //procedure MaskModifier(var code: LongInt; modifier: LongWord);
 procedure MaskModifier(Modifier: shortstring; var code: LongInt);
 procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean);
+procedure ProcessMouseWheel(x, y: LongInt);
 procedure ProcessKey(event: TSDL_KeyboardEvent); inline;
 procedure ProcessKey(code: LongInt; KeyDown: boolean);
 
@@ -82,8 +83,8 @@
 var code: LongInt;
 begin
     name:= LowerCase(name);
-    code:= cKeyMaxIndex;
-    while (code > 0) and (KeyNames[code] <> name) do dec(code);
+    code:= 0;
+    while (code <= cKeyMaxIndex) and (KeyNames[code] <> name) do inc(code);
 
     MaskModifier(Modifier, code);
     KeyNameToCode:= code;
@@ -166,7 +167,12 @@
 
 if CurrentBinds[code][0] <> #0 then
     begin
-    if (code > 3) and KeyDown and (not ((CurrentBinds[code] = 'put')) or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r')) and (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) then bShowAmmoMenu:= false;
+    if (code < cKeyMaxIndex - 2) // means not mouse buttons
+        and KeyDown
+        and (not ((CurrentBinds[code] = 'put')) or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r')) 
+        and (CurrentTeam <> nil) 
+        and (not CurrentTeam^.ExtDriven) 
+        then bShowAmmoMenu:= false;
 
     if KeyDown then
         begin
@@ -190,7 +196,7 @@
 var code: LongInt;
 begin
     code:= event.keysym.scancode;
-
+    //writelntoconsole('[KEY] '+inttostr(code)+ ' -> ''' +KeyNames[code] + ''', type = '+inttostr(event.type_));
     ProcessKey(code, event.type_ = SDL_KEYDOWN);
 end;
 {$ELSE}
@@ -205,18 +211,28 @@
 
 procedure ProcessMouse(event: TSDL_MouseButtonEvent; ButtonDown: boolean);
 begin
-case event.button of
-    SDL_BUTTON_LEFT:
-        ProcessKey(KeyNameToCode('mousel'), ButtonDown);
-    SDL_BUTTON_MIDDLE:
-        ProcessKey(KeyNameToCode('mousem'), ButtonDown);
-    SDL_BUTTON_RIGHT:
-        ProcessKey(KeyNameToCode('mouser'), ButtonDown);
-    SDL_BUTTON_WHEELDOWN:
-        ProcessKey(KeyNameToCode('wheeldown'), ButtonDown);
-    SDL_BUTTON_WHEELUP:
-        ProcessKey(KeyNameToCode('wheelup'), ButtonDown);
-    end;
+    //writelntoconsole('[MOUSE] '+inttostr(event.button));
+    case event.button of
+        SDL_BUTTON_LEFT:
+            ProcessKey(KeyNameToCode('mousel'), ButtonDown);
+        SDL_BUTTON_MIDDLE:
+            ProcessKey(KeyNameToCode('mousem'), ButtonDown);
+        SDL_BUTTON_RIGHT:
+            ProcessKey(KeyNameToCode('mouser'), ButtonDown);
+        SDL_BUTTON_WHEELDOWN:
+            ProcessKey(KeyNameToCode('wheeldown'), ButtonDown);
+        SDL_BUTTON_WHEELUP:
+            ProcessKey(KeyNameToCode('wheelup'), ButtonDown);
+        end;
+end;
+
+procedure ProcessMouseWheel(x, y: LongInt);
+begin
+    //writelntoconsole('[MOUSEWHEEL] '+inttostr(x)+', '+inttostr(y));
+    if y > 0 then
+        ProcessKey(KeyNameToCode('wheelup'), true)
+    else if y < 0 then
+        ProcessKey(KeyNameToCode('wheeldown'), true);
 end;
 
 procedure ResetKbd;