src/events/SDL_gesture.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 03 Mar 2013 01:01:33 -0800
changeset 6951 7833f01322b3
parent 6885 700f1b25f77f
child 7009 161b7b6a5303
permissions -rw-r--r--
Updated touch API * Normalized touch coordinates as floats in the 0...1 range * Removed unused touchpad concepts from the API * Added API functions to get active touch devices and current finger state
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
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
     3
  Copyright (C) 1997-2013 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 {
6069
fbb37897c788 Type of SDL_GestureTouch.id is SDL_TouchID (only for SDL_gesture.c internal)
Kees Bakker <kees@ijzerbout.nl>
parents: 6068
diff changeset
    66
    SDL_TouchID id;
6065
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 centroid;
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_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
    69
    Uint16 numDownFingers;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    70
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    71
    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
    72
    SDL_DollarTemplate *dollarTemplate;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    73
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    74
    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
    75
} SDL_GestureTouch;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    76
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
    77
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
    78
int SDL_numGestureTouches = 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    79
SDL_bool recordAll;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    80
4868
d6adaafcfb10 Fixed compiling with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 4865
diff changeset
    81
#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
    82
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
    83
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    84
    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
    85
    printf("Path:");
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
    86
    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
    87
        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
    88
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    89
    printf("\n");
4685
e0c3b09368a6 Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4684
diff changeset
    90
}
4868
d6adaafcfb10 Fixed compiling with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 4865
diff changeset
    91
#endif
4685
e0c3b09368a6 Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4684
diff changeset
    92
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    93
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
    94
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
    95
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
    96
    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
    97
    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
    98
        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
    99
            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
   100
            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
   101
                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
   102
        }
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
    return (touchId < 0);
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   105
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   106
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   107
static unsigned long SDL_HashDollar(SDL_FloatPoint* points)
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
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   109
    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
   110
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   111
    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
   112
        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
   113
        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
   114
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   115
    return hash;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   116
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   117
4665
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
   118
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   119
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
   120
{
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   121
    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
   122
4665
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
   123
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   124
    //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
   125
    //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
   126
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   127
    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
   128
                    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
   129
        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
   130
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   131
    return 1;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   132
}
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
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   135
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
   136
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   137
    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
   138
    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
   139
        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
   140
        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
   141
            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
   142
        }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   143
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   144
    return rtrn;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   145
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   146
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   147
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
   148
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   149
    int i,j;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   150
    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
   151
        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
   152
        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
   153
            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
   154
                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
   155
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   156
        }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   157
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   158
    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
   159
    return -1;
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   160
}
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
//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
   163
//Returns the index of the gesture on success, or -1
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   164
static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
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
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   166
    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
   167
    SDL_DollarTemplate *templ;
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   168
    int index;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   169
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   170
    index = inTouch->numDollarTemplates;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   171
    dollarTemplate =
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   172
        (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   173
                                          (index + 1) *
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   174
                                          sizeof(SDL_DollarTemplate));
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   175
    if (!dollarTemplate) {
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   176
        SDL_OutOfMemory();
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   177
        return -1;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   178
    }
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   179
    inTouch->dollarTemplate = dollarTemplate;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   180
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   181
    templ = &inTouch->dollarTemplate[index];
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   182
    SDL_memcpy(templ->path, path, DOLLARNPOINTS*sizeof(SDL_FloatPoint));
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   183
    templ->hash = SDL_HashDollar(templ->path);
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   184
    inTouch->numDollarTemplates++;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   185
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   186
    return index;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   187
}
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   188
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   189
static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   190
{
6071
72f06ae88e7e Fixed uninitialized variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6070
diff changeset
   191
    int index = -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
   192
    int i = 0;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   193
    if (inTouch == NULL) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   194
        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
   195
        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
   196
            inTouch = &SDL_gestureTouch[i];
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   197
            index = SDL_AddDollarGesture_one(inTouch, path);
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   198
            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
   199
                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
   200
        }
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   201
        // Use the index of the last one added.
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   202
        return index;
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   203
    } else {
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   204
        return SDL_AddDollarGesture_one(inTouch, path);
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   205
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   206
    return -1;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   207
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   208
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   209
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
   210
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   211
    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
   212
    SDL_GestureTouch *touch = NULL;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   213
    if (src == NULL) return 0;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   214
    if (touchId >= 0) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   215
        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
   216
            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
   217
                touch = &SDL_gestureTouch[i];
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   218
        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
   219
    }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   220
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   221
    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
   222
        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
   223
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   224
        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
   225
           DOLLARNPOINTS) break;
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
        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
   228
            //printf("Adding loaded gesture to 1 touch\n");
6068
c0a928f55a19 Correct usage of SDL_AddDollarGesture (return value >= 0 on success)
Kees Bakker <kees@ijzerbout.nl>
parents: 6067
diff changeset
   229
            if (SDL_AddDollarGesture(touch, templ.path) >= 0)
c0a928f55a19 Correct usage of SDL_AddDollarGesture (return value >= 0 on success)
Kees Bakker <kees@ijzerbout.nl>
parents: 6067
diff changeset
   230
                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
   231
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   232
        else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   233
            //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
   234
            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
   235
                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
   236
                //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
   237
                //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
   238
                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
   239
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   240
            loaded++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   241
        }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   242
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   243
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   244
    return loaded;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   245
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   246
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   247
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   248
static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
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
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   250
    //  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
   251
    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
   252
    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
   253
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   254
    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
   255
        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
   256
        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
   257
        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
   258
                                 (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
   259
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   260
    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
   261
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   262
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   263
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   264
static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   265
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   266
    //------------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
   267
    //-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
   268
    //-"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
   269
    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
   270
    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
   271
    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
   272
    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
   273
    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
   274
    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
   275
    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
   276
    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
   277
        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
   278
            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
   279
            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
   280
            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
   281
            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
   282
            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
   283
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   284
        else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   285
            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
   286
            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
   287
            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
   288
            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
   289
            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
   290
        }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   291
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   292
    /*
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   293
      if (f1 <= f2)
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   294
          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
   295
      else if (f1 >  f2)
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   296
          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
   297
    */
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   298
    return SDL_min(f1,f2);
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   299
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   300
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   301
//DollarPath contains raw points, plus (possibly) the calculated length
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   302
static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   303
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   304
    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
   305
    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
   306
    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
   307
    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
   308
    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
   309
    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
   310
    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
   311
    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
   312
    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
   313
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   314
    //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
   315
    if (length <= 0) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   316
        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
   317
            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
   318
            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
   319
            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
   320
        }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   321
    }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   322
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   323
    //Resample
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   324
    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
   325
    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
   326
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   327
    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
   328
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   329
    //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
   330
    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
   331
        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
   332
                                   (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
   333
        //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
   334
        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
   335
            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
   336
                ((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
   337
            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
   338
                ((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
   339
            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
   340
            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
   341
            numPoints++;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   342
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   343
            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
   344
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   345
        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
   346
    }
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   347
    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
   348
        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
   349
        return 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   350
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   351
    //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
   352
    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
   353
    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
   354
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   355
    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
   356
    centroid.y /= numPoints;
4685
e0c3b09368a6 Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4684
diff changeset
   357
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   358
    //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
   359
    //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
   360
    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
   361
    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
   362
    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
   363
    ymax = centroid.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   364
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   365
    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
   366
                            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
   367
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   368
    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
   369
        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
   370
        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
   371
        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
   372
                              (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
   373
        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
   374
                              (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
   375
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   376
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   377
        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
   378
        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
   379
        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
   380
        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
   381
    }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   382
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   383
    //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
   384
    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
   385
    h = ymax-ymin;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   386
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   387
    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
   388
        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
   389
        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
   390
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   391
    return numPoints;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   392
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   393
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   394
static float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,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
   395
{
4868
d6adaafcfb10 Fixed compiling with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 4865
diff changeset
   396
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   397
    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
   398
    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
   399
    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
   400
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   401
    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
   402
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   403
    //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
   404
    *bestTempl = -1;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   405
    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
   406
        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
   407
        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
   408
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   409
    return bestDiff;
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   410
}
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   411
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   412
int SDL_GestureAddTouch(SDL_TouchID 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
   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
    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
   415
                                                                     (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
   416
                                                                     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
   417
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   418
    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
   419
        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
   420
        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
   421
    }
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
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   423
    SDL_gestureTouch = gestureTouch;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   424
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   425
    SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   426
    SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
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[SDL_numGestureTouches].numDollarTemplates = 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
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].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
   431
6065
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_numGestureTouches++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   433
    return 0;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   434
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   435
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   436
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
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
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   438
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   439
    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
   440
        //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
   441
        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
   442
            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
   443
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   444
    return NULL;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   445
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   446
6065
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 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
   448
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   449
    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
   450
    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
   451
    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
   452
    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
   453
    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
   454
    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
   455
    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
   456
    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
   457
    return SDL_PushEvent(&event) > 0;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   458
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   459
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
   460
static 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
   461
                          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
   462
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   463
    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
   464
    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
   465
    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
   466
    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
   467
    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
   468
    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
   469
    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
   470
    //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
   471
    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
   472
    return SDL_PushEvent(&event) > 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   473
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   474
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   475
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   476
static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID 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
   477
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   478
    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
   479
    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
   480
    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
   481
    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
   482
    return SDL_PushEvent(&event) > 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   483
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   484
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   485
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   486
void SDL_GestureProcessEvent(SDL_Event* event)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   487
{
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   488
    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
   489
    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
   490
    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
   491
    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
   492
    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
   493
    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
   494
    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
   495
    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
   496
    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
   497
    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
   498
    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
   499
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   500
    if (event->type == SDL_FINGERMOTION ||
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   501
        event->type == SDL_FINGERDOWN ||
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   502
        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
   503
        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
   504
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   505
        //Shouldn't be possible
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   506
        if (inTouch == NULL) return;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   507
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   508
        x = event->tfinger.x;
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   509
        y = event->tfinger.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   510
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   511
        //Finger Up
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   512
        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
   513
            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
   514
4684
f47c2640c667 Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4683
diff changeset
   515
#ifdef ENABLE_DOLLAR
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   516
            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
   517
                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
   518
                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
   519
                //PrintPath(path);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   520
                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
   521
                    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
   522
                    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
   523
                        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
   524
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   525
                else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   526
                    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
   527
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   528
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   529
                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
   530
                    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
   531
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   532
                else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   533
                    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
   534
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   535
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   536
            else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   537
                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
   538
                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
   539
                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
   540
                                        &bestTempl,inTouch);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   541
                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
   542
                    //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
   543
                    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
   544
                    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
   545
                    //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
   546
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   547
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   548
#endif
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->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
   550
            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
   551
                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
   552
                                       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
   553
                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
   554
                                       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
   555
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   556
        }
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   557
        else if (event->type == SDL_FINGERMOTION) {
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   558
            float dx = event->tfinger.dx;
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   559
            float dy = event->tfinger.dy;
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   560
#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
   561
            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
   562
            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
   563
                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
   564
                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
   565
                pathDx =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   566
                    (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
   567
                pathDy =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   568
                    (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
   569
                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
   570
                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
   571
            }
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   572
#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
   573
            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
   574
            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
   575
            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
   576
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   577
            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
   578
            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
   579
            //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
   580
            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
   581
                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
   582
                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
   583
                //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
   584
                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
   585
                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
   586
                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
   587
                //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
   588
                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
   589
                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
   590
                //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
   591
                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
   592
                // 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
   593
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   594
                //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
   595
                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
   596
                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
   597
                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
   598
                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
   599
                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
   600
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   601
                dDist = (Dist - lDist);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   602
                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
   603
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   604
                //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
   605
                //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
   606
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   607
                //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
   608
                //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
   609
                //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
   610
                //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
   611
                //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
   612
                //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
   613
                //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
   614
                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
   615
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   616
            else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   617
                //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
   618
                //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
   619
                //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
   620
                //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
   621
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   622
            //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
   623
            //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
   624
            //break;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   625
            //pressure?
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
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   628
        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
   629
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   630
            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
   631
            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
   632
                                   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
   633
            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
   634
                                   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
   635
            //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
   636
            //     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
   637
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   638
#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
   639
            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
   640
            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
   641
            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
   642
            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
   643
#endif
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   644
        }
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   645
    }
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   646
}
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   647
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   648
/* vi: set ts=4 sw=4 expandtab: */