hedgewars/uTouch.pas
changeset 6701 58a43c2064ad
parent 6700 e04da46ee43c
child 6702 37c56511df0c
equal deleted inserted replaced
6700:e04da46ee43c 6701:58a43c2064ad
    73 
    73 
    74     //aiming
    74     //aiming
    75     aiming: boolean;
    75     aiming: boolean;
    76     aimingUp, aimingDown: boolean; 
    76     aimingUp, aimingDown: boolean; 
    77     targetAngle: LongInt;
    77     targetAngle: LongInt;
    78     stopFiring: boolean;
    78 
    79 
    79     buttonsDown: Longword;
    80     //moving
       
    81     stopLeft, stopRight, walkingLeft, walkingRight :  boolean;
       
    82 
    80 
    83 procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
    81 procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
    84 var 
    82 var 
    85     finger: PTouch_Data;
    83     finger: PTouch_Data;
    86 begin
    84 begin
    87 {$IFDEF USE_TOUCH_INTERFACE}
    85 {$IFDEF USE_TOUCH_INTERFACE}
    88 finger := addFinger(x,y,pointerId);
    86 finger := addFinger(x,y,pointerId);
    89 case pointerCount of
    87 if isOnCrosshair(finger^) then
    90         1:
    88 begin
    91         begin
    89     aiming:= true;
    92             moveCursor:= false;
    90     aim(finger^);
    93 
    91     exit;
    94             if isOnCrosshair(finger^) then
    92 end;
    95             begin
    93 
    96                 aiming:= true;
    94 inc(buttonsDown);//inc buttonsDown, if we don't see a button down we'll dec it
    97                 aim(finger^);
    95 if isOnRect(fireButton.active, finger^) then
    98                 exit;
    96     begin
    99             end;
    97     spaceKey:= true;
   100 
    98     moveCursor:= false;
   101             if isOnRect(fireButton.active, finger^) then
    99     finger^.pressedWidget:= @fireButton;
   102             begin
   100     exit;
   103                 stopFiring:= false;
   101     end;
   104                 spaceKey:= true;
   102 if isOnRect(arrowLeft.active, finger^) then
   105                 exit;
   103     begin
   106             end;
   104     leftKey:= true;
   107             if isOnRect(arrowLeft.active, finger^) then
   105     moveCursor:= false;
   108             begin
   106     finger^.pressedWidget:= @arrowLeft;
   109                 leftKey:= true;
   107     exit;
   110                 walkingLeft := true;
   108     end;
   111                 exit;
   109 if isOnRect(arrowRight.active, finger^) then
   112             end;
   110     begin
   113             if isOnRect(arrowRight.active, finger^) then
   111     rightKey:= true;
   114             begin
   112     moveCursor:= false;
   115                 rightKey:= true;
   113     finger^.pressedWidget:= @arrowRight;
   116                 walkingRight:= true;
   114     exit;
   117                 exit;
   115     end;
   118             end;
   116 if isOnRect(arrowUp.active, finger^) then
   119             if isOnRect(arrowUp.active, finger^) then
   117      begin
   120             begin
   118      upKey:= true;
   121                 upKey:= true;
   119      aimingUp:= true;
   122                 aimingUp:= true;
   120      moveCursor:= false;
   123                 exit;
   121      finger^.pressedWidget:= @arrowUp;
   124             end;
   122      exit;
   125             if isOnRect(arrowDown.active, finger^) then
   123      end;
   126             begin
   124 if isOnRect(arrowDown.active, finger^) then
   127                 downKey:= true;
   125      begin
   128                 aimingDown:= true;
   126      downKey:= true;
   129                 exit;
   127      aimingDown:= true;
   130             end;
   128      moveCursor:= false;
   131 
   129      finger^.pressedWidget:= @arrowDown;
   132             if isOnRect(backjump.active, finger^) then
   130      exit;
   133             begin
   131      end;
   134                 enterKey:= true;
   132 
   135                 exit;
   133 if isOnRect(backjump.active, finger^) then
   136             end;
   134      begin
   137             if isOnRect(forwardjump.active, finger^) then
   135      enterKey:= true;
   138             begin
   136      moveCursor:= false;
   139                 backspaceKey:= true;
   137      finger^.pressedWidget:= @backjump;
   140                 exit;
   138      exit;
   141             end;
   139      end;
   142             if isOnRect(pauseButton.active, finger^) then
   140 if isOnRect(forwardjump.active, finger^) then
   143             begin
   141      begin
   144                 isPaused:= not isPaused;
   142      backspaceKey:= true;
   145                 exit;
   143      moveCursor:= false;
   146             end;
   144      finger^.pressedWidget:= @forwardjump;
   147             moveCursor:= not bShowAmmoMenu;
   145      exit;
   148         end;
   146      end;
   149         2:
   147 if isOnRect(pauseButton.active, finger^) then
   150         begin
   148      begin
   151             aiming:= false;
   149      isPaused:= not isPaused;
   152             stopFiring:= true;
   150      moveCursor:= false;
   153             moveCursor:= false;
   151      finger^.pressedWidget:= @pauseButton;
   154             pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
   152      exit;
   155             baseZoomValue := ZoomValue
   153      end;
   156         end;
   154 
   157     end;//end case pointerCount of
   155 dec(buttonsDown);//no buttonsDown, undo the inc() above
       
   156 if buttonsDown = 0 then
       
   157     begin
       
   158     moveCursor:= true;
       
   159     if pointerCount = 2 then
       
   160         begin
       
   161         aiming:= false;
       
   162         moveCursor:= false;
       
   163         pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
       
   164         baseZoomValue := ZoomValue
       
   165     end;
       
   166 end;
   158 {$ENDIF}
   167 {$ENDIF}
   159 end;
   168 end;
   160 
   169 
   161 procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: TSDL_FingerId);
   170 procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: TSDL_FingerId);
   162 var
   171 var
   184     begin
   193     begin
   185         aim(finger^);
   194         aim(finger^);
   186         exit
   195         exit
   187     end;
   196     end;
   188 
   197 
   189 if pointerCount = 2 then
   198 if (buttonsDown = 0) and (pointerCount = 2) then
   190     begin
   199     begin
   191        secondFinger := getSecondFinger(finger^);
   200        secondFinger := getSecondFinger(finger^);
   192        currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
   201        currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
   193        zoom := currentPinchDelta/cScreenWidth;
   202        zoom := currentPinchDelta/cScreenWidth;
   194        ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
   203        ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
   201 end;
   210 end;
   202 
   211 
   203 procedure onTouchUp(x,y: Longword; pointerId: TSDL_FingerId);
   212 procedure onTouchUp(x,y: Longword; pointerId: TSDL_FingerId);
   204 var
   213 var
   205     finger: PTouch_Data;
   214     finger: PTouch_Data;
       
   215     widget: POnScreenWidget;
   206 begin
   216 begin
   207 x := x;
   217 x := x;
   208 y := y;
   218 y := y;
   209 aiming:= false;
   219 aiming:= false;
   210 stopFiring:= true;
       
   211 finger:= updateFinger(x,y,0,0,pointerId);
   220 finger:= updateFinger(x,y,0,0,pointerId);
   212 //Check for onTouchClick event
   221 //Check for onTouchClick event
   213 if ((RealTicks - finger^.timeSinceDown) < clickTime) AND not(fingerHasMoved(finger^)) then
   222 if ((RealTicks - finger^.timeSinceDown) < clickTime) AND not(fingerHasMoved(finger^)) then
   214     onTouchClick(finger^);
   223     onTouchClick(finger^);
   215 
   224 WriteToConsole(Format('%d', [buttonsDown]));
       
   225 
       
   226 widget:= finger^.pressedWidget;
       
   227 if (buttonsDown > 0) and (widget <> nil) then
       
   228     begin
       
   229     dec(buttonsDown);
       
   230     
       
   231     if widget = @arrowLeft then
       
   232         leftKey:= false;
       
   233     
       
   234     if widget = @arrowRight then
       
   235         rightKey:= false;
       
   236 
       
   237     if widget = @arrowUp then
       
   238         upKey:= false;
       
   239 
       
   240     if widget = @arrowDown then
       
   241         downKey:= false;
       
   242 
       
   243     if widget = @fireButton then
       
   244         spaceKey:= false;
       
   245 
       
   246     if widget = @backjump then
       
   247         enterKey:= false;
       
   248 
       
   249     if widget = @forwardjump then
       
   250         backspaceKey:= false;
       
   251     end;
       
   252  
   216 deleteFinger(pointerId);
   253 deleteFinger(pointerId);
   217 
       
   218 if walkingLeft then
       
   219     begin
       
   220     leftKey:= false;
       
   221     walkingLeft := false;
       
   222     end;
       
   223 
       
   224 if walkingRight then
       
   225     begin
       
   226     rightKey:= false;
       
   227     walkingRight := false;
       
   228     end;
       
   229 
       
   230 if aimingUp then
       
   231     begin
       
   232     upKey:= false;
       
   233     aimingUp:= false;
       
   234     end;
       
   235 if aimingDown then
       
   236     begin
       
   237     downKey:= false;
       
   238     aimingDown:= false;
       
   239     end;
       
   240 end;
   254 end;
   241 
   255 
   242 procedure onTouchDoubleClick(finger: TTouch_Data);
   256 procedure onTouchDoubleClick(finger: TTouch_Data);
   243 begin
   257 begin
   244 finger := finger;//avoid compiler hint
   258 finger := finger;//avoid compiler hint
   302     fingers[pointerCount].x := xCursor;
   316     fingers[pointerCount].x := xCursor;
   303     fingers[pointerCount].y := yCursor;
   317     fingers[pointerCount].y := yCursor;
   304     fingers[pointerCount].dx := 0;
   318     fingers[pointerCount].dx := 0;
   305     fingers[pointerCount].dy := 0;
   319     fingers[pointerCount].dy := 0;
   306     fingers[pointerCount].timeSinceDown:= RealTicks;
   320     fingers[pointerCount].timeSinceDown:= RealTicks;
       
   321     fingers[pointerCount].pressedWidget:= nil;
   307  
   322  
   308     addFinger:= @fingers[pointerCount];
   323     addFinger:= @fingers[pointerCount];
   309     inc(pointerCount);
   324     inc(pointerCount);
   310 end;
   325 end;
   311 
   326 
   407             begin
   422             begin
   408             upKey:= false;
   423             upKey:= false;
   409             aimingDown:= false;
   424             aimingDown:= false;
   410             end;
   425             end;
   411         end;
   426         end;
   412        
       
   413 if stopFiring then 
       
   414     begin
       
   415     spaceKey:= false;
       
   416     stopFiring:= false;
       
   417     end;
       
   418 
       
   419 if stopRight then
       
   420     begin
       
   421     stopRight := false;
       
   422     rightKey:= false;
       
   423     end;
       
   424  
       
   425 if stopLeft then
       
   426     begin
       
   427     stopLeft := false;
       
   428     leftKey:= false;
       
   429     end;
       
   430     
       
   431 end;
   427 end;
   432 
   428 
   433 function findFinger(id: TSDL_FingerId): PTouch_Data;
   429 function findFinger(id: TSDL_FingerId): PTouch_Data;
   434 var
   430 var
   435     index: LongWord;
   431     index: LongWord;
   557 procedure initModule;
   553 procedure initModule;
   558 var
   554 var
   559     index: Longword;
   555     index: Longword;
   560     //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
   556     //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
   561 begin
   557 begin
   562     stopFiring:= false;
   558     buttonsDown:= 0;
   563     walkingLeft := false;
       
   564     walkingRight := false;
       
   565 
   559 
   566     setLength(fingers, 4);
   560     setLength(fingers, 4);
   567     for index := 0 to High(fingers) do 
   561     for index := 0 to High(fingers) do 
   568         fingers[index].id := nilFingerId;
   562         fingers[index].id := nilFingerId;
   569 end;
   563 end;