# HG changeset patch # User sheepluva # Date 1452443967 -3600 # Node ID 2b30283a402c4fcdc0522c926ae3da58b6955378 # Parent e5bc40acdfaa0d67e2695d334586071b2db5a7a6 fix/clean-up mousewheel code diff -r e5bc40acdfaa -r 2b30283a402c hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sun Jan 10 12:59:03 2016 +0100 +++ b/hedgewars/SDLh.pas Sun Jan 10 17:39:27 2016 +0100 @@ -91,8 +91,8 @@ SDL_BUTTON_LEFT = 1; SDL_BUTTON_MIDDLE = 2; SDL_BUTTON_RIGHT = 3; - SDL_BUTTON_WHEELUP = 4; - SDL_BUTTON_WHEELDOWN = 5; + SDL_BUTTON_X1 = 4; + SDL_BUTTON_X2 = 5; SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32; diff -r e5bc40acdfaa -r 2b30283a402c hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sun Jan 10 12:59:03 2016 +0100 +++ b/hedgewars/hwengine.pas Sun Jan 10 17:39:27 2016 +0100 @@ -155,11 +155,13 @@ PrevTime, CurrTime: LongWord; isTerminated: boolean; previousGameState: TGameState; + wheelEvent: boolean; begin isTerminated:= false; PrevTime:= SDL_GetTicks; while isTerminated = false do begin + wheelEvent:= false; SDL_PumpEvents(); while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do @@ -187,7 +189,10 @@ if (GameState >= gsGame) then ProcessMouse(event.button, false); SDL_MOUSEWHEEL: + begin + wheelEvent:= true; ProcessMouseWheel(event.wheel.x, event.wheel.y); + end; SDL_TEXTINPUT: uChat.TextInput(event.text); @@ -239,6 +244,9 @@ end; //end case event.type_ of end; //end while SDL_PollEvent(@event) <> 0 do + if (not wheelEvent) then + ResetMouseWheel(); + if (CursorMovementX <> 0) or (CursorMovementY <> 0) then handlePositionUpdate(CursorMovementX * cameraKeyboardSpeed, CursorMovementY * cameraKeyboardSpeed); diff -r e5bc40acdfaa -r 2b30283a402c hedgewars/uInputHandler.pas --- a/hedgewars/uInputHandler.pas Sun Jan 10 12:59:03 2016 +0100 +++ b/hedgewars/uInputHandler.pas Sun Jan 10 17:39:27 2016 +0100 @@ -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;