hedgewars/uTouch.pas
author Xeli
Wed, 17 Aug 2011 12:31:10 +0200
branchhedgeroid
changeset 5579 3176ee8a9d94
child 5589 b95d10c82f7f
permissions -rw-r--r--
uTouch, has cursor move, zoom and click or tap to open the ammo menu
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
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
     7
uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, GLUnit;
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;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    15
procedure addFinger(id: SDL_FingerId);
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
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    19
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
    20
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
    21
implementation
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    22
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    23
const
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    24
    clicktime = 200;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    25
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    26
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    27
    pointerCount : Longword;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    28
    xyCoord : array of LongInt;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    29
    pointerIds : array of SDL_FingerId;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    30
    timeSinceDown: array of Longword;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    31
     
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    32
    //Pinch to zoom 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    33
    pinchSize : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    34
    baseZoomValue: GLFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    35
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    36
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
    37
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    38
    WriteToConsole('down'); 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    39
    addFinger(pointerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    40
    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
    41
    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
    42
   
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    43
    case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    44
        2:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    45
        begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    46
            pinchSize := calculateDelta(pointerId, getSecondPointer(pointerId));
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    47
            baseZoomValue := ZoomValue
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    48
        end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    49
    end;//end case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    50
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    51
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    52
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
    53
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    54
    secondId : SDL_FingerId;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    55
    currentPinchDelta, zoom : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    56
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    57
    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
    58
    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
    59
    
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    60
    case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    61
       1:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    62
           begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    63
               CursorPoint.X := CursorPoint.X - convertToCursor(cScreenWidth,dx);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    64
               CursorPoint.Y := CursorPoint.Y + convertToCursor(cScreenWidth,dy);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    65
           end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    66
       2:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    67
           begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    68
               secondId := getSecondPointer(pointerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    69
               currentPinchDelta := calculateDelta(pointerId, secondId) - pinchSize;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    70
               zoom := currentPinchDelta/cScreenWidth;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    71
               ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    72
               //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
    73
//              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
    74
//               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
    75
            end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    76
    end; //end case pointerCount of
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
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    79
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
    80
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    81
    pointerCount := pointerCount-1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    82
    deleteFinger(pointerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    83
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    84
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    85
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
    86
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    87
    WriteToConsole(Format('clicker %d', [SDL_GetTicks]));
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    88
    bShowAmmoMenu := not(bShowAmmoMenu);
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
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
    92
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    93
    convertToCursor := round(xy/32768*scale)
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    94
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    95
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    96
procedure addFinger(id: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    97
var 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    98
    index, tmp: Longword;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    99
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   100
    pointerCount := pointerCount + 1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   101
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   102
    //Check array sizes
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   103
    if length(pointerIds) < pointerCount then setLength(pointerIds, length(pointerIds)*2);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   104
    if length(xyCoord) < pointerCount*2+1 then setLength(xyCoord, length(xyCoord)*2);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   105
    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
   106
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   107
    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
   108
    begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   109
        if pointerIds[index] = -1 then 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   110
           begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   111
               pointerIds[index] := id;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   112
               break;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   113
           end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   114
    end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   115
    //set timestamp
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   116
    timeSinceDown[id] := SDL_GetTicks
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
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   119
procedure deleteFinger(id: SDL_FingerId);
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, i : Longint;
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
    index := 0;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   124
    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
   125
    begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   126
         if pointerIds[index] = id then
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   127
         begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   128
             pointerIds[index] := -1;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   129
             break;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   130
         end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   131
    end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   132
    //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
   133
    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
   134
    begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   135
        if pointerIds[i] <> -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] := pointerIds[i];
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
    if (SDL_GetTicks - timeSinceDown[id]) < clickTime then onTouchClick(xyCoord[id*2], xyCoord[id*2+1], id);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   142
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   143
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   144
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
   145
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   146
//    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
   147
    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
   148
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   149
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   150
// 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
   151
// 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
   152
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
   153
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   154
    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
   155
    else getSecondPointer := pointerIds[0];
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   156
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   157
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   158
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   159
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   160
    index: Longword;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   161
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   162
    setLength(xyCoord, 10);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   163
    setLength(pointerIds, 5);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   164
    setLength(timeSinceDown, 5);    
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   165
    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
   166
    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
   167
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   168
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   169
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   170
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   171
end.