annotate test/testgesture.c @ 5062:e8916fe9cfc8

Fixed bug #925 Changed "win32" to "windows"
author Sam Lantinga <slouken@libsdl.org>
date Thu, 20 Jan 2011 18:04:05 -0800
parents 40a43c6d9220
children c2539ff054c8
rev   line source
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
1 /* Usage:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
2 * Spacebar to begin recording a gesture on all touches.
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
3 * s to save all touches into "./gestureSave"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
4 * l to load all touches from "./gestureSave"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
5 */
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
6
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
7 #include <stdio.h>
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
8 #include <SDL.h>
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
9 #include <math.h>
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
10 #include <SDL_touch.h>
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
11 #include <SDL_gesture.h>
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
12
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
13
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
14 /* Make sure we have good macros for printing 32 and 64 bit values */
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
15 #ifndef PRIs32
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
16 #define PRIs32 "d"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
17 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
18 #ifndef PRIu32
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
19 #define PRIu32 "u"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
20 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
21 #ifndef PRIs64
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 4921
diff changeset
22 #ifdef __WINDOWS__
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
23 #define PRIs64 "I64"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
24 #else
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
25 #define PRIs64 "lld"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
26 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
27 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
28 #ifndef PRIu64
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 4921
diff changeset
29 #ifdef __WINDOWS__
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
30 #define PRIu64 "I64u"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
31 #else
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
32 #define PRIu64 "llu"
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
33 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
34 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
35
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
36 #define WIDTH 640
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
37 #define HEIGHT 480
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
38 #define BPP 4
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
39 #define DEPTH 32
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
40
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
41 //MUST BE A POWER OF 2!
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
42 #define EVENT_BUF_SIZE 256
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
43
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
44
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
45 #define VERBOSE SDL_FALSE
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
46
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
47 SDL_Event events[EVENT_BUF_SIZE];
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
48 int eventWrite;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
49
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
50 int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
51
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
52 typedef struct {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
53 float x,y;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
54 } Point;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
55
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
56 typedef struct {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
57 float ang,r;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
58 Point p;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
59 } Knob;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
60
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
61 Knob knob;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
62
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
63 void handler (int sig)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
64 {
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
65 printf ("exiting...(%d)\n", sig);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
66 exit (0);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
67 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
68
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
69 void perror_exit (char *error)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
70 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
71 perror (error);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
72 handler (9);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
73 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
74
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
75 void setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
76 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
77 Uint32 *pixmem32;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
78 Uint32 colour;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
79 Uint8 r,g,b;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
80 int x = (int)_x;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
81 int y = (int)_y;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
82 float a;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
83
4921
40a43c6d9220 Fixed crash if the gesture coordinates go negative - FIXME: Should this protection be at a lower level?
Sam Lantinga <slouken@libsdl.org>
parents: 4918
diff changeset
84 if(x < 0 || x > screen->w) return;
40a43c6d9220 Fixed crash if the gesture coordinates go negative - FIXME: Should this protection be at a lower level?
Sam Lantinga <slouken@libsdl.org>
parents: 4918
diff changeset
85 if(y < 0 || y > screen->h) return;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
86
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
87 pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
88
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
89 SDL_memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
90
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
91 SDL_GetRGB(colour,screen->format,&r,&g,&b);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
92 //r = 0;g = 0; b = 0;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
93 a = (float)((col>>24)&0xFF);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
94 if(a == 0) a = 0xFF; //Hack, to make things easier.
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
95 a /= 0xFF;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
96 r = (Uint8)(r*(1-a) + ((col>>16)&0xFF)*(a));
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
97 g = (Uint8)(g*(1-a) + ((col>> 8)&0xFF)*(a));
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
98 b = (Uint8)(b*(1-a) + ((col>> 0)&0xFF)*(a));
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
99 colour = SDL_MapRGB( screen->format,r, g, b);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
100
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
101
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
102 *pixmem32 = colour;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
103 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
104
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
105 void drawLine(SDL_Surface *screen,float x0,float y0,float x1,float y1,unsigned int col) {
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
106 float t;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
107 for(t=0;t<1;t+=(float)(1.f/SDL_max(SDL_fabs(x0-x1),SDL_fabs(y0-y1))))
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
108 setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
109 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
110
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
111 void drawCircle(SDL_Surface* screen,float x,float y,float r,unsigned int c)
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
112 {
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
113 float tx,ty;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
114 float xr;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
115 for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
116 xr = (float)sqrt(r*r - ty*ty);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
117 if(r > 0) { //r > 0 ==> filled circle
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
118 for(tx=-xr+.5f;tx<=xr-.5;tx++) {
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
119 setpix(screen,x+tx,y+ty,c);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
120 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
121 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
122 else {
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
123 setpix(screen,x-xr+.5f,y+ty,c);
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
124 setpix(screen,x+xr-.5f,y+ty,c);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
125 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
126 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
127 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
128
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
129 void drawKnob(SDL_Surface* screen,Knob k) {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
130 drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
131 drawCircle(screen,(k.p.x+k.r/2*cosf(k.ang))*screen->w,
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
132 (k.p.y+k.r/2*sinf(k.ang))*screen->h,k.r/4*screen->w,0);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
133 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
134
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
135 void DrawScreen(SDL_Surface* screen)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
136 {
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
137 int x, y, i;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
138 if(SDL_MUSTLOCK(screen))
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
139 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
140 if(SDL_LockSurface(screen) < 0) return;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
141 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
142 for(y = 0;y < screen->h;y++)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
143 for(x = 0;x < screen->w;x++)
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
144 setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
145
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
146 //draw Touch History
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
147 for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
148 SDL_Event event = events[i&(EVENT_BUF_SIZE-1)];
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
149 int age = eventWrite - i - 1;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
150 float x, y;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
151 unsigned int c, col;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
152
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
153 if(event.type == SDL_FINGERMOTION ||
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
154 event.type == SDL_FINGERDOWN ||
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
155 event.type == SDL_FINGERUP) {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
156 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
157 if(inTouch == NULL) continue;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
158
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
159 x = ((float)event.tfinger.x)/inTouch->xres;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
160 y = ((float)event.tfinger.y)/inTouch->yres;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
161
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
162 //draw the touch:
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
163 c = colors[event.tfinger.touchId%7];
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
164 col =
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
165 ((unsigned int)(c*(.1+.85))) |
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
166 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
167
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
168 if(event.type == SDL_FINGERMOTION)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
169 drawCircle(screen,x*screen->w,y*screen->h,5,col);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
170 else if(event.type == SDL_FINGERDOWN)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
171 drawCircle(screen,x*screen->w,y*screen->h,-10,col);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
172 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
173 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
174
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
175 if(knob.p.x > 0)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
176 drawKnob(screen,knob);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
177
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
178 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
179 SDL_Flip(screen);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
180 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
181
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
182 SDL_Surface* initScreen(int width,int height)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
183 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
184 return SDL_SetVideoMode(width, height, DEPTH,
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
185 SDL_HWSURFACE | SDL_RESIZABLE);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
186 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
187
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
188 int main(int argc, char* argv[])
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
189 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
190 SDL_Surface *screen;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
191 SDL_Event event;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
192 SDL_bool quitting = SDL_FALSE;
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
193 SDL_RWops *src;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
194
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
195 //gesture variables
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
196 knob.r = .1f;
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
197 knob.ang = 0;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
198
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
199 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
200
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
201 if (!(screen = initScreen(WIDTH,HEIGHT)))
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
202 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
203 SDL_Quit();
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
204 return 1;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
205 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
206
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
207 while(!quitting) {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
208 while(SDL_PollEvent(&event))
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
209 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
210 //Record _all_ events
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
211 events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
212 eventWrite++;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
213
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
214 switch (event.type)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
215 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
216 case SDL_QUIT:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
217 quitting = SDL_TRUE;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
218 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
219 case SDL_KEYDOWN:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
220 switch (event.key.keysym.sym)
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
221 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
222 case SDLK_SPACE:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
223 SDL_RecordGesture(-1);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
224 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
225 case SDLK_s:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
226 src = SDL_RWFromFile("gestureSave","w");
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
227 printf("Wrote %i templates\n",SDL_SaveAllDollarTemplates(src));
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
228 SDL_RWclose(src);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
229 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
230 case SDLK_l:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
231 src = SDL_RWFromFile("gestureSave","r");
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
232 printf("Loaded: %i\n",SDL_LoadDollarTemplates(-1,src));
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
233 SDL_RWclose(src);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
234 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
235 case SDLK_ESCAPE:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
236 quitting = SDL_TRUE;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
237 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
238 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
239 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
240 case SDL_VIDEORESIZE:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
241 if (!(screen = initScreen(event.resize.w,
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
242 event.resize.h)))
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
243 {
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
244 SDL_Quit();
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
245 return 1;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
246 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
247 break;
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
248 case SDL_FINGERMOTION:
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
249 #if VERBOSE
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
250 printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
251 event.tfinger.x,event.tfinger.y);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
252 #endif
4918
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
253 {
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
254 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
255 SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
f5f70fed2c4c Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents: 4689
diff changeset
256 }
4689
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
257 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
258 case SDL_FINGERDOWN:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
259 #if VERBOSE
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
260 printf("Finger: %"PRIs64" down - x: %i, y: %i\n",
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
261 event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
262 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
263 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
264 case SDL_FINGERUP:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
265 #if VERBOSE
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
266 printf("Finger: %"PRIs64" up - x: %i, y: %i\n",
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
267 event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
268 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
269 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
270 case SDL_MULTIGESTURE:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
271 #if VERBOSE
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
272 printf("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f\n",
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
273 event.mgesture.x,
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
274 event.mgesture.y,
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
275 event.mgesture.dTheta,
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
276 event.mgesture.dDist);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
277 printf("MG: numDownTouch = %i\n",event.mgesture.numFingers);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
278 #endif
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
279 knob.p.x = event.mgesture.x;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
280 knob.p.y = event.mgesture.y;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
281 knob.ang += event.mgesture.dTheta;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
282 knob.r += event.mgesture.dDist;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
283 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
284 case SDL_DOLLARGESTURE:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
285 printf("Gesture %"PRIs64" performed, error: %f\n",
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
286 event.dgesture.gestureId,
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
287 event.dgesture.error);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
288 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
289 case SDL_DOLLARRECORD:
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
290 printf("Recorded gesture: %"PRIs64"\n",event.dgesture.gestureId);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
291 break;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
292 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
293 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
294 DrawScreen(screen);
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
295 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
296 SDL_Quit();
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
297 return 0;
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
298 }
f9ab8df6d45a Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
299