author | Edward Rudd <urkle@outoforder.cc> |
Sun, 23 Nov 2014 15:39:28 -0500 | |
changeset 9235 | ba9988f0daec |
parent 8917 | 23182cf59f1c |
child 9273 | 9f1c18388f2c |
permissions | -rw-r--r-- |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
1 |
/* |
8149
681eb46b8ac4
Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents:
7900
diff
changeset
|
2 |
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
3 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
4 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
5 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
6 |
arising from the use of this software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
7 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
8 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
9 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
10 |
freely. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5460
diff
changeset
|
11 |
*/ |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
12 |
/* Usage: |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
13 |
* 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
|
14 |
* 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
|
15 |
* 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
|
16 |
*/ |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
17 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
18 |
#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
|
19 |
#include <math.h> |
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
20 |
|
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
21 |
#include "SDL.h" |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
22 |
#include "SDL_touch.h" |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
23 |
#include "SDL_gesture.h" |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
24 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
25 |
#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
|
26 |
#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
|
27 |
#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
|
28 |
#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
|
29 |
|
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
30 |
/* MUST BE A POWER OF 2! */ |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
31 |
#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
|
32 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
33 |
|
5458
a96fcc853bef
Use SDL_Log() so the messages show up on iPhone and Android
Sam Lantinga <slouken@libsdl.org>
parents:
5457
diff
changeset
|
34 |
#define VERBOSE 0 |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
35 |
|
5457
e4ee8761f5cd
Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents:
5456
diff
changeset
|
36 |
static SDL_Window *window; |
e4ee8761f5cd
Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents:
5456
diff
changeset
|
37 |
static SDL_Event events[EVENT_BUF_SIZE]; |
e4ee8761f5cd
Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents:
5456
diff
changeset
|
38 |
static int eventWrite; |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
39 |
|
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
40 |
|
5457
e4ee8761f5cd
Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents:
5456
diff
changeset
|
41 |
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF}; |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
42 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
43 |
typedef struct { |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
44 |
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
|
45 |
} Point; |
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 |
typedef struct { |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
48 |
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
|
49 |
Point p; |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
50 |
} Knob; |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
51 |
|
5457
e4ee8761f5cd
Make the globals static so they're initialized to zero.
Sam Lantinga <slouken@libsdl.org>
parents:
5456
diff
changeset
|
52 |
static Knob knob; |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
53 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
54 |
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
|
55 |
{ |
5460
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
56 |
SDL_Log ("exiting...(%d)", sig); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
57 |
exit (0); |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
58 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
59 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
60 |
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
|
61 |
{ |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
62 |
perror (error); |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
63 |
handler (9); |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
64 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
65 |
|
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
66 |
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
|
67 |
{ |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
68 |
Uint32 *pixmem32; |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
69 |
Uint32 colour; |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
70 |
Uint8 r,g,b; |
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
71 |
int x = (int)_x; |
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
72 |
int y = (int)_y; |
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
73 |
float a; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
74 |
|
6790
475f0a544157
Fixed bug 1672 - Found: seg-fault with testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
5535
diff
changeset
|
75 |
if(x < 0 || x >= screen->w) return; |
475f0a544157
Fixed bug 1672 - Found: seg-fault with testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
5535
diff
changeset
|
76 |
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
|
77 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
78 |
pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
79 |
|
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
80 |
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
|
81 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
82 |
SDL_GetRGB(colour,screen->format,&r,&g,&b); |
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
83 |
/* r = 0;g = 0; b = 0; */ |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
84 |
a = (float)((col>>24)&0xFF); |
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
85 |
if(a == 0) a = 0xFF; /* Hack, to make things easier. */ |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
86 |
a /= 0xFF; |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
colour = SDL_MapRGB( screen->format,r, g, b); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
91 |
|
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
92 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
93 |
*pixmem32 = colour; |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
94 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
95 |
|
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
96 |
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
|
97 |
float t; |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
101 |
|
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
102 |
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
|
103 |
{ |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
104 |
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
|
105 |
float xr; |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
106 |
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
|
107 |
xr = (float)sqrt(r*r - ty*ty); |
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
108 |
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
|
109 |
for(tx=-xr+.5f;tx<=xr-.5;tx++) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
110 |
setpix(screen,x+tx,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
|
111 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
112 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
113 |
else { |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
117 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
118 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
119 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
120 |
void drawKnob(SDL_Surface* screen,Knob k) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
121 |
drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF); |
7451
2ce2d2c71156
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7191
diff
changeset
|
122 |
drawCircle(screen,(k.p.x+k.r/2*SDL_cosf(k.ang))*screen->w, |
2ce2d2c71156
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7191
diff
changeset
|
123 |
(k.p.y+k.r/2*SDL_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
|
124 |
} |
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 |
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
|
127 |
{ |
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
128 |
int i; |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
129 |
#if 1 |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
130 |
SDL_FillRect(screen, NULL, 0); |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
131 |
#else |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
132 |
int x, y; |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
133 |
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
|
134 |
for(x = 0;x < screen->w;x++) |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
135 |
setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255); |
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
136 |
#endif |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
137 |
|
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
138 |
/* draw Touch History */ |
5460
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
139 |
for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) { |
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
140 |
const SDL_Event *event = &events[i&(EVENT_BUF_SIZE-1)]; |
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
141 |
float age = (float)(i - eventWrite) / EVENT_BUF_SIZE; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
142 |
float x, y; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
143 |
unsigned int c, col; |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
144 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
145 |
if(event->type == SDL_FINGERMOTION || |
5460
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
146 |
event->type == SDL_FINGERDOWN || |
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
147 |
event->type == SDL_FINGERUP) { |
6951 | 148 |
x = event->tfinger.x; |
149 |
y = event->tfinger.y; |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
150 |
|
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
151 |
/* draw the touch: */ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
152 |
c = colors[event->tfinger.fingerId%7]; |
5460
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
153 |
col = ((unsigned int)(c*(.1+.85))) | (unsigned int)(0xFF*age)<<24; |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
154 |
|
5460
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
155 |
if(event->type == SDL_FINGERMOTION) |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
156 |
drawCircle(screen,x*screen->w,y*screen->h,5,col); |
5460
43582fccdc0d
Removed newlines from log messages
Sam Lantinga <slouken@libsdl.org>
parents:
5458
diff
changeset
|
157 |
else if(event->type == SDL_FINGERDOWN) |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
158 |
drawCircle(screen,x*screen->w,y*screen->h,-10,col); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
159 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
160 |
} |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
161 |
|
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
162 |
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
|
163 |
drawKnob(screen,knob); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
164 |
|
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
165 |
SDL_UpdateWindowSurface(window); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
166 |
} |
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 |
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
|
169 |
{ |
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
170 |
if (!window) { |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
171 |
window = SDL_CreateWindow("Gesture Test", |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
172 |
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, |
6790
475f0a544157
Fixed bug 1672 - Found: seg-fault with testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
5535
diff
changeset
|
173 |
width, height, SDL_WINDOW_RESIZABLE); |
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
174 |
} |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
175 |
if (!window) { |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
176 |
return NULL; |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
177 |
} |
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
178 |
return SDL_GetWindowSurface(window); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
179 |
} |
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 |
int main(int argc, char* argv[]) |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
182 |
{ |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
183 |
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
|
184 |
SDL_Event event; |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
185 |
SDL_bool quitting = SDL_FALSE; |
7900
cc2289c332eb
Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7678
diff
changeset
|
186 |
SDL_RWops *stream; |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
187 |
|
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
188 |
/* Enable standard application logging */ |
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
189 |
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
190 |
|
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
191 |
/* gesture variables */ |
4918
f5f70fed2c4c
Added a Visual Studio project for testgesture
Sam Lantinga <slouken@libsdl.org>
parents:
4689
diff
changeset
|
192 |
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
|
193 |
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
|
194 |
|
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
195 |
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
196 |
|
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
197 |
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
|
198 |
{ |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
199 |
SDL_Quit(); |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
200 |
return 1; |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
201 |
} |
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 |
while(!quitting) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
204 |
while(SDL_PollEvent(&event)) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
205 |
{ |
7678
286c42d7c5ed
OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7677
diff
changeset
|
206 |
/* Record _all_ events */ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
207 |
events[eventWrite & (EVENT_BUF_SIZE-1)] = event; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
208 |
eventWrite++; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
209 |
|
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
210 |
switch (event.type) |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
211 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
212 |
case SDL_QUIT: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
213 |
quitting = SDL_TRUE; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
214 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
215 |
case SDL_KEYDOWN: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
216 |
switch (event.key.keysym.sym) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
217 |
{ |
9235
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
218 |
case SDLK_i: |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
219 |
{ |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
220 |
int i; |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
221 |
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) { |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
222 |
SDL_TouchID id = SDL_GetTouchDevice(i); |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
223 |
SDL_Log("Fingers Down on device %"SDL_PRIs64": %d", id, SDL_GetNumTouchFingers(id)); |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
224 |
} |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
225 |
break; |
ba9988f0daec
add "i" shortcut to testgesture tool to log # of fingers down on the touch devices.
Edward Rudd <urkle@outoforder.cc>
parents:
8917
diff
changeset
|
226 |
} |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
227 |
case SDLK_SPACE: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
228 |
SDL_RecordGesture(-1); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
229 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
230 |
case SDLK_s: |
7900
cc2289c332eb
Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7678
diff
changeset
|
231 |
stream = SDL_RWFromFile("gestureSave", "w"); |
cc2289c332eb
Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7678
diff
changeset
|
232 |
SDL_Log("Wrote %i templates", SDL_SaveAllDollarTemplates(stream)); |
cc2289c332eb
Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7678
diff
changeset
|
233 |
SDL_RWclose(stream); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
234 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
235 |
case SDLK_l: |
7900
cc2289c332eb
Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7678
diff
changeset
|
236 |
stream = SDL_RWFromFile("gestureSave", "r"); |
cc2289c332eb
Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7678
diff
changeset
|
237 |
SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream)); |
cc2289c332eb
Changed parameter name for gesture template save functions from "src" to "dst".
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7678
diff
changeset
|
238 |
SDL_RWclose(stream); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
239 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
240 |
case SDLK_ESCAPE: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
241 |
quitting = SDL_TRUE; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
242 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
243 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
244 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
245 |
case SDL_WINDOWEVENT: |
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
246 |
if (event.window.event == SDL_WINDOWEVENT_RESIZED) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
247 |
if (!(screen = initScreen(event.window.data1, event.window.data2))) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
248 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
249 |
SDL_Quit(); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
250 |
return 1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
251 |
} |
5456
63258b963fc1
Fixed testgesture to work on the iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
5086
diff
changeset
|
252 |
} |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
253 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
254 |
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
|
255 |
#if VERBOSE |
8917
23182cf59f1c
Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents:
8883
diff
changeset
|
256 |
SDL_Log("Finger: %"SDL_PRIs64",x: %f, y: %f",event.tfinger.fingerId, |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
257 |
event.tfinger.x,event.tfinger.y); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
258 |
#endif |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
259 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
260 |
case SDL_FINGERDOWN: |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
261 |
#if VERBOSE |
8917
23182cf59f1c
Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents:
8883
diff
changeset
|
262 |
SDL_Log("Finger: %"SDL_PRIs64" down - x: %f, y: %f", |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
263 |
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
264 |
#endif |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
265 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
266 |
case SDL_FINGERUP: |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
267 |
#if VERBOSE |
8917
23182cf59f1c
Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents:
8883
diff
changeset
|
268 |
SDL_Log("Finger: %"SDL_PRIs64" up - x: %f, y: %f", |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
269 |
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
270 |
#endif |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
271 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
272 |
case SDL_MULTIGESTURE: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
273 |
#if VERBOSE |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
274 |
SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f", |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
275 |
event.mgesture.x, |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
276 |
event.mgesture.y, |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
277 |
event.mgesture.dTheta, |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
278 |
event.mgesture.dDist); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
279 |
SDL_Log("MG: numDownTouch = %i",event.mgesture.numFingers); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
280 |
#endif |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
281 |
knob.p.x = event.mgesture.x; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
282 |
knob.p.y = event.mgesture.y; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
283 |
knob.ang += event.mgesture.dTheta; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
284 |
knob.r += event.mgesture.dDist; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
285 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
286 |
case SDL_DOLLARGESTURE: |
8917
23182cf59f1c
Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents:
8883
diff
changeset
|
287 |
SDL_Log("Gesture %"SDL_PRIs64" performed, error: %f", |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
288 |
event.dgesture.gestureId, |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
289 |
event.dgesture.error); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
290 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
291 |
case SDL_DOLLARRECORD: |
8917
23182cf59f1c
Don't redefine standard macros, use SDL specific macros instead to avoid compiler warnings
Sam Lantinga <slouken@libsdl.org>
parents:
8883
diff
changeset
|
292 |
SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
293 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
294 |
} |
4689
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 |
DrawScreen(screen); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
297 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
6951
diff
changeset
|
298 |
SDL_Quit(); |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
299 |
return 0; |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
300 |
} |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
301 |