hedgewars/uInputHandler.pas
branchqmlfrontend
changeset 11549 b69f5f22a3ba
parent 11408 b894922d58cc
parent 11491 2b30283a402c
child 11704 83c40c1eb0e7
--- a/hedgewars/uInputHandler.pas	Fri Jan 01 19:15:32 2016 +0300
+++ b/hedgewars/uInputHandler.pas	Tue Feb 09 21:11:16 2016 +0300
@@ -35,6 +35,7 @@
 procedure ProcessKey(code: LongInt; KeyDown: boolean);
 
 procedure ResetKbd;
+procedure ResetMouseWheel;
 procedure FreezeEnterKey;
 procedure InitKbdKeyTable;
 
@@ -226,20 +227,40 @@
             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;
 
+var mwheelupCode, mwheeldownCode: Integer;
+
 procedure ProcessMouseWheel(x, y: LongInt);
 begin
     //writelntoconsole('[MOUSEWHEEL] '+inttostr(x)+', '+inttostr(y));
     if y > 0 then
-        ProcessKey(KeyNameToCode('wheelup'), true)
+        begin
+        // reset other direction
+        if tkbd[mwheeldownCode] then
+            ProcessKey(mwheeldownCode, false);
+        // trigger "button down" event
+        if (not tkbd[mwheelupCode]) then
+            ProcessKey(mwheelupCode, true);
+        end
     else if y < 0 then
-        ProcessKey(KeyNameToCode('wheeldown'), true);
+        begin
+        // reset other direction
+        if tkbd[mwheelupCode] then
+            ProcessKey(mwheelupCode, false);
+        // trigger "button down" event
+        if (not tkbd[mwheeldownCode]) then
+            ProcessKey(mwheeldownCode, true);
+        end;
+end;
+
+procedure ResetMouseWheel();
+begin
+    if tkbd[mwheelupCode] then
+        ProcessKey(mwheelupCode, false);
+    if tkbd[mwheeldownCode] then
+        ProcessKey(mwheeldownCode, false);
 end;
 
 procedure ResetKbd;
@@ -311,8 +332,10 @@
     KeyNames[cKeyMaxIndex    ]:= 'mousel';
     KeyNames[cKeyMaxIndex - 1]:= 'mousem';
     KeyNames[cKeyMaxIndex - 2]:= 'mouser';
-    KeyNames[cKeyMaxIndex - 3]:= 'wheelup';
-    KeyNames[cKeyMaxIndex - 4]:= 'wheeldown';
+    mwheelupCode:= cKeyMaxIndex - 3;
+    KeyNames[mwheelupCode]:= 'wheelup';
+    mwheeldownCode:= cKeyMaxIndex - 4;
+    KeyNames[mwheeldownCode]:= 'wheeldown';
 
     for i:= 0 to cKeyMaxIndex - 5 do
         begin
@@ -596,6 +619,10 @@
 
 procedure initModule;
 begin
+    // assign 0 until InitKbdKeyTable is called
+    mwheelupCode:= 0;
+    mwheeldownCode:= 0;
+
     RegisterVariable('dbind', @chDefaultBind, true );
 end;