hedgewars/uTouch.pas
author Xeli
Mon, 06 Feb 2012 22:40:09 +0100
changeset 6640 813a173cd677
parent 6625 2d8c5815292f
child 6648 025473a2c420
permissions -rw-r--r--
the buttons actually work now!
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
6344
cba81e10235c iOS works again (also native touch interface \o/)
koda
parents: 6228
diff changeset
    27
// TODO: this type should be Int64
cba81e10235c iOS works again (also native touch interface \o/)
koda
parents: 6228
diff changeset
    28
// TODO: this type should be named TSDL_FingerId
cba81e10235c iOS works again (also native touch interface \o/)
koda
parents: 6228
diff changeset
    29
type SDL_FingerId = LongInt;
cba81e10235c iOS works again (also native touch interface \o/)
koda
parents: 6228
diff changeset
    30
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    31
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
    32
    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
    33
    Touch_Finger = record
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    34
        id                       : SDL_FingerId;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    35
        x,y                      : LongInt;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    36
        dx,dy                    : LongInt;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    37
        historicalX, historicalY : LongInt;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    38
        timeSinceDown            : Longword;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    39
        end;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    40
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    41
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    42
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
    43
procedure ProcessTouch;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    44
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
    45
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
    46
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    47
function convertToCursorX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    48
function convertToCursorY(y: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    49
function convertToCursorDeltaX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    50
function convertToCursorDeltaY(y: 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
    51
function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
    52
function updateFinger(x,y,dx,dy: 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
    53
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
    54
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
    55
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
    56
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 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
    58
procedure aim(finger: Touch_Finger);
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
    59
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
    60
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
    61
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
    62
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
    63
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
    64
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
    65
function getSecondFinger(finger: Touch_Finger): PTouch_Finger;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
    66
function isOnRect(x,y,w,h: LongInt; finger: Touch_Finger): boolean;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
    67
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
    68
implementation
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    69
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    70
const
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    71
    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
    72
    nilFingerId = High(SDL_FingerId);
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    73
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    74
var
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    75
    pointerCount : Longword;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    76
    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
    77
    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
    78
    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
    79
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
    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
    81
    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
    82
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    83
    //Pinch to zoom 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    84
    pinchSize : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    85
    baseZoomValue: GLFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
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
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
    88
    aiming, movingCrosshair: boolean;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
    89
    aimingUp, aimingDown: boolean; 
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
    90
    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
    91
    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
    92
    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
    93
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    94
    //moving
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    95
    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
    96
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
    97
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    98
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
    99
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
   100
    finger: PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   101
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   102
finger := addFinger(x,y,pointerId);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   103
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
   104
        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
   105
        begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   106
            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
   107
            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
   108
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   109
                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
   110
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   111
            end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   112
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   113
            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
   114
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   115
                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
   116
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   117
            end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   118
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   119
            if isOnRect(fireButtonX, fireButtonY, fireButtonW, fireButtonH, 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
   120
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   121
                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
   122
                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
   123
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   124
            end;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   125
            if isOnRect(arrowLeftX, arrowLeftY, arrowLeftW, arrowLeftH, 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
   126
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   127
                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
   128
                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
   129
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   130
            end;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   131
            if isOnRect(arrowRightX, arrowRightY, arrowRightW, arrowRightH, 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
   132
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   133
                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
   134
                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
   135
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   136
            end;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   137
            if isOnRect(arrowUpX, arrowUpY, arrowUpW, arrowUpH, finger^) then
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   138
            begin
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   139
                ParseCommand('+up', true);
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   140
                aimingUp:= true;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   141
                exit;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   142
            end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   143
            if isOnRect(arrowDownX, arrowDownY, arrowUpW, arrowUpH, finger^) then
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   144
            begin
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   145
                ParseCommand('+down', true);
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   146
                aimingDown:= true;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   147
                exit;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   148
            end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   149
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   150
            if isOnRect(backjumpX, backjumpY, backjumpW, backjumpH, 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
   151
            begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   152
                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
   153
                exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   154
            end;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   155
            if isOnRect(forwardjumpX, forwardjumpY, forwardjumpW, forwardjumpH, finger^) then
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   156
            begin
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   157
                ParseCommand('ljump', true);
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   158
                exit;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   159
            end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   160
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   161
          
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   162
            moveCursor:= true; 
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   163
        end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   164
        2:
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   165
        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
   166
            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
   167
            stopFiring:= true;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   168
            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
   169
            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
   170
            baseZoomValue := ZoomValue
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   171
        end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   172
    end;//end case pointerCount of
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   173
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   174
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   175
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
   176
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
   177
    finger, secondFinger: PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   178
    currentPinchDelta, zoom : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   179
begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   180
finger:= updateFinger(x,y,dx,dy,pointerId);
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   181
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   182
if moveCursor then
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   183
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   184
        if invertCursor then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   185
        begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   186
            CursorPoint.X := CursorPoint.X - finger^.dx;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   187
            CursorPoint.Y := CursorPoint.Y + finger^.dy;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   188
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   189
    else
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   190
        begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   191
            CursorPoint.X := CursorPoint.X + finger^.dx;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   192
            CursorPoint.Y := CursorPoint.Y - finger^.dy;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   193
        end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   194
        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
   195
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   196
    
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   197
    if aiming then 
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   198
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   199
        aim(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   200
        exit
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   201
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   202
    if pointerCount = 2 then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   203
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   204
       secondFinger := getSecondFinger(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   205
       currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   206
       zoom := currentPinchDelta/cScreenWidth;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   207
       ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   208
       if ZoomValue < cMaxZoomLevel then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   209
           ZoomValue := cMaxZoomLevel;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   210
       if ZoomValue > cMinZoomLevel then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   211
           ZoomValue := cMinZoomLevel;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   212
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   213
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   214
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   215
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   216
var
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   217
    finger: PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   218
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   219
x := x;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   220
y := y;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   221
aiming:= false;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   222
stopFiring:= true;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   223
finger:= updateFinger(x,y,0,0,pointerId);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   224
//Check for onTouchClick event
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   225
if ((SDL_GetTicks - finger^.timeSinceDown) < clickTime) AND not(fingerHasMoved(finger^)) then
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   226
    onTouchClick(finger^);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   227
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   228
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
   229
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   230
if walkingLeft 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
   231
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   232
        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
   233
        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
   234
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   235
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   236
if walkingRight 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
   237
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   238
        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
   239
        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
   240
    end;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   241
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   242
if aimingUp then
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   243
    begin
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   244
    ParseCommand('-up', true);
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   245
    aimingUp:= false;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   246
    end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   247
if aimingDown then
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   248
    begin
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   249
    ParseCommand('-down', true);
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   250
    aimingDown:= false;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   251
    end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   252
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   253
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   254
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   255
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
   256
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
   257
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   258
finger := finger;//avoid compiler hint
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   259
//ParseCommand('ljump', true);
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
   260
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
   261
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   262
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
   263
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   264
if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then
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
   265
    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
   266
    onTouchDoubleClick(finger);
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   267
    timeSinceClick:= -1;
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
   268
    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
   269
    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
   270
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   271
xTouchClick:= finger.x;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   272
yTouchClick:= finger.y;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   273
timeSinceClick:= SDL_GetTicks;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   274
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   275
if bShowAmmoMenu then 
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   276
    begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   277
    CursorPoint.X:= finger.x;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   278
    CursorPoint.Y:= finger.y;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   279
    doPut(CursorPoint.X, CursorPoint.Y, false); 
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   280
    exit
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   281
    end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   282
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   283
if isOnCurrentHog(finger) then
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   284
    begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   285
    bShowAmmoMenu := true;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   286
    exit;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   287
    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
   288
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   289
{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
   290
    begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   291
    ParseCommand('hjump', true);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   292
    exit;
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   293
    end;}
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   294
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   295
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   296
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
   297
var 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   298
    xCursor, yCursor, index : LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   299
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   300
    //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
   301
    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
   302
    begin
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   303
        setLength(fingers, length(fingers)*2);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   304
        for index := length(fingers) div 2 to length(fingers) do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   305
            fingers[index].id := nilFingerId;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   306
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   307
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   308
    
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   309
    xCursor := convertToCursorX(x);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   310
    yCursor := convertToCursorY(y);
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   311
    
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   312
    //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
   313
    //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
   314
    fingers[pointerCount].id := id;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   315
    fingers[pointerCount].historicalX := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   316
    fingers[pointerCount].historicalY := yCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   317
    fingers[pointerCount].x := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   318
    fingers[pointerCount].y := yCursor;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   319
    fingers[pointerCount].dx := 0;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   320
    fingers[pointerCount].dy := 0;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   321
    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
   322
 
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   323
    addFinger:= @fingers[pointerCount];
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   324
    inc(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   325
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   326
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   327
function updateFinger(x,y,dx,dy: Longword; id: SDL_FingerId): PTouch_Finger;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   328
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   329
   updateFinger:= findFinger(id);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   330
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   331
   updateFinger^.x:= convertToCursorX(x);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   332
   updateFinger^.y:= convertToCursorY(y);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   333
   updateFinger^.dx:= convertToCursorDeltaX(dx);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   334
   updateFinger^.dy:= convertToCursorDeltaY(dy);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   335
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   336
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   337
procedure deleteFinger(id: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   338
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
   339
    index : Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   340
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   341
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   342
    dec(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   343
    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
   344
    begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   345
        if fingers[index].id = id then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   346
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   347
 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   348
            //put the last finger into the spot of the finger to be removed, 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   349
            //so that all fingers are packed to the far left
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   350
            if  pointerCount <> index then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   351
                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
   352
                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
   353
                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
   354
                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
   355
                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
   356
                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
   357
                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
   358
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   359
                fingers[pointerCount].id := nilFingerId;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   360
            end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   361
        else fingers[index].id := nilFingerId;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   362
            break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   363
        end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   364
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   365
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   366
end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   367
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
   368
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
   369
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
   370
    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
   371
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
   372
    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
   373
    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
   374
    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
   375
        if CurrentHedgehog^.Gear <> nil then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   376
            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
   377
            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
   378
            if (deltaAngle <> 0) and not(movingCrosshair) then 
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   379
                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
   380
                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
   381
                movingCrosshair := true;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   382
                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
   383
            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
   384
                if movingCrosshair then 
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   385
                    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
   386
                    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
   387
                    movingCrosshair:= false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   388
                   end;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   389
            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
   390
    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
   391
    else if movingCrosshair then 
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   392
        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
   393
        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
   394
        movingCrosshair := false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   395
        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
   396
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   397
    if stopFiring then 
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   398
        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
   399
        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
   400
        stopFiring:= false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   401
        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
   402
    
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   403
    if stopRight then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   404
        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
   405
        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
   406
        ParseCommand('-right', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   407
        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
   408
 
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   409
    if stopLeft then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   410
        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
   411
        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
   412
        ParseCommand('-left', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   413
        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
   414
    
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
   415
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
   416
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   417
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
   418
var
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   419
    index: LongWord;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   420
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   421
    for index := 0 to High(fingers) do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   422
        if fingers[index].id = id then 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   423
            begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   424
            findFinger := @fingers[index];
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   425
            break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   426
            end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   427
end;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   428
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   429
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
   430
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
   431
    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
   432
    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
   433
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
   434
    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
   435
    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
   436
        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
   437
        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
   438
        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
   439
        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
   440
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   441
        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
   442
        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
   443
        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
   444
        
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
   445
        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
   446
        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
   447
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
   448
        tmp := crosshairCommand;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   449
        if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   450
            crosshairCommand := 'up'
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   451
        else
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   452
            crosshairCommand:= 'down';
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
   453
        if movingCrosshair and (tmp <> crosshairCommand) then 
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   454
            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
   455
            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
   456
            movingCrosshair := false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   457
            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
   458
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
   459
    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
   460
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
   461
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   462
//These 4 convertToCursor functions convert xy coords from the SDL coordinate system to our CursorPoint coor system
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   463
// the SDL coordinate system goes from 0 to 32768 on the x axis and 0 to 32768 on the y axis, (0,0) being top left.
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   464
// the CursorPoint coordinate system goes from -cScreenWidth/2 to cScreenWidth/2 on the x axis 
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   465
//  and 0 to cScreenHeight on the x axis, (-cScreenWidth, cScreenHeight) being top left,
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   466
function convertToCursorX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   467
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   468
    convertToCursorX := round((x/32768)*cScreenWidth) - (cScreenWidth shr 1);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   469
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   470
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   471
function convertToCursorY(y: LongInt): LongInt;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   472
begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   473
    convertToCursorY := cScreenHeight - round((y/32768)*cScreenHeight)
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   474
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   475
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   476
function convertToCursorDeltaX(x: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   477
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   478
    convertToCursorDeltaX := round(x/32768*cScreenWidth)
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   479
end;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   480
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   481
function convertToCursorDeltaY(y: LongInt): LongInt;
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   482
begin
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   483
    convertToCursorDeltaY := round(y/32768*cScreenHeight)
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5595
diff changeset
   484
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
   485
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   486
function isOnCrosshair(finger: Touch_Finger): boolean;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   487
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
   488
    x,y : hwFloat;
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   489
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
   490
    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
   491
    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
   492
    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
   493
    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
   494
end;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   495
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   496
function isOnCurrentHog(finger: Touch_Finger): boolean;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   497
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
   498
    x,y : hwFloat;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   499
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
   500
    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
   501
    y := _0;
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   502
    convertToFingerCoord(x,y, CurrentHedgehog^.Gear^.X, CurrentHedgehog^.Gear^.Y);
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
   503
    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
   504
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
   505
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
   506
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
   507
begin
6625
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   508
    x := oldX + int2hwFloat(WorldDx);
2d8c5815292f some refactoring + you can now tap on the ammo menu to select a weapon
Xeli
parents: 6580
diff changeset
   509
    y := int2hwFloat(cScreenHeight) - (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
   510
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
   511
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   512
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
   513
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
   514
//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
   515
    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
   516
//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
   517
    y := int2hwFloat(finger.y-WorldDy);
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   518
end;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   519
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   520
//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
   521
function fingerHasMoved(finger: Touch_Finger): boolean;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   522
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   523
    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
   524
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   525
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   526
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
   527
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
   528
    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
   529
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   530
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   531
// 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
   532
// 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
   533
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
   534
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   535
    if fingers[0].id = finger.id then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   536
        getSecondFinger := @fingers[1]
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   537
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6344
diff changeset
   538
        getSecondFinger := @fingers[0];
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   539
end;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   540
6640
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   541
function isOnRect(x,y,w,h: LongInt; finger: Touch_Finger): boolean;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   542
begin
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   543
WriteToConsole(Format('(%d,%d) (%d, %d) %d',[finger.x, finger.y, x,y, w]));
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   544
isOnRect:= (finger.x > x)   and
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   545
           (finger.x < x+w) and
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   546
           (cScreenHeight - finger.y > y)   and
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   547
           (cScreenHeight - finger.y < (y+w));
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   548
end;
813a173cd677 the buttons actually work now!
Xeli
parents: 6625
diff changeset
   549
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   550
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
   551
begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   552
    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
   553
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   554
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   555
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   556
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
   557
    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
   558
    //uRenderCoordScaleX, uRenderCoordScaleY: Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   559
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
   560
    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
   561
    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
   562
    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
   563
    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
   564
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   565
    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
   566
    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
   567
        fingers[index].id := nilFingerId;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   568
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   569
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   570
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   571
end.