Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
SDL_Event(3)
Edit
PageHistory
Diff
Info
LikePages
SDL_Event !!!SDL_Event NAME STRUCTURE DEFINITION STRUCTURE DATA DESCRIPTION USE SEE ALSO ---- !!NAME SDL_Event- General event structure !!STRUCTURE DEFINITION typedef 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_!QuitEvent quit; SDL_!UserEvent user; SDL_SywWMEvent syswm; } SDL_Event; !!STRUCTURE DATA __type__ The type of event __active__ ''Activation event'' __key__ ''Keyboard event'' __motion__ ''Mouse motion event'' __button__ ''Mouse button event'' __jaxis__ ''Joystick axis motion event'' __jball__ ''Joystick trackball motion event'' __jhat__ ''Joystick hat motion event'' __jbutton__ ''Joystick button event'' __resize__ ''Application window resize event'' __quit__ ''Application quit request event'' __user__ ''User defined event'' __syswm__ ''Undefined window manager event'' !!DESCRIPTION The __SDL_Event__ union is the core to all event handling is SDL, its probably the most important structure after __SDL_Surface__. __SDL_Event__ 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 __type__. __Event type Event Structure__ __SDL_ACTIVEEVENT__ __SDL_!ActiveEvent__ __SDL_KEYDOWN/UP__ __SDL_!KeyboardEvent__ __SDL_MOUSEMOTION__ __SDL_!MouseMotionEvent__ __SDL_MOUSEBUTTONDOWN/UP__ __SDL_!MouseButtonEvent__ __SDL_JOYAXISMOTION__ __SDL_!JoyAxisEvent__ __SDL_JOYBALLMOTION__ __SDL_!JoyBallEvent__ __SDL_JOYHATMOTION__ __SDL_!JoyHatEvent__ __SDL_JOYBUTTONDOWN/UP__ __SDL_!JoyButtonEvent__ __SDL_QUIT SDL_!QuitEvent__ __SDL_SYSWMEVENT__ __SDL_SysWMEvent__ __SDL_VIDEORESIZE__ __SDL_!ResizeEvent__ __SDL_USEREVENT__ __SDL_!UserEvent__ !!USE The __SDL_Event__ structure has two uses Reading events on the event queue Placing events on the event queue Reading events from the event queue is done with either __SDL_!PollEvent__ or __SDL_!PeepEvents__. We'll use __SDL_!PollEvent__ and step through an example. First off, we create an empty __SDL_Event__ structure. SDL_Event test_event; __SDL_!PollEvent__ removes the next event from the event queue, if there are no events on the queue it returns __0__ otherwise it returns __1__. We use a __while__ loop to process each event in turn. while(SDL_!PollEvent( The __SDL_!PollEvent__ function take a pointer to an __SDL_Event__ structure that is to be filled with event information. We know that if __SDL_!PollEvent__ removes an event from the queue then the event information will be placed in our __test_event__ structure, but we also know that the ''type'' of event will be placed in the __type__ member of __test_event__. So to handle each event __type__ seperately we use a __switch__ statement. switch(test_event.type) { We need to know what kind of events we're looking for ''and'' the event __type__'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 __SDL_MOUSEMOTION__ is, more than likely, the event we're looking for. A little ''more'' research tells use that __SDL_MOUSEMOTION__ events are handled within the __SDL_!MouseMotionEvent__ structure which is the __motion__ member of __SDL_Event__. We can check for the __SDL_MOUSEMOTION__ event __type__ within our __switch__ statement like so: case SDL_MOUSEMOTION: All we need do now is read the information out of the __motion__ member of __test_event__. printf( It is also possible to push events onto the event queue and so use it as a two-way communication path. Both __SDL_!PushEvent__ and __SDL_!PeepEvents__ allow you to place events onto the event queue. This is usually used to place a __SDL_USEREVENT__ 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 __type__ member and filling the appropriate member structure with information. SDL_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( !!SEE ALSO __SDL_!PollEvent__, __SDL_!PushEvent__, __SDL_!PeepEvents__ ----
One page links to
SDL_Event(3)
:
SDLManPages
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.