hedgewars/uTouch.pas
author Xeli
Wed, 17 Aug 2011 19:39:32 +0200
branchhedgeroid
changeset 5595 480d451152a5
parent 5589 b95d10c82f7f
child 5599 2e4b90f33a83
permissions -rw-r--r--
open ammo when clicking the current hog
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     1
{$INCLUDE "options.inc"}
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     2
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     3
unit uTouch;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     4
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     5
interface
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     6
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
     7
uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, uIO, GLUnit;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     8
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     9
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    10
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    11
procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    12
procedure onTouchMotion(x,y: Longword; dx,dy: LongInt; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    13
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    14
function convertToCursor(scale: LongInt; xy: LongInt): LongInt;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    15
procedure addFinger(x,y: Longword; id: SDL_FingerId);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    16
procedure deleteFinger(id: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    17
procedure onTouchClick(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    18
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
    19
function isOnCurrentHog(id: SDL_FingerId): boolean;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    20
function fingerHasMoved(id: SDL_FingerId): boolean;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    21
function calculateDelta(id1, id2: SDL_FingerId): hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    22
function getSecondPointer(id: SDL_FingerId): SDL_FingerId;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    23
implementation
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    24
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    25
const
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    26
    clicktime = 200;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    27
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    28
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    29
    pointerCount : Longword;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    30
    xyCoord : array of LongInt;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    31
    pointerIds : array of SDL_FingerId;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    32
    timeSinceDown: array of Longword;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    33
    historicalXY : array of LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    34
    //Pinch to zoom 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    35
    pinchSize : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    36
    baseZoomValue: GLFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    37
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    38
    invertCursor : boolean;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    39
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    40
procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    41
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    42
    WriteToConsole('down'); 
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    43
    addFinger(x,y,pointerId);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    44
    xyCoord[pointerId*2] := convertToCursor(cScreenWidth,x);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    45
    xyCoord[pointerId*2+1] := convertToCursor(cScreenHeight,y);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    46
   
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    47
    case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    48
        2:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    49
        begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    50
            pinchSize := calculateDelta(pointerId, getSecondPointer(pointerId));
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    51
            baseZoomValue := ZoomValue
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    52
        end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    53
    end;//end case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    54
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    55
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    56
procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    57
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    58
    secondId : SDL_FingerId;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    59
    currentPinchDelta, zoom : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    60
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    61
    xyCoord[pointerId*2] := convertToCursor(cScreenWidth, x);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    62
    xyCoord[pointerId*2+1] := convertToCursor(cScreenHeight, y);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    63
    
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    64
    case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    65
       1:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    66
           begin
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    67
               if invertCursor then
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    68
               begin
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    69
                   CursorPoint.X := CursorPoint.X - convertToCursor(cScreenWidth,dx);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    70
                   CursorPoint.Y := CursorPoint.Y + convertToCursor(cScreenWidth,dy);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    71
               end
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    72
               else
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    73
               begin
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    74
                   CursorPoint.X := CursorPoint.X + convertToCursor(cScreenWidth,dx);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    75
                   CursorPoint.Y := CursorPoint.Y - convertToCursor(cScreenWidth,dy);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    76
               end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    77
           end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    78
       2:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    79
           begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    80
               secondId := getSecondPointer(pointerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    81
               currentPinchDelta := calculateDelta(pointerId, secondId) - pinchSize;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    82
               zoom := currentPinchDelta/cScreenWidth;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    83
               ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    84
               //WriteToConsole(Format('Zoom in/out. ZoomValue = %f', [ZoomValue]));
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    85
//              if ZoomValue > cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    86
//               if ZoomValue < cMinZoomLevel then ZoomValue := cMinZoomLevel;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    87
            end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    88
    end; //end case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    89
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    90
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    91
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    92
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    93
    pointerCount := pointerCount-1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    94
    deleteFinger(pointerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    95
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    96
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    97
procedure onTouchClick(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    98
begin
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    99
    if bShowAmmoMenu then 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   100
    begin
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   101
        doPut(CursorPoint.X, CursorPoint.Y, false); 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   102
        invertCursor := true;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   103
        exit
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   104
    end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   105
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   106
    if isOnCurrentHog(pointerId) then
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   107
    begin
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   108
    bShowAmmoMenu := true;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   109
    invertCursor := false;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   110
    end;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   111
    //WriteToConsole(Format('%s, %s : %d, %d', [cstr(CurrentHedgehog^.Gear^.X), cstr(CurrentHedgehog^.Gear^.Y), x-WorldDX, y-WorldDY]));
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   112
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   113
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   114
function convertToCursor(scale: LongInt; xy: LongInt): LongInt;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   115
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   116
    convertToCursor := round(xy/32768*scale)
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   117
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   118
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   119
procedure addFinger(x,y: Longword; id: SDL_FingerId);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   120
var 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   121
    index, tmp: Longword;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   122
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   123
    pointerCount := pointerCount + 1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   124
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   125
    //Check array sizes
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   126
    if length(pointerIds) < pointerCount then setLength(pointerIds, length(pointerIds)*2);
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   127
    if length(xyCoord) < id*2+1 then 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   128
    begin 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   129
        setLength(xyCoord, id*2+1);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   130
        setLength(historicalXY, id*2+1);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   131
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   132
    if length(timeSinceDown) < id then setLength(timeSinceDown, id); 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   133
    for index := 0 to pointerCount do //place the pointer ids as far back to the left as possible
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   134
    begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   135
        if pointerIds[index] = -1 then 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   136
           begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   137
               pointerIds[index] := id;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   138
               break;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   139
           end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   140
    end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   141
    //set timestamp
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   142
    timeSinceDown[id] := SDL_GetTicks;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   143
    historicalXY[id*2] := convertToCursor(cScreenWidth,x);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   144
    historicalXY[id*2+1] := convertToCursor(cScreenHeight,y);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   145
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   146
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   147
procedure deleteFinger(id: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   148
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   149
    index, i : Longint;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   150
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   151
    index := 0;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   152
    for index := 0 to pointerCount do
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   153
    begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   154
         if pointerIds[index] = id then
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   155
         begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   156
             pointerIds[index] := -1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   157
             break;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   158
         end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   159
    end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   160
    //put the last pointerId into the stop of the id to be removed, so that all pointerIds are to the far left
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   161
    for i := pointerCount downto index do
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   162
    begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   163
        if pointerIds[i] <> -1 then
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   164
        begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   165
            pointerIds[index] := pointerIds[i];
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   166
            break;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   167
        end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   168
    end;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   169
    if ((SDL_GetTicks - timeSinceDown[id]) < clickTime) AND  not(fingerHasMoved(id)) then onTouchClick(xyCoord[id*2], xyCoord[id*2+1], id);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   170
end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   171
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   172
function isOnCurrentHog(id: SDL_FingerId): boolean;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   173
var
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   174
     x,y : hwFloat;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   175
begin
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   176
    x := CurrentHedgehog^.Gear^.X;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   177
    y := CurrentHedgehog^.Gear^.Y;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   178
    isOnCurrentHog := Distance(int2hwFloat((xyCoord[id*2] -  WorldDX) - (cScreenWidth div 2))-x, int2hwFloat(xyCoord[id*2+1] - WorldDy)-y) < int2hwFloat(20);
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   179
end;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   180
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   181
//Method to calculate the distance this finger has moved since the downEvent
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   182
function fingerHasMoved(id: SDL_FingerId): boolean;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   183
begin
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   184
//    fingerHasMoved := hwAbs(DistanceI(xyCoord[id*2]-historicalXY[id*2], xyCoord[id*2+1]-historicalXY[id*2+1])) > int2hwFloat(2000); // is 1% movement
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   185
    fingerHasMoved := trunc(sqrt(Power(xyCoord[id*2]-historicalXY[id*2],2) + Power(xyCoord[id*2+1]-historicalXY[id*2+1], 2))) > 330;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   186
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   187
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   188
function calculateDelta(id1, id2: SDL_FingerId): hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   189
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   190
//    calculateDelta := Distance(xyCoord[id2*2] - xyCoord[id1*2], xyCoord[id2*2+1] - xyCoord[id1*2+1]);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   191
    calculateDelta := int2hwFloat(trunc(sqrt(Power(xyCoord[id2*2]-xyCoord[id1*2],2) + Power(xyCoord[id2*2+1]-xyCoord[id1*2+1], 2))));
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   192
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   193
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   194
// Under the premise that all pointer ids in pointerIds:SDL_FingerId are pack to the far left.
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   195
// If the pointer to be ignored is not pointerIds[0] the second must be there
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   196
function getSecondPointer(id: SDL_FingerId): SDL_FingerId;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   197
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   198
    if pointerIds[0] = id then getSecondPointer := pointerIds[1]
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   199
    else getSecondPointer := pointerIds[0];
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   200
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   201
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   202
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   203
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   204
    index: Longword;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   205
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   206
    setLength(xyCoord, 10);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   207
    setLength(pointerIds, 5);
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   208
    setLength(timeSinceDown, 5);
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   209
    setLength(historicalXY, 10);    
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   210
    for index := Low(xyCoord) to High(xyCoord) do xyCoord[index] := -1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   211
    for index := Low(pointerIds) to High(pointerIds) do pointerIds[index] := -1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   212
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   213
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   214
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   215
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   216
end.