hedgewars/uInputHandler.pas
branchwebgl
changeset 8444 75db7bb8dce8
parent 8330 aaefa587e277
parent 8370 0c79946e96f8
child 8446 c18ba8726f5a
equal deleted inserted replaced
8340:46a9fde631f4 8444:75db7bb8dce8
    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);
    64     ControllerEnabled: Integer;
    65     ControllerEnabled: Integer;
    65     ControllerNumAxes: array[0..5] of Integer;
    66     ControllerNumAxes: array[0..5] of Integer;
    66     //ControllerNumBalls: array[0..5] of Integer;
    67     //ControllerNumBalls: array[0..5] of Integer;
    67     ControllerNumHats: array[0..5] of Integer;
    68     ControllerNumHats: array[0..5] of Integer;
    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 
   351 end;
   353 end;
   352 
   354 
   353 var Controller: array [0..5] of PSDL_Joystick;
   355 var Controller: array [0..5] of PSDL_Joystick;
   354 
   356 
   355 procedure ControllerInit;
   357 procedure ControllerInit;
   356 var i, j: Integer;
   358 var j: Integer;
   357 begin
   359 begin
   358 ControllerEnabled:= 0;
   360 ControllerEnabled:= 0;
   359 {$IFDEF IPHONE}
   361 {$IFDEF IPHONE}
   360 exit; // joystick subsystem disabled on iPhone
   362 exit; // joystick subsystem disabled on iPhone
   361 {$ENDIF}
   363 {$ENDIF}
   396                 ControllerNumHats[j]:= 20;
   398                 ControllerNumHats[j]:= 20;
   397 
   399 
   398             if ControllerNumButtons[j] > 20 then
   400             if ControllerNumButtons[j] > 20 then
   399                 ControllerNumButtons[j]:= 20;
   401                 ControllerNumButtons[j]:= 20;
   400 
   402 
   401             // reset all buttons/axes
   403             (*// reset all buttons/axes
   402             for i:= 0 to pred(ControllerNumAxes[j]) do
   404             for i:= 0 to pred(ControllerNumAxes[j]) do
   403                 ControllerAxes[j][i]:= 0;
   405                 ControllerAxes[j][i]:= 0;
   404             (*for i:= 0 to pred(ControllerNumBalls[j]) do
   406             for i:= 0 to pred(ControllerNumBalls[j]) do
   405                 begin
   407                 begin
   406                 ControllerBalls[j][i][0]:= 0;
   408                 ControllerBalls[j][i][0]:= 0;
   407                 ControllerBalls[j][i][1]:= 0;
   409                 ControllerBalls[j][i][1]:= 0;
   408                 end;*)
   410                 end;
   409             for i:= 0 to pred(ControllerNumHats[j]) do
   411             for i:= 0 to pred(ControllerNumHats[j]) do
   410                 ControllerHats[j][i]:= SDL_HAT_CENTERED;
   412                 ControllerHats[j][i]:= SDL_HAT_CENTERED;
   411             for i:= 0 to pred(ControllerNumButtons[j]) do
   413             for i:= 0 to pred(ControllerNumButtons[j]) do
   412                 ControllerButtons[j][i]:= 0;
   414                 ControllerButtons[j][i]:= 0;*)
   413             end;
   415             end;
   414         end;
   416         end;
   415     // enable event generation/controller updating
   417     // enable event generation/controller updating
   416     SDL_JoystickEventState(1);
   418     SDL_JoystickEventState(1);
   417     end
   419     end
   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