hedgewars/uTouch.pas
changeset 6723 b77e2d4d664b
parent 6716 c9e873cf2b08
child 6806 cdfb6c7099e5
equal deleted inserted replaced
6722:e3a35bc838fb 6723:b77e2d4d664b
    51 function fingerHasMoved(finger: TTouch_Data): boolean;
    51 function fingerHasMoved(finger: TTouch_Data): boolean;
    52 function calculateDelta(finger1, finger2: TTouch_Data): LongInt;
    52 function calculateDelta(finger1, finger2: TTouch_Data): LongInt;
    53 function getSecondFinger(finger: TTouch_Data): PTouch_Data;
    53 function getSecondFinger(finger: TTouch_Data): PTouch_Data;
    54 function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
    54 function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
    55 function isOnRect(x,y,w,h: LongInt; finger: TTouch_Data): boolean;
    55 function isOnRect(x,y,w,h: LongInt; finger: TTouch_Data): boolean;
       
    56 function isOnWidget(widget: TOnScreenWidget; finger: TTouch_Data): boolean;
    56 procedure printFinger(finger: TTouch_Data);
    57 procedure printFinger(finger: TTouch_Data);
    57 implementation
    58 implementation
    58 
    59 
    59 const
    60 const
    60     clickTime = 200;
    61     clickTime = 200;
    96     aim(finger^);
    97     aim(finger^);
    97     moveCursor:= false;
    98     moveCursor:= false;
    98     exit;
    99     exit;
    99 end;
   100 end;
   100 
   101 
   101 if isOnRect(fireButton.active, finger^) then
   102 if isOnWidget(fireButton, finger^) then
   102     begin
   103     begin
   103     spaceKey:= true;
   104     spaceKey:= true;
   104     moveCursor:= false;
   105     moveCursor:= false;
   105     finger^.pressedWidget:= @fireButton;
   106     finger^.pressedWidget:= @fireButton;
   106     exit;
   107     exit;
   107     end;
   108     end;
   108 if isOnRect(arrowLeft.active, finger^) then
   109 if isOnWidget(arrowLeft, finger^) then
   109     begin
   110     begin
   110     leftKey:= true;
   111     leftKey:= true;
   111     moveCursor:= false;
   112     moveCursor:= false;
   112     finger^.pressedWidget:= @arrowLeft;
   113     finger^.pressedWidget:= @arrowLeft;
   113     exit;
   114     exit;
   114     end;
   115     end;
   115 if isOnRect(arrowRight.active, finger^) then
   116 if isOnWidget(arrowRight, finger^) then
   116     begin
   117     begin
   117     rightKey:= true;
   118     rightKey:= true;
   118     moveCursor:= false;
   119     moveCursor:= false;
   119     finger^.pressedWidget:= @arrowRight;
   120     finger^.pressedWidget:= @arrowRight;
   120     exit;
   121     exit;
   121     end;
   122     end;
   122 if isOnRect(arrowUp.active, finger^) then
   123 if isOnWidget(arrowUp, finger^) then
   123      begin
   124      begin
   124      upKey:= true;
   125      upKey:= true;
   125      moveCursor:= false;
   126      moveCursor:= false;
   126      finger^.pressedWidget:= @arrowUp;
   127      finger^.pressedWidget:= @arrowUp;
   127      exit;
   128      exit;
   128      end;
   129      end;
   129 if isOnRect(arrowDown.active, finger^) then
   130 if isOnWidget(arrowDown, finger^) then
   130      begin
   131      begin
   131      downKey:= true;
   132      downKey:= true;
   132      moveCursor:= false;
   133      moveCursor:= false;
   133      finger^.pressedWidget:= @arrowDown;
   134      finger^.pressedWidget:= @arrowDown;
   134      exit;
   135      exit;
   135      end;
   136      end;
   136 
   137 
   137 if isOnRect(pauseButton.active, finger^) then
   138 if isOnWidget(pauseButton, finger^) then
   138      begin
   139      begin
   139      isPaused:= not isPaused;
   140      isPaused:= not isPaused;
   140      moveCursor:= false;
   141      moveCursor:= false;
   141      finger^.pressedWidget:= @pauseButton;
   142      finger^.pressedWidget:= @pauseButton;
   142      exit;
   143      exit;
   253 end;
   254 end;
   254 
   255 
   255 procedure onTouchLongClick(finger: TTouch_Data);
   256 procedure onTouchLongClick(finger: TTouch_Data);
   256 begin
   257 begin
   257 {$IFDEF USE_TOUCH_INTERFACE}
   258 {$IFDEF USE_TOUCH_INTERFACE}
   258 if isOnRect(jumpWidget.active, finger) then
   259 if isOnWidget(jumpWidget, finger) then
   259     begin
   260     begin
   260     ParseCommand('ljump', (CurrentTeam <> nil) and not(CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel=0));
   261     ParseCommand('ljump', (CurrentTeam <> nil) and not(CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel=0));
   261     if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
   262     if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
   262         ParseCommand('gencmd R', true);
   263         ParseCommand('gencmd R', true);
   263     exit;
   264     exit;
   290         bShowAmmoMenu:= false;
   291         bShowAmmoMenu:= false;
   291     exit;
   292     exit;
   292     end;
   293     end;
   293 
   294 
   294 {$IFDEF USE_TOUCH_INTERFACE}
   295 {$IFDEF USE_TOUCH_INTERFACE}
   295 if isOnCurrentHog(finger) or isOnRect(AMWidget.active, finger) then
   296 if isOnCurrentHog(finger) or isOnWidget(AMWidget, finger) then
   296     begin
   297     begin
   297     bShowAmmoMenu := true;
   298     bShowAmmoMenu := true;
   298     exit;
   299     exit;
   299     end;
   300     end;
   300 
   301 
   301 if isOnRect(jumpWidget.active, finger) then
   302 if isOnWidget(jumpWidget, finger) then
   302     begin
   303     begin
   303     ParseCommand('hjump', (CurrentTeam <> nil) and not(CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel=0));
   304     ParseCommand('hjump', (CurrentTeam <> nil) and not(CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel=0));
   304     if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
   305     if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
   305         ParseCommand('gencmd R', true);
   306         ParseCommand('gencmd R', true);
   306     exit;
   307     exit;
   558                (finger.x < x + w) and
   559                (finger.x < x + w) and
   559                (cScreenHeight - finger.y > y) and
   560                (cScreenHeight - finger.y > y) and
   560                (cScreenHeight - finger.y < y + h);
   561                (cScreenHeight - finger.y < y + h);
   561 end;
   562 end;
   562 
   563 
       
   564 function isOnWidget(widget: TOnScreenWidget; finger: TTouch_Data): boolean;
       
   565 begin
       
   566     isOnWidget:= widget.show and isOnRect(widget.active, finger);
       
   567 end;
       
   568 
   563 procedure printFinger(finger: TTouch_Data);
   569 procedure printFinger(finger: TTouch_Data);
   564 begin
   570 begin
   565     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
   571     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
   566 end;
   572 end;
   567 
   573