sdl2-bindings 0.0.6 → 0.1.0

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 +25 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +38 -19
  5. data/lib/sdl2.rb +56 -99
  6. data/lib/sdl2_audio.rb +62 -20
  7. data/lib/sdl2_blendmode.rb +28 -25
  8. data/lib/sdl2_clipboard.rb +9 -4
  9. data/lib/sdl2_cpuinfo.rb +31 -8
  10. data/lib/sdl2_error.rb +17 -10
  11. data/lib/sdl2_events.rb +152 -130
  12. data/lib/sdl2_filesystem.rb +8 -4
  13. data/lib/sdl2_framerate.rb +11 -4
  14. data/lib/sdl2_gamecontroller.rb +130 -55
  15. data/lib/sdl2_gesture.rb +10 -4
  16. data/lib/sdl2_gfxPrimitives.rb +65 -4
  17. data/lib/sdl2_haptic.rb +76 -44
  18. data/lib/sdl2_hidapi.rb +139 -0
  19. data/lib/sdl2_hints.rb +146 -113
  20. data/lib/sdl2_image.rb +54 -7
  21. data/lib/sdl2_imageFilter.rb +36 -4
  22. data/lib/sdl2_joystick.rb +102 -38
  23. data/lib/sdl2_keyboard.rb +23 -5
  24. data/lib/sdl2_keycode.rb +8 -5
  25. data/lib/sdl2_log.rb +48 -32
  26. data/lib/sdl2_main.rb +21 -14
  27. data/lib/sdl2_messagebox.rb +26 -22
  28. data/lib/sdl2_misc.rb +48 -0
  29. data/lib/sdl2_mixer.rb +86 -11
  30. data/lib/sdl2_mouse.rb +44 -25
  31. data/lib/sdl2_pixels.rb +115 -99
  32. data/lib/sdl2_platform.rb +7 -4
  33. data/lib/sdl2_power.rb +12 -9
  34. data/lib/sdl2_rect.rb +18 -11
  35. data/lib/sdl2_render.rb +135 -21
  36. data/lib/sdl2_rotozoom.rb +14 -4
  37. data/lib/sdl2_rwops.rb +69 -39
  38. data/lib/sdl2_scancode.rb +250 -248
  39. data/lib/sdl2_sensor.rb +115 -0
  40. data/lib/sdl2_shape.rb +17 -11
  41. data/lib/sdl2_stdinc.rb +213 -42
  42. data/lib/sdl2_surface.rb +62 -15
  43. data/lib/sdl2_syswm.rb +47 -41
  44. data/lib/sdl2_timer.rb +16 -4
  45. data/lib/sdl2_touch.rb +18 -9
  46. data/lib/sdl2_ttf.rb +180 -25
  47. data/lib/sdl2_version.rb +13 -8
  48. data/lib/sdl2_video.rb +232 -103
  49. data/lib/sdl2_vulkan.rb +12 -4
  50. metadata +21 -4
data/lib/sdl2_cpuinfo.rb CHANGED
@@ -6,11 +6,11 @@
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
 
13
- SDL_CACHELINE_SIZE = 128
13
+ CACHELINE_SIZE = 128
14
14
 
15
15
  # Enum
16
16
 
@@ -23,7 +23,7 @@ module SDL2
23
23
 
24
24
  # Function
25
25
 
26
- def self.setup_cpuinfo_symbols()
26
+ def self.setup_cpuinfo_symbols(output_error = false)
27
27
  symbols = [
28
28
  :SDL_GetCPUCount,
29
29
  :SDL_GetCPUCacheLineSize,
@@ -47,6 +47,29 @@ module SDL2
47
47
  :SDL_SIMDRealloc,
48
48
  :SDL_SIMDFree,
49
49
  ]
50
+ apis = {
51
+ :SDL_GetCPUCount => :GetCPUCount,
52
+ :SDL_GetCPUCacheLineSize => :GetCPUCacheLineSize,
53
+ :SDL_HasRDTSC => :HasRDTSC,
54
+ :SDL_HasAltiVec => :HasAltiVec,
55
+ :SDL_HasMMX => :HasMMX,
56
+ :SDL_Has3DNow => :Has3DNow,
57
+ :SDL_HasSSE => :HasSSE,
58
+ :SDL_HasSSE2 => :HasSSE2,
59
+ :SDL_HasSSE3 => :HasSSE3,
60
+ :SDL_HasSSE41 => :HasSSE41,
61
+ :SDL_HasSSE42 => :HasSSE42,
62
+ :SDL_HasAVX => :HasAVX,
63
+ :SDL_HasAVX2 => :HasAVX2,
64
+ :SDL_HasAVX512F => :HasAVX512F,
65
+ :SDL_HasARMSIMD => :HasARMSIMD,
66
+ :SDL_HasNEON => :HasNEON,
67
+ :SDL_GetSystemRAM => :GetSystemRAM,
68
+ :SDL_SIMDGetAlignment => :SIMDGetAlignment,
69
+ :SDL_SIMDAlloc => :SIMDAlloc,
70
+ :SDL_SIMDRealloc => :SIMDRealloc,
71
+ :SDL_SIMDFree => :SIMDFree,
72
+ }
50
73
  args = {
51
74
  :SDL_GetCPUCount => [],
52
75
  :SDL_GetCPUCacheLineSize => [],
@@ -66,8 +89,8 @@ module SDL2
66
89
  :SDL_HasNEON => [],
67
90
  :SDL_GetSystemRAM => [],
68
91
  :SDL_SIMDGetAlignment => [],
69
- :SDL_SIMDAlloc => [:ulong],
70
- :SDL_SIMDRealloc => [:pointer, :ulong],
92
+ :SDL_SIMDAlloc => [:int],
93
+ :SDL_SIMDRealloc => [:pointer, :int],
71
94
  :SDL_SIMDFree => [:pointer],
72
95
  }
73
96
  retvals = {
@@ -88,16 +111,16 @@ module SDL2
88
111
  :SDL_HasARMSIMD => :int,
89
112
  :SDL_HasNEON => :int,
90
113
  :SDL_GetSystemRAM => :int,
91
- :SDL_SIMDGetAlignment => :size_t,
114
+ :SDL_SIMDGetAlignment => :int,
92
115
  :SDL_SIMDAlloc => :pointer,
93
116
  :SDL_SIMDRealloc => :pointer,
94
117
  :SDL_SIMDFree => :void,
95
118
  }
96
119
  symbols.each do |sym|
97
120
  begin
98
- attach_function sym, args[sym], retvals[sym]
121
+ attach_function apis[sym], sym, args[sym], retvals[sym]
99
122
  rescue FFI::NotFoundError => error
100
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
123
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
101
124
  end
102
125
  end
103
126
  end
data/lib/sdl2_error.rb CHANGED
@@ -6,19 +6,19 @@
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
 
13
13
 
14
14
  # Enum
15
15
 
16
- SDL_ENOMEM = 0
17
- SDL_EFREAD = 1
18
- SDL_EFWRITE = 2
19
- SDL_EFSEEK = 3
20
- SDL_UNSUPPORTED = 4
21
- SDL_LASTERROR = 5
16
+ ENOMEM = 0
17
+ EFREAD = 1
18
+ EFWRITE = 2
19
+ EFSEEK = 3
20
+ UNSUPPORTED = 4
21
+ LASTERROR = 5
22
22
 
23
23
  # Typedef
24
24
 
@@ -29,7 +29,7 @@ module SDL2
29
29
 
30
30
  # Function
31
31
 
32
- def self.setup_error_symbols()
32
+ def self.setup_error_symbols(output_error = false)
33
33
  symbols = [
34
34
  :SDL_SetError,
35
35
  :SDL_GetError,
@@ -37,6 +37,13 @@ module SDL2
37
37
  :SDL_ClearError,
38
38
  :SDL_Error,
39
39
  ]
40
+ apis = {
41
+ :SDL_SetError => :SetError,
42
+ :SDL_GetError => :GetError,
43
+ :SDL_GetErrorMsg => :GetErrorMsg,
44
+ :SDL_ClearError => :ClearError,
45
+ :SDL_Error => :Error,
46
+ }
40
47
  args = {
41
48
  :SDL_SetError => [:pointer],
42
49
  :SDL_GetError => [],
@@ -53,9 +60,9 @@ module SDL2
53
60
  }
54
61
  symbols.each do |sym|
55
62
  begin
56
- attach_function sym, args[sym], retvals[sym]
63
+ attach_function apis[sym], sym, args[sym], retvals[sym]
57
64
  rescue FFI::NotFoundError => error
58
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
65
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
59
66
  end
60
67
  end
61
68
  end
data/lib/sdl2_events.rb CHANGED
@@ -7,80 +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_USEREVENT = 32768
80
- SDL_LASTEVENT = 65535
81
- SDL_ADDEVENT = 0
82
- SDL_PEEKEVENT = 1
83
- 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
84
85
 
85
86
  # Typedef
86
87
 
@@ -91,14 +92,14 @@ module SDL2
91
92
 
92
93
  # Struct
93
94
 
94
- class SDL_CommonEvent < FFI::Struct
95
+ class CommonEvent < FFI::Struct
95
96
  layout(
96
97
  :type, :uint,
97
98
  :timestamp, :uint,
98
99
  )
99
100
  end
100
101
 
101
- class SDL_DisplayEvent < FFI::Struct
102
+ class DisplayEvent < FFI::Struct
102
103
  layout(
103
104
  :type, :uint,
104
105
  :timestamp, :uint,
@@ -111,7 +112,7 @@ module SDL2
111
112
  )
112
113
  end
113
114
 
114
- class SDL_WindowEvent < FFI::Struct
115
+ class WindowEvent < FFI::Struct
115
116
  layout(
116
117
  :type, :uint,
117
118
  :timestamp, :uint,
@@ -125,7 +126,7 @@ module SDL2
125
126
  )
126
127
  end
127
128
 
128
- class SDL_KeyboardEvent < FFI::Struct
129
+ class KeyboardEvent < FFI::Struct
129
130
  layout(
130
131
  :type, :uint,
131
132
  :timestamp, :uint,
@@ -134,11 +135,11 @@ module SDL2
134
135
  :repeat, :uchar,
135
136
  :padding2, :uchar,
136
137
  :padding3, :uchar,
137
- :keysym, SDL_Keysym,
138
+ :keysym, Keysym,
138
139
  )
139
140
  end
140
141
 
141
- class SDL_TextEditingEvent < FFI::Struct
142
+ class TextEditingEvent < FFI::Struct
142
143
  layout(
143
144
  :type, :uint,
144
145
  :timestamp, :uint,
@@ -149,7 +150,7 @@ module SDL2
149
150
  )
150
151
  end
151
152
 
152
- class SDL_TextInputEvent < FFI::Struct
153
+ class TextInputEvent < FFI::Struct
153
154
  layout(
154
155
  :type, :uint,
155
156
  :timestamp, :uint,
@@ -158,7 +159,7 @@ module SDL2
158
159
  )
159
160
  end
160
161
 
161
- class SDL_MouseMotionEvent < FFI::Struct
162
+ class MouseMotionEvent < FFI::Struct
162
163
  layout(
163
164
  :type, :uint,
164
165
  :timestamp, :uint,
@@ -172,7 +173,7 @@ module SDL2
172
173
  )
173
174
  end
174
175
 
175
- class SDL_MouseButtonEvent < FFI::Struct
176
+ class MouseButtonEvent < FFI::Struct
176
177
  layout(
177
178
  :type, :uint,
178
179
  :timestamp, :uint,
@@ -187,7 +188,7 @@ module SDL2
187
188
  )
188
189
  end
189
190
 
190
- class SDL_MouseWheelEvent < FFI::Struct
191
+ class MouseWheelEvent < FFI::Struct
191
192
  layout(
192
193
  :type, :uint,
193
194
  :timestamp, :uint,
@@ -196,10 +197,12 @@ module SDL2
196
197
  :x, :int,
197
198
  :y, :int,
198
199
  :direction, :uint,
200
+ :preciseX, :float,
201
+ :preciseY, :float,
199
202
  )
200
203
  end
201
204
 
202
- class SDL_JoyAxisEvent < FFI::Struct
205
+ class JoyAxisEvent < FFI::Struct
203
206
  layout(
204
207
  :type, :uint,
205
208
  :timestamp, :uint,
@@ -213,7 +216,7 @@ module SDL2
213
216
  )
214
217
  end
215
218
 
216
- class SDL_JoyBallEvent < FFI::Struct
219
+ class JoyBallEvent < FFI::Struct
217
220
  layout(
218
221
  :type, :uint,
219
222
  :timestamp, :uint,
@@ -227,7 +230,7 @@ module SDL2
227
230
  )
228
231
  end
229
232
 
230
- class SDL_JoyHatEvent < FFI::Struct
233
+ class JoyHatEvent < FFI::Struct
231
234
  layout(
232
235
  :type, :uint,
233
236
  :timestamp, :uint,
@@ -239,7 +242,7 @@ module SDL2
239
242
  )
240
243
  end
241
244
 
242
- class SDL_JoyButtonEvent < FFI::Struct
245
+ class JoyButtonEvent < FFI::Struct
243
246
  layout(
244
247
  :type, :uint,
245
248
  :timestamp, :uint,
@@ -251,7 +254,7 @@ module SDL2
251
254
  )
252
255
  end
253
256
 
254
- class SDL_JoyDeviceEvent < FFI::Struct
257
+ class JoyDeviceEvent < FFI::Struct
255
258
  layout(
256
259
  :type, :uint,
257
260
  :timestamp, :uint,
@@ -259,7 +262,7 @@ module SDL2
259
262
  )
260
263
  end
261
264
 
262
- class SDL_ControllerAxisEvent < FFI::Struct
265
+ class ControllerAxisEvent < FFI::Struct
263
266
  layout(
264
267
  :type, :uint,
265
268
  :timestamp, :uint,
@@ -273,7 +276,7 @@ module SDL2
273
276
  )
274
277
  end
275
278
 
276
- class SDL_ControllerButtonEvent < FFI::Struct
279
+ class ControllerButtonEvent < FFI::Struct
277
280
  layout(
278
281
  :type, :uint,
279
282
  :timestamp, :uint,
@@ -285,7 +288,7 @@ module SDL2
285
288
  )
286
289
  end
287
290
 
288
- class SDL_ControllerDeviceEvent < FFI::Struct
291
+ class ControllerDeviceEvent < FFI::Struct
289
292
  layout(
290
293
  :type, :uint,
291
294
  :timestamp, :uint,
@@ -293,7 +296,7 @@ module SDL2
293
296
  )
294
297
  end
295
298
 
296
- class SDL_ControllerTouchpadEvent < FFI::Struct
299
+ class ControllerTouchpadEvent < FFI::Struct
297
300
  layout(
298
301
  :type, :uint,
299
302
  :timestamp, :uint,
@@ -306,7 +309,7 @@ module SDL2
306
309
  )
307
310
  end
308
311
 
309
- class SDL_ControllerSensorEvent < FFI::Struct
312
+ class ControllerSensorEvent < FFI::Struct
310
313
  layout(
311
314
  :type, :uint,
312
315
  :timestamp, :uint,
@@ -316,7 +319,7 @@ module SDL2
316
319
  )
317
320
  end
318
321
 
319
- class SDL_AudioDeviceEvent < FFI::Struct
322
+ class AudioDeviceEvent < FFI::Struct
320
323
  layout(
321
324
  :type, :uint,
322
325
  :timestamp, :uint,
@@ -328,7 +331,7 @@ module SDL2
328
331
  )
329
332
  end
330
333
 
331
- class SDL_TouchFingerEvent < FFI::Struct
334
+ class TouchFingerEvent < FFI::Struct
332
335
  layout(
333
336
  :type, :uint,
334
337
  :timestamp, :uint,
@@ -343,7 +346,7 @@ module SDL2
343
346
  )
344
347
  end
345
348
 
346
- class SDL_MultiGestureEvent < FFI::Struct
349
+ class MultiGestureEvent < FFI::Struct
347
350
  layout(
348
351
  :type, :uint,
349
352
  :timestamp, :uint,
@@ -357,7 +360,7 @@ module SDL2
357
360
  )
358
361
  end
359
362
 
360
- class SDL_DollarGestureEvent < FFI::Struct
363
+ class DollarGestureEvent < FFI::Struct
361
364
  layout(
362
365
  :type, :uint,
363
366
  :timestamp, :uint,
@@ -370,7 +373,7 @@ module SDL2
370
373
  )
371
374
  end
372
375
 
373
- class SDL_DropEvent < FFI::Struct
376
+ class DropEvent < FFI::Struct
374
377
  layout(
375
378
  :type, :uint,
376
379
  :timestamp, :uint,
@@ -379,7 +382,7 @@ module SDL2
379
382
  )
380
383
  end
381
384
 
382
- class SDL_SensorEvent < FFI::Struct
385
+ class SensorEvent < FFI::Struct
383
386
  layout(
384
387
  :type, :uint,
385
388
  :timestamp, :uint,
@@ -388,21 +391,21 @@ module SDL2
388
391
  )
389
392
  end
390
393
 
391
- class SDL_QuitEvent < FFI::Struct
394
+ class QuitEvent < FFI::Struct
392
395
  layout(
393
396
  :type, :uint,
394
397
  :timestamp, :uint,
395
398
  )
396
399
  end
397
400
 
398
- class SDL_OSEvent < FFI::Struct
401
+ class OSEvent < FFI::Struct
399
402
  layout(
400
403
  :type, :uint,
401
404
  :timestamp, :uint,
402
405
  )
403
406
  end
404
407
 
405
- class SDL_UserEvent < FFI::Struct
408
+ class UserEvent < FFI::Struct
406
409
  layout(
407
410
  :type, :uint,
408
411
  :timestamp, :uint,
@@ -413,7 +416,7 @@ module SDL2
413
416
  )
414
417
  end
415
418
 
416
- class SDL_SysWMEvent < FFI::Struct
419
+ class SysWMEvent < FFI::Struct
417
420
  layout(
418
421
  :type, :uint,
419
422
  :timestamp, :uint,
@@ -421,37 +424,37 @@ module SDL2
421
424
  )
422
425
  end
423
426
 
424
- class SDL_Event < FFI::Union
427
+ class Event < FFI::Union
425
428
  layout(
426
429
  :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,
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,
455
458
  :padding, [:uchar, 56],
456
459
  )
457
460
  end
@@ -459,7 +462,7 @@ module SDL2
459
462
 
460
463
  # Function
461
464
 
462
- def self.setup_events_symbols()
465
+ def self.setup_events_symbols(output_error = false)
463
466
  symbols = [
464
467
  :SDL_PumpEvents,
465
468
  :SDL_PeepEvents,
@@ -479,6 +482,25 @@ module SDL2
479
482
  :SDL_EventState,
480
483
  :SDL_RegisterEvents,
481
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
+ }
482
504
  args = {
483
505
  :SDL_PumpEvents => [],
484
506
  :SDL_PeepEvents => [:pointer, :int, :int, :uint, :uint],
@@ -519,9 +541,9 @@ module SDL2
519
541
  }
520
542
  symbols.each do |sym|
521
543
  begin
522
- attach_function sym, args[sym], retvals[sym]
544
+ attach_function apis[sym], sym, args[sym], retvals[sym]
523
545
  rescue FFI::NotFoundError => error
524
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
546
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
525
547
  end
526
548
  end
527
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