src/events/SDL_gesture.c
author Kees Bakker <kees@ijzerbout.nl>
Thu, 27 Oct 2011 22:23:09 +0200
changeset 6066 1d66a8dce3ef
parent 6065 fcd144b830ce
child 6067 9a8faef6fdbe
permissions -rw-r--r--
Reformat SDL_gesture.c (part 2, space after keywords)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    14
  claim that you wrote the original software. If you use this software
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    15
  in a product, an acknowledgment in the product documentation would be
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    16
  appreciated but is not required.
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    18
  misrepresented as being the original software.
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    20
*/
4865
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
    21
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    22
#include "SDL_config.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    23
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    24
/* General mouse handling code for SDL */
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    25
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    26
#include "SDL_events.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    27
#include "SDL_events_c.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    28
#include "SDL_gesture_c.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    29
4865
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
    30
#include <memory.h>
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
    31
#include <string.h>
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
    32
#include <stdio.h>
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
    33
#include <math.h>
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
    34
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    35
//TODO: Replace with malloc
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    36
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    37
#define MAXPATHSIZE 1024
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    38
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    39
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    40
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    41
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    42
#define DOLLARNPOINTS 64
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    43
#define DOLLARSIZE 256
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    44
4684
f47c2640c667 Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4683
diff changeset
    45
#define ENABLE_DOLLAR
f47c2640c667 Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4683
diff changeset
    46
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    47
#define PHI 0.618033989
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    48
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    49
typedef struct {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    50
    float x,y;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    51
} SDL_FloatPoint;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    52
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    53
typedef struct {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    54
    float length;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    55
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    56
    int numPoints;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    57
    SDL_FloatPoint p[MAXPATHSIZE];
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    58
} SDL_DollarPath;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    59
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    60
typedef struct {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    61
    SDL_FloatPoint path[DOLLARNPOINTS];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    62
    unsigned long hash;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    63
} SDL_DollarTemplate;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    64
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    65
typedef struct {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    66
    SDL_GestureID id;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    67
    SDL_FloatPoint res;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    68
    SDL_FloatPoint centroid;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    69
    SDL_DollarPath dollarPath;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    70
    Uint16 numDownFingers;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    71
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    72
    int numDollarTemplates;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    73
    SDL_DollarTemplate *dollarTemplate;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    74
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    75
    SDL_bool recording;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    76
} SDL_GestureTouch;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    77
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    78
SDL_GestureTouch *SDL_gestureTouch;
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
    79
int SDL_numGestureTouches = 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    80
SDL_bool recordAll;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    81
4868
d6adaafcfb10 Fixed compiling with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 4865
diff changeset
    82
#if 0
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    83
static void PrintPath(SDL_FloatPoint *path)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    84
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    85
    int i;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    86
    printf("Path:");
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
    87
    for (i=0; i<DOLLARNPOINTS; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    88
        printf(" (%f,%f)",path[i].x,path[i].y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    89
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    90
    printf("\n");
4685
e0c3b09368a6 Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4684
diff changeset
    91
}
4868
d6adaafcfb10 Fixed compiling with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 4865
diff changeset
    92
#endif
4685
e0c3b09368a6 Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4684
diff changeset
    93
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    94
int SDL_RecordGesture(SDL_TouchID touchId)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    95
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    96
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
    97
    if (touchId < 0) recordAll = SDL_TRUE;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
    98
    for (i = 0; i < SDL_numGestureTouches; i++) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
    99
        if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   100
            SDL_gestureTouch[i].recording = SDL_TRUE;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   101
            if (touchId >= 0)
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   102
                return 1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   103
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   104
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   105
    return (touchId < 0);
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   106
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   107
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   108
unsigned long SDL_HashDollar(SDL_FloatPoint* points)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   109
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   110
    unsigned long hash = 5381;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   111
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   112
    for (i = 0; i < DOLLARNPOINTS; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   113
        hash = ((hash<<5) + hash) + (unsigned long)points[i].x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   114
        hash = ((hash<<5) + hash) + (unsigned long)points[i].y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   115
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   116
    return hash;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   117
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   118
4665
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
   119
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   120
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   121
{
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   122
    if (src == NULL) return 0;
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   123
4665
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
   124
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   125
    //No Longer storing the Hash, rehash on load
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   126
    //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;
4682
4ba1048a324c Minimized functionality of gestureSDLTest.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
   127
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   128
    if (SDL_RWwrite(src,templ->path,
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   129
                    sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS)
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   130
        return 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   131
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   132
    return 1;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   133
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   134
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   135
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   136
int SDL_SaveAllDollarTemplates(SDL_RWops *src)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   137
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   138
    int i,j,rtrn = 0;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   139
    for (i = 0; i < SDL_numGestureTouches; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   140
        SDL_GestureTouch* touch = &SDL_gestureTouch[i];
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   141
        for (j = 0; j < touch->numDollarTemplates; j++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   142
            rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   143
        }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   144
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   145
    return rtrn;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   146
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   147
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   148
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   149
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   150
    int i,j;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   151
    for (i = 0; i < SDL_numGestureTouches; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   152
        SDL_GestureTouch* touch = &SDL_gestureTouch[i];
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   153
        for (j = 0; j < touch->numDollarTemplates; j++) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   154
            if (touch->dollarTemplate[i].hash == gestureId) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   155
                return SaveTemplate(&touch->dollarTemplate[i],src);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   156
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   157
        }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   158
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   159
    SDL_SetError("Unknown gestureId");
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   160
    return -1;
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   161
}
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   162
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   163
//path is an already sampled set of points
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   164
//Returns the index of the gesture on success, or -1
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   165
static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   166
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   167
    SDL_DollarTemplate* dollarTemplate;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   168
    SDL_DollarTemplate *templ;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   169
    int i = 0;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   170
    if (inTouch == NULL) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   171
        if (SDL_numGestureTouches == 0) return -1;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   172
        for (i = 0; i < SDL_numGestureTouches; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   173
            inTouch = &SDL_gestureTouch[i];
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   174
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   175
            dollarTemplate =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   176
                (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   177
                                                  (inTouch->numDollarTemplates + 1) *
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   178
                                                  sizeof(SDL_DollarTemplate));
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   179
            if (!dollarTemplate) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   180
                SDL_OutOfMemory();
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   181
                return -1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   182
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   183
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   184
            inTouch->dollarTemplate = dollarTemplate;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   185
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   186
            templ =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   187
                &inTouch->dollarTemplate[inTouch->numDollarTemplates];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   188
            SDL_memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   189
            templ->hash = SDL_HashDollar(templ->path);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   190
            inTouch->numDollarTemplates++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   191
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   192
        return inTouch->numDollarTemplates - 1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   193
    } else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   194
        SDL_DollarTemplate* dollarTemplate =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   195
            ( SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   196
                                               (inTouch->numDollarTemplates + 1) *
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   197
                                               sizeof(SDL_DollarTemplate));
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   198
        if (!dollarTemplate) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   199
            SDL_OutOfMemory();
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   200
            return -1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   201
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   202
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   203
        inTouch->dollarTemplate = dollarTemplate;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   204
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   205
        templ =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   206
            &inTouch->dollarTemplate[inTouch->numDollarTemplates];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   207
        SDL_memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   208
        templ->hash = SDL_HashDollar(templ->path);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   209
        inTouch->numDollarTemplates++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   210
        return inTouch->numDollarTemplates - 1;
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   211
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   212
    return -1;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   213
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   214
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   215
int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   216
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   217
    int i,loaded = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   218
    SDL_GestureTouch *touch = NULL;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   219
    if (src == NULL) return 0;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   220
    if (touchId >= 0) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   221
        for (i = 0; i < SDL_numGestureTouches; i++)
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   222
            if (SDL_gestureTouch[i].id == touchId)
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   223
                touch = &SDL_gestureTouch[i];
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   224
        if (touch == NULL) return -1;
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   225
    }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   226
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   227
    while (1) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   228
        SDL_DollarTemplate templ;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   229
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   230
        if (SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) <
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   231
           DOLLARNPOINTS) break;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   232
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   233
        if (touchId >= 0) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   234
            //printf("Adding loaded gesture to 1 touch\n");
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   235
            if (SDL_AddDollarGesture(touch,templ.path)) loaded++;
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   236
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   237
        else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   238
            //printf("Adding to: %i touches\n",SDL_numGestureTouches);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   239
            for (i = 0; i < SDL_numGestureTouches; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   240
                touch = &SDL_gestureTouch[i];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   241
                //printf("Adding loaded gesture to + touches\n");
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   242
                //TODO: What if this fails?
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   243
                SDL_AddDollarGesture(touch,templ.path);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   244
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   245
            loaded++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   246
        }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   247
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   248
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   249
    return loaded;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   250
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   251
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   252
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   253
float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   254
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   255
    //  SDL_FloatPoint p[DOLLARNPOINTS];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   256
    float dist = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   257
    SDL_FloatPoint p;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   258
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   259
    for (i = 0; i < DOLLARNPOINTS; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   260
        p.x = (float)(points[i].x * SDL_cos(ang) - points[i].y * SDL_sin(ang));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   261
        p.y = (float)(points[i].x * SDL_sin(ang) + points[i].y * SDL_cos(ang));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   262
        dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   263
                                 (p.y-templ[i].y)*(p.y-templ[i].y)));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   264
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   265
    return dist/DOLLARNPOINTS;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   266
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   267
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   268
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   269
float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   270
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   271
    //------------BEGIN DOLLAR BLACKBOX----------------//
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   272
    //-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-//
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   273
    //-"http://depts.washington.edu/aimgroup/proj/dollar/"-//
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   274
    double ta = -M_PI/4;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   275
    double tb = M_PI/4;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   276
    double dt = M_PI/90;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   277
    float x1 = (float)(PHI*ta + (1-PHI)*tb);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   278
    float f1 = dollarDifference(points,templ,x1);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   279
    float x2 = (float)((1-PHI)*ta + PHI*tb);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   280
    float f2 = dollarDifference(points,templ,x2);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   281
    while (SDL_fabs(ta-tb) > dt) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   282
        if (f1 < f2) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   283
            tb = x2;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   284
            x2 = x1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   285
            f2 = f1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   286
            x1 = (float)(PHI*ta + (1-PHI)*tb);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   287
            f1 = dollarDifference(points,templ,x1);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   288
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   289
        else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   290
            ta = x1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   291
            x1 = x2;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   292
            f1 = f2;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   293
            x2 = (float)((1-PHI)*ta + PHI*tb);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   294
            f2 = dollarDifference(points,templ,x2);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   295
        }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   296
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   297
    /*
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   298
      if (f1 <= f2)
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   299
          printf("Min angle (x1): %f\n",x1);
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   300
      else if (f1 >  f2)
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   301
          printf("Min angle (x2): %f\n",x2);
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   302
    */
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   303
    return SDL_min(f1,f2);
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   304
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   305
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   306
//DollarPath contains raw points, plus (possibly) the calculated length
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   307
int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   308
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   309
    int i;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   310
    float interval;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   311
    float dist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   312
    int numPoints = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   313
    SDL_FloatPoint centroid;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   314
    float xmin,xmax,ymin,ymax;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   315
    float ang;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   316
    float w,h;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   317
    float length = path->length;
4865
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
   318
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   319
    //Calculate length if it hasn't already been done
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   320
    if (length <= 0) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   321
        for (i=1;i < path->numPoints; i++) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   322
            float dx = path->p[i  ].x - path->p[i-1].x;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   323
            float dy = path->p[i  ].y - path->p[i-1].y;
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   324
            length += (float)(SDL_sqrt(dx*dx+dy*dy));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   325
        }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   326
    }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   327
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   328
    //Resample
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   329
    interval = length/(DOLLARNPOINTS - 1);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   330
    dist = interval;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   331
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   332
    centroid.x = 0;centroid.y = 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   333
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   334
    //printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   335
    for (i = 1; i < path->numPoints; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   336
        float d = (float)(SDL_sqrt((path->p[i-1].x-path->p[i].x)*(path->p[i-1].x-path->p[i].x)+
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   337
                                   (path->p[i-1].y-path->p[i].y)*(path->p[i-1].y-path->p[i].y)));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   338
        //printf("d = %f dist = %f/%f\n",d,dist,interval);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   339
        while (dist + d > interval) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   340
            points[numPoints].x = path->p[i-1].x +
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   341
                ((interval-dist)/d)*(path->p[i].x-path->p[i-1].x);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   342
            points[numPoints].y = path->p[i-1].y +
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   343
                ((interval-dist)/d)*(path->p[i].y-path->p[i-1].y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   344
            centroid.x += points[numPoints].x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   345
            centroid.y += points[numPoints].y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   346
            numPoints++;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   347
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   348
            dist -= interval;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   349
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   350
        dist += d;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   351
    }
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   352
    if (numPoints < DOLLARNPOINTS-1) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   353
        SDL_SetError("ERROR: NumPoints = %i\n",numPoints);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   354
        return 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   355
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   356
    //copy the last point
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   357
    points[DOLLARNPOINTS-1] = path->p[path->numPoints-1];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   358
    numPoints = DOLLARNPOINTS;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   359
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   360
    centroid.x /= numPoints;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   361
    centroid.y /= numPoints;
4685
e0c3b09368a6 Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4684
diff changeset
   362
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   363
    //printf("Centroid (%f,%f)",centroid.x,centroid.y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   364
    //Rotate Points so point 0 is left of centroid and solve for the bounding box
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   365
    xmin = centroid.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   366
    xmax = centroid.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   367
    ymin = centroid.y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   368
    ymax = centroid.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   369
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   370
    ang = (float)(SDL_atan2(centroid.y - points[0].y,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   371
                            centroid.x - points[0].x));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   372
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   373
    for (i = 0; i<numPoints; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   374
        float px = points[i].x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   375
        float py = points[i].y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   376
        points[i].x = (float)((px - centroid.x)*SDL_cos(ang) -
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   377
                              (py - centroid.y)*SDL_sin(ang) + centroid.x);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   378
        points[i].y = (float)((px - centroid.x)*SDL_sin(ang) +
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   379
                              (py - centroid.y)*SDL_cos(ang) + centroid.y);
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   380
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   381
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   382
        if (points[i].x < xmin) xmin = points[i].x;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   383
        if (points[i].x > xmax) xmax = points[i].x;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   384
        if (points[i].y < ymin) ymin = points[i].y;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   385
        if (points[i].y > ymax) ymax = points[i].y;
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   386
    }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   387
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   388
    //Scale points to DOLLARSIZE, and translate to the origin
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   389
    w = xmax-xmin;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   390
    h = ymax-ymin;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   391
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   392
    for (i=0; i<numPoints; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   393
        points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   394
        points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   395
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   396
    return numPoints;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   397
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   398
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   399
float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_GestureTouch* touch)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   400
{
4868
d6adaafcfb10 Fixed compiling with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 4865
diff changeset
   401
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   402
    SDL_FloatPoint points[DOLLARNPOINTS];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   403
    int i;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   404
    float bestDiff = 10000;
5981
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   405
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   406
    dollarNormalize(path,points);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   407
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   408
    //PrintPath(points);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   409
    *bestTempl = -1;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   410
    for (i = 0; i < touch->numDollarTemplates; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   411
        float diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   412
        if (diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   413
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   414
    return bestDiff;
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   415
}
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   416
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   417
int SDL_GestureAddTouch(SDL_Touch* touch)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   418
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   419
    SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   420
                                                                     (SDL_numGestureTouches + 1) *
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   421
                                                                     sizeof(SDL_GestureTouch));
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   422
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   423
    if (!gestureTouch) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   424
        SDL_OutOfMemory();
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   425
        return -1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   426
    }
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   427
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   428
    SDL_gestureTouch = gestureTouch;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   429
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   430
    SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   431
    SDL_gestureTouch[SDL_numGestureTouches].res.y = touch->yres;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   432
    SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   433
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   434
    SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   435
    SDL_gestureTouch[SDL_numGestureTouches].id = touch->id;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   436
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   437
    SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   438
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   439
    SDL_gestureTouch[SDL_numGestureTouches].recording = SDL_FALSE;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   440
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   441
    SDL_numGestureTouches++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   442
    return 0;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   443
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   444
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   445
int SDL_GestureRemoveTouch(SDL_TouchID id)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   446
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   447
    int i;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   448
    for (i = 0; i < SDL_numGestureTouches; i++) {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   449
        if (SDL_gestureTouch[i].id == id) {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   450
            SDL_numGestureTouches--;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   451
            SDL_memcpy(&SDL_gestureTouch[i], &SDL_gestureTouch[SDL_numGestureTouches], sizeof(SDL_gestureTouch[i]));
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   452
            return 1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   453
        }
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   454
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   455
    return -1;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   456
}
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   457
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   458
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   459
SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   460
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   461
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   462
    for (i = 0; i < SDL_numGestureTouches; i++) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   463
        //printf("%i ?= %i\n",SDL_gestureTouch[i].id,id);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   464
        if (SDL_gestureTouch[i].id == id)
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   465
            return &SDL_gestureTouch[i];
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   466
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   467
    return NULL;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   468
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   469
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   470
int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   471
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   472
    SDL_Event event;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   473
    event.mgesture.type = SDL_MULTIGESTURE;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   474
    event.mgesture.touchId = touch->id;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   475
    event.mgesture.x = touch->centroid.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   476
    event.mgesture.y = touch->centroid.y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   477
    event.mgesture.dTheta = dTheta;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   478
    event.mgesture.dDist = dDist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   479
    event.mgesture.numFingers = touch->numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   480
    return SDL_PushEvent(&event) > 0;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   481
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   482
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   483
int SDL_SendGestureDollar(SDL_GestureTouch* touch,
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   484
                          SDL_GestureID gestureId,float error)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   485
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   486
    SDL_Event event;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   487
    event.dgesture.type = SDL_DOLLARGESTURE;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   488
    event.dgesture.touchId = touch->id;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   489
    /*
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   490
    //TODO: Add this to give location of gesture?
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   491
    event.mgesture.x = touch->centroid.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   492
    event.mgesture.y = touch->centroid.y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   493
    */
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   494
    event.dgesture.gestureId = gestureId;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   495
    event.dgesture.error = error;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   496
    //A finger came up to trigger this event.
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   497
    event.dgesture.numFingers = touch->numDownFingers + 1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   498
    return SDL_PushEvent(&event) > 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   499
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   500
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   501
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   502
int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   503
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   504
    SDL_Event event;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   505
    event.dgesture.type = SDL_DOLLARRECORD;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   506
    event.dgesture.touchId = touch->id;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   507
    event.dgesture.gestureId = gestureId;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   508
    return SDL_PushEvent(&event) > 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   509
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   510
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   511
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   512
void SDL_GestureProcessEvent(SDL_Event* event)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   513
{
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   514
    float x,y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   515
    SDL_FloatPoint path[DOLLARNPOINTS];
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   516
    int index;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   517
    int i;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   518
    float pathDx, pathDy;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   519
    SDL_FloatPoint lastP;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   520
    SDL_FloatPoint lastCentroid;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   521
    float lDist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   522
    float Dist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   523
    float dtheta;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   524
    float dDist;
4865
fff50e86c891 Update VS2010 project to add new files; update new files so code builds on Win32/Win64
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 4689
diff changeset
   525
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   526
    if (event->type == SDL_FINGERMOTION ||
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   527
        event->type == SDL_FINGERDOWN ||
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   528
        event->type == SDL_FINGERUP) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   529
        SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   530
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   531
        //Shouldn't be possible
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   532
        if (inTouch == NULL) return;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   533
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   534
        //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   535
        //           (int)event->tfinger.y,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   536
        //   (int)inTouch->res.x,(int)inTouch->res.y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   537
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   538
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   539
        x = ((float)event->tfinger.x)/(float)inTouch->res.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   540
        y = ((float)event->tfinger.y)/(float)inTouch->res.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   541
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   542
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   543
        //Finger Up
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   544
        if (event->type == SDL_FINGERUP) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   545
            inTouch->numDownFingers--;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4686
diff changeset
   546
4684
f47c2640c667 Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4683
diff changeset
   547
#ifdef ENABLE_DOLLAR
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   548
            if (inTouch->recording) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   549
                inTouch->recording = SDL_FALSE;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   550
                dollarNormalize(&inTouch->dollarPath,path);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   551
                //PrintPath(path);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   552
                if (recordAll) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   553
                    index = SDL_AddDollarGesture(NULL,path);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   554
                    for (i = 0; i < SDL_numGestureTouches; i++)
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   555
                        SDL_gestureTouch[i].recording = SDL_FALSE;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   556
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   557
                else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   558
                    index = SDL_AddDollarGesture(inTouch,path);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   559
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   560
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   561
                if (index >= 0) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   562
                    SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   563
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   564
                else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   565
                    SDL_SendDollarRecord(inTouch,-1);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   566
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   567
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   568
            else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   569
                int bestTempl;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   570
                float error;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   571
                error = dollarRecognize(&inTouch->dollarPath,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   572
                                        &bestTempl,inTouch);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   573
                if (bestTempl >= 0){
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   574
                    //Send Event
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   575
                    unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   576
                    SDL_SendGestureDollar(inTouch,gestureId,error);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   577
                    //printf ("%s\n",);("Dollar error: %f\n",error);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   578
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   579
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   580
#endif
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   581
            //inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   582
            if (inTouch->numDownFingers > 0) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   583
                inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   584
                                       x)/inTouch->numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   585
                inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   586
                                       y)/inTouch->numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   587
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   588
        }
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   589
        else if (event->type == SDL_FINGERMOTION) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   590
            float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   591
            float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   592
            //printf("dx,dy: (%f,%f)\n",dx,dy);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   593
#ifdef ENABLE_DOLLAR
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   594
            SDL_DollarPath* path = &inTouch->dollarPath;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   595
            if (path->numPoints < MAXPATHSIZE) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   596
                path->p[path->numPoints].x = inTouch->centroid.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   597
                path->p[path->numPoints].y = inTouch->centroid.y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   598
                pathDx =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   599
                    (path->p[path->numPoints].x-path->p[path->numPoints-1].x);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   600
                pathDy =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   601
                    (path->p[path->numPoints].y-path->p[path->numPoints-1].y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   602
                path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   603
                path->numPoints++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   604
            }
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   605
#endif
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   606
            lastP.x = x - dx;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   607
            lastP.y = y - dy;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   608
            lastCentroid = inTouch->centroid;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   609
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   610
            inTouch->centroid.x += dx/inTouch->numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   611
            inTouch->centroid.y += dy/inTouch->numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   612
            //printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   613
            if (inTouch->numDownFingers > 1) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   614
                SDL_FloatPoint lv; //Vector from centroid to last x,y position
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   615
                SDL_FloatPoint v; //Vector from centroid to current x,y position
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   616
                //lv = inTouch->gestureLast[j].cv;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   617
                lv.x = lastP.x - lastCentroid.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   618
                lv.y = lastP.y - lastCentroid.y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   619
                lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   620
                //printf("lDist = %f\n",lDist);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   621
                v.x = x - inTouch->centroid.x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   622
                v.y = y - inTouch->centroid.y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   623
                //inTouch->gestureLast[j].cv = v;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   624
                Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   625
                // SDL_cos(dTheta) = (v . lv)/(|v| * |lv|)
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   626
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   627
                //Normalize Vectors to simplify angle calculation
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   628
                lv.x/=lDist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   629
                lv.y/=lDist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   630
                v.x/=Dist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   631
                v.y/=Dist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   632
                dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   633
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   634
                dDist = (Dist - lDist);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   635
                if (lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   636
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   637
                //inTouch->gestureLast[j].dDist = dDist;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   638
                //inTouch->gestureLast[j].dtheta = dtheta;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   639
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   640
                //printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   641
                //gdtheta = gdtheta*.9 + dtheta*.1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   642
                //gdDist  =  gdDist*.9 +  dDist*.1
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   643
                //knob.r += dDist/numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   644
                //knob.ang += dtheta;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   645
                //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   646
                //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   647
                SDL_SendGestureMulti(inTouch,dtheta,dDist);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   648
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   649
            else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   650
                //inTouch->gestureLast[j].dDist = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   651
                //inTouch->gestureLast[j].dtheta = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   652
                //inTouch->gestureLast[j].cv.x = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   653
                //inTouch->gestureLast[j].cv.y = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   654
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   655
            //inTouch->gestureLast[j].f.p.x = x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   656
            //inTouch->gestureLast[j].f.p.y = y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   657
            //break;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   658
            //pressure?
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   659
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   660
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   661
        if (event->type == SDL_FINGERDOWN) {
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   662
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   663
            inTouch->numDownFingers++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   664
            inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   665
                                   x)/inTouch->numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   666
            inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   667
                                   y)/inTouch->numDownFingers;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   668
            //printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   669
            //     inTouch->centroid.x,inTouch->centroid.y);
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   670
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   671
#ifdef ENABLE_DOLLAR
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   672
            inTouch->dollarPath.length = 0;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   673
            inTouch->dollarPath.p[0].x = x;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   674
            inTouch->dollarPath.p[0].y = y;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   675
            inTouch->dollarPath.numPoints = 1;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   676
#endif
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   677
        }
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   678
    }
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   679
}
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   680
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   681
/* vi: set ts=4 sw=4 expandtab: */