home *** CD-ROM | disk | FTP | other *** search
- <!-- manual page source format generated by PolyglotMan v3.0.8+X.Org, -->
- <!-- available at http://polyglotman.sourceforge.net/ -->
-
- <html>
- <head>
- <title>"SDL_Event"("3") manual page</title>
- </head>
- <body bgcolor='#efefef' text='black' link='blue' vlink='#551A8B' alink='red'>
- <a href='#toc'>Table of Contents</a><p>
-
- <h2><a name='sect0' href='#toc0'>Name</a></h2>
- SDL_Event- General event structure
- <h2><a name='sect1' href='#toc1'>Structure Definition</a></h2>
- <p>
- <br>
- <pre>CWtypedef union{
- Uint8 type;
- SDL_ActiveEvent active;
- SDL_KeyboardEvent key;
- SDL_MouseMotionEvent motion;
- SDL_MouseButtonEvent button;
- SDL_JoyAxisEvent jaxis;
- SDL_JoyBallEvent jball;
- SDL_JoyHatEvent jhat;
- SDL_JoyButtonEvent jbutton;
- SDL_ResizeEvent resize;
- SDL_ExposeEvent expose;
- SDL_QuitEvent quit;
- SDL_UserEvent user;
- SDL_SywWMEvent syswm;
- } SDL_Event;
- </pre><p>
-
- <h2><a name='sect2' href='#toc2'>Structure Data</a></h2>
-
- <dl>
-
- <dt><b>type</b> </dt>
- <dd>The type of event </dd>
-
- <dt><b>active</b> </dt>
- <dd><i>Activation event</i> </dd>
-
- <dt><b>key</b> </dt>
- <dd><i>Keyboard
- event</i> </dd>
-
- <dt><b>motion</b> </dt>
- <dd><i>Mouse motion event</i> </dd>
-
- <dt><b>button</b> </dt>
- <dd><i>Mouse button event</i> </dd>
-
- <dt><b>jaxis</b> </dt>
- <dd><i>Joystick
- axis motion event</i> </dd>
-
- <dt><b>jball</b> </dt>
- <dd><i>Joystick trackball motion event</i> </dd>
-
- <dt><b>jhat</b> </dt>
- <dd><i>Joystick hat
- motion event</i> </dd>
-
- <dt><b>jbutton</b> </dt>
- <dd><i>Joystick button event</i> </dd>
-
- <dt><b>resize</b> </dt>
- <dd><i>Application window resize
- event</i> </dd>
-
- <dt><b>expose</b> </dt>
- <dd><i>Application window expose event</i> </dd>
-
- <dt><b>quit</b> </dt>
- <dd><i>Application quit request
- event</i> </dd>
-
- <dt><b>user</b> </dt>
- <dd><i>User defined event</i> </dd>
-
- <dt><b>syswm</b> </dt>
- <dd><i>Undefined window manager event</i> </dd>
- </dl>
-
- <h2><a name='sect3' href='#toc3'>Description</a></h2>
- <p>
- The
- <b>SDL_Event</b> union is the core to all event handling is SDL, its probably
- the most important structure after <b>SDL_Surface</b>. <b>SDL_Event</b> 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 <b>type</b>. <p>
-
- <dl>
-
- <dt><b>Event <b>type</b></b> </dt>
- <dd><b>Event Structure</b>
- </dd>
-
- <dt><b>SDL_ACTIVEEVENT</b> </dt>
- <dd><i><b>SDL_ActiveEvent</b></i> </dd>
-
- <dt><b>SDL_KEYDOWN/UP</b> </dt>
- <dd><i><b>SDL_KeyboardEvent</b></i> </dd>
-
- <dt><b>SDL_MOUSEMOTION</b>
- </dt>
- <dd><i><b>SDL_MouseMotionEvent</b></i> </dd>
-
- <dt><b>SDL_MOUSEBUTTONDOWN/UP</b> </dt>
- <dd><i><b>SDL_MouseButtonEvent</b></i> </dd>
-
- <dt><b>SDL_JOYAXISMOTION</b>
- </dt>
- <dd><i><b>SDL_JoyAxisEvent</b></i> </dd>
-
- <dt><b>SDL_JOYBALLMOTION</b> </dt>
- <dd><i><b>SDL_JoyBallEvent</b></i> </dd>
-
- <dt><b>SDL_JOYHATMOTION</b> </dt>
- <dd><i><b>SDL_JoyHatEvent</b></i>
- </dd>
-
- <dt><b>SDL_JOYBUTTONDOWN/UP</b> </dt>
- <dd><i><b>SDL_JoyButtonEvent</b></i> </dd>
-
- <dt><b>SDL_QUIT</b> </dt>
- <dd><i><b>SDL_QuitEvent</b></i> </dd>
-
- <dt><b>SDL_SYSWMEVENT</b>
- </dt>
- <dd><i><b>SDL_SysWMEvent</b></i> </dd>
-
- <dt><b>SDL_VIDEORESIZE</b> </dt>
- <dd><i><b>SDL_ResizeEvent</b></i> </dd>
-
- <dt><b>SDL_VIDEOEXPOSE</b> </dt>
- <dd><i><b>SDL_ExposeEvent</b></i>
- </dd>
-
- <dt><b>SDL_USEREVENT</b> </dt>
- <dd><i><b>SDL_UserEvent</b></i> </dd>
- </dl>
-
- <h2><a name='sect4' href='#toc4'>Use</a></h2>
- <p>
- The <b>SDL_Event</b> structure has two uses
- <dl>
-
- <dt>
- </dt>
- <dd>Reading events on the event queue </dd>
-
- <dt> </dt>
- <dd>Placing events on the event queue
- </dd>
- </dl>
- <p>
- Reading events from the event queue is done with either <i><b>SDL_PollEvent</b></i> or
- <i><b>SDL_PeepEvents</b></i>. We'll use <b>SDL_PollEvent</b> and step through an example. <p>
- First
- off, we create an empty <b>SDL_Event</b> structure. <p>
- <br>
- <pre>CWSDL_Event test_event;
- </pre><p>
- <b>SDL_PollEvent</b> removes the next event from the event queue, if there are
- no events on the queue it returns <b>0</b> otherwise it returns <b>1</b>. We use a <b>while</b>
- loop to process each event in turn. <br>
- <p>
- <br>
- <pre>CWwhile(SDL_PollEvent(&test_event)) {
- </pre><p>
- The <b>SDL_PollEvent</b> function take a pointer to an <b>SDL_Event</b> structure that
- is to be filled with event information. We know that if <b>SDL_PollEvent</b> removes
- an event from the queue then the event information will be placed in our
- <b>test_event</b> structure, but we also know that the <i>type</i> of event will be placed
- in the <b>type</b> member of <b>test_event</b>. So to handle each event <b>type</b> seperately
- we use a <b>switch</b> statement. <br>
- <p>
- <br>
- <pre>CW switch(test_event.type) {
- </pre><p>
- We need to know what kind of events we're looking for <i>and</i> the event <b>type</b>'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 <b>SDL_MOUSEMOTION</b> is, more than likely, the event we're looking
- for. A little <i>more</i> research tells use that <b>SDL_MOUSEMOTION</b> events are handled
- within the <i><b>SDL_MouseMotionEvent</b></i> structure which is the <b>motion</b> member of
- <b>SDL_Event</b>. We can check for the <b>SDL_MOUSEMOTION</b> event <b>type</b> within our <b>switch</b>
- statement like so: <br>
- <p>
- <br>
- <pre>CW case SDL_MOUSEMOTION:
- </pre><p>
- All we need do now is read the information out of the <b>motion</b> member of
- <b>test_event</b>. <br>
- <p>
- <br>
- <pre>CW printf("We got a motion event.
- ");
- printf("Current mouse position is: (%d, %d)
- ", test_event.motion.x, test_event.motion.y);
- break;
- default:
- printf("Unhandled Event!
- ");
- break;
- }
- }
- printf("Event queue empty.
- ");
- </pre><p>
- <p>
- It is also possible to push events onto the event queue and so use it as
- a two-way communication path. Both <i><b>SDL_PushEvent</b></i> and <i><b>SDL_PeepEvents</b></i> allow
- you to place events onto the event queue. This is usually used to place
- a <b>SDL_USEREVENT</b> 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 <b>type</b> member and filling
- the appropriate member structure with information. <p>
- <br>
- <pre>CWSDL_Event user_event;
- user_event.type=SDL_USEREVENT;
- user_event.user.code=2;
- user_event.user.data1=NULL;
- user_event.user.data2=NULL;
- SDL_PushEvent(&user_event);
- </pre><p>
-
- <h2><a name='sect5' href='#toc5'>See Also</a></h2>
- <p>
- <i><b>SDL_PollEvent</b></i>, <i><b>SDL_PushEvent</b></i>, <i><b>SDL_PeepEvents</b></i>
- <!--
-
- <p>
-
- <hr><p>
- <a name='toc'><b>Table of Contents</b></a><p>
- <ul>
- <li><a name='toc0' href='#sect0'>Name</a></li>
- <li><a name='toc1' href='#sect1'>Structure Definition</a></li>
- <li><a name='toc2' href='#sect2'>Structure Data</a></li>
- <li><a name='toc3' href='#sect3'>Description</a></li>
- <li><a name='toc4' href='#sect4'>Use</a></li>
- <li><a name='toc5' href='#sect5'>See Also</a></li>
- </ul>
- </body>
- </html>
-