Mercurial > sdl-ios-xcode
annotate touchTest/Iphone Test/touchTestIPhone2/touchTestIPhone/main.c @ 4682:4ba1048a324c
Minimized functionality of gestureSDLTest.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Tue, 03 Aug 2010 00:18:00 -0400 |
parents | f8431f66613d |
children |
rev | line source |
---|---|
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
1 #include <stdio.h> |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
2 #include <SDL.h> |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
3 #include <math.h> |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
4 #include <SDL_touch.h> |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
5 #include <SDL_gesture.h> |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
6 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
7 #define PI 3.1415926535897 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
8 #define PHI ((sqrt(5)-1)/2) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
9 #define WIDTH 640 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
10 #define HEIGHT 480 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
11 #define BPP 4 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
12 #define DEPTH 32 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
13 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
14 #define MAXFINGERS 5 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
15 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
16 #define DOLLARNPOINTS 64 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
17 #define DOLLARSIZE 256 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
18 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
19 //MUST BE A POWER OF 2! |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
20 #define EVENT_BUF_SIZE 256 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
21 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
22 SDL_Event events[EVENT_BUF_SIZE]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
23 int eventWrite; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
24 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
25 int mousx,mousy; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
26 int keystat[512]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
27 int bstatus; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
28 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
29 int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF}; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
30 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
31 long index2fingerid[MAXFINGERS]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
32 int fingersDown; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
33 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
34 typedef struct { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
35 float x,y; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
36 } Point; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
37 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
38 typedef struct { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
39 Point p; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
40 float pressure; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
41 long id; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
42 } Finger; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
43 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
44 typedef struct { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
45 Finger f; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
46 Point cv; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
47 float dtheta,dDist; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
48 } TouchPoint; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
49 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
50 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
51 typedef struct { //dt + s |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
52 Point d,s; //direction, start |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
53 int points; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
54 } Line; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
55 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
56 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
57 typedef struct { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
58 float length; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
59 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
60 int numPoints; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
61 Point p[EVENT_BUF_SIZE]; //To be safe |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
62 } DollarPath; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
63 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
64 typedef struct { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
65 float ang,r; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
66 Point p; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
67 } Knob; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
68 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
69 Knob knob; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
70 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
71 Finger finger[MAXFINGERS]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
72 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
73 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
74 DollarPath dollarPath[MAXFINGERS]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
75 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
76 #define MAXTEMPLATES 4 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
77 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
78 Point dollarTemplate[MAXTEMPLATES][DOLLARNPOINTS]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
79 int numDollarTemplates = 0; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
80 #ifdef DRAW_VECTOR_EST |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
81 Line gestureLine[MAXFINGERS]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
82 #endif |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
83 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
84 void handler (int sig) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
85 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
86 printf ("\exiting...(%d)\n", sig); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
87 exit (0); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
88 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
89 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
90 void perror_exit (char *error) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
91 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
92 perror (error); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
93 handler (9); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
94 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
95 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
96 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
97 void setpix(SDL_Surface *screen, int x, int y, unsigned int col) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
98 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
99 Uint32 *pixmem32; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
100 Uint32 colour; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
101 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
102 if((unsigned)x > screen->w) return; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
103 if((unsigned)y > screen->h) return; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
104 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
105 pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
106 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
107 Uint8 r,g,b; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
108 float a; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
109 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
110 memcpy(&colour,pixmem32,screen->format->BytesPerPixel); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
111 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
112 SDL_GetRGB(colour,screen->format,&r,&g,&b); //Always returns 0xFFFFFF? |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
113 //r = 0;g = 0; b = 0; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
114 a = (col>>24)&0xFF; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
115 if(a == 0) a = 0xFF; //Hack, to make things easier. |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
116 a /= 0xFF; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
117 r = r*(1-a) + ((col>>16)&0xFF)*(a); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
118 g = g*(1-a) + ((col>> 8)&0xFF)*(a); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
119 b = b*(1-a) + ((col>> 0)&0xFF)*(a); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
120 colour = SDL_MapRGB( screen->format,r, g, b); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
121 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
122 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
123 *pixmem32 = colour; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
124 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
125 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
126 void drawLine(SDL_Surface *screen,int x0,int y0,int x1,int y1,unsigned int col) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
127 float t; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
128 for(t=0;t<1;t+=1.f/SDL_max(abs(x0-x1),abs(y0-y1))) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
129 setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
130 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
131 void drawCircle(SDL_Surface* screen,int x,int y,int r,unsigned int c) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
132 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
133 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
134 float a; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
135 int tx; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
136 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
137 int ty; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
138 float xr; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
139 for(ty = -abs(r);ty <= abs(r);ty++) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
140 xr = sqrt(r*r - ty*ty); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
141 if(r > 0) { //r > 0 ==> filled circle |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
142 for(tx=-xr+.5;tx<=xr-.5;tx++) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
143 setpix(screen,x+tx,y+ty,c); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
144 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
145 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
146 else { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
147 setpix(screen,x-xr+.5,y+ty,c); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
148 setpix(screen,x+xr-.5,y+ty,c); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
149 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
150 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
151 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
152 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
153 void drawKnob(SDL_Surface* screen,Knob k) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
154 //printf("Knob: x = %f, y = %f, r = %f, a = %f\n",k.p.x,k.p.y,k.r,k.ang); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
155 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
156 drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
157 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
158 drawCircle(screen,(k.p.x+k.r/2*cos(k.ang))*screen->w, |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
159 (k.p.y+k.r/2*sin(k.ang))*screen->h,k.r/4*screen->w,0); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
160 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
161 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
162 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
163 void DrawScreen(SDL_Surface* screen, int h) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
164 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
165 int x, y, xm,ym,c; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
166 if(SDL_MUSTLOCK(screen)) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
167 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
168 if(SDL_LockSurface(screen) < 0) return; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
169 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
170 for(y = 0; y < screen->h; y++ ) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
171 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
172 for( x = 0; x < screen->w; x++ ) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
173 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
174 //setpixel(screen, x, y, (x*x)/256+3*y+h, (y*y)/256+x+h, h); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
175 //xm = (x+h)%screen->w; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
176 //ym = (y+h)%screen->w; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
177 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
178 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
179 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
180 //setpix(screen,x,y,0); //Inefficient, but that's okay... |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
181 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
182 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
183 drawCircle(screen,mousx,mousy,-30,0xFFFFFF); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
184 drawLine(screen,0,0,screen->w,screen->h,0xFFFFFF); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
185 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
186 int i; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
187 //draw Touch History |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
188 TouchPoint gestureLast[MAXFINGERS]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
189 //printf("------------------Start History------------------\n"); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
190 for(i = 0;i < MAXFINGERS;i++) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
191 gestureLast[i].f.id = -1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
192 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
193 int numDownFingers = 0; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
194 Point centroid; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
195 float gdtheta,gdDist; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
196 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
197 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
198 for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
199 SDL_Event event = events[i&(EVENT_BUF_SIZE-1)]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
200 int age = eventWrite - i - 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
201 if(event.type == SDL_FINGERMOTION || |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
202 event.type == SDL_FINGERDOWN || |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
203 event.type == SDL_FINGERUP) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
204 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
205 //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
206 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
207 float x = ((float)event.tfinger.x)/inTouch->xres; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
208 float y = ((float)event.tfinger.y)/inTouch->yres; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
209 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
210 //draw the touch: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
211 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
212 unsigned int c = colors[event.tfinger.touchId%7]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
213 unsigned int col = |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
214 ((unsigned int)(c*(.1+.85))) | |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
215 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
216 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
217 if(event.type == SDL_FINGERMOTION) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
218 drawCircle(screen,x*screen->w,y*screen->h,5,col); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
219 else if(event.type == SDL_FINGERDOWN) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
220 drawCircle(screen,x*screen->w,y*screen->h,-10,col); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
221 /* |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
222 //if there is a centroid, draw it |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
223 if(numDownFingers > 1) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
224 unsigned int col = |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
225 ((unsigned int)(0xFFFFFF)) | |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
226 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
227 drawCircle(screen,centroid.x*screen->w,centroid.y*screen->h,5,col); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
228 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
229 */ |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
230 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
231 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
232 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
233 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
234 for(i=0;i<MAXFINGERS;i++) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
235 if(finger[i].p.x >= 0 && finger[i].p.y >= 0) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
236 if(finger[i].pressure > 0) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
237 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
238 ,20,0xFF*finger[i].pressure); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
239 else |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
240 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
241 ,20,0xFF); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
242 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
243 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
244 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
245 keystat[32] = 0; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
246 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
247 if(knob.p.x > 0) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
248 drawKnob(screen,knob); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
249 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
250 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
251 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
252 SDL_Flip(screen); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
253 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
254 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
255 SDL_Surface* initScreen(int width,int height) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
256 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
257 return SDL_SetVideoMode(width, height, DEPTH, |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
258 SDL_HWSURFACE | SDL_RESIZABLE); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
259 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
260 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
261 int main(int argc, char* argv[]) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
262 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
263 SDL_Surface *screen; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
264 SDL_Event event; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
265 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
266 knob.r = .1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
267 knob.ang = 0; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
268 TouchPoint gestureLast[MAXFINGERS]; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
269 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
270 int h,i; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
271 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
272 memset(keystat,0,512*sizeof(keystat[0])); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
273 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
274 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
275 if (!(screen = initScreen(WIDTH,HEIGHT))) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
276 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
277 SDL_Quit(); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
278 return 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
279 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
280 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
281 while(!keystat[27]) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
282 //Poll SDL |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
283 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
284 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
285 while(SDL_PollEvent(&event)) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
286 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
287 //Record _all_ events |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
288 events[eventWrite & (EVENT_BUF_SIZE-1)] = event; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
289 eventWrite++; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
290 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
291 switch (event.type) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
292 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
293 case SDL_QUIT: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
294 keystat[27] = 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
295 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
296 case SDL_KEYDOWN: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
297 //printf("%i\n",event.key.keysym.sym); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
298 keystat[event.key.keysym.sym] = 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
299 if(event.key.keysym.sym == 32) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
300 SDL_RecordGesture(-1); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
301 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
302 else if(event.key.keysym.sym == 115) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
303 SDL_RWops *src; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
304 //fp = fopen("gestureSave","w"); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
305 src = SDL_RWFromFile("gestureSave","w"); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
306 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
307 printf("Wrote %i templates\n",SDL_SaveAllDollarTemplates(src)); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
308 //fclose(fp); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
309 SDL_RWclose(src); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
310 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
311 else if(event.key.keysym.sym == 108) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
312 SDL_RWops *src; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
313 //fp = fopen("gestureSave","r"); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
314 src = SDL_RWFromFile("gestureSave","r"); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
315 printf("Loaded: %i\n",SDL_LoadDollarTemplates(-1,src)); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
316 //fclose(fp); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
317 SDL_RWclose(src); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
318 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
319 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
320 //keypress = 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
321 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
322 case SDL_KEYUP: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
323 //printf("%i\n",event.key.keysym.sym); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
324 keystat[event.key.keysym.sym] = 0; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
325 //keypress = 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
326 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
327 case SDL_VIDEORESIZE: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
328 if (!(screen = initScreen(event.resize.w, |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
329 event.resize.h))) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
330 { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
331 SDL_Quit(); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
332 return 1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
333 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
334 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
335 case SDL_MOUSEMOTION: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
336 mousx = event.motion.x; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
337 mousy = event.motion.y; |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4677
diff
changeset
|
338 break; |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
339 case SDL_MOUSEBUTTONDOWN: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
340 bstatus |= (1<<(event.button.button-1)); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
341 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
342 case SDL_MOUSEBUTTONUP: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
343 bstatus &= ~(1<<(event.button.button-1)); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
344 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
345 case SDL_FINGERMOTION: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
346 ; |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4677
diff
changeset
|
347 printf("Finger: %li,x: %i, y: %i\n",event.tfinger.fingerId, |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
348 event.tfinger.x,event.tfinger.y); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
349 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
350 //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
351 for(i = 0;i<MAXFINGERS;i++) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
352 if(index2fingerid[i] == event.tfinger.fingerId) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
353 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
354 if(i == MAXFINGERS) break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
355 if(inTouch > 0) { |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4677
diff
changeset
|
356 finger[i].p.x = ((float)event.tfinger.x)/inTouch->xres; |
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4677
diff
changeset
|
357 finger[i].p.y = ((float)event.tfinger.y)/inTouch->yres; |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
358 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
359 finger[i].pressure = |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
360 ((float)event.tfinger.pressure)/inTouch->pressureres; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
361 /* |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
362 printf("Finger: %i, Pressure: %f Pressureres: %i\n", |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
363 event.tfinger.fingerId, |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
364 finger[i].pressure, |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
365 inTouch->pressureres); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
366 */ |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
367 //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId, |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
368 // finger[event.tfinger.fingerId].pressure); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
369 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
370 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
371 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
372 case SDL_FINGERDOWN: |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4677
diff
changeset
|
373 printf("Finger: %li down - x: %i, y: %i\n",event.tfinger.fingerId, |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
374 event.tfinger.x,event.tfinger.y); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
375 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
376 for(i = 0;i<MAXFINGERS;i++) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
377 if(index2fingerid[i] == -1) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
378 index2fingerid[i] = event.tfinger.fingerId; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
379 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
380 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
381 finger[i].p.x = event.tfinger.x; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
382 finger[i].p.y = event.tfinger.y; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
383 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
384 case SDL_FINGERUP: |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4677
diff
changeset
|
385 printf("Figner: %li up - x: %i, y: %i\n",event.tfinger.fingerId, |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
386 event.tfinger.x,event.tfinger.y); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
387 for(i = 0;i<MAXFINGERS;i++) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
388 if(index2fingerid[i] == event.tfinger.fingerId) { |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
389 index2fingerid[i] = -1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
390 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
391 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
392 finger[i].p.x = -1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
393 finger[i].p.y = -1; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
394 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
395 case SDL_MULTIGESTURE: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
396 knob.p.x = event.mgesture.x; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
397 knob.p.y = event.mgesture.y; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
398 knob.ang += event.mgesture.dTheta; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
399 knob.r += event.mgesture.dDist; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
400 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
401 case SDL_DOLLARGESTURE: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
402 printf("Gesture %lu performed, error: %f\n", |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
403 event.dgesture.gestureId, |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
404 event.dgesture.error); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
405 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
406 case SDL_DOLLARRECORD: |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
407 printf("Recorded gesture: %lu\n",event.dgesture.gestureId); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
408 break; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
409 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
410 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
411 DrawScreen(screen,h); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
412 for(i = 0; i < 256; i++) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
413 if(keystat[i]) |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
414 printf("Key %i down\n",i); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
415 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
416 SDL_Quit(); |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
417 |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
418 return 0; |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
419 } |
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
diff
changeset
|
420 |