7 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
10 TITLE="SDL Library Documentation"
11 HREF="index.html"><LINK
13 TITLE="SDL Event Structures."
14 HREF="eventstructures.html"><LINK
16 TITLE="SDL Event Structures."
17 HREF="eventstructures.html"><LINK
19 TITLE="SDL_ActiveEvent"
20 HREF="sdlactiveevent.html"></HEAD
31 SUMMARY="Header navigation table"
40 >SDL Library Documentation</TH
48 HREF="eventstructures.html"
62 HREF="sdlactiveevent.html"
83 >SDL_Event -- General event structure</DIV
90 >Structure Definition</H2
92 CLASS="PROGRAMLISTING"
95 SDL_ActiveEvent active;
96 SDL_KeyboardEvent key;
97 SDL_MouseMotionEvent motion;
98 SDL_MouseButtonEvent button;
99 SDL_JoyAxisEvent jaxis;
100 SDL_JoyBallEvent jball;
101 SDL_JoyHatEvent jhat;
102 SDL_JoyButtonEvent jbutton;
103 SDL_ResizeEvent resize;
104 SDL_ExposeEvent expose;
107 SDL_SysWMEvent syswm;
118 CLASS="INFORMALTABLE"
141 >The type of event</TD
157 HREF="sdlactiveevent.html"
175 HREF="sdlkeyboardevent.html"
193 HREF="sdlmousemotionevent.html"
194 >Mouse motion event</A
211 HREF="sdlmousebuttonevent.html"
212 >Mouse button event</A
229 HREF="sdljoyaxisevent.html"
230 >Joystick axis motion event</A
247 HREF="sdljoyballevent.html"
248 >Joystick trackball motion event</A
265 HREF="sdljoyhatevent.html"
266 >Joystick hat motion event</A
283 HREF="sdljoybuttonevent.html"
284 >Joystick button event</A
301 HREF="sdlresizeevent.html"
302 >Application window resize event</A
319 HREF="sdlexposeevent.html"
320 >Application window expose event</A
337 HREF="sdlquitevent.html"
338 >Application quit request event</A
355 HREF="sdluserevent.html"
356 >User defined event</A
373 HREF="sdlsyswmevent.html"
374 >Undefined window manager event</A
394 > union is the core to all event handling is SDL, its probably the most important structure after <SPAN
400 > 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
408 CLASS="INFORMALTABLE"
447 HREF="sdlactiveevent.html"
450 >SDL_ActiveEvent</SPAN
466 HREF="sdlkeyboardevent.html"
469 >SDL_KeyboardEvent</SPAN
485 HREF="sdlmousemotionevent.html"
488 >SDL_MouseMotionEvent</SPAN
498 >SDL_MOUSEBUTTONDOWN/UP</TT
504 HREF="sdlmousebuttonevent.html"
507 >SDL_MouseButtonEvent</SPAN
517 >SDL_JOYAXISMOTION</TT
523 HREF="sdljoyaxisevent.html"
526 >SDL_JoyAxisEvent</SPAN
536 >SDL_JOYBALLMOTION</TT
542 HREF="sdljoyballevent.html"
545 >SDL_JoyBallEvent</SPAN
555 >SDL_JOYHATMOTION</TT
561 HREF="sdljoyhatevent.html"
564 >SDL_JoyHatEvent</SPAN
574 >SDL_JOYBUTTONDOWN/UP</TT
580 HREF="sdljoybuttonevent.html"
583 >SDL_JoyButtonEvent</SPAN
599 HREF="sdlquitevent.html"
618 HREF="sdlsyswmevent.html"
621 >SDL_SysWMEvent</SPAN
637 HREF="sdlresizeevent.html"
640 >SDL_ResizeEvent</SPAN
656 HREF="sdlexposeevent.html"
659 >SDL_ExposeEvent</SPAN
675 HREF="sdluserevent.html"
700 > structure has two uses</P
707 >Reading events on the event queue</P
711 >Placing events on the event queue</P
715 >Reading events from the event queue is done with either <A
716 HREF="sdlpollevent.html"
722 HREF="sdlpeepevents.html"
730 > and step through an example.</P
732 >First off, we create an empty <SPAN
737 CLASS="PROGRAMLISTING"
738 >SDL_Event test_event;</PRE
743 > removes the next event from the event queue, if there are no events on the queue it returns <SPAN
746 > otherwise it returns <SPAN
752 > loop to process each event in turn.
754 CLASS="PROGRAMLISTING"
755 >while(SDL_PollEvent(&test_event)) {</PRE
760 > function take a pointer to an <SPAN
763 > structure that is to be filled with event information. We know that if <TT
766 > removes an event from the queue then the event information will be placed in our <SPAN
769 > structure, but we also know that the <SPAN
775 > of event will be placed in the <TT
783 >. So to handle each event <TT
788 > seperately we use a <TT
793 CLASS="PROGRAMLISTING"
794 > switch(test_event.type) {</PRE
796 We need to know what kind of events we're looking for <SPAN
807 >'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
810 > is, more than likely, the event we're looking for. A little <A
811 HREF="sdlmousemotionevent.html"
813 > research tells use that <TT
816 > events are handled within the <A
817 HREF="sdlmousemotionevent.html"
820 >SDL_MouseMotionEvent</SPAN
822 > structure which is the <TT
830 >. We can check for the <TT
843 CLASS="PROGRAMLISTING"
844 > case SDL_MOUSEMOTION:</PRE
846 All we need do now is read the information out of the <TT
856 CLASS="PROGRAMLISTING"
857 > printf("We got a motion event.\n");
858 printf("Current mouse position is: (%d, %d)\n", test_event.motion.x, test_event.motion.y);
861 printf("Unhandled Event!\n");
865 printf("Event queue empty.\n");</PRE
868 >It is also possible to push events onto the event queue and so use it as a two-way communication path. Both <A
869 HREF="sdlpushevent.html"
875 HREF="sdlpeepevents.html"
880 > allow you to place events onto the event queue. This is usually used to place a <TT
883 > 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
888 > member and filling the appropriate member structure with information.
890 CLASS="PROGRAMLISTING"
891 >SDL_Event user_event;
893 user_event.type=SDL_USEREVENT;
894 user_event.user.code=2;
895 user_event.user.data1=NULL;
896 user_event.user.data2=NULL;
897 SDL_PushEvent(&user_event);</PRE
909 HREF="sdlpollevent.html"
916 HREF="sdlpushevent.html"
923 HREF="sdlpeepevents.html"
935 SUMMARY="Footer navigation table"
946 HREF="eventstructures.html"
964 HREF="sdlactiveevent.html"
974 >SDL Event Structures.</TD
980 HREF="eventstructures.html"