comparison touchTest/touchTest.c @ 4646:eea1bf53effa

Added include/touch.h Now reading in resolution of touch pad.
author Jim Grandpre <jim.tla@gmail.com>
date Tue, 01 Jun 2010 02:54:33 -0400
parents fb500b3e1717
children 35a80b0791aa
comparison
equal deleted inserted replaced
4645:0375d020e7e3 4646:eea1bf53effa
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 "../src/events/SDL_touch_c.h" //BAD!!! 4 #include <SDL_touch.h>
5 5
6 #define PI 3.1415926535897 6 #define PI 3.1415926535897
7 #define WIDTH 640 7 #define WIDTH 640
8 #define HEIGHT 480 8 #define HEIGHT 480
9 #define BPP 4 9 #define BPP 4
17 17
18 18
19 19
20 20
21 typedef struct { 21 typedef struct {
22 int x,y; 22 float x,y;
23 } Point; 23 } Point;
24 24
25 typedef struct { 25 typedef struct {
26 Point p; 26 Point p;
27 int pressure; 27 float pressure;
28 } Finger; 28 } Finger;
29 29
30 30
31 Finger finger[MAXFINGERS]; 31 Finger finger[MAXFINGERS];
32 32
33 void handler (int sig) 33 void handler (int sig)
34 { 34 {
35 printf ("\nexiting...(%d)\n", sig); 35 printf ("\exiting...(%d)\n", sig);
36 exit (0); 36 exit (0);
37 } 37 }
38 38
39 void perror_exit (char *error) 39 void perror_exit (char *error)
40 { 40 {
59 59
60 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)
61 { 61 {
62 62
63 float a; 63 float a;
64 for(a=0;a<PI/2;a+=1.f/(float)r) 64 int tx;
65 for(a=0;a<PI/2;a+=1.f/(float)abs(r))
65 { 66 {
67 if(r > 0) { //r<0 ==> unfilled circle
68 for(tx=x-r*cos(a);tx<x+r*cos(a);tx++) {
69 setpix(screen,tx,(int)(y+r*sin(a)),c);
70 setpix(screen,tx,(int)(y-r*sin(a)),c);
71 }
72 }
73
74 //Always Draw Outline
66 setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c); 75 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); 76 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); 77 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); 78 setpix(screen,(int)(x-r*cos(a)),(int)(y-r*sin(a)),c);
70 } 79 }
87 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h; 96 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h;
88 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c); 97 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c);
89 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255); 98 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
90 } 99 }
91 } 100 }
92 drawCircle(screen,mousx,mousy,30,0xFFFFFF); 101 drawCircle(screen,mousx,mousy,-30,0xFFFFFF);
93 102
94 int i; 103 int i;
95 for(i=0;i<MAXFINGERS;i++) 104 for(i=0;i<MAXFINGERS;i++)
96 if(finger[i].p.x >= 0 && finger[i].p.y >= 0) 105 if(finger[i].p.x >= 0 && finger[i].p.y >= 0)
97 drawCircle(screen,finger[i].p.x,finger[i].p.y,20,0xFF6600-finger[i].pressure); 106 if(finger[i].pressure > 0)
107 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h
108 ,20,0xFF*finger[i].pressure);
109 else
110 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h
111 ,20,0xFF);
98 112
99 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); 113 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
100 114
101 SDL_Flip(screen); 115 SDL_Flip(screen);
102 } 116 }
160 break; 174 break;
161 case SDL_MOUSEBUTTONUP: 175 case SDL_MOUSEBUTTONUP:
162 bstatus &= ~(1<<(event.button.button-1)); 176 bstatus &= ~(1<<(event.button.button-1));
163 break; 177 break;
164 case SDL_FINGERMOTION: 178 case SDL_FINGERMOTION:
165 179 ;
166 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId, 180 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
167 // event.tfinger.x,event.tfinger.y); 181 // event.tfinger.x,event.tfinger.y);
168 finger[event.tfinger.fingerId].p.x = event.tfinger.x; 182 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
169 finger[event.tfinger.fingerId].p.y = event.tfinger.y; 183 SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
170 finger[event.tfinger.fingerId].pressure = event.tfinger.pressure; 184
171 printf("Finger: %i, pressure: %i\n",event.tfinger.fingerId, 185 finger[event.tfinger.fingerId].p.x = ((float)event.tfinger.x)/
172 event.tfinger.pressure); 186 inTouch->xres;
187 finger[event.tfinger.fingerId].p.y = ((float)event.tfinger.y)/
188 inTouch->yres;
189
190 finger[event.tfinger.fingerId].pressure =
191 ((float)event.tfinger.pressure)/inTouch->pressureres;
192
193 printf("Finger: %i, Pressure: %f Pressureres: %i\n",
194 event.tfinger.fingerId,
195 finger[event.tfinger.fingerId].pressure,
196 inTouch->pressureres);
197 //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId,
198 // finger[event.tfinger.fingerId].pressure);
199
200
173 break; 201 break;
174 case SDL_FINGERDOWN: 202 case SDL_FINGERDOWN:
175 printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId, 203 printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,
176 event.tfinger.x,event.tfinger.y); 204 event.tfinger.x,event.tfinger.y);
177 finger[event.tfinger.fingerId].p.x = event.tfinger.x; 205 finger[event.tfinger.fingerId].p.x = event.tfinger.x;