annotate touchTest/gestureSDLTest.c @ 4689:f9ab8df6d45a

Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
author Jim Grandpre <jim.tla@gmail.com>
date Sun, 15 Aug 2010 00:36:28 -0400
parents 494f71f57a80
children
rev   line source
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4688
diff changeset
1 /* Usage:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4688
diff changeset
2 * Spacebar to begin recording a gesture on all touches.
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4688
diff changeset
3 * s to save all touches into "./gestureSave"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4688
diff changeset
4 * l to load all touches from "./gestureSave"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4688
diff changeset
5 */
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4688
diff changeset
6
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
7 #include <stdio.h>
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
8 #include <SDL.h>
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
9 #include <math.h>
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
10 #include <SDL_touch.h>
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
11 #include <SDL_gesture.h>
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
12
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents: 4688
diff changeset
13
4679
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
14 /* Make sure we have good macros for printing 32 and 64 bit values */
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
15 #ifndef PRIs32
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
16 #define PRIs32 "d"
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
17 #endif
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
18 #ifndef PRIu32
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
19 #define PRIu32 "u"
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
20 #endif
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
21 #ifndef PRIs64
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
22 #ifdef __WIN32__
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
23 #define PRIs64 "I64"
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
24 #else
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
25 #define PRIs64 "lld"
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
26 #endif
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
27 #endif
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
28 #ifndef PRIu64
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
29 #ifdef __WIN32__
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
30 #define PRIu64 "I64u"
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
31 #else
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
32 #define PRIu64 "llu"
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
33 #endif
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
34 #endif
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
35
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
36 #define WIDTH 640
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
37 #define HEIGHT 480
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
38 #define BPP 4
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
39 #define DEPTH 32
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
40
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
41 //MUST BE A POWER OF 2!
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
42 #define EVENT_BUF_SIZE 256
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
43
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: 4683
diff changeset
44
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: 4683
diff changeset
45 #define VERBOSE SDL_FALSE
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: 4683
diff changeset
46
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
47 SDL_Event events[EVENT_BUF_SIZE];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
48 int eventWrite;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
49
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
50 int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
51
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
52 typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
53 float x,y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
54 } Point;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
55
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
56 typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
57 float ang,r;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
58 Point p;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
59 } Knob;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
60
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
61 Knob knob;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
62
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
63 void handler (int sig)
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 printf ("\exiting...(%d)\n", sig);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
66 exit (0);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
67 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
68
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
69 void perror_exit (char *error)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
70 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
71 perror (error);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
72 handler (9);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
73 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
74
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
75 void setpix(SDL_Surface *screen, int x, int y, unsigned int col)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
76 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
77 Uint32 *pixmem32;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
78 Uint32 colour;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
79
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
80 if((unsigned)x > screen->w) return;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
81 if((unsigned)y > screen->h) return;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
82
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
83 pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
84
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
85 Uint8 r,g,b;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
86 float a;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
87
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
88 memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
89
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4679
diff changeset
90 SDL_GetRGB(colour,screen->format,&r,&g,&b);
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
91 //r = 0;g = 0; b = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
92 a = (col>>24)&0xFF;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
93 if(a == 0) a = 0xFF; //Hack, to make things easier.
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
94 a /= 0xFF;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
95 r = r*(1-a) + ((col>>16)&0xFF)*(a);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
96 g = g*(1-a) + ((col>> 8)&0xFF)*(a);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
97 b = b*(1-a) + ((col>> 0)&0xFF)*(a);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
98 colour = SDL_MapRGB( screen->format,r, g, b);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
99
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
100
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
101 *pixmem32 = colour;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
102 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
103
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
104 void drawLine(SDL_Surface *screen,int x0,int y0,int x1,int y1,unsigned int col) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
105 float t;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
106 for(t=0;t<1;t+=1.f/SDL_max(abs(x0-x1),abs(y0-y1)))
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
107 setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
108 }
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: 4683
diff changeset
109
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
110 void drawCircle(SDL_Surface* screen,int x,int y,int r,unsigned int c)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
111 {
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: 4683
diff changeset
112 int tx,ty;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
113 float xr;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
114 for(ty = -abs(r);ty <= abs(r);ty++) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
115 xr = sqrt(r*r - ty*ty);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
116 if(r > 0) { //r > 0 ==> filled circle
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
117 for(tx=-xr+.5;tx<=xr-.5;tx++) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
118 setpix(screen,x+tx,y+ty,c);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
119 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
120 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
121 else {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
122 setpix(screen,x-xr+.5,y+ty,c);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
123 setpix(screen,x+xr-.5,y+ty,c);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
124 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
125 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
126 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
127
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
128 void drawKnob(SDL_Surface* screen,Knob k) {
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: 4683
diff changeset
129 drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
130 drawCircle(screen,(k.p.x+k.r/2*cos(k.ang))*screen->w,
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
131 (k.p.y+k.r/2*sin(k.ang))*screen->h,k.r/4*screen->w,0);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
132 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
133
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: 4683
diff changeset
134 void DrawScreen(SDL_Surface* screen)
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
135 {
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: 4683
diff changeset
136 int x, y;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
137 if(SDL_MUSTLOCK(screen))
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
138 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
139 if(SDL_LockSurface(screen) < 0) return;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
140 }
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: 4683
diff changeset
141 for(y = 0;y < screen->h;y++)
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: 4683
diff changeset
142 for(x = 0;x < screen->w;x++)
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: 4683
diff changeset
143 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
144
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
145 int i;
4688
494f71f57a80 Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents: 4683
diff changeset
146 //draw Touch History
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
147 for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
148 SDL_Event event = events[i&(EVENT_BUF_SIZE-1)];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
149 int age = eventWrite - i - 1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
150 if(event.type == SDL_FINGERMOTION ||
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
151 event.type == SDL_FINGERDOWN ||
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
152 event.type == SDL_FINGERUP) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
153 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
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: 4683
diff changeset
154 if(inTouch == NULL) continue;
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: 4683
diff changeset
155
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
156 float x = ((float)event.tfinger.x)/inTouch->xres;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
157 float y = ((float)event.tfinger.y)/inTouch->yres;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
158
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: 4683
diff changeset
159 //draw the touch:
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
160 unsigned int c = colors[event.tfinger.touchId%7];
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
161 unsigned int col =
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
162 ((unsigned int)(c*(.1+.85))) |
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
163 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
164
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
165 if(event.type == SDL_FINGERMOTION)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
166 drawCircle(screen,x*screen->w,y*screen->h,5,col);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
167 else if(event.type == SDL_FINGERDOWN)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
168 drawCircle(screen,x*screen->w,y*screen->h,-10,col);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
169 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
170 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
171
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
172 if(knob.p.x > 0)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
173 drawKnob(screen,knob);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
174
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
175 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
176 SDL_Flip(screen);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
177 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
178
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
179 SDL_Surface* initScreen(int width,int height)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
180 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
181 return SDL_SetVideoMode(width, height, DEPTH,
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
182 SDL_HWSURFACE | SDL_RESIZABLE);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
183 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
184
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
185 int main(int argc, char* argv[])
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
186 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
187 SDL_Surface *screen;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
188 SDL_Event event;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
189
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
190 //gesture variables
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
191 knob.r = .1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
192 knob.ang = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
193
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: 4683
diff changeset
194
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: 4683
diff changeset
195 SDL_bool quitting = SDL_FALSE;
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: 4683
diff changeset
196 SDL_RWops *src;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
197
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
198 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
199
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
200 if (!(screen = initScreen(WIDTH,HEIGHT)))
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
201 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
202 SDL_Quit();
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
203 return 1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
204 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
205
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: 4683
diff changeset
206 while(!quitting) {
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
207 while(SDL_PollEvent(&event))
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
208 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
209 //Record _all_ events
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
210 events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
211 eventWrite++;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
212
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
213 switch (event.type)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
214 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
215 case SDL_QUIT:
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: 4683
diff changeset
216 quitting = SDL_TRUE;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
217 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
218 case SDL_KEYDOWN:
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: 4683
diff changeset
219 switch (event.key.keysym.sym)
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: 4683
diff changeset
220 {
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: 4683
diff changeset
221 case SDLK_SPACE:
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: 4683
diff changeset
222 SDL_RecordGesture(-1);
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: 4683
diff changeset
223 break;
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: 4683
diff changeset
224 case SDLK_s:
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: 4683
diff changeset
225 src = SDL_RWFromFile("gestureSave","w");
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: 4683
diff changeset
226 printf("Wrote %i templates\n",SDL_SaveAllDollarTemplates(src));
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: 4683
diff changeset
227 SDL_RWclose(src);
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: 4683
diff changeset
228 break;
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: 4683
diff changeset
229 case SDLK_l:
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: 4683
diff changeset
230 src = SDL_RWFromFile("gestureSave","r");
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: 4683
diff changeset
231 printf("Loaded: %i\n",SDL_LoadDollarTemplates(-1,src));
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: 4683
diff changeset
232 SDL_RWclose(src);
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: 4683
diff changeset
233 break;
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: 4683
diff changeset
234 case SDLK_ESCAPE:
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: 4683
diff changeset
235 quitting = SDL_TRUE;
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: 4683
diff changeset
236 break;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
237 }
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
238 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
239 case SDL_VIDEORESIZE:
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
240 if (!(screen = initScreen(event.resize.w,
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
241 event.resize.h)))
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
242 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
243 SDL_Quit();
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
244 return 1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
245 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
246 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
247 case SDL_FINGERMOTION:
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
248 ;
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: 4683
diff changeset
249 #if VERBOSE
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: 4683
diff changeset
250 printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
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: 4683
diff changeset
251 event.tfinger.x,event.tfinger.y);
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: 4683
diff changeset
252 #endif
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
253 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
254 SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
255 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
256 case SDL_FINGERDOWN:
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: 4683
diff changeset
257 #if VERBOSE
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: 4683
diff changeset
258 printf("Finger: %"PRIs64" down - x: %i, y: %i\n",
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: 4683
diff changeset
259 event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
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: 4683
diff changeset
260 #endif
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
261 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
262 case SDL_FINGERUP:
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: 4683
diff changeset
263 #if VERBOSE
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: 4683
diff changeset
264 printf("Finger: %"PRIs64" up - x: %i, y: %i\n",
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: 4683
diff changeset
265 event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
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: 4683
diff changeset
266 #endif
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
267 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
268 case SDL_MULTIGESTURE:
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: 4683
diff changeset
269 #if VERBOSE
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4679
diff changeset
270 printf("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f\n",
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4679
diff changeset
271 event.mgesture.x,
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4679
diff changeset
272 event.mgesture.y,
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4679
diff changeset
273 event.mgesture.dTheta,
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4679
diff changeset
274 event.mgesture.dDist);
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4682
diff changeset
275 printf("MG: numDownTouch = %i\n",event.mgesture.numFingers);
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: 4683
diff changeset
276 #endif
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
277 knob.p.x = event.mgesture.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
278 knob.p.y = event.mgesture.y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
279 knob.ang += event.mgesture.dTheta;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
280 knob.r += event.mgesture.dDist;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
281 break;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
282 case SDL_DOLLARGESTURE:
4679
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
283 printf("Gesture %"PRIs64" performed, error: %f\n",
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
284 event.dgesture.gestureId,
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
285 event.dgesture.error);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
286 break;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
287 case SDL_DOLLARRECORD:
4679
5ee96ba0c01e Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents: 4676
diff changeset
288 printf("Recorded gesture: %"PRIs64"\n",event.dgesture.gestureId);
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
289 break;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
290 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
291 }
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: 4683
diff changeset
292 DrawScreen(screen);
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
293 }
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: 4683
diff changeset
294 SDL_Quit();
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
295 return 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
296 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
297