-
Notifications
You must be signed in to change notification settings - Fork 16
/
event.c
1238 lines (1155 loc) · 43.1 KB
/
event.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "rubysdl2_internal.h"
#include <SDL_events.h>
#include <SDL_version.h>
static VALUE cEvent;
static VALUE cEvQuit;
static VALUE cEvWindow;
static VALUE cEvSysWM;
static VALUE cEvKeyboard;
static VALUE cEvKeyDown;
static VALUE cEvKeyUp;
static VALUE cEvTextEditing;
static VALUE cEvTextInput;
static VALUE cEvMouseButton;
static VALUE cEvMouseButtonDown;
static VALUE cEvMouseButtonUp;
static VALUE cEvMouseMotion;
static VALUE cEvMouseWheel;
static VALUE cEvJoyAxisMotion;
static VALUE cEvJoyBallMotion;
static VALUE cEvJoyButton;
static VALUE cEvJoyButtonDown;
static VALUE cEvJoyButtonUp;
static VALUE cEvJoyHatMotion;
static VALUE cEvJoyDevice;
static VALUE cEvJoyDeviceAdded;
static VALUE cEvJoyDeviceRemoved;
static VALUE cEvControllerAxisMotion;
static VALUE cEvControllerButton;
static VALUE cEvControllerButtonDown;
static VALUE cEvControllerButtonUp;
static VALUE cEvControllerDevice;
static VALUE cEvControllerDeviceAdded;
static VALUE cEvControllerDeviceRemoved;
static VALUE cEvControllerDeviceRemapped;
static VALUE cEvTouchFinger;
static VALUE cEvFingerDown;
static VALUE cEvFingerUp;
static VALUE cEvFingerMotion;
/* static VALUE cEvUser; */
/* static VALUE cEvDrop; */
/* TODO:
- easy
SDL_FlushEvent{,s}
SDL_HasEvent{,s}
SDL_PumpEvent
SDL_PeepEvents
SDL_DropEvent
SDL_QuitRequested
- difficult
SDL_PushEvent
SDL_WaitEvent{,Timeout}
SDL_UserEvent, SDL_RegisterEvents
*/
static VALUE event_type_to_class[SDL_LASTEVENT];
/*
* Document-class: SDL2::Event
*
* This class represents SDL's events.
*
* All events are represented by the instance of subclasses of this class.
*
* # Introduction of event subsystem
* Event handling allows your application to receive input from the user. Event handling is
* initialized (along with video) with a call to:
*
* SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
*
* Internally, SDL stores all the events waiting to be handled in an event queue.
* Using methods like {SDL2::Event.poll}, you can observe and handle input events.
*
* The queue is conceptually a sequence of objects of SDL2::Event.
* You can read an event from the queue with {SDL2::Event.poll} and
* you can process the information from the object.
*
* Note: peep and wait will be implemented later.
*
* @attribute [rw] type
* SDL's internal event type enum
* @return [Integer]
*
* @attribute [rw] timestamp
* timestamp of the event
* @return [Integer]
*/
static VALUE Event_new(SDL_Event* ev)
{
SDL_Event* e = ALLOC(SDL_Event);
*e = *ev;
return Data_Wrap_Struct(event_type_to_class[ev->type], 0, free, e);
}
static VALUE Event_s_allocate(VALUE klass)
{
SDL_Event* e;
VALUE event_type = rb_iv_get(klass, "event_type");
if (event_type == Qnil)
rb_raise(rb_eArgError, "Cannot allocate %s", rb_class2name(klass));
e = ALLOC(SDL_Event);
memset(e, 0, sizeof(SDL_Event));
e->common.type = NUM2INT(event_type);
return Data_Wrap_Struct(klass, 0, free, e);
}
/*
* Poll for currently pending events.
*
* @return [SDL2::Event] next event from the queue
* @return [nil] the queue is empty
*/
static VALUE Event_s_poll(VALUE self)
{
SDL_Event ev;
if (SDL_PollEvent(&ev)) {
return Event_new(&ev);
} else {
return Qnil;
}
}
/*
* Get whether the event is enabled.
*
* This method is available for subclasses of SDL2::Event corresponding to
* SDL's event types.
*
* @see .enabled=
*/
static VALUE Event_s_enabled_p(VALUE self)
{
VALUE event_type = rb_iv_get(self, "event_type");
if (event_type == Qnil) {
rb_warn("You cannot enable %s directly", rb_class2name(self));
return Qfalse;
}
return INT2BOOL(SDL_EventState(NUM2INT(event_type), SDL_QUERY) == SDL_ENABLE);
}
/*
* @overload enable=(bool)
* Set wheter the event is enable
*
* This method is only available for subclasses of SDL2::Event corresponding to
* SDL's event types.
*
* @example disable mouse wheel events
* SDL2::Event::MouseWheel.enable = false
*
* @param [Boolean] bool true for enabling the event.
* @return [Boolean]
* @see SDL2::Event.enabled?
*
*/
static VALUE Event_s_set_enable(VALUE self, VALUE val)
{
VALUE event_type = rb_iv_get(self, "event_type");
if (event_type == Qnil)
rb_raise(rb_eArgError, "You cannot enable %s directly", rb_class2name(self));
SDL_EventState(NUM2INT(event_type), RTEST(val) ? SDL_ENABLE : SDL_DISABLE);
return val;
}
static void set_string(char* field, VALUE str, int maxlength)
{
StringValueCStr(str);
if (RSTRING_LEN(str) > maxlength)
rb_raise(rb_eArgError, "string length must be less than %d", maxlength);
strcpy(field, RSTRING_PTR(str));
}
#define EVENT_READER(classname, name, field, c2ruby) \
static VALUE Ev##classname##_##name(VALUE self) \
{ \
SDL_Event* ev; \
Data_Get_Struct(self, SDL_Event, ev); \
return c2ruby(ev->field); \
} \
#define EVENT_WRITER(classname, name, field, ruby2c) \
static VALUE Ev##classname##_set_##name(VALUE self, VALUE val) \
{ \
SDL_Event* ev; \
Data_Get_Struct(self, SDL_Event, ev); \
ev->field = ruby2c(val); \
return Qnil; \
}
#define EVENT_ACCESSOR(classname, name, field, ruby2c, c2ruby) \
EVENT_READER(classname, name, field, c2ruby) \
EVENT_WRITER(classname, name, field, ruby2c)
#define EVENT_ACCESSOR_UINT(classname, name, field) \
EVENT_ACCESSOR(classname, name, field, NUM2UINT, UINT2NUM)
#define EVENT_ACCESSOR_UINT8(classname, name, field) \
EVENT_ACCESSOR(classname, name, field, NUM2UCHAR, UCHAR2NUM)
#define EVENT_ACCESSOR_INT(classname, name, field) \
EVENT_ACCESSOR(classname, name, field, NUM2INT, INT2NUM)
#define EVENT_ACCESSOR_DBL(classname, name, field) \
EVENT_ACCESSOR(classname, name, field, NUM2DBL, DBL2NUM)
#define EVENT_ACCESSOR_BOOL(classname, name, field) \
EVENT_ACCESSOR(classname, name, field, RTEST, INT2BOOL)
EVENT_READER(Event, type, common.type, INT2NUM);
EVENT_ACCESSOR_UINT(Event, timestamp, common.timestamp);
/* @return [String] inspection string */
static VALUE Event_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp);
}
/*
* Return the object of {SDL2::Window} corresponding to the window_id attribute.
*
* Some subclasses of SDL2::Event have window_id attribute to point the
* window which creates the event. The type of the window_id attribute
* is integer, and you need to convert it with {SDL2::Window.find_by_id}
* to get the {SDL2::Window} object. This method returns the {SDL2::Window}
* object.
*
* @return [SDL2::Window] the window which creates the event.
* @raise [NoMethodError] raised if the window_id attribute is not present.
*/
static VALUE Event_window(VALUE self)
{
VALUE window_id = rb_funcall(self, rb_intern("window_id"), 0);
return find_window_by_id(NUM2UINT(window_id));
}
/*
* Document-class: SDL2::Event::Quit
*
* This class represents the quit requested event.
*
* This event occurs when a user try to close window, command-Q on OS X,
* or any other quit request by a user. Normally if your application
* receive this event, the application should exit. But the application
* can query something to the users like "save", or ignore it.
*/
/*
* Document-class: SDL2::Event::Window
*
* This class represents window event. This type of event occurs when
* window state is changed.
*
* @attribute [rw] window_id
* the associate window id
* @return [Integer]
*
* @attribute [rw] event
* event type, one of the following:
*
* * SDL2::Event::Window::NONE - (never used)
* * SDL2::Event::Window::SHOWN - window has been shown
* * SDL2::Event::Window::HIDDEN - window has been hidden
* * SDL2::Event::Window::EXPOSED - window has been exposed and should be redrawn
* * SDL2::Event::Window::MOVED - window has been moved to data1, data2
* * SDL2::Event::Window::RESIZED - window has been resized to data1xdata2;
* this is event is always preceded by SIZE_CHANGED
* * SDL2::Event::Window::SIZE_CHANGED -
* window size has changed, either as a result of an API call or through
* the system or user changing the window size;
* this event is followed by
* RESIZED if the size was changed by an external event,
* i.e. the user or the window manager
* * SDL2::Event::Window::MINIMIZED - window has been minimized
* * SDL2::Event::Window::MAXIMIZED - window has been maximized
* * SDL2::Event::Window::RESTORED - window has been restored to normal size and position
* * SDL2::Event::Window::ENTER - window has gained mouse focus
* * SDL2::Event::Window::LEAVE - window has lost mouse focus
* * SDL2::Event::Window::FOCUS_GAINED - window has gained keyboard focus
* * SDL2::Event::Window::FOCUS_LOST -window has lost keyboard focus
* * SDL2::Event::Window::CLOSE -
* the window manager requests that the window be closed
*
* @return [Integer]
*
* @attribute data1
* event dependent data
* @return [Integer]
*
* @attribute data2
* event dependent data
* @return [Integer]
*
*/
EVENT_ACCESSOR_UINT(Window, window_id, window.windowID);
EVENT_ACCESSOR_UINT(Window, event, window.event);
EVENT_ACCESSOR_INT(Window, data1, window.data1);
EVENT_ACCESSOR_INT(Window, data2, window.data2);
/* @return [String] inspection string */
static VALUE EvWindow_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u window_id=%u event=%u data1=%d data2=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->window.windowID, ev->window.event,
ev->window.data1, ev->window.data2);
}
/*
* Document-class: SDL2::Event::Keyboard
*
* This class represents keyboard event.
*
* You don't handle the instance
* of this class directly, but you handle the instances of
* two subclasses of this subclasses:
* {SDL2::Event::KeyDown} and {SDL2::Event::KeyUp}.
*
* @attribute [rw] window_id
* the associate window id
* @return [Integer]
*
* @attribute pressed
* key is pressed
* @return [boolean]
*
* @attribute repeat
* key repeat
* @return [boolean]
*
* @attribute scancode
* physical key code
* @return [Integer]
* @see SDL2::Key::Scan
*
* @attribute sym
* virtual key code
* @return [Integer]
* @see SDL2::Key
*
* @attribute mod
* current key modifier
* @return [Integer]
* @see SDL2::Key::Mod
*
*/
EVENT_ACCESSOR_UINT(Keyboard, window_id, key.windowID);
EVENT_ACCESSOR_BOOL(Keyboard, pressed, key.state);
EVENT_ACCESSOR_BOOL(Keyboard, repeat, key.repeat);
EVENT_ACCESSOR_UINT(Keyboard, scancode, key.keysym.scancode);
EVENT_ACCESSOR_UINT(Keyboard, sym, key.keysym.sym);
EVENT_ACCESSOR_UINT(Keyboard, mod, key.keysym.mod);
/* @return [String] inspection string */
static VALUE EvKeyboard_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" window_id=%u state=%u repeat=%u"
" scancode=%u sym=%u mod=%u>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->key.windowID, ev->key.state, ev->key.repeat,
ev->key.keysym.scancode, ev->key.keysym.sym, ev->key.keysym.mod);
}
/*
* Document-class: SDL2::Event::KeyDown
*
* This class represents a key down event.
*/
/*
* Document-class: SDL2::Event::KeyUp
*
* This class represents a key up event.
*/
/*
* Document-class: SDL2::Event::TextEditing
*
* This class represents text editing event.
*
* @attribute window_id
* the associate window id
* @return [Integer]
*
* @attribute text
* the editing text
* @return [String]
*
* @attribute start
* the start cursor of selected editing text
* @return [Integer]
*
* @attribute length
* the length of selected editing text
* @return [Integer]
*/
EVENT_ACCESSOR_UINT(TextEditing, window_id, edit.windowID);
EVENT_ACCESSOR_INT(TextEditing, start, edit.start);
EVENT_ACCESSOR_INT(TextEditing, length, edit.length);
EVENT_READER(TextEditing, text, edit.text, utf8str_new_cstr);
static VALUE EvTextEditing_set_text(VALUE self, VALUE str)
{
SDL_Event* ev;
Data_Get_Struct(self, SDL_Event, ev);
set_string(ev->edit.text, str, 30);
return str;
}
/* @return [String] inspection string */
static VALUE EvTextEditing_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" window_id=%u text=%s start=%d length=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->edit.windowID, ev->edit.text, ev->edit.start, ev->edit.length);
}
/*
* Document-class: SDL2::Event::TextInput
*
* This class represents text input events.
*
* @attribute window_id
* the associate window id
* @return [Integer]
*
* @attribute text
* the input text
* @return [String]
*/
EVENT_ACCESSOR_UINT(TextInput, window_id, text.windowID);
EVENT_READER(TextInput, text, text.text, utf8str_new_cstr);
static VALUE EvTextInput_set_text(VALUE self, VALUE str)
{
SDL_Event* ev;
Data_Get_Struct(self, SDL_Event, ev);
set_string(ev->text.text, str, 30);
return str;
}
/* @return [String] inspection string */
static VALUE EvTextInput_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u window_id=%u text=%s>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->text.windowID, ev->text.text);
}
/*
* Document-class: SDL2::Event::MouseButton
*
* This class represents mouse button events.
*
* You don't handle the instance
* of this class directly, but you handle the instances of
* two subclasses of this subclasses:
* {SDL2::Event::MouseButtonDown} and {SDL2::Event::MouseButtonUp}.
*
* @attribute window_id
* the window id with mouse focus
* @return [Integer]
*
* @attribute which
* the mouse index
* @return [Integer]
*
* @attribute button
* the mouse button index
* @return [Integer]
*
* @attribute pressed
* button is pressed or not
* @return [Boolean]
*
* @attribute clicks
* 1 for single click, 2 for double click
*
* This attribute is available after SDL 2.0.2
* @return [Integer]
*
* @attribute x
* the x coordinate of the mouse pointer, relative to window
* @return [Integer]
*
* @attribute y
* the y coordinate of the mouse pointer, relative to window
* @return [Integer]
*/
EVENT_ACCESSOR_UINT(MouseButton, window_id, button.windowID);
EVENT_ACCESSOR_UINT(MouseButton, which, button.which);
EVENT_ACCESSOR_UINT8(MouseButton, button, button.button);
EVENT_ACCESSOR_BOOL(MouseButton, pressed, button.state);
#if SDL_VERSION_ATLEAST(2,0,2)
EVENT_ACCESSOR_UINT8(MouseButton, clicks, button.clicks);
#endif
EVENT_ACCESSOR_INT(MouseButton, x, button.x);
EVENT_ACCESSOR_INT(MouseButton, y, button.y);
/* @return [String] inspection string */
static VALUE EvMouseButton_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" window_id=%u which=%u button=%hhu pressed=%s"
#if SDL_VERSION_ATLEAST(2,0,2)
" clicks=%hhu"
#endif
" x=%d y=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->button.windowID, ev->button.which,
ev->button.button, INT2BOOLCSTR(ev->button.state),
#if SDL_VERSION_ATLEAST(2,0,2)
ev->button.clicks,
#endif
ev->button.x, ev->button.y);
}
/*
* Document-class: SDL2::Event::MouseButtonDown
* This class represents mouse button press events.
*/
/*
* Document-class: SDL2::Event::MouseButtonUp
* This class represents mouse button release events.
*/
/*
* Document-class: SDL2::Event::MouseMotion
*
* This class represents mouse motion events.
*
* @attribute window_id
* the window id with mouse focus
* @return [Integer]
*
* @attribute which
* the mouse index
* @return [Integer]
*
* @attribute state
* the current mouse state
* @return [Integer]
* @todo use SDL2::Mouse::State
*
* @attribute x
* the x coordinate of the mouse pointer, relative to window
* @return [Integer]
*
* @attribute y
* the y coordinate of the mouse pointer, relative to window
* @return [Integer]
*
* @attribute xrel
* the relative motion in the x direction
* @return [Integer]
*
* @attribute yrel
* the relative motion in the y direction
* @return [Integer]
*/
EVENT_ACCESSOR_UINT(MouseMotion, window_id, motion.windowID);
EVENT_ACCESSOR_UINT(MouseMotion, which, motion.which);
EVENT_ACCESSOR_UINT(MouseMotion, state, motion.state);
EVENT_ACCESSOR_INT(MouseMotion, x, motion.x);
EVENT_ACCESSOR_INT(MouseMotion, y, motion.y);
EVENT_ACCESSOR_INT(MouseMotion, xrel, motion.xrel);
EVENT_ACCESSOR_INT(MouseMotion, yrel, motion.yrel);
/* @return [String] inspection string */
static VALUE EvMouseMotion_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" window_id=%u which=%u state=%u"
" x=%d y=%d xrel=%d yrel=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->motion.windowID, ev->motion.which, ev->motion.state,
ev->motion.x, ev->motion.y, ev->motion.xrel, ev->motion.yrel);
}
/*
* Document-class: SDL2::Event::MouseWheel
*
* This class represents mouse wheel events.
*
* @attribute window_id
* the window id with mouse focus
* @return [Integer]
*
* @attribute which
* the mouse index
* @return [Integer]
*
* @attribute x
* the amount of scrolled horizontally, positive to the right and negative
* to the left
* @return [Integer]
*
* @attribute y
* the amount of scrolled vertically, positve away from the user and negative
* toward the user
* @return [Integer]
*/
EVENT_ACCESSOR_UINT(MouseWheel, window_id, wheel.windowID);
EVENT_ACCESSOR_UINT(MouseWheel, which, wheel.which);
EVENT_ACCESSOR_INT(MouseWheel, x, wheel.x);
EVENT_ACCESSOR_INT(MouseWheel, y, wheel.y);
/* @return [String] inspection string */
static VALUE EvMouseWheel_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" window_id=%u which=%u x=%d y=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->wheel.windowID, ev->wheel.which, ev->wheel.x, ev->wheel.y);
}
/*
* Document-class: SDL2::Event::JoyButton
*
* This class represents joystick button events.
*
* You don't handle the instance
* of this class directly, but you handle the instances of
* two subclasses of this subclasses:
* {SDL2::Event::JoyButtonDown} and {SDL2::Event::JoyButtonUp}.
*
* @attribute which
* the joystick index
* @return [Integer]
*
* @attribute button
* the joystick button index
* @return [Integer]
*
* @attribute pressed
* button is pressed or not
* @return [Boolean]
*
*/
EVENT_ACCESSOR_INT(JoyButton, which, jbutton.which);
EVENT_ACCESSOR_UINT8(JoyButton, button, jbutton.button);
EVENT_ACCESSOR_BOOL(JoyButton, pressed, jbutton.state);
/* @return [String] inspection string */
static VALUE EvJoyButton_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" which=%d button=%u pressed=%s>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->jbutton.which, ev->jbutton.button,
INT2BOOLCSTR(ev->jbutton.state));
}
/*
* Document-class: SDL2::Event::JoyButtonDown
*
* This class represents the joystick button press events.
*/
/*
* Document-class: SDL2::Event::JoyButtonUp
*
* This class represents the joystick button release events.
*/
/*
* Document-class: SDL2::Event::JoyAxisMotion
*
* This class represents the joystick axis motion events.
*
* @attribute which
* the joystick index
* @return [Integer]
*
* @attribute axis
* the axis index
* @return [Integer]
*
* @attribute value
* the axis value (range: -32768 to -32767, 0 for newtral)
* @return [Integer]
*/
EVENT_ACCESSOR_INT(JoyAxisMotion, which, jaxis.which);
EVENT_ACCESSOR_UINT8(JoyAxisMotion, axis, jaxis.axis);
EVENT_ACCESSOR_INT(JoyAxisMotion, value, jaxis.value);
/* @return [String] inspection string */
static VALUE EvJoyAxisMotion_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" which=%d axis=%u value=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->jaxis.which, ev->jaxis.axis, ev->jaxis.value);
}
/*
* Document-class: SDL2::Event::JoyBallMotion
*
* This class represents the joystick trackball motion events.
*
* @attribute which
* the joystick index
* @return [Integer]
*
* @attribute ball
* the joystick trackball index
* @return [Integer]
*
* @attribute xrel
* the relative motion in the x direction
* @return [Integer]
*
* @attribute yrel
* the relative motion in the y direction
* @return [Integer]
*/
EVENT_ACCESSOR_INT(JoyBallMotion, which, jball.which);
EVENT_ACCESSOR_UINT8(JoyBallMotion, ball, jball.ball);
EVENT_ACCESSOR_INT(JoyBallMotion, xrel, jball.xrel);
EVENT_ACCESSOR_INT(JoyBallMotion, yrel, jball.yrel);
/* @return [String] inspection string */
static VALUE EvJoyBallMotion_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" which=%d ball=%u xrel=%d yrel=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->jball.which, ev->jball.ball, ev->jball.xrel, ev->jball.yrel);
}
/*
* Document-class: SDL2::Event::JoyHatMotion
*
* This class represents the joystick hat position change events.
*
* @attribute which
* the joystick index
* @return [Integer]
*
* @attribute hat
* the joystick hat index
* @return [Integer]
*
* @attribute value
* the hat position value, same value as {SDL2::Joystick#hat}.
* @return [Integer]
*/
EVENT_ACCESSOR_INT(JoyHatMotion, which, jhat.which);
EVENT_ACCESSOR_UINT8(JoyHatMotion, hat, jhat.hat);
EVENT_ACCESSOR_UINT8(JoyHatMotion, value, jhat.value);
/* @return [String] inspection string */
static VALUE EvJoyHatMotion_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u which=%d hat=%u value=%u>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->jhat.which, ev->jhat.hat, ev->jhat.value);
}
/*
* Document-class: SDL2::Event::JoyDevice
*
* This class represents joystick device events
* ({SDL2::Event::JoyDeviceAdded joystick connected events} and
* {SDL2::Event::JoyDeviceRemoved joystick disconnected events}).
*/
EVENT_ACCESSOR_INT(JoyDevice, which, jdevice.which);
/* @return [String] inspection string */
static VALUE EvJoyDevice_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u which=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->jdevice.which);
}
/*
* Document-class: SDL2::Event::JoyDeviceAdded
*
* This class represents joystick device connected events.
*/
/*
* Document-class: SDL2::Event::JoyDeviceRemoved
*
* This class represents joystick device disconnected events.
*/
/*
* Document-class: SDL2::Event::ControllerAxisMotion
*
* This class represents the {SDL2::GameController controller} axis motion events.
*
* @attribute which
* the controller index
* @return [Integer]
*
* @attribute axis
* the axis index
* @return [Integer]
*
* @attribute value
* the axis value (range: -32768 to -32767, 0 for newtral)
* @return [Integer]
*/
EVENT_ACCESSOR_INT(ControllerAxis, which, caxis.which);
EVENT_ACCESSOR_UINT8(ControllerAxis, axis, caxis.axis);
EVENT_ACCESSOR_INT(ControllerAxis, value, caxis.value);
/* @return [String] inspection string */
static VALUE ControllerAxis_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" which=%d axis=%s value=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->caxis.which, SDL_GameControllerGetStringForAxis(ev->caxis.axis),
ev->caxis.value);
}
/*
* Document-class: SDL2::Event::ControllerButton
*
* This class represents the {SDL2::GameController controller} button events.
*
* You don't handle the instance
* of this class directly, but you handle the instances of
* two subclasses of this subclasses:
* {SDL2::Event::ControllerButtonDown} and {SDL2::Event::ControllerButtonUp}.
*
* @attribute which
* the controller index
* @return [Integer]
*
* @attribute button
* the controller button index
* @return [Integer]
*
* @attribute pressed
* button is pressed or not
* @return [Boolean]
*
*/
EVENT_ACCESSOR_INT(ControllerButton, which, cbutton.which);
EVENT_ACCESSOR_UINT8(ControllerButton, button, cbutton.button);
EVENT_ACCESSOR_BOOL(ControllerButton, pressed, cbutton.state);
/* @return [String] inspection string */
static VALUE ControllerButton_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" which=%d button=%s state=%s>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->cbutton.which,
SDL_GameControllerGetStringForButton(ev->cbutton.button),
INT2BOOLCSTR(ev->cbutton.state));
}
/*
* Document-class: SDL2::Event::ControllerButtonDown
*
* This class represents the {SDL2::GameController controller} button press events.
*/
/*
* Document-class: SDL2::Event::ControllerButtonUp
*
* This class represents the {SDL2::GameController controller} button release events.
*/
/*
* Document-class: SDL2::Event::ControllerDevice
*
* This class represents {SDL2::GameController controller} device events (connected/disconnected/remapped).
*
* The event of this event doesn't occur. Only the event of the following subclasses
* occur in Ruby/SDL2.
*
* * {SDL2::Event::ControllerDeviceAdded}
* * {SDL2::Event::ControllerDeviceRemoved}
* * {SDL2::Event::ControllerDeviceRemapped}
*
* @attribute which
* the controller index
* @return [Integer]
*/
EVENT_ACCESSOR_INT(ControllerDevice, which, cdevice.which);
/* @return [String] inspection string */
static VALUE ControllerDevice_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u which=%d>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
ev->cdevice.which);
}
/*
* Document-class: SDL2::Event::ControllerDeviceAdded
*
* This class represents {SDL2::GameController controller} device connected events.
*/
/*
* Document-class: SDL2::Event::ControllerDeviceRemoved
*
* This class represents {SDL2::GameController controller} device disconnected events.
*/
/*
* Document-class: SDL2::Event::ControllerDeviceRemapped
*
* This class represents {SDL2::GameController controller} device remapped events.
*/
/*
* Document-class: SDL2::Event::TouchFinger
*
* This class represents touch finger events.
*
* You don't handle the instance
* of this class directly, but you handle the instances of
* two subclasses of this subclasses:
* {SDL2::Event::FingerMotion}, {SDL2::Event::FingerDown}, and {SDL2::Event::FingerUp}.
*
* @attribute touch_id
* the touch device id
* @return [Integer]
*
* @attribute finger_id
* the finger id
* @return [Integer]
*
* @attribute x
* the x-axis location of the touch event, normalized (0...1)
* @return [Float]
*
* @attribute y
* the y-axis location of the touch event, normalized (0...1)
* @return [Float]
*
* @attribute pressure
* the quantity of pressure applied, normalized (0...1)
* @return [Float]
*/
EVENT_ACCESSOR_INT(TouchFinger, touch_id, tfinger.touchId);
EVENT_ACCESSOR_INT(TouchFinger, finger_id, tfinger.fingerId);
EVENT_ACCESSOR_DBL(TouchFinger, x, tfinger.x);
EVENT_ACCESSOR_DBL(TouchFinger, y, tfinger.y);
EVENT_ACCESSOR_DBL(TouchFinger, pressure, tfinger.pressure);
/* @return [String] inspection string */
static VALUE EvTouchFinger_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" touch_id=%d finger_id=%d"
" x=%f y=%f pressure=%f>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
(int)ev->tfinger.touchId, (int)ev->tfinger.fingerId,
ev->tfinger.x, ev->tfinger.y, ev->tfinger.pressure);
}
/*
* Document-class: SDL2::Event::FingerUp
* This class represents finger touch events.
*/
/*
* Document-class: SDL2::Event::FingerDown
* This class represents finger release events.
*/
/*
* Document-class: SDL2::Event::FingerMotion
*
* This class represents touch move events.
*
* @attribute dx
* the distance moved in the x-axis, normalized (0...1)
* @return [Float]
*
* @attribute dy
* the distance moved in the y-axis, normalized (0...1)
* @return [Float]
*
*/
EVENT_ACCESSOR_DBL(FingerMotion, dx, tfinger.dx);
EVENT_ACCESSOR_DBL(FingerMotion, dy, tfinger.dy);
/* @return [String] inspection string */
static VALUE EvFingerMotion_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u"
" touch_id=%d finger_id=%d"
" x=%f y=%f pressure=%f"
" dy=%f dx=%f>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
(int) ev->tfinger.touchId, (int) ev->tfinger.fingerId,
ev->tfinger.x, ev->tfinger.y, ev->tfinger.pressure,