hedgewars/uTouch.pas
author Xeli
Sat, 12 Nov 2011 14:45:36 +0100
branchhedgeroid
changeset 6228 1b7d4d7d162b
parent 6029 5073285b6599
child 6344 cba81e10235c
permissions -rw-r--r--
added lines to avoid compiler hints, is this really the way we want to do it though? ;/
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
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     3
 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
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
6029
5073285b6599 changed Game arguments to accept data path on 9th array element (like planned)
koda
parents: 5938
diff changeset
    25
uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, uIO, uCommands, GLUnit;
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
type
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    28
    PTouch_Finger = ^Touch_Finger;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    29
    Touch_Finger = record
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    30
        id                       : SDL_FingerId;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    31
        x,y                      : LongInt;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    32
        historicalX, historicalY : LongInt;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    33
        timeSinceDown            : Longword;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    34
        end;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    35
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    36
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    37
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
    38
procedure ProcessTouch;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    39
procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    40
procedure onTouchMotion(x,y: Longword; dx,dy: LongInt; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    41
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    42
function convertToCursor(scale: LongInt; xy: LongInt): LongInt;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    43
function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    44
procedure deleteFinger(id: SDL_FingerId);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    45
procedure onTouchClick(finger: Touch_Finger);
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
    46
procedure onTouchDoubleClick(finger: Touch_Finger);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    47
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    48
function findFinger(id: SDL_FingerId): PTouch_Finger;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    49
procedure aim(finger: Touch_Finger);
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
    50
function isOnCrosshair(finger: Touch_Finger): boolean;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    51
function isOnCurrentHog(finger: Touch_Finger): boolean;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    52
function isOnFireButton(finger: Touch_Finger): boolean;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    53
procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger);
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
    54
procedure convertToFingerCoord(var x,y: hwFloat; oldX, oldY: hwFloat);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    55
function fingerHasMoved(finger: Touch_Finger): boolean;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    56
function calculateDelta(finger1, finger2: Touch_Finger): hwFloat;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    57
function getSecondFinger(finger: Touch_Finger): PTouch_Finger;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    58
procedure printFinger(finger: Touch_Finger);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    59
implementation
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    60
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    61
const
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    62
    clicktime = 200;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    63
    nilFingerId = High(SDL_FingerId);
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    64
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    65
var
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    66
    fireButtonLeft, fireButtonRight, fireButtonTop, fireButtonBottom : LongInt;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    67
        
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    68
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    69
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    70
    leftButtonBoundary  : LongInt;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    71
    rightButtonBoundary : LongInt;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    72
    topButtonBoundary   : LongInt;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    73
    
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    74
    pointerCount : Longword;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    75
    fingers: array of Touch_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
    76
    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
    77
    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
    78
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
    79
    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
    80
    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
    81
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    82
    //Pinch to zoom 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    83
    pinchSize : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    84
    baseZoomValue: GLFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    85
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    86
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
    87
    //aiming
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
    88
    aiming, movingCrosshair: boolean; 
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
    89
    crosshairCommand: ShortString;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    90
    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
    91
    stopFiring: boolean;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    92
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    93
    //moving
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    94
    stopLeft, stopRight, walkingLeft, walkingRight :  boolean;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    95
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
    96
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    97
procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    98
var 
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    99
    finger: PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   100
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
   101
    finger := addFinger(x,y,pointerId);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   102
    case pointerCount of
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
   103
        1:
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   104
        begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   105
            moveCursor:= false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   106
            if bShowAmmoMenu then
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   107
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   108
                moveCursor := true;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   109
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   110
            end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   111
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   112
            if isOnCrosshair(finger^) 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
   113
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   114
                aiming:= true;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   115
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   116
            end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   117
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   118
            if isOnFireButton(finger^) 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
   119
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   120
                stopFiring:= false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   121
                ParseCommand('+attack', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   122
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   123
            end;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   124
            if (finger^.x < leftButtonBoundary) and (finger^.y < 390) 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
   125
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   126
                ParseCommand('+left', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   127
                walkingLeft := true;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   128
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   129
            end;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   130
            if finger^.x > rightButtonBoundary 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
   131
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   132
                ParseCommand('+right', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   133
                walkingRight:= true;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   134
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   135
            end;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   136
            if finger^.y < topButtonBoundary 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
   137
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   138
                ParseCommand('hjump', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   139
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   140
            end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   141
            moveCursor:= true; 
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   142
        end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   143
        2:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   144
        begin
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
   145
            aiming:= false;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   146
            stopFiring:= true;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   147
            moveCursor:= false;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   148
            pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   149
            baseZoomValue := ZoomValue
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   150
        end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   151
    end;//end case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   152
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   153
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   154
procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   155
var
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   156
    finger, secondFinger: PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   157
    currentPinchDelta, zoom : hwFloat;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   158
    tmpX, tmpY: LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   159
begin
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   160
    x := x;
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   161
    y := y;
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   162
    dx := dx;
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   163
    dy := dy;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   164
    finger:= findFinger(pointerId);
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   165
    tmpX := convertToCursor(cScreenWidth, x);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   166
    tmpY := convertToCursor(cScreenHeight, y);
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   167
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   168
    if moveCursor then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   169
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   170
        if invertCursor then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   171
        begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   172
            CursorPoint.X := CursorPoint.X + (finger^.x - tmpX);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   173
            CursorPoint.Y := CursorPoint.Y - (finger^.y - tmpY);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   174
        end
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   175
        else
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   176
        begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   177
            CursorPoint.X := CursorPoint.X - (finger^.x - tmpX);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   178
            CursorPoint.Y := CursorPoint.Y + (finger^.y - tmpY);
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
        finger^.x := tmpX;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   181
        finger^.y := tmpY;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   182
        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
   183
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   184
    
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   185
    finger^.x := tmpX;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   186
    finger^.y := tmpY;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   187
    
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   188
    if aiming then 
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   189
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   190
        aim(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   191
        exit
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   192
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   193
    if pointerCount = 2 then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   194
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   195
       secondFinger := getSecondFinger(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   196
       currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   197
       zoom := currentPinchDelta/cScreenWidth;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   198
       ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   199
       if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   200
       if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   201
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   202
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   203
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   204
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   205
begin
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   206
    x := x;
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   207
    y := 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
   208
    aiming:= false;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   209
    stopFiring:= true;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   210
    deleteFinger(pointerId);
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   211
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   212
    if walkingLeft then
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   213
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   214
        ParseCommand('-left', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   215
        walkingLeft := false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   216
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   217
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   218
    if walkingRight then
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   219
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   220
        ParseCommand('-right', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   221
        walkingRight := false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   222
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   223
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   224
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
   225
procedure onTouchDoubleClick(finger: Touch_Finger);
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   226
begin
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   227
    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
   228
    ParseCommand('ljump', true);
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   229
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
   230
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   231
procedure onTouchClick(finger: Touch_Finger);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   232
begin
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
   233
    if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   234
    begin
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   235
    onTouchDoubleClick(finger);
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   236
    exit; 
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   237
    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
   238
    else
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   239
    begin
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   240
        xTouchClick := finger.x;
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   241
        yTouchClick := finger.y;
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   242
        timeSinceClick := SDL_GetTicks;
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
   243
    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
   244
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   245
    if bShowAmmoMenu then 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   246
    begin
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   247
        doPut(CursorPoint.X, CursorPoint.Y, false); 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   248
        exit
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   249
    end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   250
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   251
    if isOnCurrentHog(finger) then
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   252
    begin
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   253
        bShowAmmoMenu := true;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   254
        exit;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   255
    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
   256
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   257
    if finger.y < topButtonBoundary 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
   258
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   259
        ParseCommand('hjump', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   260
        exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   261
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   262
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   263
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   264
function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   265
var 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   266
    xCursor, yCursor, index : LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   267
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   268
    //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
   269
    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
   270
    begin
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   271
        setLength(fingers, length(fingers)*2);
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   272
        for index := length(fingers) div 2 to length(fingers) do fingers[index].id := nilFingerId;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   273
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   274
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   275
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   276
    xCursor := convertToCursor(cScreenWidth, x);
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   277
    yCursor := convertToCursor(cScreenHeight, y);
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   278
    
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   279
    //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
   280
    //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
   281
    fingers[pointerCount].id := id;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   282
    fingers[pointerCount].historicalX := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   283
    fingers[pointerCount].historicalY := yCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   284
    fingers[pointerCount].x := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   285
    fingers[pointerCount].y := yCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   286
    fingers[pointerCount].timeSinceDown:= SDL_GetTicks;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   287
 
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   288
    addFinger:= @fingers[pointerCount];
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   289
    inc(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   290
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   291
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   292
procedure deleteFinger(id: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   293
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
   294
    index : Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   295
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   296
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   297
    dec(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   298
    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
   299
    begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   300
         if fingers[index].id = id then
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   301
         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
   302
             //Check for onTouchClick event
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   303
             if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND  
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   304
                 not(fingerHasMoved(fingers[index])) then onTouchClick(fingers[index]);
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   305
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   306
             //put the last finger into the spot of the finger to be removed, 
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   307
             //so that all fingers are packed to the far left
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   308
             if  pointerCount <> index then
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   309
             begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   310
                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
   311
                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
   312
                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
   313
                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
   314
                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
   315
                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
   316
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   317
                fingers[pointerCount].id := nilFingerId;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   318
             end
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   319
             else fingers[index].id := nilFingerId;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   320
             break;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   321
         end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   322
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   323
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   324
end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   325
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
   326
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
   327
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
   328
    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
   329
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
   330
    invertCursor := not(bShowAmmoMenu);
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
   331
    if aiming then
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
   332
    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
   333
        if CurrentHedgehog^.Gear <> nil then
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
   334
        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
   335
            deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle;
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
   336
            if (deltaAngle <> 0) and not(movingCrosshair) then 
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
   337
            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
   338
                ParseCommand('+' + crosshairCommand, true);
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
   339
                movingCrosshair := true;
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
   340
            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
   341
            else 
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
   342
                if movingCrosshair then 
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
   343
                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
   344
                    ParseCommand('-' + crosshairCommand, true);
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
   345
                    movingCrosshair:= false;
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
   346
                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
   347
        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
   348
    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
   349
    else if movingCrosshair then 
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
   350
    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
   351
        ParseCommand('-' + crosshairCommand, true);
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
   352
        movingCrosshair := false;
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
   353
    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
   354
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   355
    if stopFiring then 
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   356
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   357
        ParseCommand('-attack', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   358
        stopFiring:= false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   359
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   360
    
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   361
    if stopRight then
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   362
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   363
        stopRight := false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   364
        ParseCommand('-right', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   365
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   366
 
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   367
    if stopLeft then
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   368
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   369
        stopLeft := false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   370
        ParseCommand('-left', true);
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   371
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   372
    
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
   373
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
   374
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   375
function findFinger(id: SDL_FingerId): PTouch_Finger;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   376
var
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   377
    index: LongWord;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   378
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
   379
   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
   380
       if fingers[index].id = id then 
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   381
       begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   382
           findFinger := @fingers[index];
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   383
           break;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   384
       end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   385
end;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   386
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   387
procedure aim(finger: Touch_Finger);
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
   388
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
   389
    hogX, hogY, touchX, touchY, deltaX, deltaY, tmpAngle: hwFloat;
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
   390
    tmp: ShortString;
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
   391
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
   392
    if CurrentHedgehog^.Gear <> nil then
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
   393
    begin
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   394
        touchX := _0;//avoid compiler hint
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   395
        touchY := _0;
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
   396
        hogX := CurrentHedgehog^.Gear^.X;
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
   397
        hogY := CurrentHedgehog^.Gear^.Y;
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
   398
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   399
        convertToWorldCoord(touchX, touchY, finger);
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
   400
        deltaX := hwAbs(TouchX-HogX);
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
   401
        deltaY := (TouchY-HogY);
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
   402
        
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
   403
        tmpAngle:= DeltaY / Distance(deltaX, deltaY) *_2048;
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
   404
        targetAngle:= (hwRound(tmpAngle) + 2048) div 2;
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
   405
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
   406
        tmp := crosshairCommand;
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
   407
        if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then crosshairCommand := 'down'
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
   408
        else crosshairCommand:= 'up';
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
   409
        if movingCrosshair and (tmp <> crosshairCommand) then 
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
   410
        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
   411
            ParseCommand('-' + tmp, true);
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
   412
            movingCrosshair := false;
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
   413
        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
   414
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
   415
    end; //if CurrentHedgehog^.Gear <> nil
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
   416
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
   417
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
   418
function convertToCursor(scale: LongInt; xy: LongInt): 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
   419
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
   420
    convertToCursor := round(xy/32768*scale)
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
   421
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
   422
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   423
function isOnFireButton(finger: Touch_Finger): 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
   424
begin
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   425
    isOnFireButton:= (finger.x <= fireButtonRight) and (finger.x >= fireButtonLeft) and (finger.y <= fireButtonBottom) and (finger.y >= fireButtonTop);
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   426
end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   427
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   428
function isOnCrosshair(finger: Touch_Finger): boolean;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   429
var
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
   430
    x,y : hwFloat;
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   431
begin
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   432
    x := _0;//avoid compiler hint
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   433
    y := _0;
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
   434
    convertToFingerCoord(x, y, int2hwFloat(CrosshairX), int2hwFloat(CrosshairY));
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
   435
    isOnCrosshair:= Distance(int2hwFloat(finger.x)-x, int2hwFloat(finger.y)-y) < _50;
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   436
end;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   437
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   438
function isOnCurrentHog(finger: Touch_Finger): boolean;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   439
var
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
   440
    x,y : hwFloat;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   441
begin
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   442
    x := _0;
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   443
    y := _0;
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
   444
    convertToFingerCoord(x, y, CurrentHedgehog^.Gear^.X, CurrentHedgehog^.Gear^.Y);
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
   445
    isOnCurrentHog := Distance(int2hwFloat(finger.X)-x, int2hwFloat(finger.Y)-y) < _50;
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
   446
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
   447
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
   448
procedure convertToFingerCoord(var x,y : hwFloat; oldX, oldY: hwFloat);
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
   449
begin
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
   450
    x := oldX + int2hwFloat(WorldDx + (cScreenWidth div 2));
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
   451
    y := oldY + int2hwFloat(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
   452
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
   453
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   454
procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger);
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
   455
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
   456
//if x <> nil then 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   457
    x := int2hwFloat((finger.x-WorldDx) - (cScreenWidth div 2));
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
//if y <> nil then 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   459
    y := int2hwFloat(finger.y-WorldDy);
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   460
end;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   461
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   462
//Method to calculate the distance this finger has moved since the downEvent
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   463
function fingerHasMoved(finger: Touch_Finger): boolean;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   464
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   465
    fingerHasMoved := trunc(sqrt(Power(finger.X-finger.historicalX,2) + Power(finger.y-finger.historicalY, 2))) > 330;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   466
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   467
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   468
function calculateDelta(finger1, finger2: Touch_Finger): hwFloat; inline;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   469
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
   470
    calculateDelta := DistanceI(finger2.x-finger1.x, finger2.y-finger1.y);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   471
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   472
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   473
// Under the premise that all pointer ids in pointerIds:SDL_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
   474
// If the pointer to be ignored is not pointerIds[0] the second must be there
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   475
function getSecondFinger(finger: Touch_Finger): PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   476
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
   477
    if fingers[0].id = finger.id then getSecondFinger := @fingers[1]
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   478
    else getSecondFinger := @fingers[0];
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   479
end;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   480
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   481
procedure printFinger(finger: Touch_Finger);
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   482
begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   483
    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
   484
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   485
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   486
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   487
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
   488
    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
   489
    //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   490
begin
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
   491
    movingCrosshair := false;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   492
    stopFiring:= false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   493
    walkingLeft := false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   494
    walkingRight := false;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   495
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   496
    leftButtonBoundary := cScreenWidth div 4;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   497
    rightButtonBoundary := cScreenWidth div 4*3;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   498
    topButtonBoundary := cScreenHeight div 6;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   499
    
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   500
    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
   501
    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
   502
        fingers[index].id := nilFingerId;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   503
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   504
6228
1b7d4d7d162b added lines to avoid compiler hints, is this really the way we want to do it though? ;/
Xeli
parents: 6029
diff changeset
   505
    //uRenderCoordScaleX := Round(cScreenWidth/0.8 * 2);
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   506
    fireButtonLeft := Round(cScreenWidth*0.01);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   507
    fireButtonRight := Round(fireButtonLeft + (spritesData[sprFireButton].Width*0.4));
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   508
    fireButtonBottom := Round(cScreenHeight*0.99);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   509
    fireButtonTop := fireButtonBottom - Round(spritesData[sprFireButton].Height*0.4);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   510
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   511
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   512
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   513
end.