|
Size: 6404
Comment: update formatting - categories
|
Size: 6811
Comment: update content - w/ Sam (in progress)
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 6: | Line 6: |
| A union that contains the different event structures. <<Color2(green,The header says "General event structure".)>> |
A union that contains structures for the different event types. |
| Line 27: | Line 26: |
| ||[[SDL_TouchFingerEvent]]||'''tfinger'''||touch finger event data|| ||[[SDL_TouchButtonEvent]]||'''tbutton'''||touch button event data|| ||[[SDL_MultiGestureEvent]]||'''mgesture'''||multi finger gesture data|| ||[[SDL_DollarGestureEvent]]||'''dgesture'''||multi finger gesture data|| |
|
| Line 30: | Line 33: |
| <<Color2(green,The following appears to have been removed in a recent revision. Correct?)>> ||[[SDL_ProximityEvent]]||'''proximity'''||proximity In or Out event|| |
|
| Line 35: | Line 35: |
| <<Color2(green,The following seems most like it belongs in this section but with all the extra text may belong elsewhere or the text should also be in a box?)>> | {{{#!highlight cpp You can add your code example here }}} |
| Line 37: | Line 39: |
| *<<BR>> | == Remarks == The [[SDL_Event]] structure is the core to all event handling in SDL. [[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_Event Field__|| ||<style="color: #808080;">SDL_ACTIVEEVENT||<style="color: #808080;">[[SDL_ActiveEvent]]||<style="color: #808080;">'''active'''|| ||SDL_DOLLARGESTURE||[[SDL_DollarGestureEvent]]||'''dgesture'''|| ||SDL_FINGERMOTION, SDL_FINGERDOWN/UP||[[SDL_TouchFingerEvent]]||'''tfinger'''|| ||SDL_KEYDOWN/UP||[[SDL_KeyboardEvent]]||'''key'''|| ||SDL_JOYAXISMOTION||[[SDL_JoyAxisEvent]]||'''jaxis'''|| ||SDL_JOYBALLMOTION||[[SDL_JoyBallEvent]]||'''jball'''|| ||SDL_JOYHATMOTION||[[SDL_JoyHatEvent]]||'''jhat'''|| ||SDL_JOYBUTTONDOWN/UP||[[SDL_JoyButtonEvent]]||'''jbutton'''|| ||SDL_MOUSEMOTION||[[SDL_MouseMotionEvent]]||'''motion'''|| ||SDL_MOUSEBUTTONDOWN/UP||[[SDL_MouseButtonEvent]]||'''button'''|| ||SDL_MOUSEWHEEL||[[SDL_MouseWheelEvent]]||'''wheel'''|| ||SDL_MULTIGESTURE||[[SDL_MultiGestureEvent]]||'''mgesture'''|| ||SDL_QUIT||[[SDL_QuitEvent]]||'''quit'''|| ||SDL_SYSWMEVENT||[[SDL_SysWMEvent]]||'''syswm'''|| ||SDL_TEXTEDITING||[[SDL_TextEditingEvent]]||'''edit'''|| ||SDL_TEXTINPUT||[[SDL_TextInputEvent]]||'''text'''|| ||SDL_TOUCHBUTTONUP/DOWN||[[SDL_TouchButtonEvent]]||'''tbutton'''|| ||SDL_USEREVENT||[[SDL_UserEvent]]||'''user'''|| ||<style="color: #808080;">SDL_VIDEORESIZE||<style="color: #808080;">[[SDL_ResizeEvent]]||<style="color: #808080;">'''resize'''|| ||SDL_WINDOWEVENT||[[SDL_WindowEvent]]||'''window'''|| |
| Line 42: | Line 69: |
| 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. | 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. |
| Line 48: | Line 75: |
| [[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. | [[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. |
| Line 52: | Line 79: |
| The [[SDL_PollEvent]] function takes 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 separately we use a {{{switch}}} statement. | The [[SDL_PollEvent]]() function takes 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 separately we use a {{{switch}}} statement. |
| Line 73: | Line 100: |
| 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. | 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. |
| Line 83: | Line 110: |
| <<BR>>* == Remarks == ''You can add useful comments here'' <<Color2(green,Should the following be incorporated above (params) rather than listed separately here? Should it be left off entirely or moved to the !CategoryEvents page?)>> * <<BR>> The [[SDL_Event]] union is the core to all event handling in SDL; it's 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_VIDEORESIZE||[[SDL_ResizeEvent]]|| ||SDL_VIDEOEXPOSE||[[SDL_ExposeEvent]]|| ||SDL_QUIT||[[SDL_QuitEvent]]|| ||SDL_USEREVENT||[[SDL_UserEvent]]|| ||SDL_SYSWMEVENT||[[SDL_SysWMEvent]]|| <<Color2(green,SDL_MouseWheelEvent is missing)>> <<BR>>* |
DRAFT |
SDL_Event
A union that contains structures for the different event types.
Contents
Data Fields
Uint32 |
type |
event type, shared with all events |
window |
window event data |
|
key |
keyboard event data |
|
edit |
text editing event data |
|
text |
text input event data |
|
motion |
mouse motion event data |
|
button |
mouse button event data |
|
wheel |
mouse wheel event data |
|
jaxis |
joystick axis event data |
|
jball |
joystick ball event data |
|
jhat |
joystick hat event data |
|
jbutton |
joystick button event data |
|
quit |
quit request event data |
|
user |
custom event data |
|
syswm |
system dependent window event data |
|
tfinger |
touch finger event data |
|
tbutton |
touch button event data |
|
mgesture |
multi finger gesture data |
|
dgesture |
multi finger gesture data |
|
SDL_ActiveEvent |
active |
deprecated; for backwards compatibility |
SDL_ResizeEvent |
resize |
deprecated; for backwards compatibility |
Code Examples
You can add your code example here
Remarks
The SDL_Event structure is the core to all event handling in SDL. 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_Event Field |
SDL_ACTIVEEVENT |
active |
|
SDL_DOLLARGESTURE |
dgesture |
|
SDL_FINGERMOTION, SDL_FINGERDOWN/UP |
tfinger |
|
SDL_KEYDOWN/UP |
key |
|
SDL_JOYAXISMOTION |
jaxis |
|
SDL_JOYBALLMOTION |
jball |
|
SDL_JOYHATMOTION |
jhat |
|
SDL_JOYBUTTONDOWN/UP |
jbutton |
|
SDL_MOUSEMOTION |
motion |
|
SDL_MOUSEBUTTONDOWN/UP |
button |
|
SDL_MOUSEWHEEL |
wheel |
|
SDL_MULTIGESTURE |
mgesture |
|
SDL_QUIT |
quit |
|
SDL_SYSWMEVENT |
syswm |
|
SDL_TEXTEDITING |
edit |
|
SDL_TEXTINPUT |
text |
|
SDL_TOUCHBUTTONUP/DOWN |
tbutton |
|
SDL_USEREVENT |
user |
|
SDL_VIDEORESIZE |
resize |
|
SDL_WINDOWEVENT |
window |
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(&test_event)) {
The SDL_PollEvent() function takes 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 separately we use a switch statement.
switch(test_event.type) {We need to know what kind of events we're looking for and the event types of those events. So let's 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 us 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("We got a motion event.\n");
printf("Current mouse position is: (%d, %d)\n", test_event.motion.x, test_event.motion.y);
break;
default:
printf("Unhandled Event!\n");
break;
}
}
printf("Event queue empty.\n");
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(&user_event);
Related Enumerations
SDL_scancode ???
Related Structures
green
Related Functions
SDL_FilterEvents ???
