|SDL_Event(3)||SDL API Reference||SDL_Event(3)|
- The type of event
- Activation event
- Keyboard event
- Mouse motion event
- Mouse button event
- Joystick axis motion event
- Joystick trackball motion event
- Joystick hat motion event
- Joystick button event
- Application window resize event
- Application window expose event
- Application quit request event
- User defined event
- Undefined window manager event
- Event type
- Event Structure
- Reading events on the event queue
- Placing events on the event queue
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.
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.
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:
All we need do now is read the information out of the motion member of test_event.
printf("We got a motion event.
printf("Current mouse position is: (%d, %d)
", test_event.motion.x, test_event.motion.y);
printf("Event queue empty.
|Tue 11 Sep 2001, 22:59||SDL|