Mercurial > sdl-ios-xcode
annotate docs/html/sdlsettimer.html @ 1629:ef4a796e7f24
Fixed bug #55
From Christian Walther:
When writing my patch for #12, I ended up doing all sorts of changes to the way
application/window activating/deactivating is handled in the Quartz backend,
resulting in the attached patch. It does make the code a bit cleaner IMHO, but
as it might be regarded as a case of "if it ain't broken, don't fix it" I'd
like to hear other people's opinion about it. Please shout if some change
strikes you as unnecessary or wrong, and I'll explain the reasons behind it. As
far as I tested it, it does not introduce any new bugs, but I may well have
missed some.
- The most fundamental change (that triggered most of the others) is irrelevant
for the usual single-window SDL applications, it only affects the people who
are crazy enough to display other Cocoa windows alongside the SDL window (I'm
actually doing this currently, although the additional window only displays
debugging info and won't be present in the final product): Before, some things
were done on the application becoming active, some on the window becoming key,
and some on the window becoming main. Conceptually, all these actions belong to
the window becoming key, so that's what I implemented. However, since in a
single-window application these three events always happen together, the
previous implementation "ain't broken".
- This slightly changed the meaning of the SDL_APPMOUSEFOCUS flag from
SDL_GetAppState(): Before, it meant "window is main and mouse is inside window
(or mode is fullscreen)". Now, it means "window is key and mouse is inside
window (or mode is fullscreen)". It makes more sense to me that way. (See
http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html
for a discussion of what key and main windows are.) The other two flags are
unchanged: SDL_APPACTIVE = application is not hidden and window is not
minimized, SDL_APPINPUTFOCUS = window is key (or mode is fullscreen).
- As a side effect, the reorganization fixes the following two issues (and
maybe others) (but they could also be fixed in less invasive ways):
* A regression that was introduced in revision 1.42 of SDL_QuartzVideo.m
(http://libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzVideo.m.diff?r1=1.41&r2=1.42)
(from half-desirable to undesirable behavior):
Situation: While in windowed mode, hide the cursor using
SDL_ShowCursor(SDL_DISABLE), move the mouse outside of the window so that the
cursor becomes visible again, and SDL_SetVideoMode() to a fullscreen mode.
What happened before revision 1.42: The cursor is visible, but becomes
invisible as soon as the mouse is moved (half-desirable).
What happens in revision 1.42 and after (including current CVS): The cursor is
visible and stays visible (undesirable).
What happens after my patch: The cursor is invisible from the beginning
(desirable).
* When the cursor is hidden and grabbed, switch away from the application using
cmd-tab (which ungrabs and makes the cursor visible), move the cursor outside
of the SDL window, then cmd-tab back to the application. In 1.2.8 and in the
current CVS, the cursor is re-grabbed, but it stays visible (immovable in the
middle of the window). With my patch, the cursor is correctly re-grabbed and
hidden. (For some reason, it still doesn't work correctly if you switch back to
the application using the dock instead of cmd-tab. I haven't been able to
figure out why. I can step over [NSCursor hide] being called in the debugger,
but it seems to have no effect.)
- The patch includes my patch for #12 (it was easier to obtain using cvs diff
that way). If you apply both of them, you will end up with 6 duplicate lines in
SDL_QuartzEvents.m.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Apr 2006 14:17:48 +0000 |
parents | 355632dca928 |
children |
rev | line source |
---|---|
0 | 1 <HTML |
2 ><HEAD | |
3 ><TITLE | |
4 >SDL_SetTimer</TITLE | |
5 ><META | |
6 NAME="GENERATOR" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ |
0 | 8 "><LINK |
9 REL="HOME" | |
10 TITLE="SDL Library Documentation" | |
11 HREF="index.html"><LINK | |
12 REL="UP" | |
13 TITLE="Time" | |
14 HREF="time.html"><LINK | |
15 REL="PREVIOUS" | |
16 TITLE="SDL_RemoveTimer" | |
17 HREF="sdlremovetimer.html"></HEAD | |
18 ><BODY | |
19 CLASS="REFENTRY" | |
20 BGCOLOR="#FFF8DC" | |
21 TEXT="#000000" | |
22 LINK="#0000ee" | |
23 VLINK="#551a8b" | |
24 ALINK="#ff0000" | |
25 ><DIV | |
26 CLASS="NAVHEADER" | |
27 ><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
28 SUMMARY="Header navigation table" |
0 | 29 WIDTH="100%" |
30 BORDER="0" | |
31 CELLPADDING="0" | |
32 CELLSPACING="0" | |
33 ><TR | |
34 ><TH | |
35 COLSPAN="3" | |
36 ALIGN="center" | |
37 >SDL Library Documentation</TH | |
38 ></TR | |
39 ><TR | |
40 ><TD | |
41 WIDTH="10%" | |
42 ALIGN="left" | |
43 VALIGN="bottom" | |
44 ><A | |
45 HREF="sdlremovetimer.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
46 ACCESSKEY="P" |
0 | 47 >Prev</A |
48 ></TD | |
49 ><TD | |
50 WIDTH="80%" | |
51 ALIGN="center" | |
52 VALIGN="bottom" | |
53 ></TD | |
54 ><TD | |
55 WIDTH="10%" | |
56 ALIGN="right" | |
57 VALIGN="bottom" | |
58 > </TD | |
59 ></TR | |
60 ></TABLE | |
61 ><HR | |
62 ALIGN="LEFT" | |
63 WIDTH="100%"></DIV | |
64 ><H1 | |
65 ><A | |
66 NAME="SDLSETTIMER" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
67 ></A |
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
68 >SDL_SetTimer</H1 |
0 | 69 ><DIV |
70 CLASS="REFNAMEDIV" | |
71 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
72 NAME="AEN8557" |
0 | 73 ></A |
74 ><H2 | |
75 >Name</H2 | |
76 >SDL_SetTimer -- Set a callback to run after the specified number of milliseconds has | |
77 elapsed.</DIV | |
78 ><DIV | |
79 CLASS="REFSYNOPSISDIV" | |
80 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
81 NAME="AEN8560" |
0 | 82 ></A |
83 ><H2 | |
84 >Synopsis</H2 | |
85 ><DIV | |
86 CLASS="FUNCSYNOPSIS" | |
87 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
88 NAME="AEN8561" |
0 | 89 ></A |
90 ><P | |
91 ></P | |
92 ><PRE | |
93 CLASS="FUNCSYNOPSISINFO" | |
94 >#include "SDL.h"</PRE | |
95 ><P | |
96 ><CODE | |
97 ><CODE | |
98 CLASS="FUNCDEF" | |
99 >int <B | |
100 CLASS="FSFUNC" | |
101 >SDL_SetTimer</B | |
102 ></CODE | |
103 >(Uint32 interval, SDL_TimerCallback callback);</CODE | |
104 ></P | |
105 ><P | |
106 ></P | |
107 ></DIV | |
108 ></DIV | |
109 ><DIV | |
110 CLASS="REFSECT1" | |
111 ><A | |
112 NAME="SDLTIMERCALLBACK" | |
113 ></A | |
114 ><H2 | |
115 >Callback</H2 | |
116 ><P | |
117 >/* Function prototype for the timer callback function */ | |
118 typedef Uint32 (*SDL_TimerCallback)(Uint32 interval);</P | |
119 ></DIV | |
120 ><DIV | |
121 CLASS="REFSECT1" | |
122 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
123 NAME="AEN8570" |
0 | 124 ></A |
125 ><H2 | |
126 >Description</H2 | |
127 ><P | |
128 >Set a callback to run after the specified number of milliseconds has | |
129 elapsed. The callback function is passed the current timer interval | |
130 and returns the next timer interval. If the returned value is the | |
131 same as the one passed in, the periodic alarm continues, otherwise a | |
132 new alarm is scheduled.</P | |
133 ><P | |
134 >To cancel a currently running timer, call | |
135 <TT | |
136 CLASS="FUNCTION" | |
137 >SDL_SetTimer(0, NULL);</TT | |
138 ></P | |
139 ><P | |
140 >The timer callback function may run in a different thread than your | |
141 main constant, and so shouldn't call any functions from within itself.</P | |
142 ><P | |
143 >The maximum resolution of this timer is 10 ms, which means that if | |
144 you request a 16 ms timer, your callback will run approximately 20 ms | |
145 later on an unloaded system. If you wanted to set a flag signaling | |
146 a frame update at 30 frames per second (every 33 ms), you might set a | |
147 timer for 30 ms (see example below).</P | |
148 ><P | |
149 >If you use this function, you need to pass <TT | |
150 CLASS="LITERAL" | |
151 >SDL_INIT_TIMER</TT | |
152 > | |
153 to <TT | |
154 CLASS="FUNCTION" | |
155 >SDL_Init()</TT | |
156 >.</P | |
157 ><DIV | |
158 CLASS="NOTE" | |
159 ><BLOCKQUOTE | |
160 CLASS="NOTE" | |
161 ><P | |
162 ><B | |
163 >Note: </B | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
164 >This function is kept for compatibility but has been superseded |
0 | 165 by the new timer functions |
166 <A | |
167 HREF="sdladdtimer.html" | |
168 >SDL_AddTimer</A | |
169 > and | |
170 <A | |
171 HREF="sdlremovetimer.html" | |
172 >SDL_RemoveTimer</A | |
173 > which support | |
174 multiple timers.</P | |
175 ></BLOCKQUOTE | |
176 ></DIV | |
177 ></DIV | |
178 ><DIV | |
179 CLASS="REFSECT1" | |
180 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
181 NAME="AEN8584" |
0 | 182 ></A |
183 ><H2 | |
184 >Examples</H2 | |
185 ><P | |
186 ><PRE | |
187 CLASS="PROGRAMLISTING" | |
188 >SDL_SetTimer((33/10)*10, my_callback);</PRE | |
189 ></P | |
190 ></DIV | |
191 ><DIV | |
192 CLASS="REFSECT1" | |
193 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
194 NAME="AEN8588" |
0 | 195 ></A |
196 ><H2 | |
197 >See Also</H2 | |
198 ><P | |
199 ><A | |
200 HREF="sdladdtimer.html" | |
201 ><TT | |
202 CLASS="FUNCTION" | |
203 >SDL_AddTimer</TT | |
204 ></A | |
205 ></P | |
206 ></DIV | |
207 ><DIV | |
208 CLASS="NAVFOOTER" | |
209 ><HR | |
210 ALIGN="LEFT" | |
211 WIDTH="100%"><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
212 SUMMARY="Footer navigation table" |
0 | 213 WIDTH="100%" |
214 BORDER="0" | |
215 CELLPADDING="0" | |
216 CELLSPACING="0" | |
217 ><TR | |
218 ><TD | |
219 WIDTH="33%" | |
220 ALIGN="left" | |
221 VALIGN="top" | |
222 ><A | |
223 HREF="sdlremovetimer.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
224 ACCESSKEY="P" |
0 | 225 >Prev</A |
226 ></TD | |
227 ><TD | |
228 WIDTH="34%" | |
229 ALIGN="center" | |
230 VALIGN="top" | |
231 ><A | |
232 HREF="index.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
233 ACCESSKEY="H" |
0 | 234 >Home</A |
235 ></TD | |
236 ><TD | |
237 WIDTH="33%" | |
238 ALIGN="right" | |
239 VALIGN="top" | |
240 > </TD | |
241 ></TR | |
242 ><TR | |
243 ><TD | |
244 WIDTH="33%" | |
245 ALIGN="left" | |
246 VALIGN="top" | |
247 >SDL_RemoveTimer</TD | |
248 ><TD | |
249 WIDTH="34%" | |
250 ALIGN="center" | |
251 VALIGN="top" | |
252 ><A | |
253 HREF="time.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
254 ACCESSKEY="U" |
0 | 255 >Up</A |
256 ></TD | |
257 ><TD | |
258 WIDTH="33%" | |
259 ALIGN="right" | |
260 VALIGN="top" | |
261 > </TD | |
262 ></TR | |
263 ></TABLE | |
264 ></DIV | |
265 ></BODY | |
266 ></HTML | |
267 > |