hedgewars/uInputHandler.pas
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8346 3443e0de2c9d
child 8370 0c79946e96f8
equal deleted inserted replaced
8306:50fe80adbfcb 8363:0b4ac686fc44
    37 procedure FreezeEnterKey;
    37 procedure FreezeEnterKey;
    38 procedure InitKbdKeyTable;
    38 procedure InitKbdKeyTable;
    39 
    39 
    40 procedure SetBinds(var binds: TBinds);
    40 procedure SetBinds(var binds: TBinds);
    41 procedure SetDefaultBinds;
    41 procedure SetDefaultBinds;
       
    42 procedure chDefaultBind(var id: shortstring);
    42 
    43 
    43 procedure ControllerInit;
    44 procedure ControllerInit;
    44 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
    45 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
    45 procedure ControllerHatEvent(joy, hat, value: Byte);
    46 procedure ControllerHatEvent(joy, hat, value: Byte);
    46 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
    47 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
    68     ControllerNumButtons: array[0..5] of Integer;
    69     ControllerNumButtons: array[0..5] of Integer;
    69     ControllerAxes: array[0..5] of array[0..19] of Integer;
    70     ControllerAxes: array[0..5] of array[0..19] of Integer;
    70     //ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer;
    71     //ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer;
    71     ControllerHats: array[0..5] of array[0..19] of Byte;
    72     ControllerHats: array[0..5] of array[0..19] of Byte;
    72     ControllerButtons: array[0..5] of array[0..19] of Byte;
    73     ControllerButtons: array[0..5] of array[0..19] of Byte;
       
    74     usingDBinds: boolean;
    73 
    75 
    74 function  KeyNameToCode(name: shortstring): LongInt; inline;
    76 function  KeyNameToCode(name: shortstring): LongInt; inline;
    75 begin
    77 begin
    76     KeyNameToCode:= KeyNameToCode(name, '');
    78     KeyNameToCode:= KeyNameToCode(name, '');
    77 end;
    79 end;
   327 begin
   329 begin
   328 {$IFDEF MOBILE}
   330 {$IFDEF MOBILE}
   329     binds:= binds; // avoid hint
   331     binds:= binds; // avoid hint
   330     CurrentBinds:= DefaultBinds;
   332     CurrentBinds:= DefaultBinds;
   331 {$ELSE}
   333 {$ELSE}
   332 for t:= 0 to cKbdMaxIndex do
   334     for t:= 0 to cKbdMaxIndex do
   333     if (CurrentBinds[t] <> binds[t]) and tkbd[t] then
   335         if (CurrentBinds[t] <> binds[t]) and tkbd[t] then
   334         ProcessKey(t, False);
   336             ProcessKey(t, False);
   335 
   337 
   336     CurrentBinds:= binds;
   338     CurrentBinds:= binds;
   337 {$ENDIF}
   339 {$ENDIF}
   338 end;
   340 end;
   339 
   341 
   448     SDL_GetKeyState(@k);
   450     SDL_GetKeyState(@k);
   449     k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2);
   451     k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2);
   450     ProcessKey(k +  ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + button, pressed);
   452     ProcessKey(k +  ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + button, pressed);
   451 end;
   453 end;
   452 
   454 
       
   455 // Bind that isn't a team bind, but overrides defaultbinds.
       
   456 // When first called, DefaultBinds is cleared, because we assume we are getting a full list of dbinds.
       
   457 procedure chDefaultBind(var id: shortstring);
       
   458 var KeyName, Modifier, tmp: shortstring;
       
   459     b: LongInt;
       
   460 begin
       
   461 KeyName:= '';
       
   462 Modifier:= '';
       
   463 
       
   464 if (not usingDBinds) then
       
   465     begin
       
   466     usingDBinds:= true;
       
   467     FillByte(DefaultBinds, SizeOf(DefaultBinds), 0);
       
   468     end;
       
   469 
       
   470 if (Pos('mod:', id) <> 0) then
       
   471     begin
       
   472     tmp:= '';
       
   473     SplitBySpace(id, tmp);
       
   474     Modifier:= id;
       
   475     id:= tmp;
       
   476     end;
       
   477 
       
   478 SplitBySpace(id, KeyName);
       
   479 if KeyName[1]='"' then
       
   480     Delete(KeyName, 1, 1);
       
   481 if KeyName[byte(KeyName[0])]='"' then
       
   482     Delete(KeyName, byte(KeyName[0]), 1);
       
   483 b:= KeyNameToCode(id, Modifier);
       
   484 if b = 0 then
       
   485     OutError(errmsgUnknownVariable + ' "' + id + '"', false)
       
   486 else
       
   487     DefaultBinds[b]:= KeyName;
       
   488 end;
       
   489 
   453 procedure initModule;
   490 procedure initModule;
   454 begin
   491 begin
       
   492     usingDBinds:= false;
       
   493     RegisterVariable('dbind', @chDefaultBind, true );
   455 end;
   494 end;
   456 
   495 
   457 procedure freeModule;
   496 procedure freeModule;
   458 var j: LongInt;
   497 var j: LongInt;
   459 begin
   498 begin