Mercurial > sdl-ios-xcode
annotate touchTest/touchTest.c @ 4685:e0c3b09368a6
Fixed Dollar Recognition.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Sat, 07 Aug 2010 11:32:11 -0400 |
parents | 3c4e0130c9b1 |
children |
rev | line source |
---|---|
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
2 #include <SDL.h> |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
3 #include <math.h> |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
4 #include <SDL_touch.h> |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
5 |
4649 | 6 |
7 | |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
8 #define PI 3.1415926535897 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
9 #define WIDTH 640 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
10 #define HEIGHT 480 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
11 #define BPP 4 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
12 #define DEPTH 32 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
13 |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4650
diff
changeset
|
14 #define MAXFINGERS 5 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
15 |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
16 int mousx,mousy; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
17 int keystat[512]; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
18 int bstatus; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
19 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
20 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
21 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
22 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
23 typedef struct { |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
24 float x,y; |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
25 } Point; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
26 |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
27 typedef struct { |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
28 Point p; |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
29 float pressure; |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
30 } Finger; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
31 |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
32 |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
33 Finger finger[MAXFINGERS]; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
34 |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
35 void handler (int sig) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
36 { |
4649 | 37 printf ("exiting...(%d)\n", sig); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
38 exit (0); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
39 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
40 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
41 void perror_exit (char *error) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
42 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
43 perror (error); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
44 handler (9); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
45 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
46 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
47 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
48 void setpix(SDL_Surface *screen, int x, int y, int col) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
49 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
50 Uint32 *pixmem32; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
51 Uint32 colour; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
52 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
53 if((unsigned)x > screen->w) return; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
54 if((unsigned)y > screen->h) return; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
55 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
56 colour = SDL_MapRGB( screen->format, (col>>16)&0xFF, (col>>8)&0xFF, col&0xFF); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
57 |
4650 | 58 pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/screen->format->BytesPerPixel + x; //TODO : Check this. May cause crash. |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
59 *pixmem32 = colour; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
60 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
61 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
62 void drawCircle(SDL_Surface* screen,int x,int y,int r,int c) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
63 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
64 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
65 float a; |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
66 int tx; |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
67 for(a=0;a<PI/2;a+=1.f/(float)abs(r)) |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
68 { |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
69 if(r > 0) { //r<0 ==> unfilled circle |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
70 for(tx=x-r*cos(a);tx<x+r*cos(a);tx++) { |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
71 setpix(screen,tx,(int)(y+r*sin(a)),c); |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
72 setpix(screen,tx,(int)(y-r*sin(a)),c); |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
73 } |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
74 } |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
75 |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
76 //Always Draw Outline |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
77 setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
78 setpix(screen,(int)(x-r*cos(a)),(int)(y+r*sin(a)),c); |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
79 setpix(screen,(int)(x+r*cos(a)),(int)(y-r*sin(a)),c); |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
80 setpix(screen,(int)(x-r*cos(a)),(int)(y-r*sin(a)),c); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
81 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
82 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
83 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
84 void DrawScreen(SDL_Surface* screen, int h) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
85 { |
4649 | 86 int x, y, xm,ym,c,i; |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
87 if(SDL_MUSTLOCK(screen)) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
88 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
89 if(SDL_LockSurface(screen) < 0) return; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
90 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
91 for(y = 0; y < screen->h; y++ ) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
92 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
93 for( x = 0; x < screen->w; x++ ) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
94 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
95 //setpixel(screen, x, y, (x*x)/256+3*y+h, (y*y)/256+x+h, h); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
96 //xm = (x+h)%screen->w; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
97 //ym = (y+h)%screen->w; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
98 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
99 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
100 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
101 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
102 } |
4649 | 103 |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
104 drawCircle(screen,mousx,mousy,-30,0xFFFFFF); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
105 |
4649 | 106 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
107 for(i=0;i<MAXFINGERS;i++) |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
108 if(finger[i].p.x >= 0 && finger[i].p.y >= 0) |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
109 if(finger[i].pressure > 0) |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
110 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
111 ,20,0xFF*finger[i].pressure); |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
112 else |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
113 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
114 ,20,0xFF); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
115 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
116 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
117 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
118 SDL_Flip(screen); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
119 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
120 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
121 SDL_Surface* initScreen(int width,int height) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
122 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
123 return SDL_SetVideoMode(width, height, DEPTH, |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
124 SDL_HWSURFACE | SDL_RESIZABLE); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
125 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
126 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
127 int main(int argc, char* argv[]) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
128 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
129 SDL_Surface *screen; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
130 SDL_Event event; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
131 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
132 int keypress = 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
133 int h=0,s=1,i,j; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
134 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
135 memset(keystat,0,512*sizeof(keystat[0])); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
136 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
4649 | 137 screen = initScreen(WIDTH,HEIGHT); |
138 if (!screen) | |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
139 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
140 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
141 return 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
142 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
143 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
144 while(!keystat[27]) { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
145 //Poll SDL |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
146 while(SDL_PollEvent(&event)) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
147 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
148 switch (event.type) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
149 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
150 case SDL_QUIT: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
151 keystat[27] = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
152 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
153 case SDL_KEYDOWN: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
154 //printf("%i\n",event.key.keysym.sym); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
155 keystat[event.key.keysym.sym] = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
156 //keypress = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
157 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
158 case SDL_KEYUP: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
159 //printf("%i\n",event.key.keysym.sym); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
160 keystat[event.key.keysym.sym] = 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
161 //keypress = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
162 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
163 case SDL_VIDEORESIZE: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
164 if (!(screen = initScreen(event.resize.w, |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
165 event.resize.h))) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
166 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
167 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
168 return 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
169 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
170 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
171 case SDL_MOUSEMOTION: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
172 mousx = event.motion.x; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
173 mousy = event.motion.y; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
174 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
175 case SDL_MOUSEBUTTONDOWN: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
176 bstatus |= (1<<(event.button.button-1)); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
177 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
178 case SDL_MOUSEBUTTONUP: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
179 bstatus &= ~(1<<(event.button.button-1)); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
180 break; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
181 case SDL_FINGERMOTION: |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
182 ; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
183 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId, |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
184 // event.tfinger.x,event.tfinger.y); |
4649 | 185 //SDL_Touch *inTouch = SDL_GetTouch(event.tfinger.touchId); |
186 //SDL_Finger *inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); | |
187 /* | |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
188 finger[event.tfinger.fingerId].p.x = ((float)event.tfinger.x)/ |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
189 inTouch->xres; |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
190 finger[event.tfinger.fingerId].p.y = ((float)event.tfinger.y)/ |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
191 inTouch->yres; |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
192 |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
193 finger[event.tfinger.fingerId].pressure = |
4649 | 194 ((float)event.tfinger.pressure)/inTouch->pressureres;*/ |
195 /* | |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
196 printf("Finger: %i, Pressure: %f Pressureres: %i\n", |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
197 event.tfinger.fingerId, |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
198 finger[event.tfinger.fingerId].pressure, |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
199 inTouch->pressureres); |
4649 | 200 */ |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
201 //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId, |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
202 // finger[event.tfinger.fingerId].pressure); |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
203 |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
204 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
205 break; |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
206 case SDL_FINGERDOWN: |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
207 printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId, |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
208 event.tfinger.x,event.tfinger.y); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
209 finger[event.tfinger.fingerId].p.x = event.tfinger.x; |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
210 finger[event.tfinger.fingerId].p.y = event.tfinger.y; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
211 break; |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
212 case SDL_FINGERUP: |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
213 printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId, |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
214 event.tfinger.x,event.tfinger.y); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
215 finger[event.tfinger.fingerId].p.x = -1; |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
216 finger[event.tfinger.fingerId].p.y = -1; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
217 break; |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
218 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
219 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
220 //And draw |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
221 DrawScreen(screen,h); |
4650 | 222 printf("Things\n"); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
223 /* |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
224 for(i=0;i<512;i++) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
225 if(keystat[i]) printf("%i\n",i); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
226 printf("Buttons:%i\n",bstatus); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
227 */ |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
228 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
229 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
230 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
231 return 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
232 } |