Mercurial > sdl-ios-xcode
annotate test/testtimer.c @ 816:428f688f2ad2
Date: Fri, 13 Feb 2004 17:03:16 +0100
From: Max Horn
Subject: Modifier key fix
The internal modifier state can get out of sync with reality. To
trigger this, do for example this:
1) Launch an SDL app
2) Alt-click on the desktop (this will hide the SDL app).
3) Bring the SDL app back to the front
4) SDL will still think alt is pressed (and as such will treat left
clicks like middle clicks). If you press and release alt, it'll be fine
again.
The attached patch cures this by rechecking the modifier state whenever
we process an event.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 13 Feb 2004 17:57:16 +0000 |
parents | ed57c876700d |
children | be9c9c8f6d53 |
rev | line source |
---|---|
0 | 1 |
2 /* Test program to check the resolution of the SDL timer on the current | |
3 platform | |
4 */ | |
5 | |
6 #include <stdlib.h> | |
7 #include <stdio.h> | |
8 | |
9 #include "SDL.h" | |
10 | |
11 #define DEFAULT_RESOLUTION 1 | |
12 | |
13 static int ticks = 0; | |
14 | |
15 static Uint32 ticktock(Uint32 interval) | |
16 { | |
17 ++ticks; | |
18 return(interval); | |
19 } | |
20 | |
21 static Uint32 callback(Uint32 interval, void *param) | |
22 { | |
23 printf("Timer %d : param = %d\n", interval, (int) param); | |
24 return interval; | |
25 } | |
26 | |
27 int main(int argc, char *argv[]) | |
28 { | |
29 int desired; | |
30 SDL_TimerID t1, t2, t3; | |
31 | |
32 if ( SDL_Init(SDL_INIT_TIMER) < 0 ) { | |
33 fprintf(stderr, "Couldn't load SDL: %s\n", SDL_GetError()); | |
34 exit(1); | |
35 } | |
36 atexit(SDL_Quit); | |
37 | |
38 /* Start the timer */ | |
39 desired = 0; | |
40 if ( argv[1] ) { | |
41 desired = atoi(argv[1]); | |
42 } | |
43 if ( desired == 0 ) { | |
44 desired = DEFAULT_RESOLUTION; | |
45 } | |
46 SDL_SetTimer(desired, ticktock); | |
47 | |
48 /* Wait 10 seconds */ | |
49 printf("Waiting 10 seconds\n"); | |
50 SDL_Delay(10*1000); | |
51 | |
52 /* Stop the timer */ | |
53 SDL_SetTimer(0, NULL); | |
54 | |
55 /* Print the results */ | |
56 if ( ticks ) { | |
57 fprintf(stderr, | |
58 "Timer resolution: desired = %d ms, actual = %f ms\n", | |
59 desired, (double)(10*1000)/ticks); | |
60 } | |
61 | |
62 /* Test multiple timers */ | |
63 printf("Testing multiple timers...\n"); | |
64 t1 = SDL_AddTimer(100, callback, (void*)1); | |
65 if(!t1) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
66 fprintf(stderr,"Could not create timer 1: %s\n", SDL_GetError()); |
0 | 67 t2 = SDL_AddTimer(50, callback, (void*)2); |
68 if(!t2) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
69 fprintf(stderr,"Could not create timer 2: %s\n", SDL_GetError()); |
0 | 70 t3 = SDL_AddTimer(233, callback, (void*)3); |
71 if(!t3) | |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
72 fprintf(stderr,"Could not create timer 3: %s\n", SDL_GetError()); |
0 | 73 |
74 /* Wait 10 seconds */ | |
75 printf("Waiting 10 seconds\n"); | |
76 SDL_Delay(10*1000); | |
77 | |
78 printf("Removing timer 1 and waiting 5 more seconds\n"); | |
79 SDL_RemoveTimer(t1); | |
80 | |
81 SDL_Delay(5*1000); | |
82 | |
83 SDL_RemoveTimer(t2); | |
84 SDL_RemoveTimer(t3); | |
85 | |
86 return(0); | |
87 } |