Mercurial > sdl-ios-xcode
annotate docs/html/guideeventexamples.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 >Event Examples</TITLE | |
5 ><META | |
6 NAME="GENERATOR" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
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="Examples" | |
14 HREF="guideexamples.html"><LINK | |
15 REL="PREVIOUS" | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
16 TITLE="Examples" |
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
17 HREF="guideexamples.html"><LINK |
0 | 18 REL="NEXT" |
19 TITLE="Audio Examples" | |
20 HREF="guideaudioexamples.html"></HEAD | |
21 ><BODY | |
22 CLASS="SECT1" | |
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:
55
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 | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
48 HREF="guideexamples.html" |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
49 ACCESSKEY="P" |
0 | 50 >Prev</A |
51 ></TD | |
52 ><TD | |
53 WIDTH="80%" | |
54 ALIGN="center" | |
55 VALIGN="bottom" | |
56 >Chapter 4. Examples</TD | |
57 ><TD | |
58 WIDTH="10%" | |
59 ALIGN="right" | |
60 VALIGN="bottom" | |
61 ><A | |
62 HREF="guideaudioexamples.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
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 ><DIV | |
72 CLASS="SECT1" | |
73 ><H1 | |
74 CLASS="SECT1" | |
75 ><A | |
76 NAME="GUIDEEVENTEXAMPLES" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
77 ></A |
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
78 >Event Examples</H1 |
0 | 79 ><P |
80 ></P | |
81 ><DIV | |
82 CLASS="SECT2" | |
83 ><H2 | |
84 CLASS="SECT2" | |
85 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
86 NAME="AEN375" |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
87 ></A |
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
88 >Filtering and Handling Events</H2 |
0 | 89 ><P |
90 ><PRE | |
91 CLASS="PROGRAMLISTING" | |
92 >#include <stdio.h> | |
93 #include <stdlib.h> | |
94 | |
95 #include "SDL.h" | |
96 | |
97 /* This function may run in a separate event thread */ | |
98 int FilterEvents(const SDL_Event *event) { | |
99 static int boycott = 1; | |
100 | |
101 /* This quit event signals the closing of the window */ | |
102 if ( (event->type == SDL_QUIT) && boycott ) { | |
103 printf("Quit event filtered out -- try again.\n"); | |
104 boycott = 0; | |
105 return(0); | |
106 } | |
107 if ( event->type == SDL_MOUSEMOTION ) { | |
108 printf("Mouse moved to (%d,%d)\n", | |
109 event->motion.x, event->motion.y); | |
110 return(0); /* Drop it, we've handled it */ | |
111 } | |
112 return(1); | |
113 } | |
114 | |
115 int main(int argc, char *argv[]) | |
116 { | |
117 SDL_Event event; | |
118 | |
119 /* Initialize the SDL library (starts the event loop) */ | |
120 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | |
121 fprintf(stderr, | |
122 "Couldn't initialize SDL: %s\n", SDL_GetError()); | |
123 exit(1); | |
124 } | |
125 | |
126 /* Clean up on exit, exit on window close and interrupt */ | |
127 atexit(SDL_Quit); | |
128 | |
129 /* Ignore key events */ | |
130 SDL_EventState(SDL_KEYDOWN, SDL_IGNORE); | |
131 SDL_EventState(SDL_KEYUP, SDL_IGNORE); | |
132 | |
133 /* Filter quit and mouse motion events */ | |
134 SDL_SetEventFilter(FilterEvents); | |
135 | |
136 /* The mouse isn't much use unless we have a display for reference */ | |
137 if ( SDL_SetVideoMode(640, 480, 8, 0) == NULL ) { | |
138 fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n", | |
139 SDL_GetError()); | |
140 exit(1); | |
141 } | |
142 | |
143 /* Loop waiting for ESC+Mouse_Button */ | |
144 while ( SDL_WaitEvent(&event) >= 0 ) { | |
145 switch (event.type) { | |
146 case SDL_ACTIVEEVENT: { | |
147 if ( event.active.state & SDL_APPACTIVE ) { | |
148 if ( event.active.gain ) { | |
149 printf("App activated\n"); | |
150 } else { | |
151 printf("App iconified\n"); | |
152 } | |
153 } | |
154 } | |
155 break; | |
156 | |
157 case SDL_MOUSEBUTTONDOWN: { | |
158 Uint8 *keys; | |
159 | |
160 keys = SDL_GetKeyState(NULL); | |
161 if ( keys[SDLK_ESCAPE] == SDL_PRESSED ) { | |
162 printf("Bye bye...\n"); | |
163 exit(0); | |
164 } | |
165 printf("Mouse button pressed\n"); | |
166 } | |
167 break; | |
168 | |
169 case SDL_QUIT: { | |
170 printf("Quit requested, quitting.\n"); | |
171 exit(0); | |
172 } | |
173 break; | |
174 } | |
175 } | |
176 /* This should never happen */ | |
177 printf("SDL_WaitEvent error: %s\n", SDL_GetError()); | |
178 exit(1); | |
179 }</PRE | |
180 ></P | |
181 ></DIV | |
182 ></DIV | |
183 ><DIV | |
184 CLASS="NAVFOOTER" | |
185 ><HR | |
186 ALIGN="LEFT" | |
187 WIDTH="100%"><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
188 SUMMARY="Footer navigation table" |
0 | 189 WIDTH="100%" |
190 BORDER="0" | |
191 CELLPADDING="0" | |
192 CELLSPACING="0" | |
193 ><TR | |
194 ><TD | |
195 WIDTH="33%" | |
196 ALIGN="left" | |
197 VALIGN="top" | |
198 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
199 HREF="guideexamples.html" |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
200 ACCESSKEY="P" |
0 | 201 >Prev</A |
202 ></TD | |
203 ><TD | |
204 WIDTH="34%" | |
205 ALIGN="center" | |
206 VALIGN="top" | |
207 ><A | |
208 HREF="index.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
209 ACCESSKEY="H" |
0 | 210 >Home</A |
211 ></TD | |
212 ><TD | |
213 WIDTH="33%" | |
214 ALIGN="right" | |
215 VALIGN="top" | |
216 ><A | |
217 HREF="guideaudioexamples.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
218 ACCESSKEY="N" |
0 | 219 >Next</A |
220 ></TD | |
221 ></TR | |
222 ><TR | |
223 ><TD | |
224 WIDTH="33%" | |
225 ALIGN="left" | |
226 VALIGN="top" | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
227 >Examples</TD |
0 | 228 ><TD |
229 WIDTH="34%" | |
230 ALIGN="center" | |
231 VALIGN="top" | |
232 ><A | |
233 HREF="guideexamples.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
55
diff
changeset
|
234 ACCESSKEY="U" |
0 | 235 >Up</A |
236 ></TD | |
237 ><TD | |
238 WIDTH="33%" | |
239 ALIGN="right" | |
240 VALIGN="top" | |
241 >Audio Examples</TD | |
242 ></TR | |
243 ></TABLE | |
244 ></DIV | |
245 ></BODY | |
246 ></HTML | |
247 > |