Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5131 clevermous 1
2
>
3
>
4
>SDL_Event
5
>
6
NAME="GENERATOR"
7
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
8
">
9
REL="HOME"
10
TITLE="SDL Library Documentation"
11
HREF="index.html">
12
REL="UP"
13
TITLE="SDL Event Structures."
14
HREF="eventstructures.html">
15
REL="PREVIOUS"
16
TITLE="SDL Event Structures."
17
HREF="eventstructures.html">
18
REL="NEXT"
19
TITLE="SDL_ActiveEvent"
20
HREF="sdlactiveevent.html">
21
>
22
CLASS="REFENTRY"
23
BGCOLOR="#FFF8DC"
24
TEXT="#000000"
25
LINK="#0000ee"
26
VLINK="#551a8b"
27
ALINK="#ff0000"
28
>
29
CLASS="NAVHEADER"
30
>
31
WIDTH="100%"
32
BORDER="0"
33
CELLPADDING="0"
34
CELLSPACING="0"
35
>
36
>
37
COLSPAN="3"
38
ALIGN="center"
39
>SDL Library Documentation
40
>
41
>
42
>
43
WIDTH="10%"
44
ALIGN="left"
45
VALIGN="bottom"
46
>
47
HREF="eventstructures.html"
48
>Prev
49
>
50
>
51
WIDTH="80%"
52
ALIGN="center"
53
VALIGN="bottom"
54
>
55
>
56
WIDTH="10%"
57
ALIGN="right"
58
VALIGN="bottom"
59
>
60
HREF="sdlactiveevent.html"
61
>Next
62
>
63
>
64
>
65
>
66
ALIGN="LEFT"
67
WIDTH="100%">
68
>
69
>
70
NAME="SDLEVENT"
71
>SDL_Event
72
>
73
>
74
CLASS="REFNAMEDIV"
75
>
76
NAME="AEN3289"
77
>
78
>
79
>Name
80
>SDL_Event -- General event structure
81
>
82
CLASS="REFSECT1"
83
>
84
NAME="AEN3292"
85
>
86
>
87
>Structure Definition
88
>
89
CLASS="PROGRAMLISTING"
90
>typedef union{
91
  Uint8 type;
92
  SDL_ActiveEvent active;
93
  SDL_KeyboardEvent key;
94
  SDL_MouseMotionEvent motion;
95
  SDL_MouseButtonEvent button;
96
  SDL_JoyAxisEvent jaxis;
97
  SDL_JoyBallEvent jball;
98
  SDL_JoyHatEvent jhat;
99
  SDL_JoyButtonEvent jbutton;
100
  SDL_ResizeEvent resize;
101
  SDL_QuitEvent quit;
102
  SDL_UserEvent user;
103
  SDL_SywWMEvent syswm;
104
} SDL_Event;
105
>
106
>
107
CLASS="REFSECT1"
108
>
109
NAME="AEN3295"
110
>
111
>
112
>Structure Data
113
>
114
CLASS="INFORMALTABLE"
115
>
116
NAME="AEN3297"
117
>
118
>
119
>
120
>
121
BORDER="0"
122
CLASS="CALSTABLE"
123
>
124
>
125
>
126
ALIGN="LEFT"
127
VALIGN="TOP"
128
>
129
CLASS="STRUCTFIELD"
130
>
131
>type
132
>
133
>
134
>
135
ALIGN="LEFT"
136
VALIGN="TOP"
137
>The type of event
138
>
139
>
140
>
141
ALIGN="LEFT"
142
VALIGN="TOP"
143
>
144
CLASS="STRUCTFIELD"
145
>
146
>active
147
>
148
>
149
>
150
ALIGN="LEFT"
151
VALIGN="TOP"
152
>
153
HREF="sdlactiveevent.html"
154
>Activation event
155
>
156
>
157
>
158
>
159
ALIGN="LEFT"
160
VALIGN="TOP"
161
>
162
CLASS="STRUCTFIELD"
163
>
164
>key
165
>
166
>
167
>
168
ALIGN="LEFT"
169
VALIGN="TOP"
170
>
171
HREF="sdlkeyboardevent.html"
172
>Keyboard event
173
>
174
>
175
>
176
>
177
ALIGN="LEFT"
178
VALIGN="TOP"
179
>
180
CLASS="STRUCTFIELD"
181
>
182
>motion
183
>
184
>
185
>
186
ALIGN="LEFT"
187
VALIGN="TOP"
188
>
189
HREF="sdlmousemotionevent.html"
190
>Mouse motion event
191
>
192
>
193
>
194
>
195
ALIGN="LEFT"
196
VALIGN="TOP"
197
>
198
CLASS="STRUCTFIELD"
199
>
200
>button
201
>
202
>
203
>
204
ALIGN="LEFT"
205
VALIGN="TOP"
206
>
207
HREF="sdlmousebuttonevent.html"
208
>Mouse button event
209
>
210
>
211
>
212
>
213
ALIGN="LEFT"
214
VALIGN="TOP"
215
>
216
CLASS="STRUCTFIELD"
217
>
218
>jaxis
219
>
220
>
221
>
222
ALIGN="LEFT"
223
VALIGN="TOP"
224
>
225
HREF="sdljoyaxisevent.html"
226
>Joystick axis motion event
227
>
228
>
229
>
230
>
231
ALIGN="LEFT"
232
VALIGN="TOP"
233
>
234
CLASS="STRUCTFIELD"
235
>
236
>jball
237
>
238
>
239
>
240
ALIGN="LEFT"
241
VALIGN="TOP"
242
>
243
HREF="sdljoyballevent.html"
244
>Joystick trackball motion event
245
>
246
>
247
>
248
>
249
ALIGN="LEFT"
250
VALIGN="TOP"
251
>
252
CLASS="STRUCTFIELD"
253
>
254
>jhat
255
>
256
>
257
>
258
ALIGN="LEFT"
259
VALIGN="TOP"
260
>
261
HREF="sdljoyhatevent.html"
262
>Joystick hat motion event
263
>
264
>
265
>
266
>
267
ALIGN="LEFT"
268
VALIGN="TOP"
269
>
270
CLASS="STRUCTFIELD"
271
>
272
>jbutton
273
>
274
>
275
>
276
ALIGN="LEFT"
277
VALIGN="TOP"
278
>
279
HREF="sdljoybuttonevent.html"
280
>Joystick button event
281
>
282
>
283
>
284
>
285
ALIGN="LEFT"
286
VALIGN="TOP"
287
>
288
CLASS="STRUCTFIELD"
289
>
290
>resize
291
>
292
>
293
>
294
ALIGN="LEFT"
295
VALIGN="TOP"
296
>
297
HREF="sdlresizeevent.html"
298
>Application window resize event
299
>
300
>
301
>
302
>
303
ALIGN="LEFT"
304
VALIGN="TOP"
305
>
306
CLASS="STRUCTFIELD"
307
>
308
>quit
309
>
310
>
311
>
312
ALIGN="LEFT"
313
VALIGN="TOP"
314
>
315
HREF="sdlquitevent.html"
316
>Application quit request event
317
>
318
>
319
>
320
>
321
ALIGN="LEFT"
322
VALIGN="TOP"
323
>
324
CLASS="STRUCTFIELD"
325
>
326
>user
327
>
328
>
329
>
330
ALIGN="LEFT"
331
VALIGN="TOP"
332
>
333
HREF="sdluserevent.html"
334
>User defined event
335
>
336
>
337
>
338
>
339
ALIGN="LEFT"
340
VALIGN="TOP"
341
>
342
CLASS="STRUCTFIELD"
343
>
344
>syswm
345
>
346
>
347
>
348
ALIGN="LEFT"
349
VALIGN="TOP"
350
>
351
HREF="sdlsyswmevent.html"
352
>Undefined window manager event
353
>
354
>
355
>
356
>
357
>
358
>
359
>
360
>
361
>
362
CLASS="REFSECT1"
363
>
364
NAME="AEN3364"
365
>
366
>
367
>Description
368
>
369
>The 
370
CLASS="STRUCTNAME"
371
>SDL_Event
372
> union is the core to all event handling is SDL, its probably the most important structure after 
373
CLASS="STRUCTNAME"
374
>SDL_Surface
375
>. 
376
CLASS="STRUCTNAME"
377
>SDL_Event
378
> 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 
379
CLASS="STRUCTFIELD"
380
>
381
>type
382
>
383
>.
384
>
385
>
386
CLASS="INFORMALTABLE"
387
>
388
NAME="AEN3372"
389
>
390
>
391
>
392
>
393
BORDER="1"
394
CLASS="CALSTABLE"
395
>
396
>
397
>
398
ALIGN="LEFT"
399
VALIGN="TOP"
400
>Event 
401
CLASS="STRUCTFIELD"
402
>
403
>type
404
>
405
>
406
>
407
ALIGN="LEFT"
408
VALIGN="TOP"
409
>Event Structure
410
>
411
>
412
>
413
>
414
>
415
ALIGN="LEFT"
416
VALIGN="MIDDLE"
417
>
418
CLASS="LITERAL"
419
>SDL_ACTIVEEVENT
420
>
421
>
422
ALIGN="LEFT"
423
VALIGN="MIDDLE"
424
>
425
HREF="sdlactiveevent.html"
426
>
427
CLASS="STRUCTNAME"
428
>SDL_ActiveEvent
429
>
430
>
431
>
432
>
433
>
434
ALIGN="LEFT"
435
VALIGN="TOP"
436
>
437
CLASS="LITERAL"
438
>SDL_KEYDOWN/UP
439
>
440
>
441
ALIGN="LEFT"
442
VALIGN="TOP"
443
>
444
HREF="sdlkeyboardevent.html"
445
>
446
CLASS="STRUCTNAME"
447
>SDL_KeyboardEvent
448
>
449
>
450
>
451
>
452
>
453
ALIGN="LEFT"
454
VALIGN="TOP"
455
>
456
CLASS="LITERAL"
457
>SDL_MOUSEMOTION
458
>
459
>
460
ALIGN="LEFT"
461
VALIGN="TOP"
462
>
463
HREF="sdlmousemotionevent.html"
464
>
465
CLASS="STRUCTNAME"
466
>SDL_MouseMotionEvent
467
>
468
>
469
>
470
>
471
>
472
ALIGN="LEFT"
473
VALIGN="TOP"
474
>
475
CLASS="LITERAL"
476
>SDL_MOUSEBUTTONDOWN/UP
477
>
478
>
479
ALIGN="LEFT"
480
VALIGN="TOP"
481
>
482
HREF="sdlmousebuttonevent.html"
483
>
484
CLASS="STRUCTNAME"
485
>SDL_MouseButtonEvent
486
>
487
>
488
>
489
>
490
>
491
ALIGN="LEFT"
492
VALIGN="TOP"
493
>
494
CLASS="LITERAL"
495
>SDL_JOYAXISMOTION
496
>
497
>
498
ALIGN="LEFT"
499
VALIGN="TOP"
500
>
501
HREF="sdljoyaxisevent.html"
502
>
503
CLASS="STRUCTNAME"
504
>SDL_JoyAxisEvent
505
>
506
>
507
>
508
>
509
>
510
ALIGN="LEFT"
511
VALIGN="TOP"
512
>
513
CLASS="LITERAL"
514
>SDL_JOYBALLMOTION
515
>
516
>
517
ALIGN="LEFT"
518
VALIGN="TOP"
519
>
520
HREF="sdljoyballevent.html"
521
>
522
CLASS="STRUCTNAME"
523
>SDL_JoyBallEvent
524
>
525
>
526
>
527
>
528
>
529
ALIGN="LEFT"
530
VALIGN="TOP"
531
>
532
CLASS="LITERAL"
533
>SDL_JOYHATMOTION
534
>
535
>
536
ALIGN="LEFT"
537
VALIGN="TOP"
538
>
539
HREF="sdljoyhatevent.html"
540
>
541
CLASS="STRUCTNAME"
542
>SDL_JoyHatEvent
543
>
544
>
545
>
546
>
547
>
548
ALIGN="LEFT"
549
VALIGN="TOP"
550
>
551
CLASS="LITERAL"
552
>SDL_JOYBUTTONDOWN/UP
553
>
554
>
555
ALIGN="LEFT"
556
VALIGN="TOP"
557
>
558
HREF="sdljoybuttonevent.html"
559
>
560
CLASS="STRUCTNAME"
561
>SDL_JoyButtonEvent
562
>
563
>
564
>
565
>
566
>
567
ALIGN="LEFT"
568
VALIGN="TOP"
569
>
570
CLASS="LITERAL"
571
>SDL_QUIT
572
>
573
>
574
ALIGN="LEFT"
575
VALIGN="TOP"
576
>
577
HREF="sdlquitevent.html"
578
>
579
CLASS="STRUCTNAME"
580
>SDL_QuitEvent
581
>
582
>
583
>
584
>
585
>
586
ALIGN="LEFT"
587
VALIGN="TOP"
588
>
589
CLASS="LITERAL"
590
>SDL_SYSWMEVENT
591
>
592
>
593
ALIGN="LEFT"
594
VALIGN="TOP"
595
>
596
HREF="sdlsyswmevent.html"
597
>
598
CLASS="STRUCTNAME"
599
>SDL_SysWMEvent
600
>
601
>
602
>
603
>
604
>
605
ALIGN="LEFT"
606
VALIGN="TOP"
607
>
608
CLASS="LITERAL"
609
>SDL_VIDEORESIZE
610
>
611
>
612
ALIGN="LEFT"
613
VALIGN="TOP"
614
>
615
HREF="sdlresizeevent.html"
616
>
617
CLASS="STRUCTNAME"
618
>SDL_ResizeEvent
619
>
620
>
621
>
622
>
623
>
624
ALIGN="LEFT"
625
VALIGN="TOP"
626
>
627
CLASS="LITERAL"
628
>SDL_USEREVENT
629
>
630
>
631
ALIGN="LEFT"
632
VALIGN="TOP"
633
>
634
HREF="sdluserevent.html"
635
>
636
CLASS="STRUCTNAME"
637
>SDL_UserEvent
638
>
639
>
640
>
641
>
642
>
643
>
644
>
645
>
646
>
647
>
648
>
649
CLASS="REFSECT1"
650
>
651
NAME="AEN3452"
652
>
653
>
654
>Use
655
>
656
>The 
657
CLASS="STRUCTNAME"
658
>SDL_Event
659
> structure has two uses
660
>
661
>
662
>
663
COMPACT="COMPACT"
664
>
665
>
666
>Reading events on the event queue
667
>
668
>
669
>
670
>Placing events on the event queue
671
>
672
>
673
>
674
>Reading events from the event queue is done with either 
675
HREF="sdlpollevent.html"
676
>
677
CLASS="FUNCTION"
678
>SDL_PollEvent
679
>
680
> or 
681
HREF="sdlpeepevents.html"
682
>
683
CLASS="FUNCTION"
684
>SDL_PeepEvents
685
>
686
>. We'll use 
687
CLASS="FUNCTION"
688
>SDL_PollEvent
689
> and step through an example.
690
>
691
>First off, we create an empty 
692
CLASS="STRUCTNAME"
693
>SDL_Event
694
> structure.
695
696
CLASS="PROGRAMLISTING"
697
>SDL_Event test_event;
698
>
699
700
CLASS="FUNCTION"
701
>SDL_PollEvent
702
> removes the next event from the event queue, if there are no events on the queue it returns 
703
CLASS="RETURNVALUE"
704
>0
705
> otherwise it returns 
706
CLASS="RETURNVALUE"
707
>1
708
>. We use a 
709
CLASS="FUNCTION"
710
>while
711
> loop to process each event in turn.
712
713
CLASS="PROGRAMLISTING"
714
>while(SDL_PollEvent(&test_event)) {
715
>
716
The 
717
CLASS="FUNCTION"
718
>SDL_PollEvent
719
> function take a pointer to an 
720
CLASS="STRUCTNAME"
721
>SDL_Event
722
> structure that is to be filled with event information. We know that if 
723
CLASS="FUNCTION"
724
>SDL_PollEvent
725
> removes an event from the queue then the event information will be placed in our 
726
CLASS="STRUCTNAME"
727
>test_event
728
> structure, but we also know that the 
729
CLASS="EMPHASIS"
730
>type
731
> of event will be placed in the 
732
CLASS="STRUCTFIELD"
733
>
734
>type
735
>
736
> member of 
737
CLASS="STRUCTNAME"
738
>test_event
739
>. So to handle each event 
740
CLASS="STRUCTFIELD"
741
>
742
>type
743
>
744
> seperately we use a 
745
CLASS="FUNCTION"
746
>switch
747
> statement.
748
749
CLASS="PROGRAMLISTING"
750
>  switch(test_event.type) {
751
>
752
We need to know what kind of events we're looking for 
753
CLASS="EMPHASIS"
754
>and
755
> the event 
756
CLASS="STRUCTFIELD"
757
>
758
>type
759
>
760
>'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 
761
CLASS="LITERAL"
762
>SDL_MOUSEMOTION
763
> is, more than likely, the event we're looking for. A little 
764
HREF="sdlmousemotionevent.html"
765
>more
766
> research tells use that 
767
CLASS="LITERAL"
768
>SDL_MOUSEMOTION
769
> events are handled within the 
770
HREF="sdlmousemotionevent.html"
771
>
772
CLASS="STRUCTNAME"
773
>SDL_MouseMotionEvent
774
>
775
> structure which is the 
776
CLASS="STRUCTFIELD"
777
>
778
>motion
779
>
780
> member of 
781
CLASS="STRUCTNAME"
782
>SDL_Event
783
>. We can check for the 
784
CLASS="LITERAL"
785
>SDL_MOUSEMOTION
786
> event 
787
CLASS="STRUCTFIELD"
788
>
789
>type
790
>
791
> within our 
792
CLASS="FUNCTION"
793
>switch
794
> statement like so:
795
796
CLASS="PROGRAMLISTING"
797
>    case SDL_MOUSEMOTION:
798
>
799
All we need do now is read the information out of the 
800
CLASS="STRUCTFIELD"
801
>
802
>motion
803
>
804
> member of 
805
CLASS="STRUCTNAME"
806
>test_event
807
>.
808
809
CLASS="PROGRAMLISTING"
810
>      printf("We got a motion event.\n");
811
      printf("Current mouse position is: (%d, %d)\n", test_event.motion.x, test_event.motion.y);
812
      break;
813
    default:
814
      printf("Unhandled Event!\n");
815
      break;
816
  }
817
}
818
printf("Event queue empty.\n");
819
>
820
>
821
>It is also possible to push events onto the event queue and so use it as a two-way communication path. Both 
822
HREF="sdlpushevent.html"
823
>
824
CLASS="FUNCTION"
825
>SDL_PushEvent
826
>
827
> and 
828
HREF="sdlpeepevents.html"
829
>
830
CLASS="FUNCTION"
831
>SDL_PeepEvents
832
>
833
> allow you to place events onto the event queue. This is usually used to place a 
834
CLASS="LITERAL"
835
>SDL_USEREVENT
836
> 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 
837
CLASS="STRUCTFIELD"
838
>
839
>type
840
>
841
> member and filling the appropriate member structure with information.
842
843
CLASS="PROGRAMLISTING"
844
>SDL_Event user_event;
845
 
846
user_event.type=SDL_USEREVENT;
847
user_event.user.code=2;
848
user_event.user.data1=NULL;
849
user_event.user.data2=NULL;
850
SDL_PushEvent(&user_event);
851
>
852
>
853
>
854
CLASS="REFSECT1"
855
>
856
NAME="AEN3509"
857
>
858
>
859
>See Also
860
>
861
>
862
HREF="sdlpollevent.html"
863
>
864
CLASS="FUNCTION"
865
>SDL_PollEvent
866
>
867
>,
868
869
HREF="sdlpushevent.html"
870
>
871
CLASS="FUNCTION"
872
>SDL_PushEvent
873
>
874
>,
875
876
HREF="sdlpeepevents.html"
877
>
878
CLASS="FUNCTION"
879
>SDL_PeepEvents
880
>
881
>
882
>
883
>
884
CLASS="NAVFOOTER"
885
>
886
ALIGN="LEFT"
887
WIDTH="100%">
888
WIDTH="100%"
889
BORDER="0"
890
CELLPADDING="0"
891
CELLSPACING="0"
892
>
893
>
894
WIDTH="33%"
895
ALIGN="left"
896
VALIGN="top"
897
>
898
HREF="eventstructures.html"
899
>Prev
900
>
901
>
902
WIDTH="34%"
903
ALIGN="center"
904
VALIGN="top"
905
>
906
HREF="index.html"
907
>Home
908
>
909
>
910
WIDTH="33%"
911
ALIGN="right"
912
VALIGN="top"
913
>
914
HREF="sdlactiveevent.html"
915
>Next
916
>
917
>
918
>
919
>
920
WIDTH="33%"
921
ALIGN="left"
922
VALIGN="top"
923
>SDL Event Structures.
924
>
925
WIDTH="34%"
926
ALIGN="center"
927
VALIGN="top"
928
>
929
HREF="eventstructures.html"
930
>Up
931
>
932
>
933
WIDTH="33%"
934
ALIGN="right"
935
VALIGN="top"
936
>SDL_ActiveEvent
937
>
938
>
939
>
940
>
941
>
942
>