ruby-sdl2 0.1.0

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