comparison touchTest/touchTest.c @ 4649:35a80b0791aa

Addition of VC project for touchTest.c
author jimtla
date Sat, 05 Jun 2010 01:58:56 -0400
parents eea1bf53effa
children 7ad7a473b086
comparison
equal deleted inserted replaced
4648:0350b634c044 4649:35a80b0791aa
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <SDL.h> 2 #include <SDL.h>
3 #include <math.h> 3 #include <math.h>
4 #include <SDL_touch.h> 4 #include <SDL_touch.h>
5
6
5 7
6 #define PI 3.1415926535897 8 #define PI 3.1415926535897
7 #define WIDTH 640 9 #define WIDTH 640
8 #define HEIGHT 480 10 #define HEIGHT 480
9 #define BPP 4 11 #define BPP 4
30 32
31 Finger finger[MAXFINGERS]; 33 Finger finger[MAXFINGERS];
32 34
33 void handler (int sig) 35 void handler (int sig)
34 { 36 {
35 printf ("\exiting...(%d)\n", sig); 37 printf ("exiting...(%d)\n", sig);
36 exit (0); 38 exit (0);
37 } 39 }
38 40
39 void perror_exit (char *error) 41 void perror_exit (char *error)
40 { 42 {
79 } 81 }
80 } 82 }
81 83
82 void DrawScreen(SDL_Surface* screen, int h) 84 void DrawScreen(SDL_Surface* screen, int h)
83 { 85 {
84 int x, y, xm,ym,c; 86 int x, y, xm,ym,c,i;
85 if(SDL_MUSTLOCK(screen)) 87 if(SDL_MUSTLOCK(screen))
86 { 88 {
87 if(SDL_LockSurface(screen) < 0) return; 89 if(SDL_LockSurface(screen) < 0) return;
88 } 90 }
89 for(y = 0; y < screen->h; y++ ) 91 for(y = 0; y < screen->h; y++ )
96 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h; 98 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h;
97 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c); 99 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c);
98 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255); 100 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
99 } 101 }
100 } 102 }
103
101 drawCircle(screen,mousx,mousy,-30,0xFFFFFF); 104 drawCircle(screen,mousx,mousy,-30,0xFFFFFF);
102 105
103 int i; 106
104 for(i=0;i<MAXFINGERS;i++) 107 for(i=0;i<MAXFINGERS;i++)
105 if(finger[i].p.x >= 0 && finger[i].p.y >= 0) 108 if(finger[i].p.x >= 0 && finger[i].p.y >= 0)
106 if(finger[i].pressure > 0) 109 if(finger[i].pressure > 0)
107 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h 110 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h
108 ,20,0xFF*finger[i].pressure); 111 ,20,0xFF*finger[i].pressure);
129 int keypress = 0; 132 int keypress = 0;
130 int h=0,s=1,i,j; 133 int h=0,s=1,i,j;
131 134
132 memset(keystat,0,512*sizeof(keystat[0])); 135 memset(keystat,0,512*sizeof(keystat[0]));
133 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; 136 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
134 137 screen = initScreen(WIDTH,HEIGHT);
135 if (!(screen = initScreen(WIDTH,HEIGHT))) 138 if (!screen)
136 { 139 {
137 SDL_Quit(); 140 SDL_Quit();
138 return 1; 141 return 1;
139 } 142 }
140 143
177 break; 180 break;
178 case SDL_FINGERMOTION: 181 case SDL_FINGERMOTION:
179 ; 182 ;
180 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId, 183 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
181 // event.tfinger.x,event.tfinger.y); 184 // event.tfinger.x,event.tfinger.y);
182 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); 185 //SDL_Touch *inTouch = SDL_GetTouch(event.tfinger.touchId);
183 SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); 186 //SDL_Finger *inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
184 187 /*
185 finger[event.tfinger.fingerId].p.x = ((float)event.tfinger.x)/ 188 finger[event.tfinger.fingerId].p.x = ((float)event.tfinger.x)/
186 inTouch->xres; 189 inTouch->xres;
187 finger[event.tfinger.fingerId].p.y = ((float)event.tfinger.y)/ 190 finger[event.tfinger.fingerId].p.y = ((float)event.tfinger.y)/
188 inTouch->yres; 191 inTouch->yres;
189 192
190 finger[event.tfinger.fingerId].pressure = 193 finger[event.tfinger.fingerId].pressure =
191 ((float)event.tfinger.pressure)/inTouch->pressureres; 194 ((float)event.tfinger.pressure)/inTouch->pressureres;*/
192 195 /*
193 printf("Finger: %i, Pressure: %f Pressureres: %i\n", 196 printf("Finger: %i, Pressure: %f Pressureres: %i\n",
194 event.tfinger.fingerId, 197 event.tfinger.fingerId,
195 finger[event.tfinger.fingerId].pressure, 198 finger[event.tfinger.fingerId].pressure,
196 inTouch->pressureres); 199 inTouch->pressureres);
200 */
197 //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId, 201 //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId,
198 // finger[event.tfinger.fingerId].pressure); 202 // finger[event.tfinger.fingerId].pressure);
199 203
200 204
201 break; 205 break;