hedgewars/uTouch.pas
changeset 6683 75a1d84ac606
parent 6676 21cf35a570a7
child 6684 112a0eb8782b
equal deleted inserted replaced
6682:bf3cf6e60673 6683:75a1d84ac606
    61 procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger);
    61 procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger);
    62 procedure convertToFingerCoord(var x,y: hwFloat; oldX, oldY: hwFloat);
    62 procedure convertToFingerCoord(var x,y: hwFloat; oldX, oldY: hwFloat);
    63 function fingerHasMoved(finger: Touch_Finger): boolean;
    63 function fingerHasMoved(finger: Touch_Finger): boolean;
    64 function calculateDelta(finger1, finger2: Touch_Finger): hwFloat;
    64 function calculateDelta(finger1, finger2: Touch_Finger): hwFloat;
    65 function getSecondFinger(finger: Touch_Finger): PTouch_Finger;
    65 function getSecondFinger(finger: Touch_Finger): PTouch_Finger;
    66 function isOnRect(x,y,w,h: LongInt; finger: Touch_Finger): boolean;
    66 function isOnRect(widget: TOnScreenWidget; finger: Touch_Finger): boolean;
       
    67 function isOnRect(rect: TSDL_Rect; finger: Touch_Finger): boolean;
    67 procedure printFinger(finger: Touch_Finger);
    68 procedure printFinger(finger: Touch_Finger);
    68 implementation
    69 implementation
    69 
    70 
    70 const
    71 const
    71     clicktime = 200;
    72     clicktime = 200;
   109                 aiming:= true;
   110                 aiming:= true;
   110                 aim(finger^);
   111                 aim(finger^);
   111                 exit;
   112                 exit;
   112             end;
   113             end;
   113 
   114 
   114             if isOnRect(fireButtonX, fireButtonY, fireButtonW, fireButtonH, finger^) then
   115             if isOnRect(fireButton, finger^) then
   115             begin
   116             begin
   116                 stopFiring:= false;
   117                 stopFiring:= false;
   117                 spaceKey:= true;
   118                 spaceKey:= true;
   118                 exit;
   119                 exit;
   119             end;
   120             end;
   120             if isOnRect(arrowLeftX, arrowLeftY, arrowLeftW, arrowLeftH, finger^) then
   121             if isOnRect(arrowLeft, finger^) then
   121             begin
   122             begin
   122                 leftKey:= true;
   123                 leftKey:= true;
   123                 walkingLeft := true;
   124                 walkingLeft := true;
   124                 exit;
   125                 exit;
   125             end;
   126             end;
   126             if isOnRect(arrowRightX, arrowRightY, arrowRightW, arrowRightH, finger^) then
   127             if isOnRect(arrowRight, finger^) then
   127             begin
   128             begin
   128                 rightKey:= true;
   129                 rightKey:= true;
   129                 walkingRight:= true;
   130                 walkingRight:= true;
   130                 exit;
   131                 exit;
   131             end;
   132             end;
   132             if isOnRect(arrowUpX, arrowUpY, arrowUpW, arrowUpH, finger^) then
   133             if isOnRect(arrowUp, finger^) then
   133             begin
   134             begin
   134                 upKey:= true;
   135                 upKey:= true;
   135                 aimingUp:= true;
   136                 aimingUp:= true;
   136                 exit;
   137                 exit;
   137             end;
   138             end;
   138             if isOnRect(arrowDownX, arrowDownY, arrowUpW, arrowUpH, finger^) then
   139             if isOnRect(arrowDown, finger^) then
   139             begin
   140             begin
   140                 downKey:= true;
   141                 downKey:= true;
   141                 aimingDown:= true;
   142                 aimingDown:= true;
   142                 exit;
   143                 exit;
   143             end;
   144             end;
   144 
   145 
   145             if isOnRect(backjumpX, backjumpY, backjumpW, backjumpH, finger^) then
   146             if isOnRect(backjump, finger^) then
   146             begin
   147             begin
   147                 enterKey:= true;
   148                 enterKey:= true;
   148                 exit;
   149                 exit;
   149             end;
   150             end;
   150             if isOnRect(forwardjumpX, forwardjumpY, forwardjumpW, forwardjumpH, finger^) then
   151             if isOnRect(forwardjump, finger^) then
   151             begin
   152             begin
   152                 backspaceKey:= true;
   153                 backspaceKey:= true;
   153                 exit;
   154                 exit;
   154             end;
   155             end;
   155             moveCursor:= not bShowAmmoMenu;
   156             moveCursor:= not bShowAmmoMenu;
   265 yTouchClick:= finger.y;
   266 yTouchClick:= finger.y;
   266 timeSinceClick:= SDL_GetTicks;
   267 timeSinceClick:= SDL_GetTicks;
   267 
   268 
   268 if bShowAmmoMenu then
   269 if bShowAmmoMenu then
   269     begin 
   270     begin 
   270     if isOnRect(AmmoRect.x, AmmoRect.y, AmmoRect.w, AmmoRect.h, finger) then
   271     if isOnRect(AmmoRect, finger) then
   271         begin
   272         begin
   272         CursorPoint.X:= finger.x;
   273         CursorPoint.X:= finger.x;
   273         CursorPoint.Y:= finger.y;
   274         CursorPoint.Y:= finger.y;
   274         doPut(CursorPoint.X, CursorPoint.Y, false); 
   275         doPut(CursorPoint.X, CursorPoint.Y, false); 
   275         end
   276         end
   547         getSecondFinger := @fingers[1]
   548         getSecondFinger := @fingers[1]
   548     else
   549     else
   549         getSecondFinger := @fingers[0];
   550         getSecondFinger := @fingers[0];
   550 end;
   551 end;
   551 
   552 
   552 function isOnRect(x,y,w,h: LongInt; finger: Touch_Finger): boolean;
   553 function isOnRect(rect: TSDL_Rect; finger: Touch_Finger): boolean;
   553 begin
   554 var widget: TOnScreenWidget;
   554 isOnRect:= (finger.x > x)   and
   555 begin
   555            (finger.x < x+w) and
   556 	widget.x:= rect.x;
   556            (cScreenHeight - finger.y > y)   and
   557 	widget.y:= rect.y;
   557            (cScreenHeight - finger.y < (y+h));
   558 	widget.width:= rect.width;
       
   559 	widget.height:= rect.height;
       
   560 	widget.hOffset:= 0;
       
   561 	widget.vOffset:= 0;
       
   562 	exit(isOnRect(widget, finger));
       
   563 end;
       
   564 
       
   565 function isOnRect(widget: TOnScreenWidget; finger: Touch_Finger): boolean;
       
   566 begin
       
   567 with widget do
       
   568 	isOnRect:= (finger.x > x + hOffset)   and
       
   569                (finger.x < x + w + hOffset) and
       
   570                (cScreenHeight - finger.y > y + vOffset)   and
       
   571                (cScreenHeight - finger.y < y + h + vOffset));
   558 end;
   572 end;
   559 
   573 
   560 procedure printFinger(finger: Touch_Finger);
   574 procedure printFinger(finger: Touch_Finger);
   561 begin
   575 begin
   562     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
   576     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));