comparison touchTest/touchTest.c @ 4644:fb500b3e1717

Added pressure support for touch events.
author Jim Grandpre <jim.tla@gmail.com>
date Sat, 29 May 2010 02:09:16 -0400
parents 8806b78988f7
children eea1bf53effa
comparison
equal deleted inserted replaced
4643:8806b78988f7 4644:fb500b3e1717
20 20
21 typedef struct { 21 typedef struct {
22 int x,y; 22 int x,y;
23 } Point; 23 } Point;
24 24
25 typedef struct {
26 Point p;
27 int pressure;
28 } Finger;
25 29
26 Point finger[MAXFINGERS]; 30
31 Finger finger[MAXFINGERS];
27 32
28 void handler (int sig) 33 void handler (int sig)
29 { 34 {
30 printf ("\nexiting...(%d)\n", sig); 35 printf ("\nexiting...(%d)\n", sig);
31 exit (0); 36 exit (0);
54 59
55 void drawCircle(SDL_Surface* screen,int x,int y,int r,int c) 60 void drawCircle(SDL_Surface* screen,int x,int y,int r,int c)
56 { 61 {
57 62
58 float a; 63 float a;
59 for(a=0;a<2*PI;a+=1.f/(float)r) 64 for(a=0;a<PI/2;a+=1.f/(float)r)
60 { 65 {
61 setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c); 66 setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c);
67 setpix(screen,(int)(x-r*cos(a)),(int)(y+r*sin(a)),c);
68 setpix(screen,(int)(x+r*cos(a)),(int)(y-r*sin(a)),c);
69 setpix(screen,(int)(x-r*cos(a)),(int)(y-r*sin(a)),c);
62 } 70 }
63 } 71 }
64 72
65 void DrawScreen(SDL_Surface* screen, int h) 73 void DrawScreen(SDL_Surface* screen, int h)
66 { 74 {
83 } 91 }
84 drawCircle(screen,mousx,mousy,30,0xFFFFFF); 92 drawCircle(screen,mousx,mousy,30,0xFFFFFF);
85 93
86 int i; 94 int i;
87 for(i=0;i<MAXFINGERS;i++) 95 for(i=0;i<MAXFINGERS;i++)
88 if(finger[i].x >= 0 && finger[i].y >= 0) 96 if(finger[i].p.x >= 0 && finger[i].p.y >= 0)
89 drawCircle(screen,finger[i].x,finger[i].y,20,0xFF6600); 97 drawCircle(screen,finger[i].p.x,finger[i].p.y,20,0xFF6600-finger[i].pressure);
90 98
91 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); 99 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
92 100
93 SDL_Flip(screen); 101 SDL_Flip(screen);
94 } 102 }
155 break; 163 break;
156 case SDL_FINGERMOTION: 164 case SDL_FINGERMOTION:
157 165
158 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId, 166 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
159 // event.tfinger.x,event.tfinger.y); 167 // event.tfinger.x,event.tfinger.y);
160 finger[event.tfinger.fingerId].x = event.tfinger.x; 168 finger[event.tfinger.fingerId].p.x = event.tfinger.x;
161 finger[event.tfinger.fingerId].y = event.tfinger.y; 169 finger[event.tfinger.fingerId].p.y = event.tfinger.y;
170 finger[event.tfinger.fingerId].pressure = event.tfinger.pressure;
171 printf("Finger: %i, pressure: %i\n",event.tfinger.fingerId,
172 event.tfinger.pressure);
162 break; 173 break;
163 case SDL_FINGERDOWN: 174 case SDL_FINGERDOWN:
164 printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId, 175 printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,
165 event.tfinger.x,event.tfinger.y); 176 event.tfinger.x,event.tfinger.y);
166 finger[event.tfinger.fingerId].x = event.tfinger.x; 177 finger[event.tfinger.fingerId].p.x = event.tfinger.x;
167 finger[event.tfinger.fingerId].y = event.tfinger.y; 178 finger[event.tfinger.fingerId].p.y = event.tfinger.y;
168 break; 179 break;
169 case SDL_FINGERUP: 180 case SDL_FINGERUP:
170 printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId, 181 printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId,
171 event.tfinger.x,event.tfinger.y); 182 event.tfinger.x,event.tfinger.y);
172 finger[event.tfinger.fingerId].x = -1; 183 finger[event.tfinger.fingerId].p.x = -1;
173 finger[event.tfinger.fingerId].y = -1; 184 finger[event.tfinger.fingerId].p.y = -1;
174 break; 185 break;
175 } 186 }
176 } 187 }
177 //And draw 188 //And draw
178 DrawScreen(screen,h); 189 DrawScreen(screen,h);