author | Xeli |
Wed, 17 Aug 2011 17:14:47 +0200 | |
branch | hedgeroid |
changeset 5589 | b95d10c82f7f |
parent 5579 | 3176ee8a9d94 |
child 5595 | 480d451152a5 |
permissions | -rw-r--r-- |
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 | 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 | 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 |
|
5589 | 19 |
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
|
20 |
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
|
21 |
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
|
22 |
implementation |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
23 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
24 |
const |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
25 |
clicktime = 200; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
26 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
27 |
var |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
28 |
pointerCount : Longword; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
29 |
xyCoord : array of LongInt; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
30 |
pointerIds : array of SDL_FingerId; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
31 |
timeSinceDown: array of Longword; |
5589 | 32 |
historicalXY : array of LongInt; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
33 |
//Pinch to zoom |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
34 |
pinchSize : hwFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
35 |
baseZoomValue: GLFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
36 |
|
5589 | 37 |
invertCursor : boolean; |
38 |
||
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
39 |
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
|
40 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
41 |
WriteToConsole('down'); |
5589 | 42 |
addFinger(x,y,pointerId); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
46 |
case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
47 |
2: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
48 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
49 |
pinchSize := calculateDelta(pointerId, getSecondPointer(pointerId)); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
50 |
baseZoomValue := ZoomValue |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
51 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
52 |
end;//end case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
53 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
54 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
55 |
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
|
56 |
var |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
57 |
secondId : SDL_FingerId; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
58 |
currentPinchDelta, zoom : hwFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
59 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
63 |
case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
64 |
1: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
65 |
begin |
5589 | 66 |
if invertCursor then |
67 |
begin |
|
68 |
CursorPoint.X := CursorPoint.X - convertToCursor(cScreenWidth,dx); |
|
69 |
CursorPoint.Y := CursorPoint.Y + convertToCursor(cScreenWidth,dy); |
|
70 |
end |
|
71 |
else |
|
72 |
begin |
|
73 |
CursorPoint.X := CursorPoint.X + convertToCursor(cScreenWidth,dx); |
|
74 |
CursorPoint.Y := CursorPoint.Y - convertToCursor(cScreenWidth,dy); |
|
75 |
end; |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
76 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
77 |
2: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
78 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
79 |
secondId := getSecondPointer(pointerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
80 |
currentPinchDelta := calculateDelta(pointerId, secondId) - pinchSize; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
81 |
zoom := currentPinchDelta/cScreenWidth; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
82 |
ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta)); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
83 |
//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
|
84 |
// 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
|
85 |
// 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
|
86 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
87 |
end; //end case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
88 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
89 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
90 |
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
|
91 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
92 |
pointerCount := pointerCount-1; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
93 |
deleteFinger(pointerId); |
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 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
|
97 |
begin |
5589 | 98 |
if bShowAmmoMenu then |
99 |
begin |
|
100 |
doPut(CursorPoint.X, CursorPoint.Y, false); |
|
101 |
invertCursor := true; |
|
102 |
exit |
|
103 |
end; |
|
104 |
||
105 |
||
106 |
bShowAmmoMenu := true; |
|
107 |
invertCursor := false; |
|
108 |
//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
|
109 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
110 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
111 |
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
|
112 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
113 |
convertToCursor := round(xy/32768*scale) |
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 |
|
5589 | 116 |
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
|
117 |
var |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
118 |
index, tmp: Longword; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
119 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
120 |
pointerCount := pointerCount + 1; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
121 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
122 |
//Check array sizes |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
123 |
if length(pointerIds) < pointerCount then setLength(pointerIds, length(pointerIds)*2); |
5589 | 124 |
if length(xyCoord) < id*2+1 then |
125 |
begin |
|
126 |
setLength(xyCoord, id*2+1); |
|
127 |
setLength(historicalXY, id*2+1); |
|
128 |
end; |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
132 |
if pointerIds[index] = -1 then |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
133 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
134 |
pointerIds[index] := id; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
135 |
break; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
136 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
137 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
138 |
//set timestamp |
5589 | 139 |
timeSinceDown[id] := SDL_GetTicks; |
140 |
historicalXY[id*2] := convertToCursor(cScreenWidth,x); |
|
141 |
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
|
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 |
procedure deleteFinger(id: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
145 |
var |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
146 |
index, i : Longint; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
147 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
148 |
index := 0; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
149 |
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
|
150 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
151 |
if pointerIds[index] = id then |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
152 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
153 |
pointerIds[index] := -1; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
154 |
break; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
155 |
end; |
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 |
//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
|
158 |
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
|
159 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
160 |
if pointerIds[i] <> -1 then |
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 |
pointerIds[index] := pointerIds[i]; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
163 |
break; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
164 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
165 |
end; |
5589 | 166 |
if ((SDL_GetTicks - timeSinceDown[id]) < clickTime) AND not(fingerHasMoved(id)) then onTouchClick(xyCoord[id*2], xyCoord[id*2+1], id); |
167 |
end; |
|
168 |
||
169 |
//Method to calculate the distance this finger has moved since the downEvent |
|
170 |
function fingerHasMoved(id: SDL_FingerId): boolean; |
|
171 |
begin |
|
172 |
// 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; |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
174 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
175 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
176 |
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
|
177 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
178 |
// 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
|
179 |
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
|
180 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
181 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
182 |
// 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
|
183 |
// 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
|
184 |
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
|
185 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
186 |
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
|
187 |
else getSecondPointer := pointerIds[0]; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
188 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
189 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
190 |
procedure initModule; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
191 |
var |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
192 |
index: Longword; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
193 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
194 |
setLength(xyCoord, 10); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
195 |
setLength(pointerIds, 5); |
5589 | 196 |
setLength(timeSinceDown, 5); |
197 |
setLength(historicalXY, 10); |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
198 |
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
|
199 |
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
|
200 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
201 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
202 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
203 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
204 |
end. |