hedgewars/uTouch.pas
branchhedgeroid
changeset 5828 667fb58d7f18
parent 5733 5ab22736bdb6
child 5938 c186c454779d
equal deleted inserted replaced
5826:2a2cce052b4d 5828:667fb58d7f18
    58 implementation
    58 implementation
    59 
    59 
    60 const
    60 const
    61     clicktime = 200;
    61     clicktime = 200;
    62     nilFingerId = High(SDL_FingerId);
    62     nilFingerId = High(SDL_FingerId);
    63 var
    63 
       
    64 var
       
    65     fireButtonLeft, fireButtonRight, fireButtonTop, fireButtonBottom : LongInt;
       
    66         
       
    67 
       
    68 
    64     leftButtonBoundary  : LongInt;
    69     leftButtonBoundary  : LongInt;
    65     rightButtonBoundary : LongInt;
    70     rightButtonBoundary : LongInt;
    66     topButtonBoundary   : LongInt;
    71     topButtonBoundary   : LongInt;
    67     
    72     
    68     pointerCount : Longword;
    73     pointerCount : Longword;
   136         end;
   141         end;
   137         2:
   142         2:
   138         begin
   143         begin
   139             aiming:= false;
   144             aiming:= false;
   140             stopFiring:= true;
   145             stopFiring:= true;
       
   146             moveCursor:= false;
   141             pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
   147             pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
   142             baseZoomValue := ZoomValue
   148             baseZoomValue := ZoomValue
   143         end;
   149         end;
   144     end;//end case pointerCount of
   150     end;//end case pointerCount of
   145 end;
   151 end;
   146 
   152 
   147 procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: SDL_FingerId);
   153 procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: SDL_FingerId);
   148 var
   154 var
   149     finger, secondFinger: PTouch_Finger;
   155     finger, secondFinger: PTouch_Finger;
   150     currentPinchDelta, zoom : hwFloat;
   156     currentPinchDelta, zoom : hwFloat;
       
   157     tmpX, tmpY: LongInt;
   151 begin
   158 begin
   152     finger:= findFinger(pointerId);
   159     finger:= findFinger(pointerId);
   153 
   160     tmpX := convertToCursor(cScreenWidth, x);
   154     finger^.x := convertToCursor(cScreenWidth, x);
   161     tmpY := convertToCursor(cScreenHeight, y);
   155     finger^.y := convertToCursor(cScreenHeight, y);
   162 
   156 
   163     if moveCursor then
   157     case pointerCount of
   164     begin
   158        1:
   165         if invertCursor then
   159            begin
   166         begin
   160                if aiming then 
   167             CursorPoint.X := CursorPoint.X + (finger^.x - tmpX);
   161                begin
   168             CursorPoint.Y := CursorPoint.Y - (finger^.y - tmpY);
   162                    aim(finger^);
   169         end
   163                    exit
   170         else
   164                end;
   171         begin
   165                if moveCursor then
   172             CursorPoint.X := CursorPoint.X - (finger^.x - tmpX);
   166                    if invertCursor then
   173             CursorPoint.Y := CursorPoint.Y + (finger^.y - tmpY);
   167                    begin
   174         end;
   168                        CursorPoint.X := CursorPoint.X - convertToCursor(cScreenWidth,dx);
   175         finger^.x := tmpX;
   169                        CursorPoint.Y := CursorPoint.Y + convertToCursor(cScreenWidth,dy);
   176         finger^.y := tmpY;
   170                    end
   177         exit //todo change into switch rather than ugly ifs
   171                    else
   178     end;
   172                    begin
   179     
   173                        CursorPoint.X := CursorPoint.X + convertToCursor(cScreenWidth,dx);
   180     finger^.x := tmpX;
   174                        CursorPoint.Y := CursorPoint.Y - convertToCursor(cScreenWidth,dy);
   181     finger^.y := tmpY;
   175                    end;
   182     
   176            end;
   183     if aiming then 
   177        2:
   184     begin
   178            begin
   185         aim(finger^);
   179                secondFinger := getSecondFinger(finger^);
   186         exit
   180                currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
   187     end;
   181                zoom := currentPinchDelta/cScreenWidth;
   188     if pointerCount = 2 then
   182                ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
   189     begin
   183                if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
   190        secondFinger := getSecondFinger(finger^);
   184                if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel;
   191        currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
   185             end;
   192        zoom := currentPinchDelta/cScreenWidth;
   186     end; //end case pointerCount of
   193        ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
       
   194        if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
       
   195        if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel;
       
   196     end;
   187 end;
   197 end;
   188 
   198 
   189 procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
   199 procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
   190 begin
   200 begin
   191     aiming:= false;
   201     aiming:= false;
   400     convertToCursor := round(xy/32768*scale)
   410     convertToCursor := round(xy/32768*scale)
   401 end;
   411 end;
   402 
   412 
   403 function isOnFireButton(finger: Touch_Finger): boolean;
   413 function isOnFireButton(finger: Touch_Finger): boolean;
   404 begin
   414 begin
   405     printFinger(finger);
   415     isOnFireButton:= (finger.x <= fireButtonRight) and (finger.x >= fireButtonLeft) and (finger.y <= fireButtonBottom) and (finger.y >= fireButtonTop);
   406     WriteToConsole(Format('%d %d ',[round((-cScreenWidth+20)/0.8), round((cScreenHeight+55)/0.8)]));
       
   407     WriteToConsole(Format('%d, %d',[cScreenWidth, cScreenHeight]));
       
   408     isOnFireButton:= (finger.x < 205) and (finger.y > 420);
       
   409 end;
   416 end;
   410 
   417 
   411 function isOnCrosshair(finger: Touch_Finger): boolean;
   418 function isOnCrosshair(finger: Touch_Finger): boolean;
   412 var
   419 var
   413     x,y,fingerX, fingerY : hwFloat;
   420     x,y,fingerX, fingerY : hwFloat;
   462     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
   469     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
   463 end;
   470 end;
   464 
   471 
   465 procedure initModule;
   472 procedure initModule;
   466 var
   473 var
   467     index: Longword;
   474     index, uRenderCoordScaleX, uRenderCoordScaleY: Longword;
   468 begin
   475 begin
   469     movingCrosshair := false;
   476     movingCrosshair := false;
   470     stopFiring:= false;
   477     stopFiring:= false;
   471     walkingLeft := false;
   478     walkingLeft := false;
   472     walkingRight := false;
   479     walkingRight := false;
   476     topButtonBoundary := cScreenHeight div 6;
   483     topButtonBoundary := cScreenHeight div 6;
   477     
   484     
   478     setLength(fingers, 4);
   485     setLength(fingers, 4);
   479     for index := 0 to High(fingers) do 
   486     for index := 0 to High(fingers) do 
   480         fingers[index].id := nilFingerId;
   487         fingers[index].id := nilFingerId;
       
   488 
       
   489 
       
   490     uRenderCoordScaleX := Round(cScreenWidth/0.8 * 2);
       
   491     fireButtonLeft := Round(cScreenWidth*0.01);
       
   492     fireButtonRight := Round(fireButtonLeft + (spritesData[sprFireButton].Width*0.4));
       
   493     fireButtonBottom := Round(cScreenHeight*0.99);
       
   494     fireButtonTop := fireButtonBottom - Round(spritesData[sprFireButton].Height*0.4);
   481 end;
   495 end;
   482 
   496 
   483 begin
   497 begin
   484 end.
   498 end.