sdl2-bindings 0.0.9 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +129 -96
  3. data/LICENSE.txt +0 -0
  4. data/README.md +78 -55
  5. data/lib/sdl2.rb +131 -172
  6. data/lib/sdl2_audio.rb +261 -222
  7. data/lib/sdl2_blendmode.rb +72 -69
  8. data/lib/sdl2_clipboard.rb +56 -51
  9. data/lib/sdl2_cpuinfo.rb +129 -106
  10. data/lib/sdl2_error.rb +71 -64
  11. data/lib/sdl2_events.rb +564 -533
  12. data/lib/sdl2_filesystem.rb +52 -48
  13. data/lib/sdl2_framerate.rb +74 -67
  14. data/lib/sdl2_gamecontroller.rb +329 -274
  15. data/lib/sdl2_gesture.rb +61 -55
  16. data/lib/sdl2_gfxPrimitives.rb +283 -222
  17. data/lib/sdl2_haptic.rb +301 -269
  18. data/lib/sdl2_hidapi.rb +139 -118
  19. data/lib/sdl2_hints.rb +221 -198
  20. data/lib/sdl2_image.rb +232 -185
  21. data/lib/sdl2_imageFilter.rb +164 -132
  22. data/lib/sdl2_joystick.rb +294 -239
  23. data/lib/sdl2_keyboard.rb +125 -99
  24. data/lib/sdl2_keycode.rb +307 -305
  25. data/lib/sdl2_log.rb +131 -115
  26. data/lib/sdl2_main.rb +74 -67
  27. data/lib/sdl2_messagebox.rb +102 -98
  28. data/lib/sdl2_misc.rb +48 -45
  29. data/lib/sdl2_mixer.rb +392 -317
  30. data/lib/sdl2_mouse.rb +136 -117
  31. data/lib/sdl2_pixels.rb +240 -224
  32. data/lib/sdl2_platform.rb +48 -45
  33. data/lib/sdl2_power.rb +54 -51
  34. data/lib/sdl2_rect.rb +145 -102
  35. data/lib/sdl2_render.rb +408 -322
  36. data/lib/sdl2_rotozoom.rb +76 -66
  37. data/lib/sdl2_rwops.rb +242 -208
  38. data/lib/sdl2_scancode.rb +289 -287
  39. data/lib/sdl2_sensor.rb +115 -97
  40. data/lib/sdl2_shape.rb +83 -77
  41. data/lib/sdl2_sound.rb +154 -0
  42. data/lib/sdl2_stdinc.rb +556 -439
  43. data/lib/sdl2_surface.rb +229 -188
  44. data/lib/sdl2_syswm.rb +160 -157
  45. data/lib/sdl2_timer.rb +74 -65
  46. data/lib/sdl2_touch.rb +86 -75
  47. data/lib/sdl2_ttf.rb +358 -202
  48. data/lib/sdl2_version.rb +67 -62
  49. data/lib/sdl2_video.rb +540 -446
  50. data/lib/sdl2_vulkan.rb +72 -64
  51. metadata +18 -3
data/lib/sdl2_events.rb CHANGED
@@ -1,533 +1,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 SDL2
11
- extend FFI::Library
12
- # Define/Macro
13
-
14
- SDL_RELEASED = 0
15
- SDL_PRESSED = 1
16
- SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32
17
- SDL_TEXTINPUTEVENT_TEXT_SIZE = 32
18
- SDL_QUERY = -1
19
- SDL_IGNORE = 0
20
- SDL_DISABLE = 0
21
- SDL_ENABLE = 1
22
-
23
- # Enum
24
-
25
- SDL_FIRSTEVENT = 0
26
- SDL_QUIT = 256
27
- SDL_APP_TERMINATING = 257
28
- SDL_APP_LOWMEMORY = 258
29
- SDL_APP_WILLENTERBACKGROUND = 259
30
- SDL_APP_DIDENTERBACKGROUND = 260
31
- SDL_APP_WILLENTERFOREGROUND = 261
32
- SDL_APP_DIDENTERFOREGROUND = 262
33
- SDL_LOCALECHANGED = 263
34
- SDL_DISPLAYEVENT = 336
35
- SDL_WINDOWEVENT = 512
36
- SDL_SYSWMEVENT = 513
37
- SDL_KEYDOWN = 768
38
- SDL_KEYUP = 769
39
- SDL_TEXTEDITING = 770
40
- SDL_TEXTINPUT = 771
41
- SDL_KEYMAPCHANGED = 772
42
- SDL_MOUSEMOTION = 1024
43
- SDL_MOUSEBUTTONDOWN = 1025
44
- SDL_MOUSEBUTTONUP = 1026
45
- SDL_MOUSEWHEEL = 1027
46
- SDL_JOYAXISMOTION = 1536
47
- SDL_JOYBALLMOTION = 1537
48
- SDL_JOYHATMOTION = 1538
49
- SDL_JOYBUTTONDOWN = 1539
50
- SDL_JOYBUTTONUP = 1540
51
- SDL_JOYDEVICEADDED = 1541
52
- SDL_JOYDEVICEREMOVED = 1542
53
- SDL_CONTROLLERAXISMOTION = 1616
54
- SDL_CONTROLLERBUTTONDOWN = 1617
55
- SDL_CONTROLLERBUTTONUP = 1618
56
- SDL_CONTROLLERDEVICEADDED = 1619
57
- SDL_CONTROLLERDEVICEREMOVED = 1620
58
- SDL_CONTROLLERDEVICEREMAPPED = 1621
59
- SDL_CONTROLLERTOUCHPADDOWN = 1622
60
- SDL_CONTROLLERTOUCHPADMOTION = 1623
61
- SDL_CONTROLLERTOUCHPADUP = 1624
62
- SDL_CONTROLLERSENSORUPDATE = 1625
63
- SDL_FINGERDOWN = 1792
64
- SDL_FINGERUP = 1793
65
- SDL_FINGERMOTION = 1794
66
- SDL_DOLLARGESTURE = 2048
67
- SDL_DOLLARRECORD = 2049
68
- SDL_MULTIGESTURE = 2050
69
- SDL_CLIPBOARDUPDATE = 2304
70
- SDL_DROPFILE = 4096
71
- SDL_DROPTEXT = 4097
72
- SDL_DROPBEGIN = 4098
73
- SDL_DROPCOMPLETE = 4099
74
- SDL_AUDIODEVICEADDED = 4352
75
- SDL_AUDIODEVICEREMOVED = 4353
76
- SDL_SENSORUPDATE = 4608
77
- SDL_RENDER_TARGETS_RESET = 8192
78
- SDL_RENDER_DEVICE_RESET = 8193
79
- SDL_POLLSENTINEL = 32512
80
- SDL_USEREVENT = 32768
81
- SDL_LASTEVENT = 65535
82
- SDL_ADDEVENT = 0
83
- SDL_PEEKEVENT = 1
84
- SDL_GETEVENT = 2
85
-
86
- # Typedef
87
-
88
- typedef :int, :SDL_EventType
89
- typedef :int, :SDL_compile_time_assert_SDL_Event
90
- typedef :int, :SDL_eventaction
91
- callback :SDL_EventFilter, [:pointer, :pointer], :int
92
-
93
- # Struct
94
-
95
- class SDL_CommonEvent < FFI::Struct
96
- layout(
97
- :type, :uint,
98
- :timestamp, :uint,
99
- )
100
- end
101
-
102
- class SDL_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 SDL_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 SDL_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, SDL_Keysym,
139
- )
140
- end
141
-
142
- class SDL_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 SDL_TextInputEvent < FFI::Struct
154
- layout(
155
- :type, :uint,
156
- :timestamp, :uint,
157
- :windowID, :uint,
158
- :text, [:char, 32],
159
- )
160
- end
161
-
162
- class SDL_MouseMotionEvent < FFI::Struct
163
- layout(
164
- :type, :uint,
165
- :timestamp, :uint,
166
- :windowID, :uint,
167
- :which, :uint,
168
- :state, :uint,
169
- :x, :int,
170
- :y, :int,
171
- :xrel, :int,
172
- :yrel, :int,
173
- )
174
- end
175
-
176
- class SDL_MouseButtonEvent < FFI::Struct
177
- layout(
178
- :type, :uint,
179
- :timestamp, :uint,
180
- :windowID, :uint,
181
- :which, :uint,
182
- :button, :uchar,
183
- :state, :uchar,
184
- :clicks, :uchar,
185
- :padding1, :uchar,
186
- :x, :int,
187
- :y, :int,
188
- )
189
- end
190
-
191
- class SDL_MouseWheelEvent < FFI::Struct
192
- layout(
193
- :type, :uint,
194
- :timestamp, :uint,
195
- :windowID, :uint,
196
- :which, :uint,
197
- :x, :int,
198
- :y, :int,
199
- :direction, :uint,
200
- :preciseX, :float,
201
- :preciseY, :float,
202
- )
203
- end
204
-
205
- class SDL_JoyAxisEvent < FFI::Struct
206
- layout(
207
- :type, :uint,
208
- :timestamp, :uint,
209
- :which, :int,
210
- :axis, :uchar,
211
- :padding1, :uchar,
212
- :padding2, :uchar,
213
- :padding3, :uchar,
214
- :value, :short,
215
- :padding4, :ushort,
216
- )
217
- end
218
-
219
- class SDL_JoyBallEvent < FFI::Struct
220
- layout(
221
- :type, :uint,
222
- :timestamp, :uint,
223
- :which, :int,
224
- :ball, :uchar,
225
- :padding1, :uchar,
226
- :padding2, :uchar,
227
- :padding3, :uchar,
228
- :xrel, :short,
229
- :yrel, :short,
230
- )
231
- end
232
-
233
- class SDL_JoyHatEvent < FFI::Struct
234
- layout(
235
- :type, :uint,
236
- :timestamp, :uint,
237
- :which, :int,
238
- :hat, :uchar,
239
- :value, :uchar,
240
- :padding1, :uchar,
241
- :padding2, :uchar,
242
- )
243
- end
244
-
245
- class SDL_JoyButtonEvent < FFI::Struct
246
- layout(
247
- :type, :uint,
248
- :timestamp, :uint,
249
- :which, :int,
250
- :button, :uchar,
251
- :state, :uchar,
252
- :padding1, :uchar,
253
- :padding2, :uchar,
254
- )
255
- end
256
-
257
- class SDL_JoyDeviceEvent < FFI::Struct
258
- layout(
259
- :type, :uint,
260
- :timestamp, :uint,
261
- :which, :int,
262
- )
263
- end
264
-
265
- class SDL_ControllerAxisEvent < FFI::Struct
266
- layout(
267
- :type, :uint,
268
- :timestamp, :uint,
269
- :which, :int,
270
- :axis, :uchar,
271
- :padding1, :uchar,
272
- :padding2, :uchar,
273
- :padding3, :uchar,
274
- :value, :short,
275
- :padding4, :ushort,
276
- )
277
- end
278
-
279
- class SDL_ControllerButtonEvent < FFI::Struct
280
- layout(
281
- :type, :uint,
282
- :timestamp, :uint,
283
- :which, :int,
284
- :button, :uchar,
285
- :state, :uchar,
286
- :padding1, :uchar,
287
- :padding2, :uchar,
288
- )
289
- end
290
-
291
- class SDL_ControllerDeviceEvent < FFI::Struct
292
- layout(
293
- :type, :uint,
294
- :timestamp, :uint,
295
- :which, :int,
296
- )
297
- end
298
-
299
- class SDL_ControllerTouchpadEvent < FFI::Struct
300
- layout(
301
- :type, :uint,
302
- :timestamp, :uint,
303
- :which, :int,
304
- :touchpad, :int,
305
- :finger, :int,
306
- :x, :float,
307
- :y, :float,
308
- :pressure, :float,
309
- )
310
- end
311
-
312
- class SDL_ControllerSensorEvent < FFI::Struct
313
- layout(
314
- :type, :uint,
315
- :timestamp, :uint,
316
- :which, :int,
317
- :sensor, :int,
318
- :data, [:float, 3],
319
- )
320
- end
321
-
322
- class SDL_AudioDeviceEvent < FFI::Struct
323
- layout(
324
- :type, :uint,
325
- :timestamp, :uint,
326
- :which, :uint,
327
- :iscapture, :uchar,
328
- :padding1, :uchar,
329
- :padding2, :uchar,
330
- :padding3, :uchar,
331
- )
332
- end
333
-
334
- class SDL_TouchFingerEvent < FFI::Struct
335
- layout(
336
- :type, :uint,
337
- :timestamp, :uint,
338
- :touchId, :long_long,
339
- :fingerId, :long_long,
340
- :x, :float,
341
- :y, :float,
342
- :dx, :float,
343
- :dy, :float,
344
- :pressure, :float,
345
- :windowID, :uint,
346
- )
347
- end
348
-
349
- class SDL_MultiGestureEvent < FFI::Struct
350
- layout(
351
- :type, :uint,
352
- :timestamp, :uint,
353
- :touchId, :long_long,
354
- :dTheta, :float,
355
- :dDist, :float,
356
- :x, :float,
357
- :y, :float,
358
- :numFingers, :ushort,
359
- :padding, :ushort,
360
- )
361
- end
362
-
363
- class SDL_DollarGestureEvent < FFI::Struct
364
- layout(
365
- :type, :uint,
366
- :timestamp, :uint,
367
- :touchId, :long_long,
368
- :gestureId, :long_long,
369
- :numFingers, :uint,
370
- :error, :float,
371
- :x, :float,
372
- :y, :float,
373
- )
374
- end
375
-
376
- class SDL_DropEvent < FFI::Struct
377
- layout(
378
- :type, :uint,
379
- :timestamp, :uint,
380
- :file, :pointer,
381
- :windowID, :uint,
382
- )
383
- end
384
-
385
- class SDL_SensorEvent < FFI::Struct
386
- layout(
387
- :type, :uint,
388
- :timestamp, :uint,
389
- :which, :int,
390
- :data, [:float, 6],
391
- )
392
- end
393
-
394
- class SDL_QuitEvent < FFI::Struct
395
- layout(
396
- :type, :uint,
397
- :timestamp, :uint,
398
- )
399
- end
400
-
401
- class SDL_OSEvent < FFI::Struct
402
- layout(
403
- :type, :uint,
404
- :timestamp, :uint,
405
- )
406
- end
407
-
408
- class SDL_UserEvent < FFI::Struct
409
- layout(
410
- :type, :uint,
411
- :timestamp, :uint,
412
- :windowID, :uint,
413
- :code, :int,
414
- :data1, :pointer,
415
- :data2, :pointer,
416
- )
417
- end
418
-
419
- class SDL_SysWMEvent < FFI::Struct
420
- layout(
421
- :type, :uint,
422
- :timestamp, :uint,
423
- :msg, :pointer,
424
- )
425
- end
426
-
427
- class SDL_Event < FFI::Union
428
- layout(
429
- :type, :uint,
430
- :common, SDL_CommonEvent,
431
- :display, SDL_DisplayEvent,
432
- :window, SDL_WindowEvent,
433
- :key, SDL_KeyboardEvent,
434
- :edit, SDL_TextEditingEvent,
435
- :text, SDL_TextInputEvent,
436
- :motion, SDL_MouseMotionEvent,
437
- :button, SDL_MouseButtonEvent,
438
- :wheel, SDL_MouseWheelEvent,
439
- :jaxis, SDL_JoyAxisEvent,
440
- :jball, SDL_JoyBallEvent,
441
- :jhat, SDL_JoyHatEvent,
442
- :jbutton, SDL_JoyButtonEvent,
443
- :jdevice, SDL_JoyDeviceEvent,
444
- :caxis, SDL_ControllerAxisEvent,
445
- :cbutton, SDL_ControllerButtonEvent,
446
- :cdevice, SDL_ControllerDeviceEvent,
447
- :ctouchpad, SDL_ControllerTouchpadEvent,
448
- :csensor, SDL_ControllerSensorEvent,
449
- :adevice, SDL_AudioDeviceEvent,
450
- :sensor, SDL_SensorEvent,
451
- :quit, SDL_QuitEvent,
452
- :user, SDL_UserEvent,
453
- :syswm, SDL_SysWMEvent,
454
- :tfinger, SDL_TouchFingerEvent,
455
- :mgesture, SDL_MultiGestureEvent,
456
- :dgesture, SDL_DollarGestureEvent,
457
- :drop, SDL_DropEvent,
458
- :padding, [:uchar, 56],
459
- )
460
- end
461
-
462
-
463
- # Function
464
-
465
- def self.setup_events_symbols()
466
- symbols = [
467
- :SDL_PumpEvents,
468
- :SDL_PeepEvents,
469
- :SDL_HasEvent,
470
- :SDL_HasEvents,
471
- :SDL_FlushEvent,
472
- :SDL_FlushEvents,
473
- :SDL_PollEvent,
474
- :SDL_WaitEvent,
475
- :SDL_WaitEventTimeout,
476
- :SDL_PushEvent,
477
- :SDL_SetEventFilter,
478
- :SDL_GetEventFilter,
479
- :SDL_AddEventWatch,
480
- :SDL_DelEventWatch,
481
- :SDL_FilterEvents,
482
- :SDL_EventState,
483
- :SDL_RegisterEvents,
484
- ]
485
- args = {
486
- :SDL_PumpEvents => [],
487
- :SDL_PeepEvents => [:pointer, :int, :int, :uint, :uint],
488
- :SDL_HasEvent => [:uint],
489
- :SDL_HasEvents => [:uint, :uint],
490
- :SDL_FlushEvent => [:uint],
491
- :SDL_FlushEvents => [:uint, :uint],
492
- :SDL_PollEvent => [:pointer],
493
- :SDL_WaitEvent => [:pointer],
494
- :SDL_WaitEventTimeout => [:pointer, :int],
495
- :SDL_PushEvent => [:pointer],
496
- :SDL_SetEventFilter => [:SDL_EventFilter, :pointer],
497
- :SDL_GetEventFilter => [:pointer, :pointer],
498
- :SDL_AddEventWatch => [:SDL_EventFilter, :pointer],
499
- :SDL_DelEventWatch => [:SDL_EventFilter, :pointer],
500
- :SDL_FilterEvents => [:SDL_EventFilter, :pointer],
501
- :SDL_EventState => [:uint, :int],
502
- :SDL_RegisterEvents => [:int],
503
- }
504
- retvals = {
505
- :SDL_PumpEvents => :void,
506
- :SDL_PeepEvents => :int,
507
- :SDL_HasEvent => :int,
508
- :SDL_HasEvents => :int,
509
- :SDL_FlushEvent => :void,
510
- :SDL_FlushEvents => :void,
511
- :SDL_PollEvent => :int,
512
- :SDL_WaitEvent => :int,
513
- :SDL_WaitEventTimeout => :int,
514
- :SDL_PushEvent => :int,
515
- :SDL_SetEventFilter => :void,
516
- :SDL_GetEventFilter => :int,
517
- :SDL_AddEventWatch => :void,
518
- :SDL_DelEventWatch => :void,
519
- :SDL_FilterEvents => :void,
520
- :SDL_EventState => :uchar,
521
- :SDL_RegisterEvents => :uint,
522
- }
523
- symbols.each do |sym|
524
- begin
525
- attach_function sym, args[sym], retvals[sym]
526
- rescue FFI::NotFoundError => error
527
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
528
- end
529
- end
530
- end
531
-
532
- end
533
-
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
+