hedgewars/uInputHandler.pas
changeset 7088 dbec9bae4de1
parent 7071 c431a4a8ab0f
child 7089 6c7210257945
equal deleted inserted replaced
7087:d2089f2ea5af 7088:dbec9bae4de1
    66 
    66 
    67 // move cursor/camera
    67 // move cursor/camera
    68 // TODO: Scale on screen dimensions and/or axis value (game controller)?
    68 // TODO: Scale on screen dimensions and/or axis value (game controller)?
    69 //TODO what is this for?
    69 //TODO what is this for?
    70 movecursor(5 * CursorMovementX, 5 * CursorMovementY);
    70 movecursor(5 * CursorMovementX, 5 * CursorMovementY);
    71 
    71 end;
    72 
       
    73 (* 
       
    74 TODO reimplement
       
    75 $IFNDEF MOBILE
       
    76 // Controller(s)
       
    77 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
       
    78 for j:= 0 to Pred(ControllerNumControllers) do
       
    79     begin
       
    80     for i:= 0 to Pred(ControllerNumAxes[j]) do
       
    81         begin
       
    82         if ControllerAxes[j][i] > 20000 then
       
    83             tkbdn[k + 0]:= 1
       
    84         else
       
    85             tkbdn[k + 0]:= 0;
       
    86         if ControllerAxes[j][i] < -20000 then
       
    87             tkbdn[k + 1]:= 1
       
    88         else
       
    89             tkbdn[k + 1]:= 0;
       
    90         inc(k, 2);
       
    91         end;
       
    92     for i:= 0 to Pred(ControllerNumHats[j]) do
       
    93         begin
       
    94         tkbdn[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP;
       
    95         tkbdn[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT;
       
    96         tkbdn[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN;
       
    97         tkbdn[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT;
       
    98         inc(k, 4);
       
    99         end;
       
   100     for i:= 0 to Pred(ControllerNumButtons[j]) do
       
   101         begin
       
   102         tkbdn[k]:= ControllerButtons[j][i];
       
   103         inc(k, 1);
       
   104         end;
       
   105     end;
       
   106 $ENDIF *)
       
   107 
       
   108 end;
       
   109 
       
   110 
    72 
   111 procedure ProcessKey(code: LongInt; KeyDown: boolean);
    73 procedure ProcessKey(code: LongInt; KeyDown: boolean);
   112 var
    74 var
   113     Trusted: boolean;
    75     Trusted: boolean;
   114     s      : string;
    76     s      : string;
   315 DefaultBinds[KeyNameToCode('down')]:= '+down';
   277 DefaultBinds[KeyNameToCode('down')]:= '+down';
   316 DefaultBinds[KeyNameToCode('left')]:= '+left';
   278 DefaultBinds[KeyNameToCode('left')]:= '+left';
   317 DefaultBinds[KeyNameToCode('right')]:= '+right';
   279 DefaultBinds[KeyNameToCode('right')]:= '+right';
   318 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise';
   280 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise';
   319 
   281 
       
   282 
       
   283 DefaultBinds[KeyNameToCode('j0a0u')]:= '+left';
       
   284 DefaultBinds[KeyNameToCode('j0a0d')]:= '+right';
       
   285 DefaultBinds[KeyNameToCode('j0a1u')]:= '+up';
       
   286 DefaultBinds[KeyNameToCode('j0a1d')]:= '+down';
   320 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
   287 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
   321 for i:= 1 to 5  do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i);
   288 for i:= 1 to 5  do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i);
   322 
   289 
   323 SetDefaultBinds();
   290 SetDefaultBinds();
   324 end;
   291 end;
   350 
   317 
   351 procedure ControllerInit;
   318 procedure ControllerInit;
   352 var i, j: Integer;
   319 var i, j: Integer;
   353 begin
   320 begin
   354 ControllerEnabled:= 0;
   321 ControllerEnabled:= 0;
   355 {$IFDEF MOBILE}
   322 {$IFDEF IPHONE}
   356 exit; // joystick subsystem disabled on iPhone
   323 exit; // joystick subsystem disabled on iPhone
   357 {$ENDIF}
   324 {$ENDIF}
   358 
   325 
   359 SDL_InitSubSystem(SDL_INIT_JOYSTICK);
   326 SDL_InitSubSystem(SDL_INIT_JOYSTICK);
   360 ControllerNumControllers:= SDL_NumJoysticks();
   327 ControllerNumControllers:= SDL_NumJoysticks();
   414 else
   381 else
   415     WriteLnToConsole('Not using any game controller');
   382     WriteLnToConsole('Not using any game controller');
   416 end;
   383 end;
   417 
   384 
   418 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
   385 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
   419 begin
   386 var
   420     ControllerAxes[joy][axis]:= value;
   387     k: LongInt;
       
   388 begin
       
   389     SDL_GetKeyState(@k);
       
   390     k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2);
       
   391     ProcessKey(k +  axis*2, value > 20000);
       
   392     ProcessKey(k + (axis*2)+1, value < -20000);
   421 end;
   393 end;
   422 
   394 
   423 procedure ControllerHatEvent(joy, hat, value: Byte);
   395 procedure ControllerHatEvent(joy, hat, value: Byte);
   424 begin
   396 var
   425     ControllerHats[joy][hat]:= value;
   397     k: LongInt;
       
   398 begin
       
   399     SDL_GetKeyState(@k);
       
   400     k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2);
       
   401     ProcessKey(k +  ControllerNumAxes[joy]*2 + hat*4 + 0, (value and SDL_HAT_UP)   <> 0);
       
   402     ProcessKey(k +  ControllerNumAxes[joy]*2 + hat*4 + 1, (value and SDL_HAT_RIGHT)<> 0);
       
   403     ProcessKey(k +  ControllerNumAxes[joy]*2 + hat*4 + 2, (value and SDL_HAT_DOWN) <> 0);
       
   404     ProcessKey(k +  ControllerNumAxes[joy]*2 + hat*4 + 3, (value and SDL_HAT_LEFT) <> 0);
   426 end;
   405 end;
   427 
   406 
   428 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
   407 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
   429 begin
   408 var
   430     if pressed then
   409     k: LongInt;
   431         ControllerButtons[joy][button]:= 1
   410 begin
   432     else
   411     SDL_GetKeyState(@k);
   433         ControllerButtons[joy][button]:= 0;
   412     k:= k + joy * (ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + ControllerNumButtons[joy]*2);
       
   413     ProcessKey(k +  ControllerNumAxes[joy]*2 + ControllerNumHats[joy]*4 + button, pressed);
   434 end;
   414 end;
   435 
   415 
   436 procedure initModule;
   416 procedure initModule;
   437 begin
   417 begin
   438     wheelUp:= false;
   418     wheelUp:= false;