Mercurial > sdl-ios-xcode
annotate 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 |
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 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
6 #define PI 3.1415926535897 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
7 #define WIDTH 640 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
8 #define HEIGHT 480 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
9 #define BPP 4 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
10 #define DEPTH 32 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
11 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
12 #define MAXFINGERS 3 |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
13 |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
14 int mousx,mousy; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
15 int keystat[512]; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
16 int bstatus; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
17 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
18 |
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 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
|
22 float x,y; |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
23 } Point; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
24 |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
25 typedef struct { |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
26 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
|
27 float pressure; |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
28 } 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
|
29 |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
30 |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
31 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
|
32 |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
33 void handler (int sig) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
34 { |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
35 printf ("\exiting...(%d)\n", sig); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
36 exit (0); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
37 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
38 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
39 void perror_exit (char *error) |
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 perror (error); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
42 handler (9); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
43 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
44 |
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 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
|
47 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
48 Uint32 *pixmem32; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
49 Uint32 colour; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
50 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
51 if((unsigned)x > screen->w) return; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
52 if((unsigned)y > screen->h) return; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
53 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
54 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
|
55 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
56 pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
57 *pixmem32 = colour; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
58 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
59 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
60 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
|
61 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
62 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
63 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
|
64 int tx; |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
65 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
|
66 { |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 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
|
71 } |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
72 } |
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 //Always Draw Outline |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 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
|
79 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
80 } |
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 void DrawScreen(SDL_Surface* screen, int h) |
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 int x, y, xm,ym,c; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
85 if(SDL_MUSTLOCK(screen)) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
86 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
87 if(SDL_LockSurface(screen) < 0) return; |
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 for(y = 0; y < screen->h; y++ ) |
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( x = 0; x < screen->w; x++ ) |
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 //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
|
94 //xm = (x+h)%screen->w; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
95 //ym = (y+h)%screen->w; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
96 //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
|
97 //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
|
98 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
|
99 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
100 } |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
101 drawCircle(screen,mousx,mousy,-30,0xFFFFFF); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
102 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
103 int i; |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
104 for(i=0;i<MAXFINGERS;i++) |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 ,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
|
109 else |
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); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
112 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
113 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
114 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
115 SDL_Flip(screen); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
116 } |
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_Surface* initScreen(int width,int height) |
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 return SDL_SetVideoMode(width, height, DEPTH, |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
121 SDL_HWSURFACE | SDL_RESIZABLE); |
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 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
124 int main(int argc, char* argv[]) |
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 SDL_Surface *screen; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
127 SDL_Event event; |
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 int keypress = 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
130 int h=0,s=1,i,j; |
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 memset(keystat,0,512*sizeof(keystat[0])); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
133 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
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 if (!(screen = initScreen(WIDTH,HEIGHT))) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
136 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
137 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
138 return 1; |
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 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
141 while(!keystat[27]) { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
142 //Poll SDL |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
143 while(SDL_PollEvent(&event)) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
144 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
145 switch (event.type) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
146 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
147 case SDL_QUIT: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
148 keystat[27] = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
149 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
150 case SDL_KEYDOWN: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
151 //printf("%i\n",event.key.keysym.sym); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
152 keystat[event.key.keysym.sym] = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
153 //keypress = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
154 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
155 case SDL_KEYUP: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
156 //printf("%i\n",event.key.keysym.sym); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
157 keystat[event.key.keysym.sym] = 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
158 //keypress = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
159 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
160 case SDL_VIDEORESIZE: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
161 if (!(screen = initScreen(event.resize.w, |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
162 event.resize.h))) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
163 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
164 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
165 return 1; |
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 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
168 case SDL_MOUSEMOTION: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
169 mousx = event.motion.x; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
170 mousy = event.motion.y; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
171 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
172 case SDL_MOUSEBUTTONDOWN: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
173 bstatus |= (1<<(event.button.button-1)); |
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_MOUSEBUTTONUP: |
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; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
178 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
|
179 ; |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
180 //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
|
181 // event.tfinger.x,event.tfinger.y); |
4646
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
182 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
183 SDL_Finger* inFinger = SDL_GetFinger(inTouch,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
|
184 |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
185 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
|
186 inTouch->xres; |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
187 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
|
188 inTouch->yres; |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
189 |
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].pressure = |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
191 ((float)event.tfinger.pressure)/inTouch->pressureres; |
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 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
|
194 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
|
195 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
|
196 inTouch->pressureres); |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
197 //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
|
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 |
eea1bf53effa
Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents:
4644
diff
changeset
|
200 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
201 break; |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
202 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
|
203 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
|
204 event.tfinger.x,event.tfinger.y); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
205 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
|
206 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
|
207 break; |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
208 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
|
209 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
|
210 event.tfinger.x,event.tfinger.y); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
211 finger[event.tfinger.fingerId].p.x = -1; |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
212 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
|
213 break; |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
214 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
215 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
216 //And draw |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
217 DrawScreen(screen,h); |
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 for(i=0;i<512;i++) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
220 if(keystat[i]) printf("%i\n",i); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
221 printf("Buttons:%i\n",bstatus); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
222 */ |
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 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
225 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
226 return 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
227 } |