hedgewars/uInputHandler.pas
changeset 11486 2b30283a402c
parent 11368 c481d087f653
child 11544 b69f5f22a3ba
child 11664 64465e0eb852
equal deleted inserted replaced
11485:e5bc40acdfaa 11486:2b30283a402c
    33 procedure ProcessMouseWheel(x, y: LongInt);
    33 procedure ProcessMouseWheel(x, y: LongInt);
    34 procedure ProcessKey(event: TSDL_KeyboardEvent); inline;
    34 procedure ProcessKey(event: TSDL_KeyboardEvent); inline;
    35 procedure ProcessKey(code: LongInt; KeyDown: boolean);
    35 procedure ProcessKey(code: LongInt; KeyDown: boolean);
    36 
    36 
    37 procedure ResetKbd;
    37 procedure ResetKbd;
       
    38 procedure ResetMouseWheel;
    38 procedure FreezeEnterKey;
    39 procedure FreezeEnterKey;
    39 procedure InitKbdKeyTable;
    40 procedure InitKbdKeyTable;
    40 
    41 
    41 procedure SetBinds(var binds: TBinds);
    42 procedure SetBinds(var binds: TBinds);
    42 procedure SetDefaultBinds;
    43 procedure SetDefaultBinds;
   224             ProcessKey(KeyNameToCode('mousel'), ButtonDown);
   225             ProcessKey(KeyNameToCode('mousel'), ButtonDown);
   225         SDL_BUTTON_MIDDLE:
   226         SDL_BUTTON_MIDDLE:
   226             ProcessKey(KeyNameToCode('mousem'), ButtonDown);
   227             ProcessKey(KeyNameToCode('mousem'), ButtonDown);
   227         SDL_BUTTON_RIGHT:
   228         SDL_BUTTON_RIGHT:
   228             ProcessKey(KeyNameToCode('mouser'), ButtonDown);
   229             ProcessKey(KeyNameToCode('mouser'), ButtonDown);
   229         SDL_BUTTON_WHEELDOWN:
       
   230             ProcessKey(KeyNameToCode('wheeldown'), ButtonDown);
       
   231         SDL_BUTTON_WHEELUP:
       
   232             ProcessKey(KeyNameToCode('wheelup'), ButtonDown);
       
   233         end;
   230         end;
   234 end;
   231 end;
       
   232 
       
   233 var mwheelupCode, mwheeldownCode: Integer;
   235 
   234 
   236 procedure ProcessMouseWheel(x, y: LongInt);
   235 procedure ProcessMouseWheel(x, y: LongInt);
   237 begin
   236 begin
   238     //writelntoconsole('[MOUSEWHEEL] '+inttostr(x)+', '+inttostr(y));
   237     //writelntoconsole('[MOUSEWHEEL] '+inttostr(x)+', '+inttostr(y));
   239     if y > 0 then
   238     if y > 0 then
   240         ProcessKey(KeyNameToCode('wheelup'), true)
   239         begin
       
   240         // reset other direction
       
   241         if tkbd[mwheeldownCode] then
       
   242             ProcessKey(mwheeldownCode, false);
       
   243         // trigger "button down" event
       
   244         if (not tkbd[mwheelupCode]) then
       
   245             ProcessKey(mwheelupCode, true);
       
   246         end
   241     else if y < 0 then
   247     else if y < 0 then
   242         ProcessKey(KeyNameToCode('wheeldown'), true);
   248         begin
       
   249         // reset other direction
       
   250         if tkbd[mwheelupCode] then
       
   251             ProcessKey(mwheelupCode, false);
       
   252         // trigger "button down" event
       
   253         if (not tkbd[mwheeldownCode]) then
       
   254             ProcessKey(mwheeldownCode, true);
       
   255         end;
       
   256 end;
       
   257 
       
   258 procedure ResetMouseWheel();
       
   259 begin
       
   260     if tkbd[mwheelupCode] then
       
   261         ProcessKey(mwheelupCode, false);
       
   262     if tkbd[mwheeldownCode] then
       
   263         ProcessKey(mwheeldownCode, false);
   243 end;
   264 end;
   244 
   265 
   245 procedure ResetKbd;
   266 procedure ResetKbd;
   246 var t: LongInt;
   267 var t: LongInt;
   247 begin
   268 begin
   309     s: string[15];
   330     s: string[15];
   310 begin
   331 begin
   311     KeyNames[cKeyMaxIndex    ]:= 'mousel';
   332     KeyNames[cKeyMaxIndex    ]:= 'mousel';
   312     KeyNames[cKeyMaxIndex - 1]:= 'mousem';
   333     KeyNames[cKeyMaxIndex - 1]:= 'mousem';
   313     KeyNames[cKeyMaxIndex - 2]:= 'mouser';
   334     KeyNames[cKeyMaxIndex - 2]:= 'mouser';
   314     KeyNames[cKeyMaxIndex - 3]:= 'wheelup';
   335     mwheelupCode:= cKeyMaxIndex - 3;
   315     KeyNames[cKeyMaxIndex - 4]:= 'wheeldown';
   336     KeyNames[mwheelupCode]:= 'wheelup';
       
   337     mwheeldownCode:= cKeyMaxIndex - 4;
       
   338     KeyNames[mwheeldownCode]:= 'wheeldown';
   316 
   339 
   317     for i:= 0 to cKeyMaxIndex - 5 do
   340     for i:= 0 to cKeyMaxIndex - 5 do
   318         begin
   341         begin
   319         s:= shortstring(SDL_GetScancodeName(TSDL_Scancode(i)));
   342         s:= shortstring(SDL_GetScancodeName(TSDL_Scancode(i)));
   320 
   343 
   594     addBind(DefaultBinds, id)
   617     addBind(DefaultBinds, id)
   595 end;
   618 end;
   596 
   619 
   597 procedure initModule;
   620 procedure initModule;
   598 begin
   621 begin
       
   622     // assign 0 until InitKbdKeyTable is called
       
   623     mwheelupCode:= 0;
       
   624     mwheeldownCode:= 0;
       
   625 
   599     RegisterVariable('dbind', @chDefaultBind, true );
   626     RegisterVariable('dbind', @chDefaultBind, true );
   600 end;
   627 end;
   601 
   628 
   602 procedure freeModule;
   629 procedure freeModule;
   603 var j: LongInt;
   630 var j: LongInt;