hedgewars/uTouch.pas
branchhedgeroid
changeset 5595 480d451152a5
parent 5589 b95d10c82f7f
child 5599 2e4b90f33a83
equal deleted inserted replaced
5593:bc37bad14800 5595:480d451152a5
    14 function convertToCursor(scale: LongInt; xy: LongInt): LongInt;
    14 function convertToCursor(scale: LongInt; xy: LongInt): LongInt;
    15 procedure addFinger(x,y: Longword; id: SDL_FingerId);
    15 procedure addFinger(x,y: Longword; id: SDL_FingerId);
    16 procedure deleteFinger(id: SDL_FingerId);
    16 procedure deleteFinger(id: SDL_FingerId);
    17 procedure onTouchClick(x,y: Longword; pointerId: SDL_FingerId);
    17 procedure onTouchClick(x,y: Longword; pointerId: SDL_FingerId);
    18 
    18 
       
    19 function isOnCurrentHog(id: SDL_FingerId): boolean;
    19 function fingerHasMoved(id: SDL_FingerId): boolean;
    20 function fingerHasMoved(id: SDL_FingerId): boolean;
    20 function calculateDelta(id1, id2: SDL_FingerId): hwFloat;
    21 function calculateDelta(id1, id2: SDL_FingerId): hwFloat;
    21 function getSecondPointer(id: SDL_FingerId): SDL_FingerId;
    22 function getSecondPointer(id: SDL_FingerId): SDL_FingerId;
    22 implementation
    23 implementation
    23 
    24 
   100         doPut(CursorPoint.X, CursorPoint.Y, false); 
   101         doPut(CursorPoint.X, CursorPoint.Y, false); 
   101         invertCursor := true;
   102         invertCursor := true;
   102         exit
   103         exit
   103     end;
   104     end;
   104 
   105 
   105 
   106     if isOnCurrentHog(pointerId) then
       
   107     begin
   106     bShowAmmoMenu := true;
   108     bShowAmmoMenu := true;
   107     invertCursor := false;
   109     invertCursor := false;
       
   110     end;
   108     //WriteToConsole(Format('%s, %s : %d, %d', [cstr(CurrentHedgehog^.Gear^.X), cstr(CurrentHedgehog^.Gear^.Y), x-WorldDX, y-WorldDY]));
   111     //WriteToConsole(Format('%s, %s : %d, %d', [cstr(CurrentHedgehog^.Gear^.X), cstr(CurrentHedgehog^.Gear^.Y), x-WorldDX, y-WorldDY]));
   109 end;
   112 end;
   110 
   113 
   111 function convertToCursor(scale: LongInt; xy: LongInt): LongInt;
   114 function convertToCursor(scale: LongInt; xy: LongInt): LongInt;
   112 begin
   115 begin
   164         end;
   167         end;
   165     end;
   168     end;
   166     if ((SDL_GetTicks - timeSinceDown[id]) < clickTime) AND  not(fingerHasMoved(id)) then onTouchClick(xyCoord[id*2], xyCoord[id*2+1], id);
   169     if ((SDL_GetTicks - timeSinceDown[id]) < clickTime) AND  not(fingerHasMoved(id)) then onTouchClick(xyCoord[id*2], xyCoord[id*2+1], id);
   167 end;
   170 end;
   168 
   171 
       
   172 function isOnCurrentHog(id: SDL_FingerId): boolean;
       
   173 var
       
   174      x,y : hwFloat;
       
   175 begin
       
   176     x := CurrentHedgehog^.Gear^.X;
       
   177     y := CurrentHedgehog^.Gear^.Y;
       
   178     isOnCurrentHog := Distance(int2hwFloat((xyCoord[id*2] -  WorldDX) - (cScreenWidth div 2))-x, int2hwFloat(xyCoord[id*2+1] - WorldDy)-y) < int2hwFloat(20);
       
   179 end;
       
   180 
   169 //Method to calculate the distance this finger has moved since the downEvent
   181 //Method to calculate the distance this finger has moved since the downEvent
   170 function fingerHasMoved(id: SDL_FingerId): boolean;
   182 function fingerHasMoved(id: SDL_FingerId): boolean;
   171 begin
   183 begin
   172 //    fingerHasMoved := hwAbs(DistanceI(xyCoord[id*2]-historicalXY[id*2], xyCoord[id*2+1]-historicalXY[id*2+1])) > int2hwFloat(2000); // is 1% movement
   184 //    fingerHasMoved := hwAbs(DistanceI(xyCoord[id*2]-historicalXY[id*2], xyCoord[id*2+1]-historicalXY[id*2+1])) > int2hwFloat(2000); // is 1% movement
   173     fingerHasMoved := trunc(sqrt(Power(xyCoord[id*2]-historicalXY[id*2],2) + Power(xyCoord[id*2+1]-historicalXY[id*2+1], 2))) > 330;
   185     fingerHasMoved := trunc(sqrt(Power(xyCoord[id*2]-historicalXY[id*2],2) + Power(xyCoord[id*2+1]-historicalXY[id*2+1], 2))) > 330;