Mercurial > sdl-ios-xcode
annotate docs/html/sdladdtimer.html @ 1212:7663bb0f52c7
To: sdl@libsdl.org
From: Christian Walther <cwalther@gmx.ch>
Date: Thu, 15 Dec 2005 21:19:53 +0100
Subject: [SDL] More mouse enhancements for Mac OS X
The attached patch brings two more enhancements to mouse handling on Mac
OS X (Quartz):
1. Currently, after launching an SDL application, SDL's notion of the
mouse position is stuck in the top left corner (0,0) until the first
time the mouse is moved. That's because the UpdateMouse() function isn't
implemented in the Quartz driver. This patch adds it.
2. When grabbing input while the mouse cursor is hidden, the function
CGAssociateMouseAndMouseCursorPosition(0) is called, which prevents the
system's notion of the mouse location from moving (and therefore leaving
the SDL window) even when the mouse is moved. However, apparently the
Wacom tablet driver (and maybe other special pointing device drivers)
doesn't care about that setting and still allows the mouse location to
go outside of the window. Interestingly, the system cursor, which is
made visible by the existing code in SDL in that case, does not follow
the mouse location, but appears in the middle of the SDL window. The
mouse location being outside of the window however means that mouse
button events go to background applications (or the dock or whatever is
there), which is very confusing to the user who sees no cursor outside
of the SDL window.
I have not found any way of intercepting these events (and that's
probably by design, as "normal" applications shouldn't prevent the user
from bringing other applications' windows to the front by clicking on
them). An idea would be placing a fully transparent, screen-filling
window in front of everything, but I fear that this might affect
rendering performance (by doing unnecessary compositing, using up
memory, or whatever).
The deluxe solution to the problem would be talking to the tablet
driver using AppleEvents to tell it to constrain its mapped area to the
window (see Wacom's "TabletEventDemo" sample app,
http://www.wacomeng.com/devsupport/mac/downloads.html), but I think that
the bloat that solution would add to SDL would outweigh its usefulness.
What I did instead in my patch is reassociating mouse and cursor when
the mouse leaves the window while an invisible grab is in effect, and
restoring the grab when the window is entered. That way, the grab can
still be effectively broken by a tablet, but at least it's obvious to
the user that it is broken. That change is minimal - it doesn't affect
operation with a mouse (or a trackpad), and the code that it adds is not
executed on every PumpEvents() call, only when entering and leaving the
window.
Unless there are any concerns about the patch, please apply. Feel free
to shorten the lengthy comment in SDL_QuartzEvents.m if you think it's
too verbose.
Thanks
-Christian
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 02 Jan 2006 00:31:00 +0000 |
parents | 355632dca928 |
children |
rev | line source |
---|---|
0 | 1 <HTML |
2 ><HEAD | |
3 ><TITLE | |
4 >SDL_AddTimer</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_Delay" | |
17 HREF="sdldelay.html"><LINK | |
18 REL="NEXT" | |
19 TITLE="SDL_RemoveTimer" | |
20 HREF="sdlremovetimer.html"></HEAD | |
21 ><BODY | |
22 CLASS="REFENTRY" | |
23 BGCOLOR="#FFF8DC" | |
24 TEXT="#000000" | |
25 LINK="#0000ee" | |
26 VLINK="#551a8b" | |
27 ALINK="#ff0000" | |
28 ><DIV | |
29 CLASS="NAVHEADER" | |
30 ><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
31 SUMMARY="Header navigation table" |
0 | 32 WIDTH="100%" |
33 BORDER="0" | |
34 CELLPADDING="0" | |
35 CELLSPACING="0" | |
36 ><TR | |
37 ><TH | |
38 COLSPAN="3" | |
39 ALIGN="center" | |
40 >SDL Library Documentation</TH | |
41 ></TR | |
42 ><TR | |
43 ><TD | |
44 WIDTH="10%" | |
45 ALIGN="left" | |
46 VALIGN="bottom" | |
47 ><A | |
48 HREF="sdldelay.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
49 ACCESSKEY="P" |
0 | 50 >Prev</A |
51 ></TD | |
52 ><TD | |
53 WIDTH="80%" | |
54 ALIGN="center" | |
55 VALIGN="bottom" | |
56 ></TD | |
57 ><TD | |
58 WIDTH="10%" | |
59 ALIGN="right" | |
60 VALIGN="bottom" | |
61 ><A | |
62 HREF="sdlremovetimer.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
63 ACCESSKEY="N" |
0 | 64 >Next</A |
65 ></TD | |
66 ></TR | |
67 ></TABLE | |
68 ><HR | |
69 ALIGN="LEFT" | |
70 WIDTH="100%"></DIV | |
71 ><H1 | |
72 ><A | |
73 NAME="SDLADDTIMER" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
74 ></A |
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
75 >SDL_AddTimer</H1 |
0 | 76 ><DIV |
77 CLASS="REFNAMEDIV" | |
78 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
79 NAME="AEN8482" |
0 | 80 ></A |
81 ><H2 | |
82 >Name</H2 | |
83 >SDL_AddTimer -- Add a timer which will call a callback after the specified number of milliseconds has | |
84 elapsed.</DIV | |
85 ><DIV | |
86 CLASS="REFSYNOPSISDIV" | |
87 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
88 NAME="AEN8485" |
0 | 89 ></A |
90 ><H2 | |
91 >Synopsis</H2 | |
92 ><DIV | |
93 CLASS="FUNCSYNOPSIS" | |
94 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
95 NAME="AEN8486" |
0 | 96 ></A |
97 ><P | |
98 ></P | |
99 ><PRE | |
100 CLASS="FUNCSYNOPSISINFO" | |
101 >#include "SDL.h"</PRE | |
102 ><P | |
103 ><CODE | |
104 ><CODE | |
105 CLASS="FUNCDEF" | |
106 >SDL_TimerID <B | |
107 CLASS="FSFUNC" | |
108 >SDL_AddTimer</B | |
109 ></CODE | |
110 >(Uint32 interval, SDL_NewTimerCallback callback, void *param);</CODE | |
111 ></P | |
112 ><P | |
113 ></P | |
114 ></DIV | |
115 ></DIV | |
116 ><DIV | |
117 CLASS="REFSECT1" | |
118 ><A | |
119 NAME="SDLNEWTIMERCALLBACK" | |
120 ></A | |
121 ><H2 | |
122 >Callback</H2 | |
123 ><PRE | |
124 CLASS="PROGRAMLISTING" | |
125 >/* type definition for the "new" timer callback function */ | |
126 typedef Uint32 (*SDL_NewTimerCallback)(Uint32 interval, void *param);</PRE | |
127 ></DIV | |
128 ><DIV | |
129 CLASS="REFSECT1" | |
130 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
131 NAME="AEN8495" |
0 | 132 ></A |
133 ><H2 | |
134 >Description</H2 | |
135 ><P | |
136 >Adds a callback function to be run after the specified number of | |
137 milliseconds has elapsed. The callback function is passed the current | |
138 timer interval and the user supplied parameter from the | |
139 <TT | |
140 CLASS="FUNCTION" | |
141 >SDL_AddTimer</TT | |
142 > call and returns the next timer | |
143 interval. If the returned value from the callback is the same as the one | |
144 passed in, the periodic alarm continues, otherwise a new alarm is | |
145 scheduled.</P | |
146 ><P | |
147 >To cancel a currently running timer call | |
148 <A | |
149 HREF="sdlremovetimer.html" | |
150 >SDL_RemoveTimer</A | |
151 > with the | |
152 timer ID returned from | |
153 <TT | |
154 CLASS="FUNCTION" | |
155 >SDL_AddTimer</TT | |
156 >.</P | |
157 ><P | |
158 >The timer callback function may run in a different thread than your | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
159 main program, and so shouldn't call any functions from within itself. |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
160 You may always call <A |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
161 HREF="sdlpushevent.html" |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
162 >SDL_PushEvent</A |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
163 >, however.</P |
0 | 164 ><P |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
165 >The granularity of the timer is platform-dependent, but you should count |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
166 on it being at least 10 ms as this is the most common number. |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
167 This means that if |
0 | 168 you request a 16 ms timer, your callback will run approximately 20 ms |
169 later on an unloaded system. If you wanted to set a flag signaling | |
170 a frame update at 30 frames per second (every 33 ms), you might set a | |
171 timer for 30 ms (see example below). | |
172 | |
173 If you use this function, you need to pass <TT | |
174 CLASS="LITERAL" | |
175 >SDL_INIT_TIMER</TT | |
176 > | |
177 to <A | |
178 HREF="sdlinit.html" | |
179 >SDL_Init</A | |
180 >.</P | |
181 ></DIV | |
182 ><DIV | |
183 CLASS="REFSECT1" | |
184 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
185 NAME="AEN8507" |
0 | 186 ></A |
187 ><H2 | |
188 >Return Value</H2 | |
189 ><P | |
190 >Returns an ID value for the added timer or | |
191 <SPAN | |
192 CLASS="RETURNVALUE" | |
193 >NULL</SPAN | |
194 > if there was an error.</P | |
195 ></DIV | |
196 ><DIV | |
197 CLASS="REFSECT1" | |
198 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
199 NAME="AEN8511" |
0 | 200 ></A |
201 ><H2 | |
202 >Examples</H2 | |
203 ><P | |
204 ><PRE | |
205 CLASS="PROGRAMLISTING" | |
206 >my_timer_id = SDL_AddTimer((33/10)*10, my_callbackfunc, my_callback_param);</PRE | |
207 ></P | |
208 ></DIV | |
209 ><DIV | |
210 CLASS="REFSECT1" | |
211 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
212 NAME="AEN8515" |
0 | 213 ></A |
214 ><H2 | |
215 >See Also</H2 | |
216 ><P | |
217 ><A | |
218 HREF="sdlremovetimer.html" | |
219 ><TT | |
220 CLASS="FUNCTION" | |
221 >SDL_RemoveTimer</TT | |
222 ></A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
223 >, |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
224 <A |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
225 HREF="sdlpushevent.html" |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
226 ><TT |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
227 CLASS="FUNCTION" |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
228 >SDL_PushEvent</TT |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
229 ></A |
0 | 230 ></P |
231 ></DIV | |
232 ><DIV | |
233 CLASS="NAVFOOTER" | |
234 ><HR | |
235 ALIGN="LEFT" | |
236 WIDTH="100%"><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
237 SUMMARY="Footer navigation table" |
0 | 238 WIDTH="100%" |
239 BORDER="0" | |
240 CELLPADDING="0" | |
241 CELLSPACING="0" | |
242 ><TR | |
243 ><TD | |
244 WIDTH="33%" | |
245 ALIGN="left" | |
246 VALIGN="top" | |
247 ><A | |
248 HREF="sdldelay.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
249 ACCESSKEY="P" |
0 | 250 >Prev</A |
251 ></TD | |
252 ><TD | |
253 WIDTH="34%" | |
254 ALIGN="center" | |
255 VALIGN="top" | |
256 ><A | |
257 HREF="index.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
258 ACCESSKEY="H" |
0 | 259 >Home</A |
260 ></TD | |
261 ><TD | |
262 WIDTH="33%" | |
263 ALIGN="right" | |
264 VALIGN="top" | |
265 ><A | |
266 HREF="sdlremovetimer.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
267 ACCESSKEY="N" |
0 | 268 >Next</A |
269 ></TD | |
270 ></TR | |
271 ><TR | |
272 ><TD | |
273 WIDTH="33%" | |
274 ALIGN="left" | |
275 VALIGN="top" | |
276 >SDL_Delay</TD | |
277 ><TD | |
278 WIDTH="34%" | |
279 ALIGN="center" | |
280 VALIGN="top" | |
281 ><A | |
282 HREF="time.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
283 ACCESSKEY="U" |
0 | 284 >Up</A |
285 ></TD | |
286 ><TD | |
287 WIDTH="33%" | |
288 ALIGN="right" | |
289 VALIGN="top" | |
290 >SDL_RemoveTimer</TD | |
291 ></TR | |
292 ></TABLE | |
293 ></DIV | |
294 ></BODY | |
295 ></HTML | |
296 > |