hedgewars/uTouch.pas
author Xeli
Sat, 18 Feb 2012 15:24:20 +0100
changeset 6712 c582869fbe7f
parent 6707 07c8704b6b08
child 6714 f2f93017132c
permissions -rw-r--r--
changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     1
(*
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6698
diff changeset
     3
 * Copyright (c) 2012 Richard Deurwaarder <xeli@xelification.com>
5621
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    17
 *)
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    18
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    20
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    21
unit uTouch;
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
interface
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    24
6712
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
    25
uses sysutils, uConsole, uVariables, SDLh, uFloat, uConsts, uCommands, uIO, GLUnit, uTypes;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    26
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    27
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    28
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    29
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
    30
procedure ProcessTouch;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    31
procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    32
procedure onTouchMotion(x,y: Longword; dx,dy: LongInt; pointerId: TSDL_FingerId);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    33
procedure onTouchUp(x,y: Longword; pointerId: TSDL_FingerId);
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    34
function convertToCursorX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    35
function convertToCursorY(y: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    36
function convertToCursorDeltaX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    37
function convertToCursorDeltaY(y: LongInt): LongInt;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    38
function addFinger(x,y: Longword; id: TSDL_FingerId): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    39
function updateFinger(x,y,dx,dy: Longword; id: TSDL_FingerId): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    40
procedure deleteFinger(id: TSDL_FingerId);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    41
procedure onTouchClick(finger: TTouch_Data);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    42
procedure onTouchDoubleClick(finger: TTouch_Data);
6712
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
    43
procedure onTouchLongClick(finger: TTouch_Data);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    44
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    45
function findFinger(id: TSDL_FingerId): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    46
procedure aim(finger: TTouch_Data);
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    47
function isOnCrosshair(finger: TTouch_Data): boolean;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    48
function isOnCurrentHog(finger: TTouch_Data): boolean;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    49
procedure convertToWorldCoord(var x,y: LongInt; finger: TTouch_Data);
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    50
procedure convertToFingerCoord(var x,y: LongInt; oldX, oldY: LongInt);
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    51
function fingerHasMoved(finger: TTouch_Data): boolean;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    52
function calculateDelta(finger1, finger2: TTouch_Data): LongInt;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    53
function getSecondFinger(finger: TTouch_Data): PTouch_Data;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    54
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    55
function isOnRect(x,y,w,h: LongInt; finger: TTouch_Data): boolean;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    56
procedure printFinger(finger: TTouch_Data);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    57
implementation
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    58
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    59
const
6712
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
    60
    clickTime = 200;
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
    61
    longClickTime = 400;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    62
    nilFingerId = High(TSDL_FingerId);
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    63
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    64
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    65
    pointerCount : Longword;
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    66
    fingers: array of TTouch_Data;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    67
    moveCursor : boolean;
5617
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
    68
    invertCursor : boolean;
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
    69
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
    70
    xTouchClick,yTouchClick : LongInt;
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
    71
    timeSinceClick : Longword;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    72
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    73
    //Pinch to zoom 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
    74
    pinchSize : LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    75
    baseZoomValue: GLFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    76
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
    77
    //aiming
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    78
    aimingCrosshair: boolean;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
    79
    aimingUp, aimingDown: boolean; 
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    80
    targetAngle: LongInt;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    81
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
    82
    buttonsDown: Longword;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    83
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    84
procedure onTouchDown(x,y: Longword; pointerId: TSDL_FingerId);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    85
var 
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
    86
    finger: PTouch_Data;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    87
begin
6676
21cf35a570a7 add keywords for landscape ammomenu and touch interface
koda
parents: 6654
diff changeset
    88
{$IFDEF USE_TOUCH_INTERFACE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
    89
finger := addFinger(x,y,pointerId);
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    90
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    91
inc(buttonsDown);//inc buttonsDown, if we don't see a button down we'll dec it
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    92
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
    93
if isOnCrosshair(finger^) then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
    94
begin
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    95
    aimingCrosshair:= true;
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
    96
    aim(finger^);
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
    97
    moveCursor:= false;
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
    98
    exit;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
    99
end;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   100
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   101
if isOnRect(fireButton.active, finger^) then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   102
    begin
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   103
    spaceKey:= true;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   104
    moveCursor:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   105
    finger^.pressedWidget:= @fireButton;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   106
    exit;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   107
    end;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   108
if isOnRect(arrowLeft.active, finger^) then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   109
    begin
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   110
    leftKey:= true;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   111
    moveCursor:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   112
    finger^.pressedWidget:= @arrowLeft;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   113
    exit;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   114
    end;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   115
if isOnRect(arrowRight.active, finger^) then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   116
    begin
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   117
    rightKey:= true;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   118
    moveCursor:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   119
    finger^.pressedWidget:= @arrowRight;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   120
    exit;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   121
    end;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   122
if isOnRect(arrowUp.active, finger^) then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   123
     begin
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   124
     upKey:= true;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   125
     moveCursor:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   126
     finger^.pressedWidget:= @arrowUp;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   127
     exit;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   128
     end;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   129
if isOnRect(arrowDown.active, finger^) then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   130
     begin
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   131
     downKey:= true;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   132
     moveCursor:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   133
     finger^.pressedWidget:= @arrowDown;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   134
     exit;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   135
     end;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   136
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   137
if isOnRect(pauseButton.active, finger^) then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   138
     begin
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   139
     isPaused:= not isPaused;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   140
     moveCursor:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   141
     finger^.pressedWidget:= @pauseButton;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   142
     exit;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   143
     end;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   144
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   145
dec(buttonsDown);//no buttonsDown, undo the inc() above
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   146
if buttonsDown = 0 then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   147
    begin
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   148
    moveCursor:= true;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   149
    if pointerCount = 2 then
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   150
        begin
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   151
        moveCursor:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   152
        pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   153
        baseZoomValue := ZoomValue
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   154
    end;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   155
end;
6676
21cf35a570a7 add keywords for landscape ammomenu and touch interface
koda
parents: 6654
diff changeset
   156
{$ENDIF}
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   157
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   158
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   159
procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: TSDL_FingerId);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   160
var
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   161
    finger, secondFinger: PTouch_Data;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   162
    currentPinchDelta, zoom : single;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   163
begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   164
finger:= updateFinger(x,y,dx,dy,pointerId);
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   165
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   166
if moveCursor then
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   167
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   168
        if invertCursor then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   169
        begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   170
            CursorPoint.X := CursorPoint.X - finger^.dx;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   171
            CursorPoint.Y := CursorPoint.Y + finger^.dy;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   172
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   173
    else
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   174
        begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   175
            CursorPoint.X := CursorPoint.X + finger^.dx;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   176
            CursorPoint.Y := CursorPoint.Y - finger^.dy;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   177
        end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   178
        exit //todo change into switch rather than ugly ifs
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   179
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   180
    
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   181
if aimingCrosshair then 
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   182
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   183
        aim(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   184
        exit
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   185
    end;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   186
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   187
if (buttonsDown = 0) and (pointerCount = 2) then
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   188
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   189
       secondFinger := getSecondFinger(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   190
       currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   191
       zoom := currentPinchDelta/cScreenWidth;
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   192
       ZoomValue := baseZoomValue - (zoom * cMinMaxZoomLevelDelta);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   193
       if ZoomValue < cMaxZoomLevel then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   194
           ZoomValue := cMaxZoomLevel;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   195
       if ZoomValue > cMinZoomLevel then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   196
           ZoomValue := cMinZoomLevel;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   197
    end;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   198
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   199
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   200
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   201
procedure onTouchUp(x,y: Longword; pointerId: TSDL_FingerId);
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   202
var
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   203
    finger: PTouch_Data;
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   204
    widget: POnScreenWidget;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   205
begin
6707
07c8704b6b08 one more USE_TOUCH_INTERFACE
koda
parents: 6705
diff changeset
   206
{$IFDEF USE_TOUCH_INTERFACE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   207
x := x;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   208
y := y;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   209
finger:= updateFinger(x,y,0,0,pointerId);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   210
//Check for onTouchClick event
6712
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   211
if not(fingerHasMoved(finger^)) then
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   212
    if (RealTicks - finger^.timeSinceDown) < clickTime then
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   213
        onTouchClick(finger^)
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   214
    else
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   215
        onTouchLongClick(finger^);
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   216
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   217
if aimingCrosshair then
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   218
    begin
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   219
    aimingCrosshair:= false;
6705
d2e95dcf2bb0 stop the crosshair from twitching when it's not supposed to move + fix aimingUp/Down booleans
Xeli
parents: 6704
diff changeset
   220
    upKey:= false;
d2e95dcf2bb0 stop the crosshair from twitching when it's not supposed to move + fix aimingUp/Down booleans
Xeli
parents: 6704
diff changeset
   221
    downKey:= false;
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   222
    dec(buttonsDown);
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   223
    end;
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   224
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   225
widget:= finger^.pressedWidget;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   226
if (buttonsDown > 0) and (widget <> nil) then
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   227
    begin
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   228
    dec(buttonsDown);
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   229
    
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   230
    if widget = @arrowLeft then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   231
        leftKey:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   232
    
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   233
    if widget = @arrowRight then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   234
        rightKey:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   235
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   236
    if widget = @arrowUp then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   237
        upKey:= false;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   238
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   239
    if widget = @arrowDown then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   240
        downKey:= false;
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   241
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   242
    if widget = @fireButton then
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   243
        spaceKey:= false;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   244
    end;
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   245
 
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   246
deleteFinger(pointerId);
6707
07c8704b6b08 one more USE_TOUCH_INTERFACE
koda
parents: 6705
diff changeset
   247
{$ENDIF}
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   248
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   249
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   250
procedure onTouchDoubleClick(finger: TTouch_Data);
5617
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   251
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   252
finger := finger;//avoid compiler hint
5617
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   253
end;
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   254
6712
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   255
procedure onTouchLongClick(finger: TTouch_Data);
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   256
begin
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   257
if isOnRect(backjump.active, finger) then
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   258
    begin
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   259
    ParseCommand('ljump', (CurrentTeam <> nil) and not(CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel=0));
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   260
    if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   261
        ParseCommand('gencmd R', true);
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   262
    exit;
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   263
    end;
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   264
end;
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   265
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   266
procedure onTouchClick(finger: TTouch_Data);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   267
begin
6712
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   268
//if (RealTicks - timeSinceClick < 300) and (sqrt(sqr(finger.X-xTouchClick) + sqr(finger.Y-yTouchClick)) < 30) then
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   269
//    begin
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   270
//    onTouchDoubleClick(finger);
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   271
//    timeSinceClick:= 0;//we make an assumption there won't be an 'click' in the first 300 ticks(milliseconds) 
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   272
//    exit; 
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   273
//    end;
5617
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   274
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   275
xTouchClick:= finger.x;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   276
yTouchClick:= finger.y;
6687
98be933770e0 use realtick rather than SDL_GetTicks
Xeli
parents: 6685
diff changeset
   277
timeSinceClick:= RealTicks;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   278
6648
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   279
if bShowAmmoMenu then
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   280
    begin 
6683
75a1d84ac606 small refactoring to touch screen buttons, use a record to store values, added 'offset' fields to adjust active button area
koda
parents: 6676
diff changeset
   281
    if isOnRect(AmmoRect, finger) then
6648
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   282
        begin
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   283
        CursorPoint.X:= finger.x;
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   284
        CursorPoint.Y:= finger.y;
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   285
        doPut(CursorPoint.X, CursorPoint.Y, false); 
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   286
        end
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   287
    else
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   288
        bShowAmmoMenu:= false;
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   289
    exit;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   290
    end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   291
6648
025473a2c420 prevent the cursor from being shown on the mobile version, and close the menu on tap when the tap is not on the ammo menu
Xeli
parents: 6640
diff changeset
   292
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   293
if isOnCurrentHog(finger) then
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   294
    begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   295
    bShowAmmoMenu := true;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   296
    exit;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   297
    end;
6712
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   298
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   299
if isOnRect(backjump.active, finger) then
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   300
    begin
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   301
    ParseCommand('hjump', (CurrentTeam <> nil) and not(CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel=0));
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   302
    if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   303
        ParseCommand('gencmd R', true);
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   304
    exit;
c582869fbe7f changed jumping, on x button tap is high jump, on longpress + release is low jump (read: it only does a low jump when you release)
Xeli
parents: 6707
diff changeset
   305
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   306
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   307
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   308
function addFinger(x,y: Longword; id: TSDL_FingerId): PTouch_Data;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   309
var 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   310
    xCursor, yCursor, index : LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   311
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   312
    //Check array sizes
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   313
    if length(fingers) < Integer(pointerCount) then 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   314
    begin
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   315
        setLength(fingers, length(fingers)*2);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   316
        for index := length(fingers) div 2 to length(fingers) do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   317
            fingers[index].id := nilFingerId;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   318
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   319
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   320
    
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   321
    xCursor := convertToCursorX(x);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   322
    yCursor := convertToCursorY(y);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   323
    
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   324
    //on removing fingers, all fingers are moved to the left
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   325
    //with dynamic arrays being zero based, the new position of the finger is the old pointerCount
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   326
    fingers[pointerCount].id := id;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   327
    fingers[pointerCount].historicalX := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   328
    fingers[pointerCount].historicalY := yCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   329
    fingers[pointerCount].x := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   330
    fingers[pointerCount].y := yCursor;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   331
    fingers[pointerCount].dx := 0;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   332
    fingers[pointerCount].dy := 0;
6687
98be933770e0 use realtick rather than SDL_GetTicks
Xeli
parents: 6685
diff changeset
   333
    fingers[pointerCount].timeSinceDown:= RealTicks;
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   334
    fingers[pointerCount].pressedWidget:= nil;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   335
 
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   336
    addFinger:= @fingers[pointerCount];
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   337
    inc(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   338
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   339
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   340
function updateFinger(x,y,dx,dy: Longword; id: TSDL_FingerId): PTouch_Data;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   341
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   342
   updateFinger:= findFinger(id);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   343
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   344
   updateFinger^.x:= convertToCursorX(x);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   345
   updateFinger^.y:= convertToCursorY(y);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   346
   updateFinger^.dx:= convertToCursorDeltaX(dx);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   347
   updateFinger^.dy:= convertToCursorDeltaY(dy);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   348
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   349
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   350
procedure deleteFinger(id: TSDL_FingerId);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   351
var
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   352
    index : Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   353
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   354
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   355
    dec(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   356
    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
   357
    begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   358
        if fingers[index].id = id then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   359
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   360
 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   361
            //put the last finger into the spot of the finger to be removed, 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   362
            //so that all fingers are packed to the far left
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   363
            if  pointerCount <> index then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   364
                begin
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   365
                fingers[index].id := fingers[pointerCount].id;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   366
                fingers[index].x := fingers[pointerCount].x;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   367
                fingers[index].y := fingers[pointerCount].y;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   368
                fingers[index].historicalX := fingers[pointerCount].historicalX;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   369
                fingers[index].historicalY := fingers[pointerCount].historicalY;    
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   370
                fingers[index].timeSinceDown := fingers[pointerCount].timeSinceDown;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   371
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   372
                fingers[pointerCount].id := nilFingerId;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   373
            end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   374
        else fingers[index].id := nilFingerId;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   375
            break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   376
        end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   377
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   378
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   379
end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   380
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   381
procedure ProcessTouch;
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   382
var
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   383
    deltaAngle: LongInt;
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   384
begin
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   385
invertCursor := not(bShowAmmoMenu);
6705
d2e95dcf2bb0 stop the crosshair from twitching when it's not supposed to move + fix aimingUp/Down booleans
Xeli
parents: 6704
diff changeset
   386
if aimingCrosshair then
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   387
    if CurrentHedgehog^.Gear <> nil then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   388
        begin
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   389
        deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle;
6705
d2e95dcf2bb0 stop the crosshair from twitching when it's not supposed to move + fix aimingUp/Down booleans
Xeli
parents: 6704
diff changeset
   390
        if (deltaAngle > -5) and (deltaAngle < 5) then 
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   391
            begin
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   392
                upKey:= false;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   393
                aimingUp:= false;
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   394
                downKey:= false;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   395
                aimingDown:= false;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   396
            end
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   397
        else
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   398
            begin
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   399
            if (deltaAngle < 0) then
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   400
                begin
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   401
                if aimingUp then
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   402
                    begin
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   403
                    upKey:= false;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   404
                    aimingUp:= false;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   405
                    end;
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   406
                downKey:= true;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   407
                aimingDown:= true;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   408
                end
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   409
            else
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   410
                begin
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   411
                if aimingDown then
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   412
                    begin
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   413
                    downKey:= false;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   414
                    aimingDown:= false;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   415
                    end;
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   416
                upKey:= true;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   417
                aimingUp:= true;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   418
                end; 
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   419
            end;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   420
        end
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   421
    else  
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   422
        begin
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   423
        if aimingUp then
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   424
            begin
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   425
            upKey:= false;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   426
            aimingUp:= false;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   427
            end;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   428
        if aimingDown then
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   429
            begin
6654
120e95c10532 use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
Xeli
parents: 6651
diff changeset
   430
            upKey:= false;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   431
            aimingDown:= false;
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   432
            end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   433
        end;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   434
end;
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   435
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   436
function findFinger(id: TSDL_FingerId): PTouch_Data;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   437
var
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   438
    index: LongWord;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   439
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   440
    for index := 0 to High(fingers) do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   441
        if fingers[index].id = id then 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   442
            begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   443
            findFinger := @fingers[index];
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   444
            break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   445
            end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   446
end;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   447
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   448
procedure aim(finger: TTouch_Data);
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   449
var 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   450
    hogX, hogY, touchX, touchY, deltaX, deltaY: LongInt;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   451
begin
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   452
    if CurrentHedgehog^.Gear <> nil then
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   453
        begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   454
        touchX := 0;//avoid compiler hint
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   455
        touchY := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   456
        hogX := hwRound(CurrentHedgehog^.Gear^.X);
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   457
        hogY := hwRound(CurrentHedgehog^.Gear^.Y);
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   458
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   459
        convertToWorldCoord(touchX, touchY, finger);
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   460
        deltaX := abs(TouchX-HogX);
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   461
        deltaY := TouchY-HogY;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   462
        
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   463
        targetAngle:= (Round(DeltaY / sqrt(sqr(deltaX) + sqr(deltaY)) * 2048) + 2048) div 2;
6651
4103354b7599 fixed aiming by touching the crosshair, made it compatible with the aiming buttons and disabled camera movement when touching buttons + some formatting fixes
Xeli
parents: 6648
diff changeset
   464
        end; //if CurrentHedgehog^.Gear <> nil
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   465
end;
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   466
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   467
// These 4 convertToCursor functions convert xy coords from the SDL coordinate system to our CursorPoint coor system:
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   468
// - the SDL coordinate system goes from 0 to 32768 on the x axis and 0 to 32768 on the y axis, (0,0) being top left;
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   469
// - the CursorPoint coordinate system goes from -cScreenWidth/2 to cScreenWidth/2 on the x axis
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   470
//   and 0 to cScreenHeight on the x axis, (-cScreenWidth, cScreenHeight) being top left.
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   471
function convertToCursorX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   472
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   473
    convertToCursorX := round((x/32768)*cScreenWidth) - (cScreenWidth shr 1);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   474
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   475
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   476
function convertToCursorY(y: LongInt): LongInt;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   477
begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   478
    convertToCursorY := cScreenHeight - round((y/32768)*cScreenHeight)
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   479
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   480
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   481
function convertToCursorDeltaX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   482
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   483
    convertToCursorDeltaX := round(x/32768*cScreenWidth)
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   484
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   485
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   486
function convertToCursorDeltaY(y: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   487
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   488
    convertToCursorDeltaY := round(y/32768*cScreenHeight)
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   489
end;
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   490
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   491
function isOnCrosshair(finger: TTouch_Data): boolean;
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   492
var
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   493
    x,y : LongInt;
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   494
begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   495
    x := 0;//avoid compiler hint
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   496
    y := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   497
    convertToFingerCoord(x, y, CrosshairX, CrosshairY);
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   498
  isOnCrosshair:= sqrt(sqr(finger.x-x) + sqr(finger.y-y)) < 50;
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   499
//    isOnCrosshair:= isOnRect(x-24, y-24, 48, 48, finger);
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   500
end;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   501
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   502
function isOnCurrentHog(finger: TTouch_Data): boolean;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   503
var
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   504
    x,y : LongInt;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   505
begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   506
    x := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   507
    y := 0;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   508
    convertToFingerCoord(x,y, hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y));
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   509
    isOnCurrentHog := sqrt(sqr(finger.X-x) + sqr(finger.Y-y)) < 50;
5938
c186c454779d isOnCurrentHog and isOnCrosshair now look at the distance relative to the screen rather than world coords, this means that zooming out doesn't make it harder to touch the hog or crosshair
Xeli
parents: 5828
diff changeset
   510
end;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   511
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   512
procedure convertToFingerCoord(var x,y : LongInt; oldX, oldY: LongInt);
5938
c186c454779d isOnCurrentHog and isOnCrosshair now look at the distance relative to the screen rather than world coords, this means that zooming out doesn't make it harder to touch the hog or crosshair
Xeli
parents: 5828
diff changeset
   513
begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   514
    x := oldX + WorldDx;
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   515
    y := cScreenHeight - (oldY + WorldDy);
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   516
end;
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   517
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   518
procedure convertToWorldCoord(var x,y: LongInt; finger: TTouch_Data);
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   519
begin
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   520
//if x <> nil then 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   521
    x := finger.x-WorldDx;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   522
//if y <> nil then 
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   523
    y := (cScreenHeight - finger.y)-WorldDy;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   524
end;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   525
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   526
//Method to calculate the distance this finger has moved since the downEvent
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   527
function fingerHasMoved(finger: TTouch_Data): boolean;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   528
begin
6704
77c93096d055 change power() to sqr
Xeli
parents: 6703
diff changeset
   529
    fingerHasMoved := trunc(sqrt(sqr(finger.X-finger.historicalX) + sqr(finger.y-finger.historicalY))) > 330;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   530
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   531
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   532
function calculateDelta(finger1, finger2: TTouch_Data): LongInt; inline;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   533
begin
6702
37c56511df0c remove all hwFloat calculations
Xeli
parents: 6701
diff changeset
   534
    calculateDelta := Round(sqrt(sqr(finger2.x-finger1.x) + sqr(finger2.y-finger1.y)));
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   535
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   536
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   537
// Under the premise that all pointer ids in pointerIds:TSDL_FingerId are packed to the far left.
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   538
// If the pointer to be ignored is not pointerIds[0] the second must be there
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   539
function getSecondFinger(finger: TTouch_Data): PTouch_Data;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   540
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   541
    if fingers[0].id = finger.id then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   542
        getSecondFinger := @fingers[1]
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   543
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   544
        getSecondFinger := @fingers[0];
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   545
end;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   546
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   547
function isOnRect(rect: TSDL_Rect; finger: TTouch_Data): boolean;
6698
804e9076d136 forgot begin
Xeli
parents: 6695
diff changeset
   548
begin
6703
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   549
    isOnRect:= isOnRect(rect.x, rect.y, rect.w, rect.h, finger);
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   550
end;
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   551
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   552
function isOnRect(x,y,w,h: LongInt; finger: TTouch_Data): boolean;
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   553
begin
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   554
    isOnRect:= (finger.x > x)   and
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   555
               (finger.x < x + w) and
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   556
               (cScreenHeight - finger.y > y) and
abe2abfe9de2 fix crosshair aiming
Xeli
parents: 6702
diff changeset
   557
               (cScreenHeight - finger.y < y + h);
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   558
end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   559
6693
b6a69c0bc541 carried out some cosmetic TODOs in uTouch
koda
parents: 6687
diff changeset
   560
procedure printFinger(finger: TTouch_Data);
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   561
begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   562
    WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   563
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   564
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   565
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   566
var
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   567
    index: Longword;
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   568
    //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   569
begin
6701
58a43c2064ad the onScreenwidgets are multitouch now, frequently (alternating) tapping left and right still causes it to bug though, but you have to try hard to duplicate it, works ok for now
Xeli
parents: 6700
diff changeset
   570
    buttonsDown:= 0;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   571
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   572
    setLength(fingers, 4);
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   573
    for index := 0 to High(fingers) do 
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   574
        fingers[index].id := nilFingerId;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   575
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   576
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   577
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   578
end.