Penguin
Blame: SDL_Event(3)
EditPageHistoryDiffInfoLikePages
Annotated edit history of SDL_Event(3) version 2, including all changes. View license author blame.
Rev Author # Line
1 perry 1 SDL_Event
2 !!!SDL_Event
3 NAME
4 STRUCTURE DEFINITION
5 STRUCTURE DATA
6 DESCRIPTION
7 USE
8 SEE ALSO
9 ----
10 !!NAME
11
12
13 SDL_Event- General event structure
14 !!STRUCTURE DEFINITION
15
16
17 typedef union{
18 Uint8 type;
2 perry 19 SDL_!ActiveEvent active;
20 SDL_!KeyboardEvent key;
21 SDL_!MouseMotionEvent motion;
22 SDL_!MouseButtonEvent button;
23 SDL_!JoyAxisEvent jaxis;
24 SDL_!JoyBallEvent jball;
25 SDL_!JoyHatEvent jhat;
26 SDL_!JoyButtonEvent jbutton;
27 SDL_!ResizeEvent resize;
28 SDL_!QuitEvent quit;
29 SDL_!UserEvent user;
1 perry 30 SDL_SywWMEvent syswm;
31 } SDL_Event;
32 !!STRUCTURE DATA
33
34
35 __type__ The type of event
36
37
38 __active__ ''Activation event''
39
40
41 __key__ ''Keyboard event''
42
43
44 __motion__ ''Mouse motion event''
45
46
47 __button__ ''Mouse button event''
48
49
50 __jaxis__ ''Joystick axis motion event''
51
52
53 __jball__ ''Joystick trackball motion
54 event''
55
56
57 __jhat__ ''Joystick hat motion event''
58
59
60 __jbutton__ ''Joystick button event''
61
62
63 __resize__ ''Application window resize
64 event''
65
66
67 __quit__ ''Application quit request
68 event''
69
70
71 __user__ ''User defined event''
72
73
74 __syswm__ ''Undefined window manager
75 event''
76 !!DESCRIPTION
77
78
79 The __SDL_Event__ union is the core to all event handling
80 is SDL, its probably the most important structure after
81 __SDL_Surface__. __SDL_Event__ is a union of all event
82 structures used in SDL, using it is a simple matter of
83 knowing which union member relates to which event
84 __type__.
85
86
87 __Event type Event Structure__
88
89
90 __SDL_ACTIVEEVENT__
91
92
2 perry 93 __SDL_!ActiveEvent__
1 perry 94
95
96 __SDL_KEYDOWN/UP__
97
98
2 perry 99 __SDL_!KeyboardEvent__
1 perry 100
101
102 __SDL_MOUSEMOTION__
103
104
2 perry 105 __SDL_!MouseMotionEvent__
1 perry 106
107
108 __SDL_MOUSEBUTTONDOWN/UP__
109
110
2 perry 111 __SDL_!MouseButtonEvent__
1 perry 112
113
114 __SDL_JOYAXISMOTION__
115
116
2 perry 117 __SDL_!JoyAxisEvent__
1 perry 118
119
120 __SDL_JOYBALLMOTION__
121
122
2 perry 123 __SDL_!JoyBallEvent__
1 perry 124
125
126 __SDL_JOYHATMOTION__
127
128
2 perry 129 __SDL_!JoyHatEvent__
1 perry 130
131
132 __SDL_JOYBUTTONDOWN/UP__
133
134
2 perry 135 __SDL_!JoyButtonEvent__
1 perry 136
137
2 perry 138 __SDL_QUIT SDL_!QuitEvent__
1 perry 139
140
141 __SDL_SYSWMEVENT__
142
143
144 __SDL_SysWMEvent__
145
146
147 __SDL_VIDEORESIZE__
148
149
2 perry 150 __SDL_!ResizeEvent__
1 perry 151
152
153 __SDL_USEREVENT__
154
155
2 perry 156 __SDL_!UserEvent__
1 perry 157 !!USE
158
159
160 The __SDL_Event__ structure has two uses
161
162
163 Reading events on the event queue
164
165
166 Placing events on the event queue
167
168
169 Reading events from the event queue is done with either
2 perry 170 __SDL_!PollEvent__ or __SDL_!PeepEvents__. We'll use
171 __SDL_!PollEvent__ and step through an
1 perry 172 example.
173
174
175 First off, we create an empty __SDL_Event__
176 structure.
177
178
179 SDL_Event test_event;
2 perry 180 __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.
1 perry 181
182
2 perry 183 while(SDL_!PollEvent(
184 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.
1 perry 185
186
187 switch(test_event.type) {
2 perry 188 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:
1 perry 189
190
191 case SDL_MOUSEMOTION:
192 All we need do now is read the information out of the __motion__ member of __test_event__.
193
194
195 printf(
196
197
198 It is also possible to push events onto the event queue and
199 so use it as a two-way communication path. Both
2 perry 200 __SDL_!PushEvent__ and __SDL_!PeepEvents__ allow you to
1 perry 201 place events onto the event queue. This is usually used to
202 place a __SDL_USEREVENT__ on the event queue, however you
203 could use it to post fake input events if you wished.
204 Creating your own events is a simple matter of choosing the
205 event type you want, setting the __type__ member and
206 filling the appropriate member structure with
207 information.
208
209
210 SDL_Event user_event;
211 user_event.type=SDL_USEREVENT;
212 user_event.user.code=2;
213 user_event.user.data1=NULL;
214 user_event.user.data2=NULL;
2 perry 215 SDL_!PushEvent(
1 perry 216 !!SEE ALSO
217
218
2 perry 219 __SDL_!PollEvent__, __SDL_!PushEvent__,
220 __SDL_!PeepEvents__
1 perry 221 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.