Merge branch 'master' of git.shadowcat.co.uk:SDL-Site
[sdlgit/SDL-Site.git] / pages / SDL-Event.html-inc
1 <div class="pod">
2 <!-- INDEX START -->
3 <h3 id="TOP">Index</h3>
4
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
7 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
8 <li><a href="#METHODS">METHODS</a>
9 <ul><li><a href="#new">new</a></li>
10 <li><a href="#type">type</a></li>
11 <li><a href="#active">active</a>
12 <ul><li><a href="#active_type">active_type</a></li>
13 <li><a href="#active_gain">active_gain</a></li>
14 <li><a href="#active_state">active_state</a></li>
15 </ul>
16 </li>
17 <li><a href="#key">key</a>
18 <ul><li><a href="#key_type">key_type</a></li>
19 <li><a href="#key_state">key_state</a></li>
20 <li><a href="#key_keysym">key_keysym</a></li>
21 <li><a href="#key_scancode">key_scancode</a></li>
22 <li><a href="#key_sym">key_sym</a></li>
23 <li><a href="#key_mod">key_mod</a></li>
24 <li><a href="#key_unicode">key_unicode</a></li>
25 </ul>
26 </li>
27 <li><a href="#motion">motion</a>
28 <ul><li><a href="#motion_type">motion_type</a></li>
29 <li><a href="#motion_state">motion_state</a></li>
30 <li><a href="#motion_x_motion_y">motion_x, motion_y</a></li>
31 <li><a href="#motion_xrel_motion_yrel">motion_xrel, motion_yrel</a></li>
32 </ul>
33 </li>
34 <li><a href="#button">button</a>
35 <ul><li><a href="#button_type">button_type</a></li>
36 <li><a href="#button_which">button_which</a></li>
37 <li><a href="#button_button">button_button</a></li>
38 <li><a href="#button_state">button_state</a></li>
39 <li><a href="#button_x_button_y">button_x, button_y</a></li>
40 </ul>
41 </li>
42 <li><a href="#jaxis">jaxis</a>
43 <ul><li><a href="#jaxis_type">jaxis_type</a></li>
44 <li><a href="#jaxis_which">jaxis_which</a></li>
45 <li><a href="#jaxis_axis">jaxis_axis</a></li>
46 <li><a href="#jaxis_value">jaxis_value</a></li>
47 </ul>
48 </li>
49 <li><a href="#jbutton">jbutton</a>
50 <ul><li><a href="#jbutton_type">jbutton_type</a></li>
51 <li><a href="#jbutton_which">jbutton_which</a></li>
52 <li><a href="#jbutton_button">jbutton_button</a></li>
53 <li><a href="#jbutton_state">jbutton_state</a></li>
54 </ul>
55 </li>
56 <li><a href="#jhat">jhat</a>
57 <ul><li><a href="#jhat_type">jhat_type</a></li>
58 <li><a href="#jhat_which">jhat_which</a></li>
59 <li><a href="#jhat_hat">jhat_hat</a></li>
60 <li><a href="#jhat_value">jhat_value</a></li>
61 </ul>
62 </li>
63 <li><a href="#jball">jball</a>
64 <ul><li><a href="#jball_type">jball_type</a></li>
65 <li><a href="#jball_which">jball_which</a></li>
66 <li><a href="#jball_ball">jball_ball</a></li>
67 <li><a href="#jball_xrel_jball_yrel">jball_xrel, jball_yrel</a></li>
68 </ul>
69 </li>
70 <li><a href="#resize">resize</a>
71 <ul><li><a href="#resize_type">resize_type</a></li>
72 <li><a href="#resize_x_resize_y">resize_x, resize_y</a></li>
73 </ul>
74 </li>
75 <li><a href="#expose">expose</a>
76 <ul><li><a href="#expose_type">expose_type</a></li>
77 </ul>
78 </li>
79 <li><a href="#syswm">syswm</a>
80 <ul><li><a href="#syswm_type">syswm_type</a></li>
81 <li><a href="#syswm_msg">syswm_msg</a></li>
82 </ul>
83 </li>
84 <li><a href="#user">user</a>
85 <ul><li><a href="#user_type">user_type</a></li>
86 <li><a href="#user_code">user_code</a></li>
87 <li><a href="#user_data1_user_data2">user_data1, user_data2</a></li>
88 </ul>
89 </li>
90 <li><a href="#quit">quit</a>
91 <ul><li><a href="#quit_type">quit_type</a></li>
92 </ul>
93 </li>
94 </ul>
95 </li>
96 <li><a href="#AUTHOR">AUTHOR</a></li>
97 <li><a href="#SEE_ALSO">SEE ALSO</a>
98 </li>
99 </ul><hr />
100 <!-- INDEX END -->
101
102 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
103 <div id="NAME_CONTENT">
104 <p>SDL::Event - General event structure</p>
105
106 </div>
107 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
108 <div id="SYNOPSIS_CONTENT">
109 <pre> use SDL::Event;                             # for the event object itself
110  use SDL::Events qw(pump_events poll_event); # functions for event queue handling
111
112  SDL::init(SDL_INIT_VIDEO);
113  my $event = SDL::Event-&gt;new();
114
115  while(1)
116  {
117      pump_events();
118
119      if(poll_event($event))
120      {
121         if($event-&gt;type == SDL_MOUSEBUTTONDOWN)
122         {
123             # now you can handle the details
124             $event-&gt;button_which;
125             $event-&gt;button_button;
126             $event-&gt;button_x;
127             $event-&gt;button_y;
128         }
129
130         last if $event-&gt;type == SDL_QUIT;
131      }
132
133      # your screen drawing code will be here
134  }
135
136 </pre>
137
138 </div>
139 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
140 <div id="DESCRIPTION_CONTENT">
141 <p>Event handling allows your application to receive input from the user. 
142 Event handling is initalised (along with video) with a call to:</p>
143 <p><code>SDL::init(SDL_INIT_VIDEO);</code></p>
144 <p>Internally, SDL stores all the events waiting to be handled in an event queue. 
145 Using functions like <code>SDL::Events::poll_event()</code>, <code>SDL::Events::peep_events</code> 
146 and <code>SDL::Events::wait_event()</code> you can observe and handle waiting input events.</p>
147 <p>The key to event handling in SDL is the <code>SDL::Event</code> union. 
148 The event queue itself is composed of a series of <code>SDL::Event</code> unions, one for each waiting event. 
149 <code>SDL::Event</code> unions are read from the queue with the <code>SDL::Events::poll_event()</code> function 
150 and it is then up to the application to process the information stored with them. </p>
151
152 </div>
153 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
154 <div id="METHODS_CONTENT">
155
156 </div>
157 <h2 id="new">new</h2>
158 <div id="new_CONTENT">
159 <p><code>new</code> creates an empty event-object, which can be used store information. 
160 Either by calling <code>poll_event($event)</code> that transferes one event from the queue into our object 
161 or by setting all the needed data manually in order to push the event to the queue.</p>
162 <pre> use SDL::Event;
163
164  my $event = SDL::Event-&gt;new();
165
166 </pre>
167
168 </div>
169 <h2 id="type">type</h2>
170 <div id="type_CONTENT">
171 <p>SDL::Event is a union of all event structures used in SDL, using it is a simple matter of knowing 
172 which union member relates to which event <code>type</code>.</p>
173 <pre> print 'heureka' if $event-&gt;type = SDL_MOUSEBUTTONDOWN;
174
175 </pre>
176 <p>Available type constants:</p>
177 <ul>
178                 <li><a href="#active">SDL_ACTIVEEVENT</a> - Application visibility event structure      </li>
179                 <li><a href="#active">SDL_KEYDOWN</a> - Keyboard event structure        </li>
180                 <li><a href="#active">SDL_KEYUP</a> - Keyboard event structure  </li>
181                 <li><a href="#active">SDL_MOUSEMOTION</a> - Mouse motion event structure        </li>
182                 <li><a href="#active">SDL_MOUSEBUTTONDOWN</a> - Mouse button event structure    </li>
183                 <li><a href="#button">SDL_MOUSEBUTTONUP</a> - Mouse button event structure      </li>
184                 <li><a href="#active">SDL_JOYAXISMOTION</a> - Joystick axis motion event structure      </li>
185                 <li><a href="#active">SDL_JOYBALLMOTION</a> - Joystick trackball motion event structure         </li>
186                 <li><a href="#active">SDL_JOYHATMOTION</a> - Joystick hat position change event structure       </li>
187                 <li><a href="#active">SDL_JOYBUTTONDOWN</a> - Joystick button event structure   </li>
188                 <li><a href="#active">SDL_JOYBUTTONUP</a> - Joystick button event structure     </li>
189                 <li><a href="#active">SDL_VIDEORESIZE</a> - Window resize event structure       </li>
190                 <li><a href="#active">SDL_VIDEOEXPOSE</a> - Window expose event         </li>
191                 <li><a href="#active">SDL_QUIT</a> - Quit requested event       </li>
192                 <li><a href="#active">SDL_USEREVENT</a> - A user-defined event type     </li>
193                 <li><a href="#active">SDL_SYSWMEVENT</a> - Platform-dependent window manager event. </li>
194 </ul>
195
196 <p>TODO: SDL_EVENTMASK()</p>
197
198 </div>
199 <h2 id="active">active</h2>
200 <div id="active_CONTENT">
201 <p><code>active</code> is a member of the <code>SDL::Event</code> union and is used when an event of type <code>SDL_ACTIVEEVENT</code> is reported.</p>
202 <p>When the mouse leaves or enters the window area a <code>SDL_APPMOUSEFOCUS</code> type activation event occurs, 
203 if the mouse entered the window then <strong>gain</strong> will be 1, otherwise <strong>gain</strong> will be 0. </p>
204 <p>A <code>SDL_APPINPUTFOCUS</code> type activation event occurs when the application loses or gains keyboard focus. 
205 This usually occurs when another application is made active. </p>
206 <p>Finally, a <code>SDL_APPACTIVE</code> type event occurs when the application is either minimised/iconified (<strong>gain</strong>=0) or restored. </p>
207 <p>A single event can have multiple values set in <strong>state</strong>.</p>
208 <p><strong>Note:</strong> This event does not occur when an application window is first created. </p>
209 <p>A new ActiveEvent (to fake focus loss) will be created like this:</p>
210 <pre> my $event = SDL::Event-&gt;new();
211     $event-&gt;type(SDL_ACTIVEEVENT);
212     $event-&gt;active_gain(0);
213     $event-&gt;active_state(SDL_APPMOUSEFOCUS);
214
215  # I think this is wrong, -&gt;active_type() should get SDL_APPMOUSEFOCUS, but what state gets?
216
217 </pre>
218
219 </div>
220 <h3 id="active_type">active_type</h3>
221 <div id="active_type_CONTENT">
222
223 </div>
224 <h3 id="active_gain">active_gain</h3>
225 <div id="active_gain_CONTENT">
226
227 </div>
228 <h3 id="active_state">active_state</h3>
229 <div id="active_state_CONTENT">
230
231 </div>
232 <h2 id="key">key</h2>
233 <div id="key_CONTENT">
234
235 </div>
236 <h3 id="key_type">key_type</h3>
237 <div id="key_type_CONTENT">
238
239 </div>
240 <h3 id="key_state">key_state</h3>
241 <div id="key_state_CONTENT">
242
243 </div>
244 <h3 id="key_keysym">key_keysym</h3>
245 <div id="key_keysym_CONTENT">
246
247 </div>
248 <h3 id="key_scancode">key_scancode</h3>
249 <div id="key_scancode_CONTENT">
250
251 </div>
252 <h3 id="key_sym">key_sym</h3>
253 <div id="key_sym_CONTENT">
254
255 </div>
256 <h3 id="key_mod">key_mod</h3>
257 <div id="key_mod_CONTENT">
258
259 </div>
260 <h3 id="key_unicode">key_unicode</h3>
261 <div id="key_unicode_CONTENT">
262
263 </div>
264 <h2 id="motion">motion</h2>
265 <div id="motion_CONTENT">
266
267 </div>
268 <h3 id="motion_type">motion_type</h3>
269 <div id="motion_type_CONTENT">
270
271 </div>
272 <h3 id="motion_state">motion_state</h3>
273 <div id="motion_state_CONTENT">
274
275 </div>
276 <h3 id="motion_x_motion_y">motion_x, motion_y</h3>
277 <div id="motion_x_motion_y_CONTENT">
278
279 </div>
280 <h3 id="motion_xrel_motion_yrel">motion_xrel, motion_yrel</h3>
281 <div id="motion_xrel_motion_yrel_CONTENT">
282
283 </div>
284 <h2 id="button">button</h2>
285 <div id="button_CONTENT">
286
287 </div>
288 <h3 id="button_type">button_type</h3>
289 <div id="button_type_CONTENT">
290
291 </div>
292 <h3 id="button_which">button_which</h3>
293 <div id="button_which_CONTENT">
294
295 </div>
296 <h3 id="button_button">button_button</h3>
297 <div id="button_button_CONTENT">
298
299 </div>
300 <h3 id="button_state">button_state</h3>
301 <div id="button_state_CONTENT">
302
303 </div>
304 <h3 id="button_x_button_y">button_x, button_y</h3>
305 <div id="button_x_button_y_CONTENT">
306
307 </div>
308 <h2 id="jaxis">jaxis</h2>
309 <div id="jaxis_CONTENT">
310
311 </div>
312 <h3 id="jaxis_type">jaxis_type</h3>
313 <div id="jaxis_type_CONTENT">
314
315 </div>
316 <h3 id="jaxis_which">jaxis_which</h3>
317 <div id="jaxis_which_CONTENT">
318
319 </div>
320 <h3 id="jaxis_axis">jaxis_axis</h3>
321 <div id="jaxis_axis_CONTENT">
322
323 </div>
324 <h3 id="jaxis_value">jaxis_value</h3>
325 <div id="jaxis_value_CONTENT">
326
327 </div>
328 <h2 id="jbutton">jbutton</h2>
329 <div id="jbutton_CONTENT">
330
331 </div>
332 <h3 id="jbutton_type">jbutton_type</h3>
333 <div id="jbutton_type_CONTENT">
334
335 </div>
336 <h3 id="jbutton_which">jbutton_which</h3>
337 <div id="jbutton_which_CONTENT">
338
339 </div>
340 <h3 id="jbutton_button">jbutton_button</h3>
341 <div id="jbutton_button_CONTENT">
342
343 </div>
344 <h3 id="jbutton_state">jbutton_state</h3>
345 <div id="jbutton_state_CONTENT">
346
347 </div>
348 <h2 id="jhat">jhat</h2>
349 <div id="jhat_CONTENT">
350
351 </div>
352 <h3 id="jhat_type">jhat_type</h3>
353 <div id="jhat_type_CONTENT">
354
355 </div>
356 <h3 id="jhat_which">jhat_which</h3>
357 <div id="jhat_which_CONTENT">
358
359 </div>
360 <h3 id="jhat_hat">jhat_hat</h3>
361 <div id="jhat_hat_CONTENT">
362
363 </div>
364 <h3 id="jhat_value">jhat_value</h3>
365 <div id="jhat_value_CONTENT">
366
367 </div>
368 <h2 id="jball">jball</h2>
369 <div id="jball_CONTENT">
370
371 </div>
372 <h3 id="jball_type">jball_type</h3>
373 <div id="jball_type_CONTENT">
374
375 </div>
376 <h3 id="jball_which">jball_which</h3>
377 <div id="jball_which_CONTENT">
378
379 </div>
380 <h3 id="jball_ball">jball_ball</h3>
381 <div id="jball_ball_CONTENT">
382
383 </div>
384 <h3 id="jball_xrel_jball_yrel">jball_xrel, jball_yrel</h3>
385 <div id="jball_xrel_jball_yrel_CONTENT">
386
387 </div>
388 <h2 id="resize">resize</h2>
389 <div id="resize_CONTENT">
390
391 </div>
392 <h3 id="resize_type">resize_type</h3>
393 <div id="resize_type_CONTENT">
394
395 </div>
396 <h3 id="resize_x_resize_y">resize_x, resize_y</h3>
397 <div id="resize_x_resize_y_CONTENT">
398
399 </div>
400 <h2 id="expose">expose</h2>
401 <div id="expose_CONTENT">
402
403 </div>
404 <h3 id="expose_type">expose_type</h3>
405 <div id="expose_type_CONTENT">
406
407 </div>
408 <h2 id="syswm">syswm</h2>
409 <div id="syswm_CONTENT">
410
411 </div>
412 <h3 id="syswm_type">syswm_type</h3>
413 <div id="syswm_type_CONTENT">
414
415 </div>
416 <h3 id="syswm_msg">syswm_msg</h3>
417 <div id="syswm_msg_CONTENT">
418
419 </div>
420 <h2 id="user">user</h2>
421 <div id="user_CONTENT">
422
423 </div>
424 <h3 id="user_type">user_type</h3>
425 <div id="user_type_CONTENT">
426
427 </div>
428 <h3 id="user_code">user_code</h3>
429 <div id="user_code_CONTENT">
430
431 </div>
432 <h3 id="user_data1_user_data2">user_data1, user_data2</h3>
433 <div id="user_data1_user_data2_CONTENT">
434
435 </div>
436 <h2 id="quit">quit</h2>
437 <div id="quit_CONTENT">
438
439 </div>
440 <h3 id="quit_type">quit_type</h3>
441 <div id="quit_type_CONTENT">
442 <p>Create a new SDL::Event object.</p>
443
444 </div>
445 <h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p>
446 <div id="AUTHOR_CONTENT">
447
448 </div>
449 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
450 <div id="SEE_ALSO_CONTENT">
451 <p><cite>perl</cite></p>
452
453 </div>
454 </div>