src/events/SDL_gesture.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 01 Jun 2013 21:09:36 +0200
changeset 7252 8ecb54eeaeec
parent 7191 75360622e65f
child 7508 1f64c6874619
permissions -rw-r--r--
Corrected indentation of license.
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
7252
8ecb54eeaeec Corrected indentation of license.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7191
diff changeset
    14
     claim that you wrote the original software. If you use this software
8ecb54eeaeec Corrected indentation of license.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7191
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
8ecb54eeaeec Corrected indentation of license.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7191
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
7252
8ecb54eeaeec Corrected indentation of license.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7191
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
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6951
diff changeset
    30
#if !defined(__PSP__)
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
    31
#include <memory.h>
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6951
diff changeset
    32
#endif
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6951
diff changeset
    33
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
    34
#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
    35
#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
    36
#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
    37
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
    38
/* 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
    39
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    40
#define MAXPATHSIZE 1024
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    41
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
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7009
diff changeset
   158
    return SDL_SetError("Unknown gestureId");
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   159
}
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
//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
   162
//Returns the index of the gesture on success, or -1
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   163
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
   164
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   165
    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
   166
    SDL_DollarTemplate *templ;
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   167
    int index;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   168
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   169
    index = inTouch->numDollarTemplates;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   170
    dollarTemplate =
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   171
        (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   172
                                          (index + 1) *
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   173
                                          sizeof(SDL_DollarTemplate));
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   174
    if (!dollarTemplate) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7009
diff changeset
   175
        return SDL_OutOfMemory();
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   176
    }
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   177
    inTouch->dollarTemplate = dollarTemplate;
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
    templ = &inTouch->dollarTemplate[index];
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   180
    SDL_memcpy(templ->path, path, DOLLARNPOINTS*sizeof(SDL_FloatPoint));
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   181
    templ->hash = SDL_HashDollar(templ->path);
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   182
    inTouch->numDollarTemplates++;
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   183
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   184
    return index;
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
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   187
static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   188
{
6071
72f06ae88e7e Fixed uninitialized variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6070
diff changeset
   189
    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
   190
    int i = 0;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   191
    if (inTouch == NULL) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   192
        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
   193
        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
   194
            inTouch = &SDL_gestureTouch[i];
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   195
            index = SDL_AddDollarGesture_one(inTouch, path);
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   196
            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
   197
                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
   198
        }
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   199
        // Use the index of the last one added.
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   200
        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
   201
    } else {
6067
9a8faef6fdbe Refactor SDL_AddDollarGesture
Kees Bakker <kees@ijzerbout.nl>
parents: 6066
diff changeset
   202
        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
   203
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   204
    return -1;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   205
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   206
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   207
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
   208
{
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 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
   210
    SDL_GestureTouch *touch = NULL;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   211
    if (src == NULL) return 0;
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   212
    if (touchId >= 0) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   213
        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
   214
            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
   215
                touch = &SDL_gestureTouch[i];
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   216
        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
   217
    }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   218
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   219
    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
   220
        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
   221
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   222
        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
   223
           DOLLARNPOINTS) break;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   224
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   225
        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
   226
            //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
   227
            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
   228
                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
   229
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   230
        else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   231
            //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
   232
            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
   233
                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
   234
                //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
   235
                //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
   236
                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
   237
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   238
            loaded++;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   239
        }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   240
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   241
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   242
    return loaded;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   243
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   244
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   245
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   246
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
   247
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   248
    //  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
   249
    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
   250
    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
   251
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   252
    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
   253
        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
   254
        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
   255
        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
   256
                                 (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
   257
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   258
    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
   259
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   260
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   261
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   262
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
   263
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   264
    //------------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
   265
    //-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
   266
    //-"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
   267
    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
   268
    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
   269
    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
   270
    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
   271
    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
   272
    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
   273
    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
   274
    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
   275
        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
   276
            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
   277
            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
   278
            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
   279
            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
   280
            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
   281
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   282
        else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   283
            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
   284
            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
   285
            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
   286
            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
   287
            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
   288
        }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   289
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   290
    /*
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   291
      if (f1 <= f2)
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   292
          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
   293
      else 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 (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
   295
    */
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   296
    return SDL_min(f1,f2);
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   297
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   298
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   299
//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
   300
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
   301
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   302
    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
   303
    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
   304
    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
   305
    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
   306
    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
   307
    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
   308
    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
   309
    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
   310
    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
   311
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   312
    //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
   313
    if (length <= 0) {
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   314
        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
   315
            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
   316
            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
   317
            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
   318
        }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   319
    }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   320
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   321
    //Resample
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   322
    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
   323
    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
   324
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   325
    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
   326
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   327
    //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
   328
    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
   329
        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
   330
                                   (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
   331
        //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
   332
        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
   333
            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
   334
                ((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
   335
            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
   336
                ((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
   337
            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
   338
            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
   339
            numPoints++;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   340
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   341
            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
   342
        }
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 += d;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   344
    }
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   345
    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
   346
        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
   347
        return 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   348
    }
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   349
    //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
   350
    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
   351
    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
   352
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   353
    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
   354
    centroid.y /= numPoints;
4685
e0c3b09368a6 Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4684
diff changeset
   355
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   356
    //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
   357
    //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
   358
    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
   359
    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
   360
    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
   361
    ymax = centroid.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   362
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   363
    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
   364
                            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
   365
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   366
    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
   367
        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
   368
        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
   369
        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
   370
                              (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
   371
        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
   372
                              (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
   373
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   374
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   375
        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
   376
        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
   377
        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
   378
        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
   379
    }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   380
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
    //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
   382
    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
   383
    h = ymax-ymin;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   384
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   385
    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
   386
        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
   387
        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
   388
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   389
    return numPoints;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   390
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   391
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   392
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
   393
{
4868
d6adaafcfb10 Fixed compiling with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 4865
diff changeset
   394
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
    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
   396
    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
   397
    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
   398
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   399
    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
   400
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   401
    //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
   402
    *bestTempl = -1;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   403
    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
   404
        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
   405
        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
   406
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   407
    return bestDiff;
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   408
}
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
   409
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   410
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
   411
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   412
    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
   413
                                                                     (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
   414
                                                                     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
   415
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   416
    if (!gestureTouch) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7009
diff changeset
   417
        return SDL_OutOfMemory();
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   418
    }
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
   419
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   420
    SDL_gestureTouch = gestureTouch;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   421
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   422
    SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   423
    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
   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].numDollarTemplates = 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   426
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   427
    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
   428
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   429
    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
   430
    return 0;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   431
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   432
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   433
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
   434
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   435
    int i;
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   436
    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
   437
        //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
   438
        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
   439
            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
   440
    }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   441
    return NULL;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   442
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   443
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   444
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
   445
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   446
    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
   447
    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
   448
    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
   449
    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
   450
    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
   451
    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
   452
    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
   453
    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
   454
    return SDL_PushEvent(&event) > 0;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   455
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   456
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5981
diff changeset
   457
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
   458
                          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
   459
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   460
    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
   461
    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
   462
    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
   463
    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
   464
    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
   465
    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
   466
    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
   467
    //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
   468
    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
   469
    return SDL_PushEvent(&event) > 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   470
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   471
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   472
6070
69b6275bb5dc Merge from https://bitbucket.org/keestux/sdl ... SDL_gesture code cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044 6069
diff changeset
   473
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
   474
{
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   475
    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
   476
    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
   477
    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
   478
    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
   479
    return SDL_PushEvent(&event) > 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   480
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   481
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   482
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   483
void SDL_GestureProcessEvent(SDL_Event* event)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   484
{
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   485
    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
   486
    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
   487
    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
   488
    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
   489
    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
   490
    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
   491
    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
   492
    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
   493
    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
   494
    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
   495
    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
   496
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   497
    if (event->type == SDL_FINGERMOTION ||
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   498
        event->type == SDL_FINGERDOWN ||
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   499
        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
   500
        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
   501
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   502
        //Shouldn't be possible
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   503
        if (inTouch == NULL) return;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   504
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   505
        x = event->tfinger.x;
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   506
        y = event->tfinger.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   507
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   508
        //Finger Up
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   509
        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
   510
            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
   511
4684
f47c2640c667 Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4683
diff changeset
   512
#ifdef ENABLE_DOLLAR
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   513
            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
   514
                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
   515
                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
   516
                //PrintPath(path);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   517
                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
   518
                    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
   519
                    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
   520
                        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
   521
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   522
                else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   523
                    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
   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
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   526
                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
   527
                    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
   528
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   529
                else {
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,-1);
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
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   533
            else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   534
                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
   535
                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
   536
                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
   537
                                        &bestTempl,inTouch);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   538
                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
   539
                    //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
   540
                    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
   541
                    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
   542
                    //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
   543
                }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   544
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   545
#endif
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   546
            //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
   547
            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
   548
                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
   549
                                       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
   550
                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
   551
                                       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
   552
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   553
        }
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   554
        else if (event->type == SDL_FINGERMOTION) {
6951
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   555
            float dx = event->tfinger.dx;
7833f01322b3 Updated touch API
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   556
            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
   557
#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
   558
            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
   559
            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
   560
                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
   561
                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
   562
                pathDx =
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-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
   564
                pathDy =
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   565
                    (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
   566
                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
   567
                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
   568
            }
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   569
#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
   570
            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
   571
            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
   572
            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
   573
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   574
            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
   575
            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
   576
            //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
   577
            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
   578
                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
   579
                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
   580
                //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
   581
                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
   582
                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
   583
                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
   584
                //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
   585
                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
   586
                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
   587
                //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
   588
                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
   589
                // 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
   590
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   591
                //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
   592
                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
   593
                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
   594
                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
   595
                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
   596
                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
   597
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   598
                dDist = (Dist - lDist);
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   599
                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
   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
                //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
   602
                //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
   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
                //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
   605
                //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
   606
                //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
   607
                //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
   608
                //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
   609
                //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
   610
                //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
   611
                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
   612
            }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   613
            else {
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   614
                //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
   615
                //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
   616
                //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
   617
                //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
   618
            }
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].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
   620
            //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
   621
            //break;
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   622
            //pressure?
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   623
        }
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   624
6066
1d66a8dce3ef Reformat SDL_gesture.c (part 2, space after keywords)
Kees Bakker <kees@ijzerbout.nl>
parents: 6065
diff changeset
   625
        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
   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
            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
   628
            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
   629
                                   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
   630
            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
   631
                                   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
   632
            //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
   633
            //     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
   634
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   635
#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
   636
            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
   637
            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
   638
            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
   639
            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
   640
#endif
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   641
        }
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   642
    }
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   643
}
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
   644
6065
fcd144b830ce Reformat SDL_gesture.c (part 1, reindent using Emacs, c-basic-offset 4)
Kees Bakker <kees@ijzerbout.nl>
parents: 5981
diff changeset
   645
/* vi: set ts=4 sw=4 expandtab: */