sdl2-bindings 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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_stdinc.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
- SDL_ICONV_ERROR = -1
14
- SDL_ICONV_E2BIG = -2
15
- SDL_ICONV_EILSEQ = -3
16
- SDL_ICONV_EINVAL = -4
13
+ ICONV_ERROR = -1
14
+ ICONV_E2BIG = -2
15
+ ICONV_EILSEQ = -3
16
+ ICONV_EINVAL = -4
17
17
 
18
18
  # Enum
19
19
 
20
- SDL_FALSE = 0
21
- SDL_TRUE = 1
20
+ FALSE = 0
21
+ TRUE = 1
22
22
 
23
23
  # Typedef
24
24
 
@@ -50,7 +50,7 @@ module SDL2
50
50
 
51
51
  # Function
52
52
 
53
- def self.setup_stdinc_symbols()
53
+ def self.setup_stdinc_symbols(output_error = false)
54
54
  symbols = [
55
55
  :SDL_malloc,
56
56
  :SDL_calloc,
@@ -176,6 +176,131 @@ module SDL2
176
176
  :SDL_iconv_string,
177
177
  :SDL_memcpy4,
178
178
  ]
179
+ apis = {
180
+ :SDL_malloc => :malloc,
181
+ :SDL_calloc => :calloc,
182
+ :SDL_realloc => :realloc,
183
+ :SDL_free => :free,
184
+ :SDL_GetMemoryFunctions => :GetMemoryFunctions,
185
+ :SDL_SetMemoryFunctions => :SetMemoryFunctions,
186
+ :SDL_GetNumAllocations => :GetNumAllocations,
187
+ :SDL_getenv => :getenv,
188
+ :SDL_setenv => :setenv,
189
+ :SDL_qsort => :qsort,
190
+ :SDL_abs => :abs,
191
+ :SDL_isalpha => :isalpha,
192
+ :SDL_isalnum => :isalnum,
193
+ :SDL_isblank => :isblank,
194
+ :SDL_iscntrl => :iscntrl,
195
+ :SDL_isdigit => :isdigit,
196
+ :SDL_isxdigit => :isxdigit,
197
+ :SDL_ispunct => :ispunct,
198
+ :SDL_isspace => :isspace,
199
+ :SDL_isupper => :isupper,
200
+ :SDL_islower => :islower,
201
+ :SDL_isprint => :isprint,
202
+ :SDL_isgraph => :isgraph,
203
+ :SDL_toupper => :toupper,
204
+ :SDL_tolower => :tolower,
205
+ :SDL_crc32 => :crc32,
206
+ :SDL_memset => :memset,
207
+ :SDL_memset4 => :memset4,
208
+ :SDL_memcpy => :memcpy,
209
+ :SDL_memmove => :memmove,
210
+ :SDL_memcmp => :memcmp,
211
+ :SDL_wcslen => :wcslen,
212
+ :SDL_wcslcpy => :wcslcpy,
213
+ :SDL_wcslcat => :wcslcat,
214
+ :SDL_wcsdup => :wcsdup,
215
+ :SDL_wcsstr => :wcsstr,
216
+ :SDL_wcscmp => :wcscmp,
217
+ :SDL_wcsncmp => :wcsncmp,
218
+ :SDL_wcscasecmp => :wcscasecmp,
219
+ :SDL_wcsncasecmp => :wcsncasecmp,
220
+ :SDL_strlen => :strlen,
221
+ :SDL_strlcpy => :strlcpy,
222
+ :SDL_utf8strlcpy => :utf8strlcpy,
223
+ :SDL_strlcat => :strlcat,
224
+ :SDL_strdup => :strdup,
225
+ :SDL_strrev => :strrev,
226
+ :SDL_strupr => :strupr,
227
+ :SDL_strlwr => :strlwr,
228
+ :SDL_strchr => :strchr,
229
+ :SDL_strrchr => :strrchr,
230
+ :SDL_strstr => :strstr,
231
+ :SDL_strtokr => :strtokr,
232
+ :SDL_utf8strlen => :utf8strlen,
233
+ :SDL_itoa => :itoa,
234
+ :SDL_uitoa => :uitoa,
235
+ :SDL_ltoa => :ltoa,
236
+ :SDL_ultoa => :ultoa,
237
+ :SDL_lltoa => :lltoa,
238
+ :SDL_ulltoa => :ulltoa,
239
+ :SDL_atoi => :atoi,
240
+ :SDL_atof => :atof,
241
+ :SDL_strtol => :strtol,
242
+ :SDL_strtoul => :strtoul,
243
+ :SDL_strtoll => :strtoll,
244
+ :SDL_strtoull => :strtoull,
245
+ :SDL_strtod => :strtod,
246
+ :SDL_strcmp => :strcmp,
247
+ :SDL_strncmp => :strncmp,
248
+ :SDL_strcasecmp => :strcasecmp,
249
+ :SDL_strncasecmp => :strncasecmp,
250
+ :SDL_sscanf => :sscanf,
251
+ :SDL_vsscanf => :vsscanf,
252
+ :SDL_snprintf => :snprintf,
253
+ :SDL_vsnprintf => :vsnprintf,
254
+ :SDL_asprintf => :asprintf,
255
+ :SDL_vasprintf => :vasprintf,
256
+ :SDL_acos => :acos,
257
+ :SDL_acosf => :acosf,
258
+ :SDL_asin => :asin,
259
+ :SDL_asinf => :asinf,
260
+ :SDL_atan => :atan,
261
+ :SDL_atanf => :atanf,
262
+ :SDL_atan2 => :atan2,
263
+ :SDL_atan2f => :atan2f,
264
+ :SDL_ceil => :ceil,
265
+ :SDL_ceilf => :ceilf,
266
+ :SDL_copysign => :copysign,
267
+ :SDL_copysignf => :copysignf,
268
+ :SDL_cos => :cos,
269
+ :SDL_cosf => :cosf,
270
+ :SDL_exp => :exp,
271
+ :SDL_expf => :expf,
272
+ :SDL_fabs => :fabs,
273
+ :SDL_fabsf => :fabsf,
274
+ :SDL_floor => :floor,
275
+ :SDL_floorf => :floorf,
276
+ :SDL_trunc => :trunc,
277
+ :SDL_truncf => :truncf,
278
+ :SDL_fmod => :fmod,
279
+ :SDL_fmodf => :fmodf,
280
+ :SDL_log => :log,
281
+ :SDL_logf => :logf,
282
+ :SDL_log10 => :log10,
283
+ :SDL_log10f => :log10f,
284
+ :SDL_pow => :pow,
285
+ :SDL_powf => :powf,
286
+ :SDL_round => :round,
287
+ :SDL_roundf => :roundf,
288
+ :SDL_lround => :lround,
289
+ :SDL_lroundf => :lroundf,
290
+ :SDL_scalbn => :scalbn,
291
+ :SDL_scalbnf => :scalbnf,
292
+ :SDL_sin => :sin,
293
+ :SDL_sinf => :sinf,
294
+ :SDL_sqrt => :sqrt,
295
+ :SDL_sqrtf => :sqrtf,
296
+ :SDL_tan => :tan,
297
+ :SDL_tanf => :tanf,
298
+ :SDL_iconv_open => :iconv_open,
299
+ :SDL_iconv_close => :iconv_close,
300
+ :SDL_iconv => :iconv,
301
+ :SDL_iconv_string => :iconv_string,
302
+ :SDL_memcpy4 => :memcpy4,
303
+ }
179
304
  args = {
180
305
  :SDL_malloc => [:int],
181
306
  :SDL_calloc => [:int, :int],
@@ -428,9 +553,9 @@ module SDL2
428
553
  }
429
554
  symbols.each do |sym|
430
555
  begin
431
- attach_function sym, args[sym], retvals[sym]
556
+ attach_function apis[sym], sym, args[sym], retvals[sym]
432
557
  rescue FFI::NotFoundError => error
433
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
558
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
434
559
  end
435
560
  end
436
561
  end
data/lib/sdl2_surface.rb CHANGED
@@ -7,22 +7,22 @@
7
7
  require 'ffi'
8
8
  require_relative 'sdl2_rect'
9
9
 
10
- module SDL2
10
+ module SDL
11
11
  extend FFI::Library
12
12
  # Define/Macro
13
13
 
14
- SDL_SWSURFACE = 0
15
- SDL_PREALLOC = 0x00000001
16
- SDL_RLEACCEL = 0x00000002
17
- SDL_DONTFREE = 0x00000004
18
- SDL_SIMD_ALIGNED = 0x00000008
14
+ SWSURFACE = 0
15
+ PREALLOC = 0x00000001
16
+ RLEACCEL = 0x00000002
17
+ DONTFREE = 0x00000004
18
+ SIMD_ALIGNED = 0x00000008
19
19
 
20
20
  # Enum
21
21
 
22
- SDL_YUV_CONVERSION_JPEG = 0
23
- SDL_YUV_CONVERSION_BT601 = 1
24
- SDL_YUV_CONVERSION_BT709 = 2
25
- SDL_YUV_CONVERSION_AUTOMATIC = 3
22
+ YUV_CONVERSION_JPEG = 0
23
+ YUV_CONVERSION_BT601 = 1
24
+ YUV_CONVERSION_BT709 = 2
25
+ YUV_CONVERSION_AUTOMATIC = 3
26
26
 
27
27
  # Typedef
28
28
 
@@ -31,7 +31,7 @@ module SDL2
31
31
 
32
32
  # Struct
33
33
 
34
- class SDL_Surface < FFI::Struct
34
+ class Surface < FFI::Struct
35
35
  layout(
36
36
  :flags, :uint,
37
37
  :format, :pointer,
@@ -42,7 +42,7 @@ module SDL2
42
42
  :userdata, :pointer,
43
43
  :locked, :int,
44
44
  :list_blitmap, :pointer,
45
- :clip_rect, SDL_Rect,
45
+ :clip_rect, Rect,
46
46
  :map, :pointer,
47
47
  :refcount, :int,
48
48
  )
@@ -51,7 +51,7 @@ module SDL2
51
51
 
52
52
  # Function
53
53
 
54
- def self.setup_surface_symbols()
54
+ def self.setup_surface_symbols(output_error = false)
55
55
  symbols = [
56
56
  :SDL_CreateRGBSurface,
57
57
  :SDL_CreateRGBSurfaceWithFormat,
@@ -93,6 +93,47 @@ module SDL2
93
93
  :SDL_GetYUVConversionMode,
94
94
  :SDL_GetYUVConversionModeForResolution,
95
95
  ]
96
+ apis = {
97
+ :SDL_CreateRGBSurface => :CreateRGBSurface,
98
+ :SDL_CreateRGBSurfaceWithFormat => :CreateRGBSurfaceWithFormat,
99
+ :SDL_CreateRGBSurfaceFrom => :CreateRGBSurfaceFrom,
100
+ :SDL_CreateRGBSurfaceWithFormatFrom => :CreateRGBSurfaceWithFormatFrom,
101
+ :SDL_FreeSurface => :FreeSurface,
102
+ :SDL_SetSurfacePalette => :SetSurfacePalette,
103
+ :SDL_LockSurface => :LockSurface,
104
+ :SDL_UnlockSurface => :UnlockSurface,
105
+ :SDL_LoadBMP_RW => :LoadBMP_RW,
106
+ :SDL_SaveBMP_RW => :SaveBMP_RW,
107
+ :SDL_SetSurfaceRLE => :SetSurfaceRLE,
108
+ :SDL_HasSurfaceRLE => :HasSurfaceRLE,
109
+ :SDL_SetColorKey => :SetColorKey,
110
+ :SDL_HasColorKey => :HasColorKey,
111
+ :SDL_GetColorKey => :GetColorKey,
112
+ :SDL_SetSurfaceColorMod => :SetSurfaceColorMod,
113
+ :SDL_GetSurfaceColorMod => :GetSurfaceColorMod,
114
+ :SDL_SetSurfaceAlphaMod => :SetSurfaceAlphaMod,
115
+ :SDL_GetSurfaceAlphaMod => :GetSurfaceAlphaMod,
116
+ :SDL_SetSurfaceBlendMode => :SetSurfaceBlendMode,
117
+ :SDL_GetSurfaceBlendMode => :GetSurfaceBlendMode,
118
+ :SDL_SetClipRect => :SetClipRect,
119
+ :SDL_GetClipRect => :GetClipRect,
120
+ :SDL_DuplicateSurface => :DuplicateSurface,
121
+ :SDL_ConvertSurface => :ConvertSurface,
122
+ :SDL_ConvertSurfaceFormat => :ConvertSurfaceFormat,
123
+ :SDL_ConvertPixels => :ConvertPixels,
124
+ :SDL_PremultiplyAlpha => :PremultiplyAlpha,
125
+ :SDL_FillRect => :FillRect,
126
+ :SDL_FillRects => :FillRects,
127
+ :SDL_UpperBlit => :UpperBlit,
128
+ :SDL_LowerBlit => :LowerBlit,
129
+ :SDL_SoftStretch => :SoftStretch,
130
+ :SDL_SoftStretchLinear => :SoftStretchLinear,
131
+ :SDL_UpperBlitScaled => :UpperBlitScaled,
132
+ :SDL_LowerBlitScaled => :LowerBlitScaled,
133
+ :SDL_SetYUVConversionMode => :SetYUVConversionMode,
134
+ :SDL_GetYUVConversionMode => :GetYUVConversionMode,
135
+ :SDL_GetYUVConversionModeForResolution => :GetYUVConversionModeForResolution,
136
+ }
96
137
  args = {
97
138
  :SDL_CreateRGBSurface => [:uint, :int, :int, :int, :uint, :uint, :uint, :uint],
98
139
  :SDL_CreateRGBSurfaceWithFormat => [:uint, :int, :int, :int, :uint],
@@ -177,9 +218,9 @@ module SDL2
177
218
  }
178
219
  symbols.each do |sym|
179
220
  begin
180
- attach_function sym, args[sym], retvals[sym]
221
+ attach_function apis[sym], sym, args[sym], retvals[sym]
181
222
  rescue FFI::NotFoundError => error
182
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
223
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
183
224
  end
184
225
  end
185
226
  end
data/lib/sdl2_syswm.rb CHANGED
@@ -7,35 +7,35 @@
7
7
  require 'ffi'
8
8
  require_relative 'sdl2_version'
9
9
 
10
- module SDL2
10
+ module SDL
11
11
  extend FFI::Library
12
12
  # Define/Macro
13
13
 
14
- SDL_METALVIEW_TAG = 255
14
+ METALVIEW_TAG = 255
15
15
 
16
16
  # Enum
17
17
 
18
- SDL_SYSWM_UNKNOWN = 0
19
- SDL_SYSWM_WINDOWS = 1
20
- SDL_SYSWM_X11 = 2
21
- SDL_SYSWM_DIRECTFB = 3
22
- SDL_SYSWM_COCOA = 4
23
- SDL_SYSWM_UIKIT = 5
24
- SDL_SYSWM_WAYLAND = 6
25
- SDL_SYSWM_MIR = 7
26
- SDL_SYSWM_WINRT = 8
27
- SDL_SYSWM_ANDROID = 9
28
- SDL_SYSWM_VIVANTE = 10
29
- SDL_SYSWM_OS2 = 11
30
- SDL_SYSWM_HAIKU = 12
31
- SDL_SYSWM_KMSDRM = 13
32
- SDL_SYSWM_RISCOS = 14
18
+ SYSWM_UNKNOWN = 0
19
+ SYSWM_WINDOWS = 1
20
+ SYSWM_X11 = 2
21
+ SYSWM_DIRECTFB = 3
22
+ SYSWM_COCOA = 4
23
+ SYSWM_UIKIT = 5
24
+ SYSWM_WAYLAND = 6
25
+ SYSWM_MIR = 7
26
+ SYSWM_WINRT = 8
27
+ SYSWM_ANDROID = 9
28
+ SYSWM_VIVANTE = 10
29
+ SYSWM_OS2 = 11
30
+ SYSWM_HAIKU = 12
31
+ SYSWM_KMSDRM = 13
32
+ SYSWM_RISCOS = 14
33
33
 
34
34
  # Typedef
35
35
 
36
36
  typedef :int, :SDL_SYSWM_TYPE
37
37
 
38
- class SDL_SysWMmsg_def_win < FFI::Struct
38
+ class SysWMmsg_def_win < FFI::Struct
39
39
  layout(
40
40
  :hwnd, :pointer,
41
41
  :msg, :uint32,
@@ -44,46 +44,46 @@ module SDL2
44
44
  )
45
45
  end
46
46
 
47
- class SDL_SysWMmsg_value_win < FFI::Union
47
+ class SysWMmsg_value_win < FFI::Union
48
48
  layout(
49
- :win, SDL_SysWMmsg_def_win.by_value,
49
+ :win, SysWMmsg_def_win.by_value,
50
50
  :dummy, :int
51
51
  )
52
52
  end
53
53
 
54
- class SDL_SysWMmsg_win < FFI::Struct
54
+ class SysWMmsg_win < FFI::Struct
55
55
  layout(
56
- :version, SDL_version.by_value,
56
+ :version, Version.by_value,
57
57
  :subsystem, :int,
58
- :msg, SDL_SysWMmsg_value_win.by_value
58
+ :msg, SysWMmsg_value_win.by_value
59
59
  )
60
60
  end
61
61
 
62
62
 
63
- class SDL_SysWMmsg_def_cocoa < FFI::Struct
63
+ class SysWMmsg_def_cocoa < FFI::Struct
64
64
  layout(
65
65
  :dummy, :int
66
66
  )
67
67
  end
68
68
 
69
- class SDL_SysWMmsg_value_cocoa < FFI::Union
69
+ class SysWMmsg_value_cocoa < FFI::Union
70
70
  layout(
71
- :cocoa, SDL_SysWMmsg_def_cocoa.by_value,
71
+ :cocoa, SysWMmsg_def_cocoa.by_value,
72
72
  :dummy, :int
73
73
  )
74
74
  end
75
75
 
76
- class SDL_SysWMmsg_cocoa < FFI::Struct
76
+ class SysWMmsg_cocoa < FFI::Struct
77
77
  layout(
78
- :version, SDL_version.by_value,
78
+ :version, Version.by_value,
79
79
  :subsystem, :int,
80
- :msg, SDL_SysWMmsg_value_cocoa.by_value
80
+ :msg, SysWMmsg_value_cocoa.by_value
81
81
  )
82
82
  end
83
83
 
84
84
  ################################################################################
85
85
 
86
- class SDL_SysWMinfo_def_win < FFI::Struct
86
+ class SysWMinfo_def_win < FFI::Struct
87
87
  layout(
88
88
  :window, :pointer,
89
89
  :hdc, :pointer,
@@ -91,40 +91,40 @@ module SDL2
91
91
  )
92
92
  end
93
93
 
94
- class SDL_SysWMinfo_value_win < FFI::Union
94
+ class SysWMinfo_value_win < FFI::Union
95
95
  layout(
96
- :win, SDL_SysWMinfo_def_win.by_value,
96
+ :win, SysWMinfo_def_win.by_value,
97
97
  :dummy, [:uint8, 64]
98
98
  )
99
99
  end
100
100
 
101
- class SDL_SysWMinfo_win < FFI::Struct
101
+ class SysWMinfo_win < FFI::Struct
102
102
  layout(
103
- :version, SDL_version.by_value,
103
+ :version, Version.by_value,
104
104
  :subsystem, :int,
105
- :info, SDL_SysWMinfo_value_win.by_value
105
+ :info, SysWMinfo_value_win.by_value
106
106
  )
107
107
  end
108
108
 
109
109
 
110
- class SDL_SysWMinfo_def_cocoa < FFI::Struct
110
+ class SysWMinfo_def_cocoa < FFI::Struct
111
111
  layout(
112
112
  :window, :pointer
113
113
  )
114
114
  end
115
115
 
116
- class SDL_SysWMinfo_value_cocoa < FFI::Union
116
+ class SysWMinfo_value_cocoa < FFI::Union
117
117
  layout(
118
- :cocoa, SDL_SysWMinfo_def_cocoa.by_value,
118
+ :cocoa, SysWMinfo_def_cocoa.by_value,
119
119
  :dummy, [:uint8, 64]
120
120
  )
121
121
  end
122
122
 
123
- class SDL_SysWMinfo_cocoa < FFI::Struct
123
+ class SysWMinfo_cocoa < FFI::Struct
124
124
  layout(
125
- :version, SDL_version.by_value,
125
+ :version, Version.by_value,
126
126
  :subsystem, :int,
127
- :info, SDL_SysWMinfo_value_cocoa.by_value
127
+ :info, SysWMinfo_value_cocoa.by_value
128
128
  )
129
129
  end
130
130
 
@@ -134,10 +134,13 @@ module SDL2
134
134
 
135
135
  # Function
136
136
 
137
- def self.setup_syswm_symbols()
137
+ def self.setup_syswm_symbols(output_error = false)
138
138
  symbols = [
139
139
  :SDL_GetWindowWMInfo,
140
140
  ]
141
+ apis = {
142
+ :SDL_GetWindowWMInfo => :GetWindowWMInfo,
143
+ }
141
144
  args = {
142
145
  :SDL_GetWindowWMInfo => [:pointer, :pointer],
143
146
  }
@@ -146,9 +149,9 @@ module SDL2
146
149
  }
147
150
  symbols.each do |sym|
148
151
  begin
149
- attach_function sym, args[sym], retvals[sym]
152
+ attach_function apis[sym], sym, args[sym], retvals[sym]
150
153
  rescue FFI::NotFoundError => error
151
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
154
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
152
155
  end
153
156
  end
154
157
  end
data/lib/sdl2_timer.rb CHANGED
@@ -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
 
@@ -24,7 +24,7 @@ module SDL2
24
24
 
25
25
  # Function
26
26
 
27
- def self.setup_timer_symbols()
27
+ def self.setup_timer_symbols(output_error = false)
28
28
  symbols = [
29
29
  :SDL_GetTicks,
30
30
  :SDL_GetTicks64,
@@ -34,6 +34,15 @@ module SDL2
34
34
  :SDL_AddTimer,
35
35
  :SDL_RemoveTimer,
36
36
  ]
37
+ apis = {
38
+ :SDL_GetTicks => :GetTicks,
39
+ :SDL_GetTicks64 => :GetTicks64,
40
+ :SDL_GetPerformanceCounter => :GetPerformanceCounter,
41
+ :SDL_GetPerformanceFrequency => :GetPerformanceFrequency,
42
+ :SDL_Delay => :Delay,
43
+ :SDL_AddTimer => :AddTimer,
44
+ :SDL_RemoveTimer => :RemoveTimer,
45
+ }
37
46
  args = {
38
47
  :SDL_GetTicks => [],
39
48
  :SDL_GetTicks64 => [],
@@ -54,9 +63,9 @@ module SDL2
54
63
  }
55
64
  symbols.each do |sym|
56
65
  begin
57
- attach_function sym, args[sym], retvals[sym]
66
+ attach_function apis[sym], sym, args[sym], retvals[sym]
58
67
  rescue FFI::NotFoundError => error
59
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
68
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
60
69
  end
61
70
  end
62
71
  end
data/lib/sdl2_touch.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
- SDL_TOUCH_MOUSEID = -1
14
- SDL_MOUSE_TOUCHID = -1
13
+ TOUCH_MOUSEID = -1
14
+ MOUSE_TOUCHID = -1
15
15
 
16
16
  # Enum
17
17
 
18
- SDL_TOUCH_DEVICE_INVALID = -1
19
- SDL_TOUCH_DEVICE_DIRECT = 0
20
- SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE = 1
21
- SDL_TOUCH_DEVICE_INDIRECT_RELATIVE = 2
18
+ TOUCH_DEVICE_INVALID = -1
19
+ TOUCH_DEVICE_DIRECT = 0
20
+ TOUCH_DEVICE_INDIRECT_ABSOLUTE = 1
21
+ TOUCH_DEVICE_INDIRECT_RELATIVE = 2
22
22
 
23
23
  # Typedef
24
24
 
@@ -28,7 +28,7 @@ module SDL2
28
28
 
29
29
  # Struct
30
30
 
31
- class SDL_Finger < FFI::Struct
31
+ class Finger < FFI::Struct
32
32
  layout(
33
33
  :id, :long_long,
34
34
  :x, :float,
@@ -40,7 +40,7 @@ module SDL2
40
40
 
41
41
  # Function
42
42
 
43
- def self.setup_touch_symbols()
43
+ def self.setup_touch_symbols(output_error = false)
44
44
  symbols = [
45
45
  :SDL_GetNumTouchDevices,
46
46
  :SDL_GetTouchDevice,
@@ -48,6 +48,13 @@ module SDL2
48
48
  :SDL_GetNumTouchFingers,
49
49
  :SDL_GetTouchFinger,
50
50
  ]
51
+ apis = {
52
+ :SDL_GetNumTouchDevices => :GetNumTouchDevices,
53
+ :SDL_GetTouchDevice => :GetTouchDevice,
54
+ :SDL_GetTouchDeviceType => :GetTouchDeviceType,
55
+ :SDL_GetNumTouchFingers => :GetNumTouchFingers,
56
+ :SDL_GetTouchFinger => :GetTouchFinger,
57
+ }
51
58
  args = {
52
59
  :SDL_GetNumTouchDevices => [],
53
60
  :SDL_GetTouchDevice => [:int],
@@ -64,9 +71,9 @@ module SDL2
64
71
  }
65
72
  symbols.each do |sym|
66
73
  begin
67
- attach_function sym, args[sym], retvals[sym]
74
+ attach_function apis[sym], sym, args[sym], retvals[sym]
68
75
  rescue FFI::NotFoundError => error
69
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
76
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
70
77
  end
71
78
  end
72
79
  end