sdl2-bindings 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +140 -124
  3. data/LICENSE.txt +0 -0
  4. data/README.md +93 -77
  5. data/lib/sdl2.rb +131 -131
  6. data/lib/sdl2_audio.rb +265 -261
  7. data/lib/sdl2_blendmode.rb +72 -72
  8. data/lib/sdl2_clipboard.rb +56 -56
  9. data/lib/sdl2_cpuinfo.rb +137 -129
  10. data/lib/sdl2_error.rb +71 -71
  11. data/lib/sdl2_events.rb +575 -564
  12. data/lib/sdl2_filesystem.rb +52 -52
  13. data/lib/sdl2_framerate.rb +74 -74
  14. data/lib/sdl2_gamecontroller.rb +345 -329
  15. data/lib/sdl2_gesture.rb +61 -61
  16. data/lib/sdl2_gfxPrimitives.rb +283 -283
  17. data/lib/sdl2_guid.rb +58 -0
  18. data/lib/sdl2_haptic.rb +301 -301
  19. data/lib/sdl2_hidapi.rb +139 -139
  20. data/lib/sdl2_hints.rb +240 -221
  21. data/lib/sdl2_image.rb +296 -232
  22. data/lib/sdl2_imageFilter.rb +164 -164
  23. data/lib/sdl2_joystick.rb +332 -294
  24. data/lib/sdl2_keyboard.rb +129 -125
  25. data/lib/sdl2_keycode.rb +311 -307
  26. data/lib/sdl2_log.rb +131 -131
  27. data/lib/sdl2_main.rb +74 -74
  28. data/lib/sdl2_messagebox.rb +102 -102
  29. data/lib/sdl2_misc.rb +48 -48
  30. data/lib/sdl2_mixer.rb +464 -392
  31. data/lib/sdl2_mouse.rb +136 -136
  32. data/lib/sdl2_pixels.rb +240 -240
  33. data/lib/sdl2_platform.rb +48 -48
  34. data/lib/sdl2_power.rb +54 -54
  35. data/lib/sdl2_rect.rb +145 -145
  36. data/lib/sdl2_render.rb +408 -408
  37. data/lib/sdl2_rotozoom.rb +76 -76
  38. data/lib/sdl2_rwops.rb +242 -238
  39. data/lib/sdl2_scancode.rb +293 -289
  40. data/lib/sdl2_sensor.rb +115 -115
  41. data/lib/sdl2_shape.rb +83 -83
  42. data/lib/sdl2_sound.rb +154 -154
  43. data/lib/sdl2_stdinc.rb +564 -556
  44. data/lib/sdl2_surface.rb +229 -229
  45. data/lib/sdl2_syswm.rb +160 -160
  46. data/lib/sdl2_timer.rb +74 -74
  47. data/lib/sdl2_touch.rb +86 -86
  48. data/lib/sdl2_ttf.rb +414 -358
  49. data/lib/sdl2_version.rb +67 -67
  50. data/lib/sdl2_video.rb +549 -540
  51. data/lib/sdl2_vulkan.rb +72 -72
  52. metadata +4 -3
data/lib/sdl2_events.rb CHANGED
@@ -1,564 +1,575 @@
1
- # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby
2
- #
3
- # * https://github.com/vaiorabbit/sdl2-bindings
4
- #
5
- # [NOTICE] This is an automatically generated file.
6
-
7
- require 'ffi'
8
- require_relative 'sdl2_keyboard'
9
-
10
- module SDL
11
- extend FFI::Library
12
- # Define/Macro
13
-
14
- RELEASED = 0
15
- PRESSED = 1
16
- TEXTEDITINGEVENT_TEXT_SIZE = 32
17
- TEXTINPUTEVENT_TEXT_SIZE = 32
18
- QUERY = -1
19
- IGNORE = 0
20
- DISABLE = 0
21
- ENABLE = 1
22
-
23
- # Enum
24
-
25
- FIRSTEVENT = 0
26
- QUIT = 256
27
- APP_TERMINATING = 257
28
- APP_LOWMEMORY = 258
29
- APP_WILLENTERBACKGROUND = 259
30
- APP_DIDENTERBACKGROUND = 260
31
- APP_WILLENTERFOREGROUND = 261
32
- APP_DIDENTERFOREGROUND = 262
33
- LOCALECHANGED = 263
34
- DISPLAYEVENT = 336
35
- WINDOWEVENT = 512
36
- SYSWMEVENT = 513
37
- KEYDOWN = 768
38
- KEYUP = 769
39
- TEXTEDITING = 770
40
- TEXTINPUT = 771
41
- KEYMAPCHANGED = 772
42
- TEXTEDITING_EXT = 773
43
- MOUSEMOTION = 1024
44
- MOUSEBUTTONDOWN = 1025
45
- MOUSEBUTTONUP = 1026
46
- MOUSEWHEEL = 1027
47
- JOYAXISMOTION = 1536
48
- JOYBALLMOTION = 1537
49
- JOYHATMOTION = 1538
50
- JOYBUTTONDOWN = 1539
51
- JOYBUTTONUP = 1540
52
- JOYDEVICEADDED = 1541
53
- JOYDEVICEREMOVED = 1542
54
- CONTROLLERAXISMOTION = 1616
55
- CONTROLLERBUTTONDOWN = 1617
56
- CONTROLLERBUTTONUP = 1618
57
- CONTROLLERDEVICEADDED = 1619
58
- CONTROLLERDEVICEREMOVED = 1620
59
- CONTROLLERDEVICEREMAPPED = 1621
60
- CONTROLLERTOUCHPADDOWN = 1622
61
- CONTROLLERTOUCHPADMOTION = 1623
62
- CONTROLLERTOUCHPADUP = 1624
63
- CONTROLLERSENSORUPDATE = 1625
64
- FINGERDOWN = 1792
65
- FINGERUP = 1793
66
- FINGERMOTION = 1794
67
- DOLLARGESTURE = 2048
68
- DOLLARRECORD = 2049
69
- MULTIGESTURE = 2050
70
- CLIPBOARDUPDATE = 2304
71
- DROPFILE = 4096
72
- DROPTEXT = 4097
73
- DROPBEGIN = 4098
74
- DROPCOMPLETE = 4099
75
- AUDIODEVICEADDED = 4352
76
- AUDIODEVICEREMOVED = 4353
77
- SENSORUPDATE = 4608
78
- RENDER_TARGETS_RESET = 8192
79
- RENDER_DEVICE_RESET = 8193
80
- POLLSENTINEL = 32512
81
- USEREVENT = 32768
82
- LASTEVENT = 65535
83
- ADDEVENT = 0
84
- PEEKEVENT = 1
85
- GETEVENT = 2
86
-
87
- # Typedef
88
-
89
- typedef :int, :SDL_EventType
90
- typedef :int, :SDL_eventaction
91
- callback :SDL_EventFilter, [:pointer, :pointer], :int
92
-
93
- # Struct
94
-
95
- class CommonEvent < FFI::Struct
96
- layout(
97
- :type, :uint,
98
- :timestamp, :uint,
99
- )
100
- end
101
-
102
- class DisplayEvent < FFI::Struct
103
- layout(
104
- :type, :uint,
105
- :timestamp, :uint,
106
- :display, :uint,
107
- :event, :uchar,
108
- :padding1, :uchar,
109
- :padding2, :uchar,
110
- :padding3, :uchar,
111
- :data1, :int,
112
- )
113
- end
114
-
115
- class WindowEvent < FFI::Struct
116
- layout(
117
- :type, :uint,
118
- :timestamp, :uint,
119
- :windowID, :uint,
120
- :event, :uchar,
121
- :padding1, :uchar,
122
- :padding2, :uchar,
123
- :padding3, :uchar,
124
- :data1, :int,
125
- :data2, :int,
126
- )
127
- end
128
-
129
- class KeyboardEvent < FFI::Struct
130
- layout(
131
- :type, :uint,
132
- :timestamp, :uint,
133
- :windowID, :uint,
134
- :state, :uchar,
135
- :repeat, :uchar,
136
- :padding2, :uchar,
137
- :padding3, :uchar,
138
- :keysym, Keysym,
139
- )
140
- end
141
-
142
- class TextEditingEvent < FFI::Struct
143
- layout(
144
- :type, :uint,
145
- :timestamp, :uint,
146
- :windowID, :uint,
147
- :text, [:char, 32],
148
- :start, :int,
149
- :length, :int,
150
- )
151
- end
152
-
153
- class TextEditingExtEvent < FFI::Struct
154
- layout(
155
- :type, :uint,
156
- :timestamp, :uint,
157
- :windowID, :uint,
158
- :text, :pointer,
159
- :start, :int,
160
- :length, :int,
161
- )
162
- end
163
-
164
- class TextInputEvent < FFI::Struct
165
- layout(
166
- :type, :uint,
167
- :timestamp, :uint,
168
- :windowID, :uint,
169
- :text, [:char, 32],
170
- )
171
- end
172
-
173
- class MouseMotionEvent < FFI::Struct
174
- layout(
175
- :type, :uint,
176
- :timestamp, :uint,
177
- :windowID, :uint,
178
- :which, :uint,
179
- :state, :uint,
180
- :x, :int,
181
- :y, :int,
182
- :xrel, :int,
183
- :yrel, :int,
184
- )
185
- end
186
-
187
- class MouseButtonEvent < FFI::Struct
188
- layout(
189
- :type, :uint,
190
- :timestamp, :uint,
191
- :windowID, :uint,
192
- :which, :uint,
193
- :button, :uchar,
194
- :state, :uchar,
195
- :clicks, :uchar,
196
- :padding1, :uchar,
197
- :x, :int,
198
- :y, :int,
199
- )
200
- end
201
-
202
- class MouseWheelEvent < FFI::Struct
203
- layout(
204
- :type, :uint,
205
- :timestamp, :uint,
206
- :windowID, :uint,
207
- :which, :uint,
208
- :x, :int,
209
- :y, :int,
210
- :direction, :uint,
211
- :preciseX, :float,
212
- :preciseY, :float,
213
- )
214
- end
215
-
216
- class JoyAxisEvent < FFI::Struct
217
- layout(
218
- :type, :uint,
219
- :timestamp, :uint,
220
- :which, :int,
221
- :axis, :uchar,
222
- :padding1, :uchar,
223
- :padding2, :uchar,
224
- :padding3, :uchar,
225
- :value, :short,
226
- :padding4, :ushort,
227
- )
228
- end
229
-
230
- class JoyBallEvent < FFI::Struct
231
- layout(
232
- :type, :uint,
233
- :timestamp, :uint,
234
- :which, :int,
235
- :ball, :uchar,
236
- :padding1, :uchar,
237
- :padding2, :uchar,
238
- :padding3, :uchar,
239
- :xrel, :short,
240
- :yrel, :short,
241
- )
242
- end
243
-
244
- class JoyHatEvent < FFI::Struct
245
- layout(
246
- :type, :uint,
247
- :timestamp, :uint,
248
- :which, :int,
249
- :hat, :uchar,
250
- :value, :uchar,
251
- :padding1, :uchar,
252
- :padding2, :uchar,
253
- )
254
- end
255
-
256
- class JoyButtonEvent < FFI::Struct
257
- layout(
258
- :type, :uint,
259
- :timestamp, :uint,
260
- :which, :int,
261
- :button, :uchar,
262
- :state, :uchar,
263
- :padding1, :uchar,
264
- :padding2, :uchar,
265
- )
266
- end
267
-
268
- class JoyDeviceEvent < FFI::Struct
269
- layout(
270
- :type, :uint,
271
- :timestamp, :uint,
272
- :which, :int,
273
- )
274
- end
275
-
276
- class ControllerAxisEvent < FFI::Struct
277
- layout(
278
- :type, :uint,
279
- :timestamp, :uint,
280
- :which, :int,
281
- :axis, :uchar,
282
- :padding1, :uchar,
283
- :padding2, :uchar,
284
- :padding3, :uchar,
285
- :value, :short,
286
- :padding4, :ushort,
287
- )
288
- end
289
-
290
- class ControllerButtonEvent < FFI::Struct
291
- layout(
292
- :type, :uint,
293
- :timestamp, :uint,
294
- :which, :int,
295
- :button, :uchar,
296
- :state, :uchar,
297
- :padding1, :uchar,
298
- :padding2, :uchar,
299
- )
300
- end
301
-
302
- class ControllerDeviceEvent < FFI::Struct
303
- layout(
304
- :type, :uint,
305
- :timestamp, :uint,
306
- :which, :int,
307
- )
308
- end
309
-
310
- class ControllerTouchpadEvent < FFI::Struct
311
- layout(
312
- :type, :uint,
313
- :timestamp, :uint,
314
- :which, :int,
315
- :touchpad, :int,
316
- :finger, :int,
317
- :x, :float,
318
- :y, :float,
319
- :pressure, :float,
320
- )
321
- end
322
-
323
- class ControllerSensorEvent < FFI::Struct
324
- layout(
325
- :type, :uint,
326
- :timestamp, :uint,
327
- :which, :int,
328
- :sensor, :int,
329
- :data, [:float, 3],
330
- )
331
- end
332
-
333
- class AudioDeviceEvent < FFI::Struct
334
- layout(
335
- :type, :uint,
336
- :timestamp, :uint,
337
- :which, :uint,
338
- :iscapture, :uchar,
339
- :padding1, :uchar,
340
- :padding2, :uchar,
341
- :padding3, :uchar,
342
- )
343
- end
344
-
345
- class TouchFingerEvent < FFI::Struct
346
- layout(
347
- :type, :uint,
348
- :timestamp, :uint,
349
- :touchId, :long_long,
350
- :fingerId, :long_long,
351
- :x, :float,
352
- :y, :float,
353
- :dx, :float,
354
- :dy, :float,
355
- :pressure, :float,
356
- :windowID, :uint,
357
- )
358
- end
359
-
360
- class MultiGestureEvent < FFI::Struct
361
- layout(
362
- :type, :uint,
363
- :timestamp, :uint,
364
- :touchId, :long_long,
365
- :dTheta, :float,
366
- :dDist, :float,
367
- :x, :float,
368
- :y, :float,
369
- :numFingers, :ushort,
370
- :padding, :ushort,
371
- )
372
- end
373
-
374
- class DollarGestureEvent < FFI::Struct
375
- layout(
376
- :type, :uint,
377
- :timestamp, :uint,
378
- :touchId, :long_long,
379
- :gestureId, :long_long,
380
- :numFingers, :uint,
381
- :error, :float,
382
- :x, :float,
383
- :y, :float,
384
- )
385
- end
386
-
387
- class DropEvent < FFI::Struct
388
- layout(
389
- :type, :uint,
390
- :timestamp, :uint,
391
- :file, :pointer,
392
- :windowID, :uint,
393
- )
394
- end
395
-
396
- class SensorEvent < FFI::Struct
397
- layout(
398
- :type, :uint,
399
- :timestamp, :uint,
400
- :which, :int,
401
- :data, [:float, 6],
402
- )
403
- end
404
-
405
- class QuitEvent < FFI::Struct
406
- layout(
407
- :type, :uint,
408
- :timestamp, :uint,
409
- )
410
- end
411
-
412
- class OSEvent < FFI::Struct
413
- layout(
414
- :type, :uint,
415
- :timestamp, :uint,
416
- )
417
- end
418
-
419
- class UserEvent < FFI::Struct
420
- layout(
421
- :type, :uint,
422
- :timestamp, :uint,
423
- :windowID, :uint,
424
- :code, :int,
425
- :data1, :pointer,
426
- :data2, :pointer,
427
- )
428
- end
429
-
430
- class SysWMEvent < FFI::Struct
431
- layout(
432
- :type, :uint,
433
- :timestamp, :uint,
434
- :msg, :pointer,
435
- )
436
- end
437
-
438
- class Event < FFI::Union
439
- layout(
440
- :type, :uint,
441
- :common, CommonEvent,
442
- :display, DisplayEvent,
443
- :window, WindowEvent,
444
- :key, KeyboardEvent,
445
- :edit, TextEditingEvent,
446
- :editExt, TextEditingExtEvent,
447
- :text, TextInputEvent,
448
- :motion, MouseMotionEvent,
449
- :button, MouseButtonEvent,
450
- :wheel, MouseWheelEvent,
451
- :jaxis, JoyAxisEvent,
452
- :jball, JoyBallEvent,
453
- :jhat, JoyHatEvent,
454
- :jbutton, JoyButtonEvent,
455
- :jdevice, JoyDeviceEvent,
456
- :caxis, ControllerAxisEvent,
457
- :cbutton, ControllerButtonEvent,
458
- :cdevice, ControllerDeviceEvent,
459
- :ctouchpad, ControllerTouchpadEvent,
460
- :csensor, ControllerSensorEvent,
461
- :adevice, AudioDeviceEvent,
462
- :sensor, SensorEvent,
463
- :quit, QuitEvent,
464
- :user, UserEvent,
465
- :syswm, SysWMEvent,
466
- :tfinger, TouchFingerEvent,
467
- :mgesture, MultiGestureEvent,
468
- :dgesture, DollarGestureEvent,
469
- :drop, DropEvent,
470
- :padding, [:uchar, 56],
471
- )
472
- end
473
-
474
-
475
- # Function
476
-
477
- def self.setup_events_symbols(output_error = false)
478
- symbols = [
479
- :SDL_PumpEvents,
480
- :SDL_PeepEvents,
481
- :SDL_HasEvent,
482
- :SDL_HasEvents,
483
- :SDL_FlushEvent,
484
- :SDL_FlushEvents,
485
- :SDL_PollEvent,
486
- :SDL_WaitEvent,
487
- :SDL_WaitEventTimeout,
488
- :SDL_PushEvent,
489
- :SDL_SetEventFilter,
490
- :SDL_GetEventFilter,
491
- :SDL_AddEventWatch,
492
- :SDL_DelEventWatch,
493
- :SDL_FilterEvents,
494
- :SDL_EventState,
495
- :SDL_RegisterEvents,
496
- ]
497
- apis = {
498
- :SDL_PumpEvents => :PumpEvents,
499
- :SDL_PeepEvents => :PeepEvents,
500
- :SDL_HasEvent => :HasEvent,
501
- :SDL_HasEvents => :HasEvents,
502
- :SDL_FlushEvent => :FlushEvent,
503
- :SDL_FlushEvents => :FlushEvents,
504
- :SDL_PollEvent => :PollEvent,
505
- :SDL_WaitEvent => :WaitEvent,
506
- :SDL_WaitEventTimeout => :WaitEventTimeout,
507
- :SDL_PushEvent => :PushEvent,
508
- :SDL_SetEventFilter => :SetEventFilter,
509
- :SDL_GetEventFilter => :GetEventFilter,
510
- :SDL_AddEventWatch => :AddEventWatch,
511
- :SDL_DelEventWatch => :DelEventWatch,
512
- :SDL_FilterEvents => :FilterEvents,
513
- :SDL_EventState => :EventState,
514
- :SDL_RegisterEvents => :RegisterEvents,
515
- }
516
- args = {
517
- :SDL_PumpEvents => [],
518
- :SDL_PeepEvents => [:pointer, :int, :int, :uint, :uint],
519
- :SDL_HasEvent => [:uint],
520
- :SDL_HasEvents => [:uint, :uint],
521
- :SDL_FlushEvent => [:uint],
522
- :SDL_FlushEvents => [:uint, :uint],
523
- :SDL_PollEvent => [:pointer],
524
- :SDL_WaitEvent => [:pointer],
525
- :SDL_WaitEventTimeout => [:pointer, :int],
526
- :SDL_PushEvent => [:pointer],
527
- :SDL_SetEventFilter => [:SDL_EventFilter, :pointer],
528
- :SDL_GetEventFilter => [:pointer, :pointer],
529
- :SDL_AddEventWatch => [:SDL_EventFilter, :pointer],
530
- :SDL_DelEventWatch => [:SDL_EventFilter, :pointer],
531
- :SDL_FilterEvents => [:SDL_EventFilter, :pointer],
532
- :SDL_EventState => [:uint, :int],
533
- :SDL_RegisterEvents => [:int],
534
- }
535
- retvals = {
536
- :SDL_PumpEvents => :void,
537
- :SDL_PeepEvents => :int,
538
- :SDL_HasEvent => :int,
539
- :SDL_HasEvents => :int,
540
- :SDL_FlushEvent => :void,
541
- :SDL_FlushEvents => :void,
542
- :SDL_PollEvent => :int,
543
- :SDL_WaitEvent => :int,
544
- :SDL_WaitEventTimeout => :int,
545
- :SDL_PushEvent => :int,
546
- :SDL_SetEventFilter => :void,
547
- :SDL_GetEventFilter => :int,
548
- :SDL_AddEventWatch => :void,
549
- :SDL_DelEventWatch => :void,
550
- :SDL_FilterEvents => :void,
551
- :SDL_EventState => :uchar,
552
- :SDL_RegisterEvents => :uint,
553
- }
554
- symbols.each do |sym|
555
- begin
556
- attach_function apis[sym], sym, args[sym], retvals[sym]
557
- rescue FFI::NotFoundError => error
558
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
559
- end
560
- end
561
- end
562
-
563
- end
564
-
1
+ # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby
2
+ #
3
+ # * https://github.com/vaiorabbit/sdl2-bindings
4
+ #
5
+ # [NOTICE] This is an automatically generated file.
6
+
7
+ require 'ffi'
8
+ require_relative 'sdl2_keyboard'
9
+
10
+ module SDL
11
+ extend FFI::Library
12
+ # Define/Macro
13
+
14
+ RELEASED = 0
15
+ PRESSED = 1
16
+ TEXTEDITINGEVENT_TEXT_SIZE = 32
17
+ TEXTINPUTEVENT_TEXT_SIZE = 32
18
+ QUERY = -1
19
+ IGNORE = 0
20
+ DISABLE = 0
21
+ ENABLE = 1
22
+
23
+ # Enum
24
+
25
+ FIRSTEVENT = 0
26
+ QUIT = 256
27
+ APP_TERMINATING = 257
28
+ APP_LOWMEMORY = 258
29
+ APP_WILLENTERBACKGROUND = 259
30
+ APP_DIDENTERBACKGROUND = 260
31
+ APP_WILLENTERFOREGROUND = 261
32
+ APP_DIDENTERFOREGROUND = 262
33
+ LOCALECHANGED = 263
34
+ DISPLAYEVENT = 336
35
+ WINDOWEVENT = 512
36
+ SYSWMEVENT = 513
37
+ KEYDOWN = 768
38
+ KEYUP = 769
39
+ TEXTEDITING = 770
40
+ TEXTINPUT = 771
41
+ KEYMAPCHANGED = 772
42
+ TEXTEDITING_EXT = 773
43
+ MOUSEMOTION = 1024
44
+ MOUSEBUTTONDOWN = 1025
45
+ MOUSEBUTTONUP = 1026
46
+ MOUSEWHEEL = 1027
47
+ JOYAXISMOTION = 1536
48
+ JOYBALLMOTION = 1537
49
+ JOYHATMOTION = 1538
50
+ JOYBUTTONDOWN = 1539
51
+ JOYBUTTONUP = 1540
52
+ JOYDEVICEADDED = 1541
53
+ JOYDEVICEREMOVED = 1542
54
+ JOYBATTERYUPDATED = 1543
55
+ CONTROLLERAXISMOTION = 1616
56
+ CONTROLLERBUTTONDOWN = 1617
57
+ CONTROLLERBUTTONUP = 1618
58
+ CONTROLLERDEVICEADDED = 1619
59
+ CONTROLLERDEVICEREMOVED = 1620
60
+ CONTROLLERDEVICEREMAPPED = 1621
61
+ CONTROLLERTOUCHPADDOWN = 1622
62
+ CONTROLLERTOUCHPADMOTION = 1623
63
+ CONTROLLERTOUCHPADUP = 1624
64
+ CONTROLLERSENSORUPDATE = 1625
65
+ FINGERDOWN = 1792
66
+ FINGERUP = 1793
67
+ FINGERMOTION = 1794
68
+ DOLLARGESTURE = 2048
69
+ DOLLARRECORD = 2049
70
+ MULTIGESTURE = 2050
71
+ CLIPBOARDUPDATE = 2304
72
+ DROPFILE = 4096
73
+ DROPTEXT = 4097
74
+ DROPBEGIN = 4098
75
+ DROPCOMPLETE = 4099
76
+ AUDIODEVICEADDED = 4352
77
+ AUDIODEVICEREMOVED = 4353
78
+ SENSORUPDATE = 4608
79
+ RENDER_TARGETS_RESET = 8192
80
+ RENDER_DEVICE_RESET = 8193
81
+ POLLSENTINEL = 32512
82
+ USEREVENT = 32768
83
+ LASTEVENT = 65535
84
+ ADDEVENT = 0
85
+ PEEKEVENT = 1
86
+ GETEVENT = 2
87
+
88
+ # Typedef
89
+
90
+ typedef :int, :SDL_EventType
91
+ typedef :int, :SDL_eventaction
92
+ callback :SDL_EventFilter, [:pointer, :pointer], :int
93
+
94
+ # Struct
95
+
96
+ class CommonEvent < FFI::Struct
97
+ layout(
98
+ :type, :uint,
99
+ :timestamp, :uint,
100
+ )
101
+ end
102
+
103
+ class DisplayEvent < FFI::Struct
104
+ layout(
105
+ :type, :uint,
106
+ :timestamp, :uint,
107
+ :display, :uint,
108
+ :event, :uchar,
109
+ :padding1, :uchar,
110
+ :padding2, :uchar,
111
+ :padding3, :uchar,
112
+ :data1, :int,
113
+ )
114
+ end
115
+
116
+ class WindowEvent < FFI::Struct
117
+ layout(
118
+ :type, :uint,
119
+ :timestamp, :uint,
120
+ :windowID, :uint,
121
+ :event, :uchar,
122
+ :padding1, :uchar,
123
+ :padding2, :uchar,
124
+ :padding3, :uchar,
125
+ :data1, :int,
126
+ :data2, :int,
127
+ )
128
+ end
129
+
130
+ class KeyboardEvent < FFI::Struct
131
+ layout(
132
+ :type, :uint,
133
+ :timestamp, :uint,
134
+ :windowID, :uint,
135
+ :state, :uchar,
136
+ :repeat, :uchar,
137
+ :padding2, :uchar,
138
+ :padding3, :uchar,
139
+ :keysym, Keysym,
140
+ )
141
+ end
142
+
143
+ class TextEditingEvent < FFI::Struct
144
+ layout(
145
+ :type, :uint,
146
+ :timestamp, :uint,
147
+ :windowID, :uint,
148
+ :text, [:char, 32],
149
+ :start, :int,
150
+ :length, :int,
151
+ )
152
+ end
153
+
154
+ class TextEditingExtEvent < FFI::Struct
155
+ layout(
156
+ :type, :uint,
157
+ :timestamp, :uint,
158
+ :windowID, :uint,
159
+ :text, :pointer,
160
+ :start, :int,
161
+ :length, :int,
162
+ )
163
+ end
164
+
165
+ class TextInputEvent < FFI::Struct
166
+ layout(
167
+ :type, :uint,
168
+ :timestamp, :uint,
169
+ :windowID, :uint,
170
+ :text, [:char, 32],
171
+ )
172
+ end
173
+
174
+ class MouseMotionEvent < FFI::Struct
175
+ layout(
176
+ :type, :uint,
177
+ :timestamp, :uint,
178
+ :windowID, :uint,
179
+ :which, :uint,
180
+ :state, :uint,
181
+ :x, :int,
182
+ :y, :int,
183
+ :xrel, :int,
184
+ :yrel, :int,
185
+ )
186
+ end
187
+
188
+ class MouseButtonEvent < FFI::Struct
189
+ layout(
190
+ :type, :uint,
191
+ :timestamp, :uint,
192
+ :windowID, :uint,
193
+ :which, :uint,
194
+ :button, :uchar,
195
+ :state, :uchar,
196
+ :clicks, :uchar,
197
+ :padding1, :uchar,
198
+ :x, :int,
199
+ :y, :int,
200
+ )
201
+ end
202
+
203
+ class MouseWheelEvent < FFI::Struct
204
+ layout(
205
+ :type, :uint,
206
+ :timestamp, :uint,
207
+ :windowID, :uint,
208
+ :which, :uint,
209
+ :x, :int,
210
+ :y, :int,
211
+ :direction, :uint,
212
+ :preciseX, :float,
213
+ :preciseY, :float,
214
+ )
215
+ end
216
+
217
+ class JoyAxisEvent < FFI::Struct
218
+ layout(
219
+ :type, :uint,
220
+ :timestamp, :uint,
221
+ :which, :int,
222
+ :axis, :uchar,
223
+ :padding1, :uchar,
224
+ :padding2, :uchar,
225
+ :padding3, :uchar,
226
+ :value, :short,
227
+ :padding4, :ushort,
228
+ )
229
+ end
230
+
231
+ class JoyBallEvent < FFI::Struct
232
+ layout(
233
+ :type, :uint,
234
+ :timestamp, :uint,
235
+ :which, :int,
236
+ :ball, :uchar,
237
+ :padding1, :uchar,
238
+ :padding2, :uchar,
239
+ :padding3, :uchar,
240
+ :xrel, :short,
241
+ :yrel, :short,
242
+ )
243
+ end
244
+
245
+ class JoyHatEvent < FFI::Struct
246
+ layout(
247
+ :type, :uint,
248
+ :timestamp, :uint,
249
+ :which, :int,
250
+ :hat, :uchar,
251
+ :value, :uchar,
252
+ :padding1, :uchar,
253
+ :padding2, :uchar,
254
+ )
255
+ end
256
+
257
+ class JoyButtonEvent < FFI::Struct
258
+ layout(
259
+ :type, :uint,
260
+ :timestamp, :uint,
261
+ :which, :int,
262
+ :button, :uchar,
263
+ :state, :uchar,
264
+ :padding1, :uchar,
265
+ :padding2, :uchar,
266
+ )
267
+ end
268
+
269
+ class JoyDeviceEvent < FFI::Struct
270
+ layout(
271
+ :type, :uint,
272
+ :timestamp, :uint,
273
+ :which, :int,
274
+ )
275
+ end
276
+
277
+ class JoyBatteryEvent < FFI::Struct
278
+ layout(
279
+ :type, :uint,
280
+ :timestamp, :uint,
281
+ :which, :int,
282
+ :level, :int,
283
+ )
284
+ end
285
+
286
+ class ControllerAxisEvent < FFI::Struct
287
+ layout(
288
+ :type, :uint,
289
+ :timestamp, :uint,
290
+ :which, :int,
291
+ :axis, :uchar,
292
+ :padding1, :uchar,
293
+ :padding2, :uchar,
294
+ :padding3, :uchar,
295
+ :value, :short,
296
+ :padding4, :ushort,
297
+ )
298
+ end
299
+
300
+ class ControllerButtonEvent < FFI::Struct
301
+ layout(
302
+ :type, :uint,
303
+ :timestamp, :uint,
304
+ :which, :int,
305
+ :button, :uchar,
306
+ :state, :uchar,
307
+ :padding1, :uchar,
308
+ :padding2, :uchar,
309
+ )
310
+ end
311
+
312
+ class ControllerDeviceEvent < FFI::Struct
313
+ layout(
314
+ :type, :uint,
315
+ :timestamp, :uint,
316
+ :which, :int,
317
+ )
318
+ end
319
+
320
+ class ControllerTouchpadEvent < FFI::Struct
321
+ layout(
322
+ :type, :uint,
323
+ :timestamp, :uint,
324
+ :which, :int,
325
+ :touchpad, :int,
326
+ :finger, :int,
327
+ :x, :float,
328
+ :y, :float,
329
+ :pressure, :float,
330
+ )
331
+ end
332
+
333
+ class ControllerSensorEvent < FFI::Struct
334
+ layout(
335
+ :type, :uint,
336
+ :timestamp, :uint,
337
+ :which, :int,
338
+ :sensor, :int,
339
+ :data, [:float, 3],
340
+ )
341
+ end
342
+
343
+ class AudioDeviceEvent < FFI::Struct
344
+ layout(
345
+ :type, :uint,
346
+ :timestamp, :uint,
347
+ :which, :uint,
348
+ :iscapture, :uchar,
349
+ :padding1, :uchar,
350
+ :padding2, :uchar,
351
+ :padding3, :uchar,
352
+ )
353
+ end
354
+
355
+ class TouchFingerEvent < FFI::Struct
356
+ layout(
357
+ :type, :uint,
358
+ :timestamp, :uint,
359
+ :touchId, :long_long,
360
+ :fingerId, :long_long,
361
+ :x, :float,
362
+ :y, :float,
363
+ :dx, :float,
364
+ :dy, :float,
365
+ :pressure, :float,
366
+ :windowID, :uint,
367
+ )
368
+ end
369
+
370
+ class MultiGestureEvent < FFI::Struct
371
+ layout(
372
+ :type, :uint,
373
+ :timestamp, :uint,
374
+ :touchId, :long_long,
375
+ :dTheta, :float,
376
+ :dDist, :float,
377
+ :x, :float,
378
+ :y, :float,
379
+ :numFingers, :ushort,
380
+ :padding, :ushort,
381
+ )
382
+ end
383
+
384
+ class DollarGestureEvent < FFI::Struct
385
+ layout(
386
+ :type, :uint,
387
+ :timestamp, :uint,
388
+ :touchId, :long_long,
389
+ :gestureId, :long_long,
390
+ :numFingers, :uint,
391
+ :error, :float,
392
+ :x, :float,
393
+ :y, :float,
394
+ )
395
+ end
396
+
397
+ class DropEvent < FFI::Struct
398
+ layout(
399
+ :type, :uint,
400
+ :timestamp, :uint,
401
+ :file, :pointer,
402
+ :windowID, :uint,
403
+ )
404
+ end
405
+
406
+ class SensorEvent < FFI::Struct
407
+ layout(
408
+ :type, :uint,
409
+ :timestamp, :uint,
410
+ :which, :int,
411
+ :data, [:float, 6],
412
+ )
413
+ end
414
+
415
+ class QuitEvent < FFI::Struct
416
+ layout(
417
+ :type, :uint,
418
+ :timestamp, :uint,
419
+ )
420
+ end
421
+
422
+ class OSEvent < FFI::Struct
423
+ layout(
424
+ :type, :uint,
425
+ :timestamp, :uint,
426
+ )
427
+ end
428
+
429
+ class UserEvent < FFI::Struct
430
+ layout(
431
+ :type, :uint,
432
+ :timestamp, :uint,
433
+ :windowID, :uint,
434
+ :code, :int,
435
+ :data1, :pointer,
436
+ :data2, :pointer,
437
+ )
438
+ end
439
+
440
+ class SysWMEvent < FFI::Struct
441
+ layout(
442
+ :type, :uint,
443
+ :timestamp, :uint,
444
+ :msg, :pointer,
445
+ )
446
+ end
447
+
448
+ class Event < FFI::Union
449
+ layout(
450
+ :type, :uint,
451
+ :common, CommonEvent,
452
+ :display, DisplayEvent,
453
+ :window, WindowEvent,
454
+ :key, KeyboardEvent,
455
+ :edit, TextEditingEvent,
456
+ :editExt, TextEditingExtEvent,
457
+ :text, TextInputEvent,
458
+ :motion, MouseMotionEvent,
459
+ :button, MouseButtonEvent,
460
+ :wheel, MouseWheelEvent,
461
+ :jaxis, JoyAxisEvent,
462
+ :jball, JoyBallEvent,
463
+ :jhat, JoyHatEvent,
464
+ :jbutton, JoyButtonEvent,
465
+ :jdevice, JoyDeviceEvent,
466
+ :jbattery, JoyBatteryEvent,
467
+ :caxis, ControllerAxisEvent,
468
+ :cbutton, ControllerButtonEvent,
469
+ :cdevice, ControllerDeviceEvent,
470
+ :ctouchpad, ControllerTouchpadEvent,
471
+ :csensor, ControllerSensorEvent,
472
+ :adevice, AudioDeviceEvent,
473
+ :sensor, SensorEvent,
474
+ :quit, QuitEvent,
475
+ :user, UserEvent,
476
+ :syswm, SysWMEvent,
477
+ :tfinger, TouchFingerEvent,
478
+ :mgesture, MultiGestureEvent,
479
+ :dgesture, DollarGestureEvent,
480
+ :drop, DropEvent,
481
+ :padding, [:uchar, 56],
482
+ )
483
+ end
484
+
485
+
486
+ # Function
487
+
488
+ def self.setup_events_symbols(output_error = false)
489
+ symbols = [
490
+ :SDL_PumpEvents,
491
+ :SDL_PeepEvents,
492
+ :SDL_HasEvent,
493
+ :SDL_HasEvents,
494
+ :SDL_FlushEvent,
495
+ :SDL_FlushEvents,
496
+ :SDL_PollEvent,
497
+ :SDL_WaitEvent,
498
+ :SDL_WaitEventTimeout,
499
+ :SDL_PushEvent,
500
+ :SDL_SetEventFilter,
501
+ :SDL_GetEventFilter,
502
+ :SDL_AddEventWatch,
503
+ :SDL_DelEventWatch,
504
+ :SDL_FilterEvents,
505
+ :SDL_EventState,
506
+ :SDL_RegisterEvents,
507
+ ]
508
+ apis = {
509
+ :SDL_PumpEvents => :PumpEvents,
510
+ :SDL_PeepEvents => :PeepEvents,
511
+ :SDL_HasEvent => :HasEvent,
512
+ :SDL_HasEvents => :HasEvents,
513
+ :SDL_FlushEvent => :FlushEvent,
514
+ :SDL_FlushEvents => :FlushEvents,
515
+ :SDL_PollEvent => :PollEvent,
516
+ :SDL_WaitEvent => :WaitEvent,
517
+ :SDL_WaitEventTimeout => :WaitEventTimeout,
518
+ :SDL_PushEvent => :PushEvent,
519
+ :SDL_SetEventFilter => :SetEventFilter,
520
+ :SDL_GetEventFilter => :GetEventFilter,
521
+ :SDL_AddEventWatch => :AddEventWatch,
522
+ :SDL_DelEventWatch => :DelEventWatch,
523
+ :SDL_FilterEvents => :FilterEvents,
524
+ :SDL_EventState => :EventState,
525
+ :SDL_RegisterEvents => :RegisterEvents,
526
+ }
527
+ args = {
528
+ :SDL_PumpEvents => [],
529
+ :SDL_PeepEvents => [:pointer, :int, :int, :uint, :uint],
530
+ :SDL_HasEvent => [:uint],
531
+ :SDL_HasEvents => [:uint, :uint],
532
+ :SDL_FlushEvent => [:uint],
533
+ :SDL_FlushEvents => [:uint, :uint],
534
+ :SDL_PollEvent => [:pointer],
535
+ :SDL_WaitEvent => [:pointer],
536
+ :SDL_WaitEventTimeout => [:pointer, :int],
537
+ :SDL_PushEvent => [:pointer],
538
+ :SDL_SetEventFilter => [:SDL_EventFilter, :pointer],
539
+ :SDL_GetEventFilter => [:pointer, :pointer],
540
+ :SDL_AddEventWatch => [:SDL_EventFilter, :pointer],
541
+ :SDL_DelEventWatch => [:SDL_EventFilter, :pointer],
542
+ :SDL_FilterEvents => [:SDL_EventFilter, :pointer],
543
+ :SDL_EventState => [:uint, :int],
544
+ :SDL_RegisterEvents => [:int],
545
+ }
546
+ retvals = {
547
+ :SDL_PumpEvents => :void,
548
+ :SDL_PeepEvents => :int,
549
+ :SDL_HasEvent => :int,
550
+ :SDL_HasEvents => :int,
551
+ :SDL_FlushEvent => :void,
552
+ :SDL_FlushEvents => :void,
553
+ :SDL_PollEvent => :int,
554
+ :SDL_WaitEvent => :int,
555
+ :SDL_WaitEventTimeout => :int,
556
+ :SDL_PushEvent => :int,
557
+ :SDL_SetEventFilter => :void,
558
+ :SDL_GetEventFilter => :int,
559
+ :SDL_AddEventWatch => :void,
560
+ :SDL_DelEventWatch => :void,
561
+ :SDL_FilterEvents => :void,
562
+ :SDL_EventState => :uchar,
563
+ :SDL_RegisterEvents => :uint,
564
+ }
565
+ symbols.each do |sym|
566
+ begin
567
+ attach_function apis[sym], sym, args[sym], retvals[sym]
568
+ rescue FFI::NotFoundError => error
569
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
570
+ end
571
+ end
572
+ end
573
+
574
+ end
575
+