sdl2-bindings 0.0.5 → 0.0.9

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