Mercurial > sdl-ios-xcode
annotate 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 |
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> |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
4 #include "../src/events/SDL_touch_c.h" //BAD!!! |
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 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
22 int x,y; |
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; |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
27 int pressure; |
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 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
35 printf ("\nexiting...(%d)\n", sig); |
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; |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
64 for(a=0;a<PI/2;a+=1.f/(float)r) |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
65 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
71 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
72 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
73 void DrawScreen(SDL_Surface* screen, int h) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
74 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
75 int x, y, xm,ym,c; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
76 if(SDL_MUSTLOCK(screen)) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
77 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
78 if(SDL_LockSurface(screen) < 0) return; |
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 for(y = 0; y < screen->h; y++ ) |
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 for( x = 0; x < screen->w; x++ ) |
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 //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
|
85 //xm = (x+h)%screen->w; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
86 //ym = (y+h)%screen->w; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
87 //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
|
88 //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
|
89 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
|
90 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
91 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
92 drawCircle(screen,mousx,mousy,30,0xFFFFFF); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
93 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
94 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
|
95 for(i=0;i<MAXFINGERS;i++) |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
96 if(finger[i].p.x >= 0 && finger[i].p.y >= 0) |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
97 drawCircle(screen,finger[i].p.x,finger[i].p.y,20,0xFF6600-finger[i].pressure); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
98 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
99 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
100 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
101 SDL_Flip(screen); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
102 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
103 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
104 SDL_Surface* initScreen(int width,int height) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
105 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
106 return SDL_SetVideoMode(width, height, DEPTH, |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
107 SDL_HWSURFACE | SDL_RESIZABLE); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
108 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
109 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
110 int main(int argc, char* argv[]) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
111 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
112 SDL_Surface *screen; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
113 SDL_Event event; |
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 int keypress = 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
116 int h=0,s=1,i,j; |
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 memset(keystat,0,512*sizeof(keystat[0])); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
119 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
|
120 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
121 if (!(screen = initScreen(WIDTH,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 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
124 return 1; |
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 while(!keystat[27]) { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
128 //Poll SDL |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
129 while(SDL_PollEvent(&event)) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
130 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
131 switch (event.type) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
132 { |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
133 case SDL_QUIT: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
134 keystat[27] = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
135 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
136 case SDL_KEYDOWN: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
137 //printf("%i\n",event.key.keysym.sym); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
138 keystat[event.key.keysym.sym] = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
139 //keypress = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
140 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
141 case SDL_KEYUP: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
142 //printf("%i\n",event.key.keysym.sym); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
143 keystat[event.key.keysym.sym] = 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
144 //keypress = 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
145 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
146 case SDL_VIDEORESIZE: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
147 if (!(screen = initScreen(event.resize.w, |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
148 event.resize.h))) |
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 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
151 return 1; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
152 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
153 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
154 case SDL_MOUSEMOTION: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
155 mousx = event.motion.x; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
156 mousy = event.motion.y; |
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_MOUSEBUTTONDOWN: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
159 bstatus |= (1<<(event.button.button-1)); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
160 break; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
161 case SDL_MOUSEBUTTONUP: |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
162 bstatus &= ~(1<<(event.button.button-1)); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
163 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
|
164 case SDL_FINGERMOTION: |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
165 |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
166 //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
|
167 // event.tfinger.x,event.tfinger.y); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
168 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
|
169 finger[event.tfinger.fingerId].p.y = event.tfinger.y; |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
170 finger[event.tfinger.fingerId].pressure = event.tfinger.pressure; |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
171 printf("Finger: %i, pressure: %i\n",event.tfinger.fingerId, |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
172 event.tfinger.pressure); |
4643
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
173 break; |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
174 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
|
175 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
|
176 event.tfinger.x,event.tfinger.y); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
177 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
|
178 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
|
179 break; |
8806b78988f7
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
180 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
|
181 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
|
182 event.tfinger.x,event.tfinger.y); |
4644
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
183 finger[event.tfinger.fingerId].p.x = -1; |
fb500b3e1717
Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4643
diff
changeset
|
184 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
|
185 break; |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
186 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
187 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
188 //And draw |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
189 DrawScreen(screen,h); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
190 /* |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
191 for(i=0;i<512;i++) |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
192 if(keystat[i]) printf("%i\n",i); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
193 printf("Buttons:%i\n",bstatus); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
194 */ |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
195 } |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
196 SDL_Quit(); |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
197 |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
198 return 0; |
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
199 } |