Mercurial > sdl-ios-xcode
annotate touchTest/gestureSDLTest.c @ 4688:494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Fri, 13 Aug 2010 23:08:32 -0400 |
parents | 15dfe42edbfd |
children | f9ab8df6d45a |
rev | line source |
---|---|
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
2 #include <SDL.h> |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
3 #include <math.h> |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
4 #include <SDL_touch.h> |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
5 #include <SDL_gesture.h> |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
6 |
4679
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
7 /* 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
|
8 #ifndef PRIs32 |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
9 #define PRIs32 "d" |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
10 #endif |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
11 #ifndef PRIu32 |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
12 #define PRIu32 "u" |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
13 #endif |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
14 #ifndef PRIs64 |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
15 #ifdef __WIN32__ |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
16 #define PRIs64 "I64" |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
17 #else |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
18 #define PRIs64 "lld" |
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
19 #endif |
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 PRIu64 |
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 PRIu64 "I64u" |
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 PRIu64 "llu" |
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 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
29 #define WIDTH 640 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
30 #define HEIGHT 480 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
31 #define BPP 4 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
32 #define DEPTH 32 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
33 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
34 //MUST BE A POWER OF 2! |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
35 #define EVENT_BUF_SIZE 256 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
36 |
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
|
37 |
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
|
38 #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
|
39 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
40 SDL_Event events[EVENT_BUF_SIZE]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
41 int eventWrite; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
42 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
43 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
|
44 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
45 typedef struct { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
46 float x,y; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
47 } Point; |
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 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
50 float ang,r; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
51 Point p; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
52 } Knob; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
53 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
54 Knob knob; |
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 void handler (int sig) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
57 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
58 printf ("\exiting...(%d)\n", sig); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
59 exit (0); |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
62 void perror_exit (char *error) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
63 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
64 perror (error); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
65 handler (9); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
66 } |
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 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
|
69 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
70 Uint32 *pixmem32; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
71 Uint32 colour; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
72 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
73 if((unsigned)x > screen->w) return; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
74 if((unsigned)y > screen->h) return; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
75 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
76 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
|
77 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
78 Uint8 r,g,b; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
79 float a; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
80 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
81 memcpy(&colour,pixmem32,screen->format->BytesPerPixel); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
82 |
4681 | 83 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
|
84 //r = 0;g = 0; b = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
85 a = (col>>24)&0xFF; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
86 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
|
87 a /= 0xFF; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 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
|
92 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
93 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
94 *pixmem32 = colour; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
95 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
96 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
97 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
|
98 float t; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
99 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
|
100 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
|
101 } |
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
|
102 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
103 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
|
104 { |
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
|
105 int tx,ty; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
106 float xr; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
107 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
|
108 xr = sqrt(r*r - ty*ty); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
113 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
114 else { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
115 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
|
116 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
|
117 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
118 } |
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 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
|
122 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
|
123 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
|
124 (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
|
125 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
126 |
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
|
127 void DrawScreen(SDL_Surface* screen) |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
128 { |
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 int x, y; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
130 if(SDL_MUSTLOCK(screen)) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
131 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
132 if(SDL_LockSurface(screen) < 0) return; |
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 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
|
135 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
|
136 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
|
137 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
138 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
|
139 //draw Touch History |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
140 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
|
141 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
|
142 int age = eventWrite - i - 1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
143 if(event.type == SDL_FINGERMOTION || |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
144 event.type == SDL_FINGERDOWN || |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
145 event.type == SDL_FINGERUP) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
146 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
|
147 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
|
148 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
149 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
|
150 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
|
151 |
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
|
152 //draw the touch: |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
153 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
|
154 unsigned int col = |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
155 ((unsigned int)(c*(.1+.85))) | |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
156 ((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
|
157 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
158 if(event.type == SDL_FINGERMOTION) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
159 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
|
160 else if(event.type == SDL_FINGERDOWN) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
161 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
|
162 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
163 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
164 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
165 if(knob.p.x > 0) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
166 drawKnob(screen,knob); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
167 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
168 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
|
169 SDL_Flip(screen); |
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 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
|
173 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
174 return SDL_SetVideoMode(width, height, DEPTH, |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
175 SDL_HWSURFACE | SDL_RESIZABLE); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
176 } |
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 int main(int argc, char* argv[]) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
179 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
180 SDL_Surface *screen; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
181 SDL_Event event; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
182 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
183 //gesture variables |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
184 knob.r = .1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
185 knob.ang = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
186 |
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
|
187 |
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
|
188 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
|
189 SDL_RWops *src; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
190 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
191 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
|
192 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
193 if (!(screen = initScreen(WIDTH,HEIGHT))) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
194 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
195 SDL_Quit(); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
196 return 1; |
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 |
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
|
199 while(!quitting) { |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
200 while(SDL_PollEvent(&event)) |
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 //Record _all_ events |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
203 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
|
204 eventWrite++; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
205 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
206 switch (event.type) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
207 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
208 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
|
209 quitting = SDL_TRUE; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
210 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
211 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
|
212 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
|
213 { |
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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 break; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
230 } |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
231 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
232 case SDL_VIDEORESIZE: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
233 if (!(screen = initScreen(event.resize.w, |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
234 event.resize.h))) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
235 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
236 SDL_Quit(); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
237 return 1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
238 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
239 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
240 case SDL_FINGERMOTION: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
241 ; |
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
|
242 #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
|
243 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
|
244 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
|
245 #endif |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
246 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
|
247 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
|
248 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
249 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
|
250 #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
|
251 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
|
252 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
|
253 #endif |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
254 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
255 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
|
256 #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
|
257 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
|
258 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
|
259 #endif |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
260 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
261 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
|
262 #if VERBOSE |
4681 | 263 printf("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f\n", |
264 event.mgesture.x, | |
265 event.mgesture.y, | |
266 event.mgesture.dTheta, | |
267 event.mgesture.dDist); | |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
268 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
|
269 #endif |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
270 knob.p.x = event.mgesture.x; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
271 knob.p.y = event.mgesture.y; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
272 knob.ang += event.mgesture.dTheta; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
273 knob.r += event.mgesture.dDist; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
274 break; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
275 case SDL_DOLLARGESTURE: |
4679
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
276 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
|
277 event.dgesture.gestureId, |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
278 event.dgesture.error); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
279 break; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
280 case SDL_DOLLARRECORD: |
4679
5ee96ba0c01e
Fixed various type and print format issues
Sam Lantinga <slouken@libsdl.org>
parents:
4676
diff
changeset
|
281 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
|
282 break; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
283 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
284 } |
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
|
285 DrawScreen(screen); |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
286 } |
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
|
287 SDL_Quit(); |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
288 return 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
289 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
290 |