Mercurial > sdl-ios-xcode
annotate docs/html/sdlevent.html @ 77:1e7e61b9b0f9
Don't crash if freeing a cursor after quit...
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Tue, 19 Jun 2001 21:07:12 +0000 |
parents | 55f1f1b3e27d |
children | e5bc29de3f0a |
rev | line source |
---|---|
0 | 1 <HTML |
2 ><HEAD | |
3 ><TITLE | |
4 >SDL_Event</TITLE | |
5 ><META | |
6 NAME="GENERATOR" | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.64 |
0 | 8 "><LINK |
9 REL="HOME" | |
10 TITLE="SDL Library Documentation" | |
11 HREF="index.html"><LINK | |
12 REL="UP" | |
13 TITLE="SDL Event Structures." | |
14 HREF="eventstructures.html"><LINK | |
15 REL="PREVIOUS" | |
16 TITLE="SDL Event Structures." | |
17 HREF="eventstructures.html"><LINK | |
18 REL="NEXT" | |
19 TITLE="SDL_ActiveEvent" | |
20 HREF="sdlactiveevent.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 | |
31 WIDTH="100%" | |
32 BORDER="0" | |
33 CELLPADDING="0" | |
34 CELLSPACING="0" | |
35 ><TR | |
36 ><TH | |
37 COLSPAN="3" | |
38 ALIGN="center" | |
39 >SDL Library Documentation</TH | |
40 ></TR | |
41 ><TR | |
42 ><TD | |
43 WIDTH="10%" | |
44 ALIGN="left" | |
45 VALIGN="bottom" | |
46 ><A | |
47 HREF="eventstructures.html" | |
48 >Prev</A | |
49 ></TD | |
50 ><TD | |
51 WIDTH="80%" | |
52 ALIGN="center" | |
53 VALIGN="bottom" | |
54 ></TD | |
55 ><TD | |
56 WIDTH="10%" | |
57 ALIGN="right" | |
58 VALIGN="bottom" | |
59 ><A | |
60 HREF="sdlactiveevent.html" | |
61 >Next</A | |
62 ></TD | |
63 ></TR | |
64 ></TABLE | |
65 ><HR | |
66 ALIGN="LEFT" | |
67 WIDTH="100%"></DIV | |
68 ><H1 | |
69 ><A | |
70 NAME="SDLEVENT" | |
71 >SDL_Event</A | |
72 ></H1 | |
73 ><DIV | |
74 CLASS="REFNAMEDIV" | |
75 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
76 NAME="AEN3289" |
0 | 77 ></A |
78 ><H2 | |
79 >Name</H2 | |
80 >SDL_Event -- General event structure</DIV | |
81 ><DIV | |
82 CLASS="REFSECT1" | |
83 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
84 NAME="AEN3292" |
0 | 85 ></A |
86 ><H2 | |
87 >Structure Definition</H2 | |
88 ><PRE | |
89 CLASS="PROGRAMLISTING" | |
90 >typedef union{ | |
91 Uint8 type; | |
92 SDL_ActiveEvent active; | |
93 SDL_KeyboardEvent key; | |
94 SDL_MouseMotionEvent motion; | |
95 SDL_MouseButtonEvent button; | |
96 SDL_JoyAxisEvent jaxis; | |
97 SDL_JoyBallEvent jball; | |
98 SDL_JoyHatEvent jhat; | |
99 SDL_JoyButtonEvent jbutton; | |
100 SDL_ResizeEvent resize; | |
101 SDL_QuitEvent quit; | |
102 SDL_UserEvent user; | |
103 SDL_SywWMEvent syswm; | |
104 } SDL_Event;</PRE | |
105 ></DIV | |
106 ><DIV | |
107 CLASS="REFSECT1" | |
108 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
109 NAME="AEN3295" |
0 | 110 ></A |
111 ><H2 | |
112 >Structure Data</H2 | |
113 ><DIV | |
114 CLASS="INFORMALTABLE" | |
115 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
116 NAME="AEN3297" |
0 | 117 ></A |
118 ><P | |
119 ></P | |
120 ><TABLE | |
121 BORDER="0" | |
122 CLASS="CALSTABLE" | |
123 ><TBODY | |
124 ><TR | |
125 ><TD | |
126 ALIGN="LEFT" | |
127 VALIGN="TOP" | |
128 ><TT | |
129 CLASS="STRUCTFIELD" | |
130 ><I | |
131 >type</I | |
132 ></TT | |
133 ></TD | |
134 ><TD | |
135 ALIGN="LEFT" | |
136 VALIGN="TOP" | |
137 >The type of event</TD | |
138 ></TR | |
139 ><TR | |
140 ><TD | |
141 ALIGN="LEFT" | |
142 VALIGN="TOP" | |
143 ><TT | |
144 CLASS="STRUCTFIELD" | |
145 ><I | |
146 >active</I | |
147 ></TT | |
148 ></TD | |
149 ><TD | |
150 ALIGN="LEFT" | |
151 VALIGN="TOP" | |
152 ><A | |
153 HREF="sdlactiveevent.html" | |
154 >Activation event</A | |
155 ></TD | |
156 ></TR | |
157 ><TR | |
158 ><TD | |
159 ALIGN="LEFT" | |
160 VALIGN="TOP" | |
161 ><TT | |
162 CLASS="STRUCTFIELD" | |
163 ><I | |
164 >key</I | |
165 ></TT | |
166 ></TD | |
167 ><TD | |
168 ALIGN="LEFT" | |
169 VALIGN="TOP" | |
170 ><A | |
171 HREF="sdlkeyboardevent.html" | |
172 >Keyboard event</A | |
173 ></TD | |
174 ></TR | |
175 ><TR | |
176 ><TD | |
177 ALIGN="LEFT" | |
178 VALIGN="TOP" | |
179 ><TT | |
180 CLASS="STRUCTFIELD" | |
181 ><I | |
182 >motion</I | |
183 ></TT | |
184 ></TD | |
185 ><TD | |
186 ALIGN="LEFT" | |
187 VALIGN="TOP" | |
188 ><A | |
189 HREF="sdlmousemotionevent.html" | |
190 >Mouse motion event</A | |
191 ></TD | |
192 ></TR | |
193 ><TR | |
194 ><TD | |
195 ALIGN="LEFT" | |
196 VALIGN="TOP" | |
197 ><TT | |
198 CLASS="STRUCTFIELD" | |
199 ><I | |
200 >button</I | |
201 ></TT | |
202 ></TD | |
203 ><TD | |
204 ALIGN="LEFT" | |
205 VALIGN="TOP" | |
206 ><A | |
207 HREF="sdlmousebuttonevent.html" | |
208 >Mouse button event</A | |
209 ></TD | |
210 ></TR | |
211 ><TR | |
212 ><TD | |
213 ALIGN="LEFT" | |
214 VALIGN="TOP" | |
215 ><TT | |
216 CLASS="STRUCTFIELD" | |
217 ><I | |
218 >jaxis</I | |
219 ></TT | |
220 ></TD | |
221 ><TD | |
222 ALIGN="LEFT" | |
223 VALIGN="TOP" | |
224 ><A | |
225 HREF="sdljoyaxisevent.html" | |
226 >Joystick axis motion event</A | |
227 ></TD | |
228 ></TR | |
229 ><TR | |
230 ><TD | |
231 ALIGN="LEFT" | |
232 VALIGN="TOP" | |
233 ><TT | |
234 CLASS="STRUCTFIELD" | |
235 ><I | |
236 >jball</I | |
237 ></TT | |
238 ></TD | |
239 ><TD | |
240 ALIGN="LEFT" | |
241 VALIGN="TOP" | |
242 ><A | |
243 HREF="sdljoyballevent.html" | |
244 >Joystick trackball motion event</A | |
245 ></TD | |
246 ></TR | |
247 ><TR | |
248 ><TD | |
249 ALIGN="LEFT" | |
250 VALIGN="TOP" | |
251 ><TT | |
252 CLASS="STRUCTFIELD" | |
253 ><I | |
254 >jhat</I | |
255 ></TT | |
256 ></TD | |
257 ><TD | |
258 ALIGN="LEFT" | |
259 VALIGN="TOP" | |
260 ><A | |
261 HREF="sdljoyhatevent.html" | |
262 >Joystick hat motion event</A | |
263 ></TD | |
264 ></TR | |
265 ><TR | |
266 ><TD | |
267 ALIGN="LEFT" | |
268 VALIGN="TOP" | |
269 ><TT | |
270 CLASS="STRUCTFIELD" | |
271 ><I | |
272 >jbutton</I | |
273 ></TT | |
274 ></TD | |
275 ><TD | |
276 ALIGN="LEFT" | |
277 VALIGN="TOP" | |
278 ><A | |
279 HREF="sdljoybuttonevent.html" | |
280 >Joystick button event</A | |
281 ></TD | |
282 ></TR | |
283 ><TR | |
284 ><TD | |
285 ALIGN="LEFT" | |
286 VALIGN="TOP" | |
287 ><TT | |
288 CLASS="STRUCTFIELD" | |
289 ><I | |
290 >resize</I | |
291 ></TT | |
292 ></TD | |
293 ><TD | |
294 ALIGN="LEFT" | |
295 VALIGN="TOP" | |
296 ><A | |
297 HREF="sdlresizeevent.html" | |
298 >Application window resize event</A | |
299 ></TD | |
300 ></TR | |
301 ><TR | |
302 ><TD | |
303 ALIGN="LEFT" | |
304 VALIGN="TOP" | |
305 ><TT | |
306 CLASS="STRUCTFIELD" | |
307 ><I | |
308 >quit</I | |
309 ></TT | |
310 ></TD | |
311 ><TD | |
312 ALIGN="LEFT" | |
313 VALIGN="TOP" | |
314 ><A | |
315 HREF="sdlquitevent.html" | |
316 >Application quit request event</A | |
317 ></TD | |
318 ></TR | |
319 ><TR | |
320 ><TD | |
321 ALIGN="LEFT" | |
322 VALIGN="TOP" | |
323 ><TT | |
324 CLASS="STRUCTFIELD" | |
325 ><I | |
326 >user</I | |
327 ></TT | |
328 ></TD | |
329 ><TD | |
330 ALIGN="LEFT" | |
331 VALIGN="TOP" | |
332 ><A | |
333 HREF="sdluserevent.html" | |
334 >User defined event</A | |
335 ></TD | |
336 ></TR | |
337 ><TR | |
338 ><TD | |
339 ALIGN="LEFT" | |
340 VALIGN="TOP" | |
341 ><TT | |
342 CLASS="STRUCTFIELD" | |
343 ><I | |
344 >syswm</I | |
345 ></TT | |
346 ></TD | |
347 ><TD | |
348 ALIGN="LEFT" | |
349 VALIGN="TOP" | |
350 ><A | |
351 HREF="sdlsyswmevent.html" | |
352 >Undefined window manager event</A | |
353 ></TD | |
354 ></TR | |
355 ></TBODY | |
356 ></TABLE | |
357 ><P | |
358 ></P | |
359 ></DIV | |
360 ></DIV | |
361 ><DIV | |
362 CLASS="REFSECT1" | |
363 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
364 NAME="AEN3364" |
0 | 365 ></A |
366 ><H2 | |
367 >Description</H2 | |
368 ><P | |
369 >The <SPAN | |
370 CLASS="STRUCTNAME" | |
371 >SDL_Event</SPAN | |
372 > union is the core to all event handling is SDL, its probably the most important structure after <SPAN | |
373 CLASS="STRUCTNAME" | |
374 >SDL_Surface</SPAN | |
375 >. <SPAN | |
376 CLASS="STRUCTNAME" | |
377 >SDL_Event</SPAN | |
378 > is a union of all event structures used in SDL, using it is a simple matter of knowing which union member relates to which event <TT | |
379 CLASS="STRUCTFIELD" | |
380 ><I | |
381 >type</I | |
382 ></TT | |
383 >.</P | |
384 ><P | |
385 ><DIV | |
386 CLASS="INFORMALTABLE" | |
387 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
388 NAME="AEN3372" |
0 | 389 ></A |
390 ><P | |
391 ></P | |
392 ><TABLE | |
393 BORDER="1" | |
394 CLASS="CALSTABLE" | |
395 ><THEAD | |
396 ><TR | |
397 ><TH | |
398 ALIGN="LEFT" | |
399 VALIGN="TOP" | |
400 >Event <TT | |
401 CLASS="STRUCTFIELD" | |
402 ><I | |
403 >type</I | |
404 ></TT | |
405 ></TH | |
406 ><TH | |
407 ALIGN="LEFT" | |
408 VALIGN="TOP" | |
409 >Event Structure</TH | |
410 ></TR | |
411 ></THEAD | |
412 ><TBODY | |
413 ><TR | |
414 ><TD | |
415 ALIGN="LEFT" | |
416 VALIGN="MIDDLE" | |
417 ><TT | |
418 CLASS="LITERAL" | |
419 >SDL_ACTIVEEVENT</TT | |
420 ></TD | |
421 ><TD | |
422 ALIGN="LEFT" | |
423 VALIGN="MIDDLE" | |
424 ><A | |
425 HREF="sdlactiveevent.html" | |
426 ><SPAN | |
427 CLASS="STRUCTNAME" | |
428 >SDL_ActiveEvent</SPAN | |
429 ></A | |
430 ></TD | |
431 ></TR | |
432 ><TR | |
433 ><TD | |
434 ALIGN="LEFT" | |
435 VALIGN="TOP" | |
436 ><TT | |
437 CLASS="LITERAL" | |
438 >SDL_KEYDOWN/UP</TT | |
439 ></TD | |
440 ><TD | |
441 ALIGN="LEFT" | |
442 VALIGN="TOP" | |
443 ><A | |
444 HREF="sdlkeyboardevent.html" | |
445 ><SPAN | |
446 CLASS="STRUCTNAME" | |
447 >SDL_KeyboardEvent</SPAN | |
448 ></A | |
449 ></TD | |
450 ></TR | |
451 ><TR | |
452 ><TD | |
453 ALIGN="LEFT" | |
454 VALIGN="TOP" | |
455 ><TT | |
456 CLASS="LITERAL" | |
457 >SDL_MOUSEMOTION</TT | |
458 ></TD | |
459 ><TD | |
460 ALIGN="LEFT" | |
461 VALIGN="TOP" | |
462 ><A | |
463 HREF="sdlmousemotionevent.html" | |
464 ><SPAN | |
465 CLASS="STRUCTNAME" | |
466 >SDL_MouseMotionEvent</SPAN | |
467 ></A | |
468 ></TD | |
469 ></TR | |
470 ><TR | |
471 ><TD | |
472 ALIGN="LEFT" | |
473 VALIGN="TOP" | |
474 ><TT | |
475 CLASS="LITERAL" | |
476 >SDL_MOUSEBUTTONDOWN/UP</TT | |
477 ></TD | |
478 ><TD | |
479 ALIGN="LEFT" | |
480 VALIGN="TOP" | |
481 ><A | |
482 HREF="sdlmousebuttonevent.html" | |
483 ><SPAN | |
484 CLASS="STRUCTNAME" | |
485 >SDL_MouseButtonEvent</SPAN | |
486 ></A | |
487 ></TD | |
488 ></TR | |
489 ><TR | |
490 ><TD | |
491 ALIGN="LEFT" | |
492 VALIGN="TOP" | |
493 ><TT | |
494 CLASS="LITERAL" | |
495 >SDL_JOYAXISMOTION</TT | |
496 ></TD | |
497 ><TD | |
498 ALIGN="LEFT" | |
499 VALIGN="TOP" | |
500 ><A | |
501 HREF="sdljoyaxisevent.html" | |
502 ><SPAN | |
503 CLASS="STRUCTNAME" | |
504 >SDL_JoyAxisEvent</SPAN | |
505 ></A | |
506 ></TD | |
507 ></TR | |
508 ><TR | |
509 ><TD | |
510 ALIGN="LEFT" | |
511 VALIGN="TOP" | |
512 ><TT | |
513 CLASS="LITERAL" | |
514 >SDL_JOYBALLMOTION</TT | |
515 ></TD | |
516 ><TD | |
517 ALIGN="LEFT" | |
518 VALIGN="TOP" | |
519 ><A | |
520 HREF="sdljoyballevent.html" | |
521 ><SPAN | |
522 CLASS="STRUCTNAME" | |
523 >SDL_JoyBallEvent</SPAN | |
524 ></A | |
525 ></TD | |
526 ></TR | |
527 ><TR | |
528 ><TD | |
529 ALIGN="LEFT" | |
530 VALIGN="TOP" | |
531 ><TT | |
532 CLASS="LITERAL" | |
533 >SDL_JOYHATMOTION</TT | |
534 ></TD | |
535 ><TD | |
536 ALIGN="LEFT" | |
537 VALIGN="TOP" | |
538 ><A | |
539 HREF="sdljoyhatevent.html" | |
540 ><SPAN | |
541 CLASS="STRUCTNAME" | |
542 >SDL_JoyHatEvent</SPAN | |
543 ></A | |
544 ></TD | |
545 ></TR | |
546 ><TR | |
547 ><TD | |
548 ALIGN="LEFT" | |
549 VALIGN="TOP" | |
550 ><TT | |
551 CLASS="LITERAL" | |
552 >SDL_JOYBUTTONDOWN/UP</TT | |
553 ></TD | |
554 ><TD | |
555 ALIGN="LEFT" | |
556 VALIGN="TOP" | |
557 ><A | |
558 HREF="sdljoybuttonevent.html" | |
559 ><SPAN | |
560 CLASS="STRUCTNAME" | |
561 >SDL_JoyButtonEvent</SPAN | |
562 ></A | |
563 ></TD | |
564 ></TR | |
565 ><TR | |
566 ><TD | |
567 ALIGN="LEFT" | |
568 VALIGN="TOP" | |
569 ><TT | |
570 CLASS="LITERAL" | |
571 >SDL_QUIT</TT | |
572 ></TD | |
573 ><TD | |
574 ALIGN="LEFT" | |
575 VALIGN="TOP" | |
576 ><A | |
577 HREF="sdlquitevent.html" | |
578 ><SPAN | |
579 CLASS="STRUCTNAME" | |
580 >SDL_QuitEvent</SPAN | |
581 ></A | |
582 ></TD | |
583 ></TR | |
584 ><TR | |
585 ><TD | |
586 ALIGN="LEFT" | |
587 VALIGN="TOP" | |
588 ><TT | |
589 CLASS="LITERAL" | |
590 >SDL_SYSWMEVENT</TT | |
591 ></TD | |
592 ><TD | |
593 ALIGN="LEFT" | |
594 VALIGN="TOP" | |
595 ><A | |
596 HREF="sdlsyswmevent.html" | |
597 ><SPAN | |
598 CLASS="STRUCTNAME" | |
599 >SDL_SysWMEvent</SPAN | |
600 ></A | |
601 ></TD | |
602 ></TR | |
603 ><TR | |
604 ><TD | |
605 ALIGN="LEFT" | |
606 VALIGN="TOP" | |
607 ><TT | |
608 CLASS="LITERAL" | |
609 >SDL_VIDEORESIZE</TT | |
610 ></TD | |
611 ><TD | |
612 ALIGN="LEFT" | |
613 VALIGN="TOP" | |
614 ><A | |
615 HREF="sdlresizeevent.html" | |
616 ><SPAN | |
617 CLASS="STRUCTNAME" | |
618 >SDL_ResizeEvent</SPAN | |
619 ></A | |
620 ></TD | |
621 ></TR | |
622 ><TR | |
623 ><TD | |
624 ALIGN="LEFT" | |
625 VALIGN="TOP" | |
626 ><TT | |
627 CLASS="LITERAL" | |
628 >SDL_USEREVENT</TT | |
629 ></TD | |
630 ><TD | |
631 ALIGN="LEFT" | |
632 VALIGN="TOP" | |
633 ><A | |
634 HREF="sdluserevent.html" | |
635 ><SPAN | |
636 CLASS="STRUCTNAME" | |
637 >SDL_UserEvent</SPAN | |
638 ></A | |
639 ></TD | |
640 ></TR | |
641 ></TBODY | |
642 ></TABLE | |
643 ><P | |
644 ></P | |
645 ></DIV | |
646 ></P | |
647 ></DIV | |
648 ><DIV | |
649 CLASS="REFSECT1" | |
650 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
651 NAME="AEN3452" |
0 | 652 ></A |
653 ><H2 | |
654 >Use</H2 | |
655 ><P | |
656 >The <SPAN | |
657 CLASS="STRUCTNAME" | |
658 >SDL_Event</SPAN | |
659 > structure has two uses</P | |
660 ><P | |
661 ></P | |
662 ><UL | |
663 COMPACT="COMPACT" | |
664 ><LI | |
665 ><P | |
666 >Reading events on the event queue</P | |
667 ></LI | |
668 ><LI | |
669 ><P | |
670 >Placing events on the event queue</P | |
671 ></LI | |
672 ></UL | |
673 ><P | |
674 >Reading events from the event queue is done with either <A | |
675 HREF="sdlpollevent.html" | |
676 ><TT | |
677 CLASS="FUNCTION" | |
678 >SDL_PollEvent</TT | |
679 ></A | |
680 > or <A | |
681 HREF="sdlpeepevents.html" | |
682 ><TT | |
683 CLASS="FUNCTION" | |
684 >SDL_PeepEvents</TT | |
685 ></A | |
686 >. We'll use <TT | |
687 CLASS="FUNCTION" | |
688 >SDL_PollEvent</TT | |
689 > and step through an example.</P | |
690 ><P | |
691 >First off, we create an empty <SPAN | |
692 CLASS="STRUCTNAME" | |
693 >SDL_Event</SPAN | |
694 > structure. | |
695 <PRE | |
696 CLASS="PROGRAMLISTING" | |
697 >SDL_Event test_event;</PRE | |
698 > | |
699 <TT | |
700 CLASS="FUNCTION" | |
701 >SDL_PollEvent</TT | |
702 > removes the next event from the event queue, if there are no events on the queue it returns <SPAN | |
703 CLASS="RETURNVALUE" | |
704 >0</SPAN | |
705 > otherwise it returns <SPAN | |
706 CLASS="RETURNVALUE" | |
707 >1</SPAN | |
708 >. We use a <TT | |
709 CLASS="FUNCTION" | |
710 >while</TT | |
711 > loop to process each event in turn. | |
712 <PRE | |
713 CLASS="PROGRAMLISTING" | |
714 >while(SDL_PollEvent(&test_event)) {</PRE | |
715 > | |
716 The <TT | |
717 CLASS="FUNCTION" | |
718 >SDL_PollEvent</TT | |
719 > function take a pointer to an <SPAN | |
720 CLASS="STRUCTNAME" | |
721 >SDL_Event</SPAN | |
722 > structure that is to be filled with event information. We know that if <TT | |
723 CLASS="FUNCTION" | |
724 >SDL_PollEvent</TT | |
725 > removes an event from the queue then the event information will be placed in our <SPAN | |
726 CLASS="STRUCTNAME" | |
727 >test_event</SPAN | |
728 > structure, but we also know that the <I | |
729 CLASS="EMPHASIS" | |
730 >type</I | |
731 > of event will be placed in the <TT | |
732 CLASS="STRUCTFIELD" | |
733 ><I | |
734 >type</I | |
735 ></TT | |
736 > member of <SPAN | |
737 CLASS="STRUCTNAME" | |
738 >test_event</SPAN | |
739 >. So to handle each event <TT | |
740 CLASS="STRUCTFIELD" | |
741 ><I | |
742 >type</I | |
743 ></TT | |
744 > seperately we use a <TT | |
745 CLASS="FUNCTION" | |
746 >switch</TT | |
747 > statement. | |
748 <PRE | |
749 CLASS="PROGRAMLISTING" | |
750 > switch(test_event.type) {</PRE | |
751 > | |
752 We need to know what kind of events we're looking for <I | |
753 CLASS="EMPHASIS" | |
754 >and</I | |
755 > the event <TT | |
756 CLASS="STRUCTFIELD" | |
757 ><I | |
758 >type</I | |
759 ></TT | |
760 >'s of those events. So lets assume we want to detect where the user is moving the mouse pointer within our application. We look through our event types and notice that <TT | |
761 CLASS="LITERAL" | |
762 >SDL_MOUSEMOTION</TT | |
763 > is, more than likely, the event we're looking for. A little <A | |
764 HREF="sdlmousemotionevent.html" | |
765 >more</A | |
766 > research tells use that <TT | |
767 CLASS="LITERAL" | |
768 >SDL_MOUSEMOTION</TT | |
769 > events are handled within the <A | |
770 HREF="sdlmousemotionevent.html" | |
771 ><SPAN | |
772 CLASS="STRUCTNAME" | |
773 >SDL_MouseMotionEvent</SPAN | |
774 ></A | |
775 > structure which is the <TT | |
776 CLASS="STRUCTFIELD" | |
777 ><I | |
778 >motion</I | |
779 ></TT | |
780 > member of <SPAN | |
781 CLASS="STRUCTNAME" | |
782 >SDL_Event</SPAN | |
783 >. We can check for the <TT | |
784 CLASS="LITERAL" | |
785 >SDL_MOUSEMOTION</TT | |
786 > event <TT | |
787 CLASS="STRUCTFIELD" | |
788 ><I | |
789 >type</I | |
790 ></TT | |
791 > within our <TT | |
792 CLASS="FUNCTION" | |
793 >switch</TT | |
794 > statement like so: | |
795 <PRE | |
796 CLASS="PROGRAMLISTING" | |
797 > case SDL_MOUSEMOTION:</PRE | |
798 > | |
799 All we need do now is read the information out of the <TT | |
800 CLASS="STRUCTFIELD" | |
801 ><I | |
802 >motion</I | |
803 ></TT | |
804 > member of <SPAN | |
805 CLASS="STRUCTNAME" | |
806 >test_event</SPAN | |
807 >. | |
808 <PRE | |
809 CLASS="PROGRAMLISTING" | |
810 > printf("We got a motion event.\n"); | |
811 printf("Current mouse position is: (%d, %d)\n", test_event.motion.x, test_event.motion.y); | |
812 break; | |
813 default: | |
814 printf("Unhandled Event!\n"); | |
815 break; | |
816 } | |
817 } | |
818 printf("Event queue empty.\n");</PRE | |
819 ></P | |
820 ><P | |
821 >It is also possible to push events onto the event queue and so use it as a two-way communication path. Both <A | |
822 HREF="sdlpushevent.html" | |
823 ><TT | |
824 CLASS="FUNCTION" | |
825 >SDL_PushEvent</TT | |
826 ></A | |
827 > and <A | |
828 HREF="sdlpeepevents.html" | |
829 ><TT | |
830 CLASS="FUNCTION" | |
831 >SDL_PeepEvents</TT | |
832 ></A | |
833 > allow you to place events onto the event queue. This is usually used to place a <TT | |
834 CLASS="LITERAL" | |
835 >SDL_USEREVENT</TT | |
836 > on the event queue, however you could use it to post fake input events if you wished. Creating your own events is a simple matter of choosing the event type you want, setting the <TT | |
837 CLASS="STRUCTFIELD" | |
838 ><I | |
839 >type</I | |
840 ></TT | |
841 > member and filling the appropriate member structure with information. | |
842 <PRE | |
843 CLASS="PROGRAMLISTING" | |
844 >SDL_Event user_event; | |
845 | |
846 user_event.type=SDL_USEREVENT; | |
847 user_event.user.code=2; | |
848 user_event.user.data1=NULL; | |
849 user_event.user.data2=NULL; | |
850 SDL_PushEvent(&user_event);</PRE | |
851 ></P | |
852 ></DIV | |
853 ><DIV | |
854 CLASS="REFSECT1" | |
855 ><A | |
55
55f1f1b3e27d
Added new docs for SDL 1.2.1
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
856 NAME="AEN3509" |
0 | 857 ></A |
858 ><H2 | |
859 >See Also</H2 | |
860 ><P | |
861 ><A | |
862 HREF="sdlpollevent.html" | |
863 ><TT | |
864 CLASS="FUNCTION" | |
865 >SDL_PollEvent</TT | |
866 ></A | |
867 >, | |
868 <A | |
869 HREF="sdlpushevent.html" | |
870 ><TT | |
871 CLASS="FUNCTION" | |
872 >SDL_PushEvent</TT | |
873 ></A | |
874 >, | |
875 <A | |
876 HREF="sdlpeepevents.html" | |
877 ><TT | |
878 CLASS="FUNCTION" | |
879 >SDL_PeepEvents</TT | |
880 ></A | |
881 ></P | |
882 ></DIV | |
883 ><DIV | |
884 CLASS="NAVFOOTER" | |
885 ><HR | |
886 ALIGN="LEFT" | |
887 WIDTH="100%"><TABLE | |
888 WIDTH="100%" | |
889 BORDER="0" | |
890 CELLPADDING="0" | |
891 CELLSPACING="0" | |
892 ><TR | |
893 ><TD | |
894 WIDTH="33%" | |
895 ALIGN="left" | |
896 VALIGN="top" | |
897 ><A | |
898 HREF="eventstructures.html" | |
899 >Prev</A | |
900 ></TD | |
901 ><TD | |
902 WIDTH="34%" | |
903 ALIGN="center" | |
904 VALIGN="top" | |
905 ><A | |
906 HREF="index.html" | |
907 >Home</A | |
908 ></TD | |
909 ><TD | |
910 WIDTH="33%" | |
911 ALIGN="right" | |
912 VALIGN="top" | |
913 ><A | |
914 HREF="sdlactiveevent.html" | |
915 >Next</A | |
916 ></TD | |
917 ></TR | |
918 ><TR | |
919 ><TD | |
920 WIDTH="33%" | |
921 ALIGN="left" | |
922 VALIGN="top" | |
923 >SDL Event Structures.</TD | |
924 ><TD | |
925 WIDTH="34%" | |
926 ALIGN="center" | |
927 VALIGN="top" | |
928 ><A | |
929 HREF="eventstructures.html" | |
930 >Up</A | |
931 ></TD | |
932 ><TD | |
933 WIDTH="33%" | |
934 ALIGN="right" | |
935 VALIGN="top" | |
936 >SDL_ActiveEvent</TD | |
937 ></TR | |
938 ></TABLE | |
939 ></DIV | |
940 ></BODY | |
941 ></HTML | |
942 > |