sdl2-bindings 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +12 -0
  3. data/README.md +39 -26
  4. data/lib/sdl2.rb +54 -99
  5. data/lib/sdl2_audio.rb +59 -20
  6. data/lib/sdl2_blendmode.rb +28 -25
  7. data/lib/sdl2_clipboard.rb +9 -4
  8. data/lib/sdl2_cpuinfo.rb +28 -5
  9. data/lib/sdl2_error.rb +17 -10
  10. data/lib/sdl2_events.rb +150 -131
  11. data/lib/sdl2_filesystem.rb +8 -4
  12. data/lib/sdl2_framerate.rb +11 -4
  13. data/lib/sdl2_gamecontroller.rb +112 -57
  14. data/lib/sdl2_gesture.rb +10 -4
  15. data/lib/sdl2_gfxPrimitives.rb +65 -4
  16. data/lib/sdl2_haptic.rb +76 -44
  17. data/lib/sdl2_hidapi.rb +26 -5
  18. data/lib/sdl2_hints.rb +146 -137
  19. data/lib/sdl2_image.rb +54 -7
  20. data/lib/sdl2_imageFilter.rb +36 -4
  21. data/lib/sdl2_joystick.rb +93 -38
  22. data/lib/sdl2_keyboard.rb +23 -5
  23. data/lib/sdl2_keycode.rb +6 -4
  24. data/lib/sdl2_log.rb +48 -32
  25. data/lib/sdl2_main.rb +21 -14
  26. data/lib/sdl2_messagebox.rb +26 -22
  27. data/lib/sdl2_misc.rb +7 -4
  28. data/lib/sdl2_mixer.rb +86 -11
  29. data/lib/sdl2_mouse.rb +44 -25
  30. data/lib/sdl2_pixels.rb +115 -99
  31. data/lib/sdl2_platform.rb +7 -4
  32. data/lib/sdl2_power.rb +12 -9
  33. data/lib/sdl2_rect.rb +18 -11
  34. data/lib/sdl2_render.rb +107 -25
  35. data/lib/sdl2_rotozoom.rb +14 -4
  36. data/lib/sdl2_rwops.rb +58 -28
  37. data/lib/sdl2_scancode.rb +250 -248
  38. data/lib/sdl2_sensor.rb +27 -9
  39. data/lib/sdl2_shape.rb +17 -11
  40. data/lib/sdl2_stdinc.rb +135 -10
  41. data/lib/sdl2_surface.rb +56 -15
  42. data/lib/sdl2_syswm.rb +47 -44
  43. data/lib/sdl2_timer.rb +13 -4
  44. data/lib/sdl2_touch.rb +18 -11
  45. data/lib/sdl2_ttf.rb +180 -25
  46. data/lib/sdl2_version.rb +13 -8
  47. data/lib/sdl2_video.rb +204 -110
  48. data/lib/sdl2_vulkan.rb +12 -4
  49. metadata +17 -3
data/lib/sdl2_events.rb CHANGED
@@ -7,81 +7,81 @@
7
7
  require 'ffi'
8
8
  require_relative 'sdl2_keyboard'
9
9
 
10
- module SDL2
10
+ module SDL
11
11
  extend FFI::Library
12
12
  # Define/Macro
13
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
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
22
 
23
23
  # Enum
24
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
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
+ MOUSEMOTION = 1024
43
+ MOUSEBUTTONDOWN = 1025
44
+ MOUSEBUTTONUP = 1026
45
+ MOUSEWHEEL = 1027
46
+ JOYAXISMOTION = 1536
47
+ JOYBALLMOTION = 1537
48
+ JOYHATMOTION = 1538
49
+ JOYBUTTONDOWN = 1539
50
+ JOYBUTTONUP = 1540
51
+ JOYDEVICEADDED = 1541
52
+ JOYDEVICEREMOVED = 1542
53
+ CONTROLLERAXISMOTION = 1616
54
+ CONTROLLERBUTTONDOWN = 1617
55
+ CONTROLLERBUTTONUP = 1618
56
+ CONTROLLERDEVICEADDED = 1619
57
+ CONTROLLERDEVICEREMOVED = 1620
58
+ CONTROLLERDEVICEREMAPPED = 1621
59
+ CONTROLLERTOUCHPADDOWN = 1622
60
+ CONTROLLERTOUCHPADMOTION = 1623
61
+ CONTROLLERTOUCHPADUP = 1624
62
+ CONTROLLERSENSORUPDATE = 1625
63
+ FINGERDOWN = 1792
64
+ FINGERUP = 1793
65
+ FINGERMOTION = 1794
66
+ DOLLARGESTURE = 2048
67
+ DOLLARRECORD = 2049
68
+ MULTIGESTURE = 2050
69
+ CLIPBOARDUPDATE = 2304
70
+ DROPFILE = 4096
71
+ DROPTEXT = 4097
72
+ DROPBEGIN = 4098
73
+ DROPCOMPLETE = 4099
74
+ AUDIODEVICEADDED = 4352
75
+ AUDIODEVICEREMOVED = 4353
76
+ SENSORUPDATE = 4608
77
+ RENDER_TARGETS_RESET = 8192
78
+ RENDER_DEVICE_RESET = 8193
79
+ POLLSENTINEL = 32512
80
+ USEREVENT = 32768
81
+ LASTEVENT = 65535
82
+ ADDEVENT = 0
83
+ PEEKEVENT = 1
84
+ GETEVENT = 2
85
85
 
86
86
  # Typedef
87
87
 
@@ -92,14 +92,14 @@ module SDL2
92
92
 
93
93
  # Struct
94
94
 
95
- class SDL_CommonEvent < FFI::Struct
95
+ class CommonEvent < FFI::Struct
96
96
  layout(
97
97
  :type, :uint,
98
98
  :timestamp, :uint,
99
99
  )
100
100
  end
101
101
 
102
- class SDL_DisplayEvent < FFI::Struct
102
+ class DisplayEvent < FFI::Struct
103
103
  layout(
104
104
  :type, :uint,
105
105
  :timestamp, :uint,
@@ -112,7 +112,7 @@ module SDL2
112
112
  )
113
113
  end
114
114
 
115
- class SDL_WindowEvent < FFI::Struct
115
+ class WindowEvent < FFI::Struct
116
116
  layout(
117
117
  :type, :uint,
118
118
  :timestamp, :uint,
@@ -126,7 +126,7 @@ module SDL2
126
126
  )
127
127
  end
128
128
 
129
- class SDL_KeyboardEvent < FFI::Struct
129
+ class KeyboardEvent < FFI::Struct
130
130
  layout(
131
131
  :type, :uint,
132
132
  :timestamp, :uint,
@@ -135,11 +135,11 @@ module SDL2
135
135
  :repeat, :uchar,
136
136
  :padding2, :uchar,
137
137
  :padding3, :uchar,
138
- :keysym, SDL_Keysym,
138
+ :keysym, Keysym,
139
139
  )
140
140
  end
141
141
 
142
- class SDL_TextEditingEvent < FFI::Struct
142
+ class TextEditingEvent < FFI::Struct
143
143
  layout(
144
144
  :type, :uint,
145
145
  :timestamp, :uint,
@@ -150,7 +150,7 @@ module SDL2
150
150
  )
151
151
  end
152
152
 
153
- class SDL_TextInputEvent < FFI::Struct
153
+ class TextInputEvent < FFI::Struct
154
154
  layout(
155
155
  :type, :uint,
156
156
  :timestamp, :uint,
@@ -159,7 +159,7 @@ module SDL2
159
159
  )
160
160
  end
161
161
 
162
- class SDL_MouseMotionEvent < FFI::Struct
162
+ class MouseMotionEvent < FFI::Struct
163
163
  layout(
164
164
  :type, :uint,
165
165
  :timestamp, :uint,
@@ -173,7 +173,7 @@ module SDL2
173
173
  )
174
174
  end
175
175
 
176
- class SDL_MouseButtonEvent < FFI::Struct
176
+ class MouseButtonEvent < FFI::Struct
177
177
  layout(
178
178
  :type, :uint,
179
179
  :timestamp, :uint,
@@ -188,7 +188,7 @@ module SDL2
188
188
  )
189
189
  end
190
190
 
191
- class SDL_MouseWheelEvent < FFI::Struct
191
+ class MouseWheelEvent < FFI::Struct
192
192
  layout(
193
193
  :type, :uint,
194
194
  :timestamp, :uint,
@@ -202,7 +202,7 @@ module SDL2
202
202
  )
203
203
  end
204
204
 
205
- class SDL_JoyAxisEvent < FFI::Struct
205
+ class JoyAxisEvent < FFI::Struct
206
206
  layout(
207
207
  :type, :uint,
208
208
  :timestamp, :uint,
@@ -216,7 +216,7 @@ module SDL2
216
216
  )
217
217
  end
218
218
 
219
- class SDL_JoyBallEvent < FFI::Struct
219
+ class JoyBallEvent < FFI::Struct
220
220
  layout(
221
221
  :type, :uint,
222
222
  :timestamp, :uint,
@@ -230,7 +230,7 @@ module SDL2
230
230
  )
231
231
  end
232
232
 
233
- class SDL_JoyHatEvent < FFI::Struct
233
+ class JoyHatEvent < FFI::Struct
234
234
  layout(
235
235
  :type, :uint,
236
236
  :timestamp, :uint,
@@ -242,7 +242,7 @@ module SDL2
242
242
  )
243
243
  end
244
244
 
245
- class SDL_JoyButtonEvent < FFI::Struct
245
+ class JoyButtonEvent < FFI::Struct
246
246
  layout(
247
247
  :type, :uint,
248
248
  :timestamp, :uint,
@@ -254,7 +254,7 @@ module SDL2
254
254
  )
255
255
  end
256
256
 
257
- class SDL_JoyDeviceEvent < FFI::Struct
257
+ class JoyDeviceEvent < FFI::Struct
258
258
  layout(
259
259
  :type, :uint,
260
260
  :timestamp, :uint,
@@ -262,7 +262,7 @@ module SDL2
262
262
  )
263
263
  end
264
264
 
265
- class SDL_ControllerAxisEvent < FFI::Struct
265
+ class ControllerAxisEvent < FFI::Struct
266
266
  layout(
267
267
  :type, :uint,
268
268
  :timestamp, :uint,
@@ -276,7 +276,7 @@ module SDL2
276
276
  )
277
277
  end
278
278
 
279
- class SDL_ControllerButtonEvent < FFI::Struct
279
+ class ControllerButtonEvent < FFI::Struct
280
280
  layout(
281
281
  :type, :uint,
282
282
  :timestamp, :uint,
@@ -288,7 +288,7 @@ module SDL2
288
288
  )
289
289
  end
290
290
 
291
- class SDL_ControllerDeviceEvent < FFI::Struct
291
+ class ControllerDeviceEvent < FFI::Struct
292
292
  layout(
293
293
  :type, :uint,
294
294
  :timestamp, :uint,
@@ -296,7 +296,7 @@ module SDL2
296
296
  )
297
297
  end
298
298
 
299
- class SDL_ControllerTouchpadEvent < FFI::Struct
299
+ class ControllerTouchpadEvent < FFI::Struct
300
300
  layout(
301
301
  :type, :uint,
302
302
  :timestamp, :uint,
@@ -309,7 +309,7 @@ module SDL2
309
309
  )
310
310
  end
311
311
 
312
- class SDL_ControllerSensorEvent < FFI::Struct
312
+ class ControllerSensorEvent < FFI::Struct
313
313
  layout(
314
314
  :type, :uint,
315
315
  :timestamp, :uint,
@@ -319,7 +319,7 @@ module SDL2
319
319
  )
320
320
  end
321
321
 
322
- class SDL_AudioDeviceEvent < FFI::Struct
322
+ class AudioDeviceEvent < FFI::Struct
323
323
  layout(
324
324
  :type, :uint,
325
325
  :timestamp, :uint,
@@ -331,7 +331,7 @@ module SDL2
331
331
  )
332
332
  end
333
333
 
334
- class SDL_TouchFingerEvent < FFI::Struct
334
+ class TouchFingerEvent < FFI::Struct
335
335
  layout(
336
336
  :type, :uint,
337
337
  :timestamp, :uint,
@@ -346,7 +346,7 @@ module SDL2
346
346
  )
347
347
  end
348
348
 
349
- class SDL_MultiGestureEvent < FFI::Struct
349
+ class MultiGestureEvent < FFI::Struct
350
350
  layout(
351
351
  :type, :uint,
352
352
  :timestamp, :uint,
@@ -360,7 +360,7 @@ module SDL2
360
360
  )
361
361
  end
362
362
 
363
- class SDL_DollarGestureEvent < FFI::Struct
363
+ class DollarGestureEvent < FFI::Struct
364
364
  layout(
365
365
  :type, :uint,
366
366
  :timestamp, :uint,
@@ -373,7 +373,7 @@ module SDL2
373
373
  )
374
374
  end
375
375
 
376
- class SDL_DropEvent < FFI::Struct
376
+ class DropEvent < FFI::Struct
377
377
  layout(
378
378
  :type, :uint,
379
379
  :timestamp, :uint,
@@ -382,7 +382,7 @@ module SDL2
382
382
  )
383
383
  end
384
384
 
385
- class SDL_SensorEvent < FFI::Struct
385
+ class SensorEvent < FFI::Struct
386
386
  layout(
387
387
  :type, :uint,
388
388
  :timestamp, :uint,
@@ -391,21 +391,21 @@ module SDL2
391
391
  )
392
392
  end
393
393
 
394
- class SDL_QuitEvent < FFI::Struct
394
+ class QuitEvent < FFI::Struct
395
395
  layout(
396
396
  :type, :uint,
397
397
  :timestamp, :uint,
398
398
  )
399
399
  end
400
400
 
401
- class SDL_OSEvent < FFI::Struct
401
+ class OSEvent < FFI::Struct
402
402
  layout(
403
403
  :type, :uint,
404
404
  :timestamp, :uint,
405
405
  )
406
406
  end
407
407
 
408
- class SDL_UserEvent < FFI::Struct
408
+ class UserEvent < FFI::Struct
409
409
  layout(
410
410
  :type, :uint,
411
411
  :timestamp, :uint,
@@ -416,7 +416,7 @@ module SDL2
416
416
  )
417
417
  end
418
418
 
419
- class SDL_SysWMEvent < FFI::Struct
419
+ class SysWMEvent < FFI::Struct
420
420
  layout(
421
421
  :type, :uint,
422
422
  :timestamp, :uint,
@@ -424,37 +424,37 @@ module SDL2
424
424
  )
425
425
  end
426
426
 
427
- class SDL_Event < FFI::Union
427
+ class Event < FFI::Union
428
428
  layout(
429
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,
430
+ :common, CommonEvent,
431
+ :display, DisplayEvent,
432
+ :window, WindowEvent,
433
+ :key, KeyboardEvent,
434
+ :edit, TextEditingEvent,
435
+ :text, TextInputEvent,
436
+ :motion, MouseMotionEvent,
437
+ :button, MouseButtonEvent,
438
+ :wheel, MouseWheelEvent,
439
+ :jaxis, JoyAxisEvent,
440
+ :jball, JoyBallEvent,
441
+ :jhat, JoyHatEvent,
442
+ :jbutton, JoyButtonEvent,
443
+ :jdevice, JoyDeviceEvent,
444
+ :caxis, ControllerAxisEvent,
445
+ :cbutton, ControllerButtonEvent,
446
+ :cdevice, ControllerDeviceEvent,
447
+ :ctouchpad, ControllerTouchpadEvent,
448
+ :csensor, ControllerSensorEvent,
449
+ :adevice, AudioDeviceEvent,
450
+ :sensor, SensorEvent,
451
+ :quit, QuitEvent,
452
+ :user, UserEvent,
453
+ :syswm, SysWMEvent,
454
+ :tfinger, TouchFingerEvent,
455
+ :mgesture, MultiGestureEvent,
456
+ :dgesture, DollarGestureEvent,
457
+ :drop, DropEvent,
458
458
  :padding, [:uchar, 56],
459
459
  )
460
460
  end
@@ -462,7 +462,7 @@ module SDL2
462
462
 
463
463
  # Function
464
464
 
465
- def self.setup_events_symbols()
465
+ def self.setup_events_symbols(output_error = false)
466
466
  symbols = [
467
467
  :SDL_PumpEvents,
468
468
  :SDL_PeepEvents,
@@ -482,6 +482,25 @@ module SDL2
482
482
  :SDL_EventState,
483
483
  :SDL_RegisterEvents,
484
484
  ]
485
+ apis = {
486
+ :SDL_PumpEvents => :PumpEvents,
487
+ :SDL_PeepEvents => :PeepEvents,
488
+ :SDL_HasEvent => :HasEvent,
489
+ :SDL_HasEvents => :HasEvents,
490
+ :SDL_FlushEvent => :FlushEvent,
491
+ :SDL_FlushEvents => :FlushEvents,
492
+ :SDL_PollEvent => :PollEvent,
493
+ :SDL_WaitEvent => :WaitEvent,
494
+ :SDL_WaitEventTimeout => :WaitEventTimeout,
495
+ :SDL_PushEvent => :PushEvent,
496
+ :SDL_SetEventFilter => :SetEventFilter,
497
+ :SDL_GetEventFilter => :GetEventFilter,
498
+ :SDL_AddEventWatch => :AddEventWatch,
499
+ :SDL_DelEventWatch => :DelEventWatch,
500
+ :SDL_FilterEvents => :FilterEvents,
501
+ :SDL_EventState => :EventState,
502
+ :SDL_RegisterEvents => :RegisterEvents,
503
+ }
485
504
  args = {
486
505
  :SDL_PumpEvents => [],
487
506
  :SDL_PeepEvents => [:pointer, :int, :int, :uint, :uint],
@@ -522,9 +541,9 @@ module SDL2
522
541
  }
523
542
  symbols.each do |sym|
524
543
  begin
525
- attach_function sym, args[sym], retvals[sym]
544
+ attach_function apis[sym], sym, args[sym], retvals[sym]
526
545
  rescue FFI::NotFoundError => error
527
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
546
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
528
547
  end
529
548
  end
530
549
  end
@@ -6,7 +6,7 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
@@ -22,11 +22,15 @@ module SDL2
22
22
 
23
23
  # Function
24
24
 
25
- def self.setup_filesystem_symbols()
25
+ def self.setup_filesystem_symbols(output_error = false)
26
26
  symbols = [
27
27
  :SDL_GetBasePath,
28
28
  :SDL_GetPrefPath,
29
29
  ]
30
+ apis = {
31
+ :SDL_GetBasePath => :GetBasePath,
32
+ :SDL_GetPrefPath => :GetPrefPath,
33
+ }
30
34
  args = {
31
35
  :SDL_GetBasePath => [],
32
36
  :SDL_GetPrefPath => [:pointer, :pointer],
@@ -37,9 +41,9 @@ module SDL2
37
41
  }
38
42
  symbols.each do |sym|
39
43
  begin
40
- attach_function sym, args[sym], retvals[sym]
44
+ attach_function apis[sym], sym, args[sym], retvals[sym]
41
45
  rescue FFI::NotFoundError => error
42
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
46
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
43
47
  end
44
48
  end
45
49
  end
@@ -6,7 +6,7 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
@@ -32,7 +32,7 @@ module SDL2
32
32
 
33
33
  # Function
34
34
 
35
- def self.setup_gfx_framerate_symbols()
35
+ def self.setup_gfx_framerate_symbols(output_error = false)
36
36
  symbols = [
37
37
  :SDL_initFramerate,
38
38
  :SDL_setFramerate,
@@ -40,6 +40,13 @@ module SDL2
40
40
  :SDL_getFramecount,
41
41
  :SDL_framerateDelay,
42
42
  ]
43
+ apis = {
44
+ :SDL_initFramerate => :initFramerate,
45
+ :SDL_setFramerate => :setFramerate,
46
+ :SDL_getFramerate => :getFramerate,
47
+ :SDL_getFramecount => :getFramecount,
48
+ :SDL_framerateDelay => :framerateDelay,
49
+ }
43
50
  args = {
44
51
  :SDL_initFramerate => [:pointer],
45
52
  :SDL_setFramerate => [:pointer, :uint],
@@ -56,9 +63,9 @@ module SDL2
56
63
  }
57
64
  symbols.each do |sym|
58
65
  begin
59
- attach_function sym, args[sym], retvals[sym]
66
+ attach_function apis[sym], sym, args[sym], retvals[sym]
60
67
  rescue FFI::NotFoundError => error
61
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
68
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
62
69
  end
63
70
  end
64
71
  end