sdl2-bindings 0.0.6 → 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 (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
@@ -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
@@ -7,79 +7,81 @@
7
7
  require 'ffi'
8
8
  require_relative 'sdl2_joystick'
9
9
 
10
- module SDL2
10
+ module SDL
11
11
  extend FFI::Library
12
12
  # Define/Macro
13
13
 
14
14
 
15
15
  # Enum
16
16
 
17
- SDL_CONTROLLER_TYPE_UNKNOWN = 0
18
- SDL_CONTROLLER_TYPE_XBOX360 = 1
19
- SDL_CONTROLLER_TYPE_XBOXONE = 2
20
- SDL_CONTROLLER_TYPE_PS3 = 3
21
- SDL_CONTROLLER_TYPE_PS4 = 4
22
- SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO = 5
23
- SDL_CONTROLLER_TYPE_VIRTUAL = 6
24
- SDL_CONTROLLER_TYPE_PS5 = 7
25
- SDL_CONTROLLER_BINDTYPE_NONE = 0
26
- SDL_CONTROLLER_BINDTYPE_BUTTON = 1
27
- SDL_CONTROLLER_BINDTYPE_AXIS = 2
28
- SDL_CONTROLLER_BINDTYPE_HAT = 3
29
- SDL_CONTROLLER_AXIS_INVALID = -1
30
- SDL_CONTROLLER_AXIS_LEFTX = 0
31
- SDL_CONTROLLER_AXIS_LEFTY = 1
32
- SDL_CONTROLLER_AXIS_RIGHTX = 2
33
- SDL_CONTROLLER_AXIS_RIGHTY = 3
34
- SDL_CONTROLLER_AXIS_TRIGGERLEFT = 4
35
- SDL_CONTROLLER_AXIS_TRIGGERRIGHT = 5
36
- SDL_CONTROLLER_AXIS_MAX = 6
37
- SDL_CONTROLLER_BUTTON_INVALID = -1
38
- SDL_CONTROLLER_BUTTON_A = 0
39
- SDL_CONTROLLER_BUTTON_B = 1
40
- SDL_CONTROLLER_BUTTON_X = 2
41
- SDL_CONTROLLER_BUTTON_Y = 3
42
- SDL_CONTROLLER_BUTTON_BACK = 4
43
- SDL_CONTROLLER_BUTTON_GUIDE = 5
44
- SDL_CONTROLLER_BUTTON_START = 6
45
- SDL_CONTROLLER_BUTTON_LEFTSTICK = 7
46
- SDL_CONTROLLER_BUTTON_RIGHTSTICK = 8
47
- SDL_CONTROLLER_BUTTON_LEFTSHOULDER = 9
48
- SDL_CONTROLLER_BUTTON_RIGHTSHOULDER = 10
49
- SDL_CONTROLLER_BUTTON_DPAD_UP = 11
50
- SDL_CONTROLLER_BUTTON_DPAD_DOWN = 12
51
- SDL_CONTROLLER_BUTTON_DPAD_LEFT = 13
52
- SDL_CONTROLLER_BUTTON_DPAD_RIGHT = 14
53
- SDL_CONTROLLER_BUTTON_MISC1 = 15
54
- SDL_CONTROLLER_BUTTON_PADDLE1 = 16
55
- SDL_CONTROLLER_BUTTON_PADDLE2 = 17
56
- SDL_CONTROLLER_BUTTON_PADDLE3 = 18
57
- SDL_CONTROLLER_BUTTON_PADDLE4 = 19
58
- SDL_CONTROLLER_BUTTON_TOUCHPAD = 20
59
- SDL_CONTROLLER_BUTTON_MAX = 21
17
+ CONTROLLER_TYPE_UNKNOWN = 0
18
+ CONTROLLER_TYPE_XBOX360 = 1
19
+ CONTROLLER_TYPE_XBOXONE = 2
20
+ CONTROLLER_TYPE_PS3 = 3
21
+ CONTROLLER_TYPE_PS4 = 4
22
+ CONTROLLER_TYPE_NINTENDO_SWITCH_PRO = 5
23
+ CONTROLLER_TYPE_VIRTUAL = 6
24
+ CONTROLLER_TYPE_PS5 = 7
25
+ CONTROLLER_TYPE_AMAZON_LUNA = 8
26
+ CONTROLLER_TYPE_GOOGLE_STADIA = 9
27
+ CONTROLLER_BINDTYPE_NONE = 0
28
+ CONTROLLER_BINDTYPE_BUTTON = 1
29
+ CONTROLLER_BINDTYPE_AXIS = 2
30
+ CONTROLLER_BINDTYPE_HAT = 3
31
+ CONTROLLER_AXIS_INVALID = -1
32
+ CONTROLLER_AXIS_LEFTX = 0
33
+ CONTROLLER_AXIS_LEFTY = 1
34
+ CONTROLLER_AXIS_RIGHTX = 2
35
+ CONTROLLER_AXIS_RIGHTY = 3
36
+ CONTROLLER_AXIS_TRIGGERLEFT = 4
37
+ CONTROLLER_AXIS_TRIGGERRIGHT = 5
38
+ CONTROLLER_AXIS_MAX = 6
39
+ CONTROLLER_BUTTON_INVALID = -1
40
+ CONTROLLER_BUTTON_A = 0
41
+ CONTROLLER_BUTTON_B = 1
42
+ CONTROLLER_BUTTON_X = 2
43
+ CONTROLLER_BUTTON_Y = 3
44
+ CONTROLLER_BUTTON_BACK = 4
45
+ CONTROLLER_BUTTON_GUIDE = 5
46
+ CONTROLLER_BUTTON_START = 6
47
+ CONTROLLER_BUTTON_LEFTSTICK = 7
48
+ CONTROLLER_BUTTON_RIGHTSTICK = 8
49
+ CONTROLLER_BUTTON_LEFTSHOULDER = 9
50
+ CONTROLLER_BUTTON_RIGHTSHOULDER = 10
51
+ CONTROLLER_BUTTON_DPAD_UP = 11
52
+ CONTROLLER_BUTTON_DPAD_DOWN = 12
53
+ CONTROLLER_BUTTON_DPAD_LEFT = 13
54
+ CONTROLLER_BUTTON_DPAD_RIGHT = 14
55
+ CONTROLLER_BUTTON_MISC1 = 15
56
+ CONTROLLER_BUTTON_PADDLE1 = 16
57
+ CONTROLLER_BUTTON_PADDLE2 = 17
58
+ CONTROLLER_BUTTON_PADDLE3 = 18
59
+ CONTROLLER_BUTTON_PADDLE4 = 19
60
+ CONTROLLER_BUTTON_TOUCHPAD = 20
61
+ CONTROLLER_BUTTON_MAX = 21
60
62
 
61
63
  # Typedef
62
64
 
63
65
 
64
- class SDL_GameControllerButtonBind_value_hat < FFI::Struct
66
+ class GameControllerButtonBind_value_hat < FFI::Struct
65
67
  layout(
66
68
  :hat, :int,
67
69
  :hat_mask, :int,
68
70
  )
69
71
  end
70
72
 
71
- class SDL_GameControllerButtonBind_value < FFI::Struct
73
+ class GameControllerButtonBind_value < FFI::Struct
72
74
  layout(
73
75
  :button, :int,
74
76
  :axis, :int,
75
- :hat, SDL_GameControllerButtonBind_value_hat.by_value,
77
+ :hat, GameControllerButtonBind_value_hat,
76
78
  )
77
79
  end
78
80
 
79
- class SDL_GameControllerButtonBind < FFI::Struct
81
+ class GameControllerButtonBind < FFI::Struct
80
82
  layout(
81
83
  :bindType, :int,
82
- :value, SDL_GameControllerButtonBind_value.by_value,
84
+ :value, GameControllerButtonBind_value,
83
85
  )
84
86
  end
85
87
 
@@ -93,7 +95,7 @@ module SDL2
93
95
 
94
96
  # Function
95
97
 
96
- def self.setup_gamecontroller_symbols()
98
+ def self.setup_gamecontroller_symbols(output_error = false)
97
99
  symbols = [
98
100
  :SDL_GameControllerAddMappingsFromRW,
99
101
  :SDL_GameControllerAddMapping,
@@ -136,19 +138,80 @@ module SDL2
136
138
  :SDL_GameControllerHasSensor,
137
139
  :SDL_GameControllerSetSensorEnabled,
138
140
  :SDL_GameControllerIsSensorEnabled,
141
+ :SDL_GameControllerGetSensorDataRate,
139
142
  :SDL_GameControllerGetSensorData,
140
143
  :SDL_GameControllerRumble,
141
144
  :SDL_GameControllerRumbleTriggers,
142
145
  :SDL_GameControllerHasLED,
146
+ :SDL_GameControllerHasRumble,
147
+ :SDL_GameControllerHasRumbleTriggers,
143
148
  :SDL_GameControllerSetLED,
149
+ :SDL_GameControllerSendEffect,
144
150
  :SDL_GameControllerClose,
151
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton,
152
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis,
145
153
  ]
154
+ apis = {
155
+ :SDL_GameControllerAddMappingsFromRW => :GameControllerAddMappingsFromRW,
156
+ :SDL_GameControllerAddMapping => :GameControllerAddMapping,
157
+ :SDL_GameControllerNumMappings => :GameControllerNumMappings,
158
+ :SDL_GameControllerMappingForIndex => :GameControllerMappingForIndex,
159
+ :SDL_GameControllerMappingForGUID => :GameControllerMappingForGUID,
160
+ :SDL_GameControllerMapping => :GameControllerMapping,
161
+ :SDL_IsGameController => :IsGameController,
162
+ :SDL_GameControllerNameForIndex => :GameControllerNameForIndex,
163
+ :SDL_GameControllerTypeForIndex => :GameControllerTypeForIndex,
164
+ :SDL_GameControllerMappingForDeviceIndex => :GameControllerMappingForDeviceIndex,
165
+ :SDL_GameControllerOpen => :GameControllerOpen,
166
+ :SDL_GameControllerFromInstanceID => :GameControllerFromInstanceID,
167
+ :SDL_GameControllerFromPlayerIndex => :GameControllerFromPlayerIndex,
168
+ :SDL_GameControllerName => :GameControllerName,
169
+ :SDL_GameControllerGetType => :GameControllerGetType,
170
+ :SDL_GameControllerGetPlayerIndex => :GameControllerGetPlayerIndex,
171
+ :SDL_GameControllerSetPlayerIndex => :GameControllerSetPlayerIndex,
172
+ :SDL_GameControllerGetVendor => :GameControllerGetVendor,
173
+ :SDL_GameControllerGetProduct => :GameControllerGetProduct,
174
+ :SDL_GameControllerGetProductVersion => :GameControllerGetProductVersion,
175
+ :SDL_GameControllerGetSerial => :GameControllerGetSerial,
176
+ :SDL_GameControllerGetAttached => :GameControllerGetAttached,
177
+ :SDL_GameControllerGetJoystick => :GameControllerGetJoystick,
178
+ :SDL_GameControllerEventState => :GameControllerEventState,
179
+ :SDL_GameControllerUpdate => :GameControllerUpdate,
180
+ :SDL_GameControllerGetAxisFromString => :GameControllerGetAxisFromString,
181
+ :SDL_GameControllerGetStringForAxis => :GameControllerGetStringForAxis,
182
+ :SDL_GameControllerGetBindForAxis => :GameControllerGetBindForAxis,
183
+ :SDL_GameControllerHasAxis => :GameControllerHasAxis,
184
+ :SDL_GameControllerGetAxis => :GameControllerGetAxis,
185
+ :SDL_GameControllerGetButtonFromString => :GameControllerGetButtonFromString,
186
+ :SDL_GameControllerGetStringForButton => :GameControllerGetStringForButton,
187
+ :SDL_GameControllerGetBindForButton => :GameControllerGetBindForButton,
188
+ :SDL_GameControllerHasButton => :GameControllerHasButton,
189
+ :SDL_GameControllerGetButton => :GameControllerGetButton,
190
+ :SDL_GameControllerGetNumTouchpads => :GameControllerGetNumTouchpads,
191
+ :SDL_GameControllerGetNumTouchpadFingers => :GameControllerGetNumTouchpadFingers,
192
+ :SDL_GameControllerGetTouchpadFinger => :GameControllerGetTouchpadFinger,
193
+ :SDL_GameControllerHasSensor => :GameControllerHasSensor,
194
+ :SDL_GameControllerSetSensorEnabled => :GameControllerSetSensorEnabled,
195
+ :SDL_GameControllerIsSensorEnabled => :GameControllerIsSensorEnabled,
196
+ :SDL_GameControllerGetSensorDataRate => :GameControllerGetSensorDataRate,
197
+ :SDL_GameControllerGetSensorData => :GameControllerGetSensorData,
198
+ :SDL_GameControllerRumble => :GameControllerRumble,
199
+ :SDL_GameControllerRumbleTriggers => :GameControllerRumbleTriggers,
200
+ :SDL_GameControllerHasLED => :GameControllerHasLED,
201
+ :SDL_GameControllerHasRumble => :GameControllerHasRumble,
202
+ :SDL_GameControllerHasRumbleTriggers => :GameControllerHasRumbleTriggers,
203
+ :SDL_GameControllerSetLED => :GameControllerSetLED,
204
+ :SDL_GameControllerSendEffect => :GameControllerSendEffect,
205
+ :SDL_GameControllerClose => :GameControllerClose,
206
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton => :GameControllerGetAppleSFSymbolsNameForButton,
207
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis => :GameControllerGetAppleSFSymbolsNameForAxis,
208
+ }
146
209
  args = {
147
210
  :SDL_GameControllerAddMappingsFromRW => [:pointer, :int],
148
211
  :SDL_GameControllerAddMapping => [:pointer],
149
212
  :SDL_GameControllerNumMappings => [],
150
213
  :SDL_GameControllerMappingForIndex => [:int],
151
- :SDL_GameControllerMappingForGUID => [SDL_JoystickGUID],
214
+ :SDL_GameControllerMappingForGUID => [JoystickGUID.by_value],
152
215
  :SDL_GameControllerMapping => [:pointer],
153
216
  :SDL_IsGameController => [:int],
154
217
  :SDL_GameControllerNameForIndex => [:int],
@@ -185,12 +248,18 @@ module SDL2
185
248
  :SDL_GameControllerHasSensor => [:pointer, :int],
186
249
  :SDL_GameControllerSetSensorEnabled => [:pointer, :int, :int],
187
250
  :SDL_GameControllerIsSensorEnabled => [:pointer, :int],
251
+ :SDL_GameControllerGetSensorDataRate => [:pointer, :int],
188
252
  :SDL_GameControllerGetSensorData => [:pointer, :int, :pointer, :int],
189
253
  :SDL_GameControllerRumble => [:pointer, :ushort, :ushort, :uint],
190
254
  :SDL_GameControllerRumbleTriggers => [:pointer, :ushort, :ushort, :uint],
191
255
  :SDL_GameControllerHasLED => [:pointer],
256
+ :SDL_GameControllerHasRumble => [:pointer],
257
+ :SDL_GameControllerHasRumbleTriggers => [:pointer],
192
258
  :SDL_GameControllerSetLED => [:pointer, :uchar, :uchar, :uchar],
259
+ :SDL_GameControllerSendEffect => [:pointer, :pointer, :int],
193
260
  :SDL_GameControllerClose => [:pointer],
261
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton => [:pointer, :int],
262
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis => [:pointer, :int],
194
263
  }
195
264
  retvals = {
196
265
  :SDL_GameControllerAddMappingsFromRW => :int,
@@ -220,12 +289,12 @@ module SDL2
220
289
  :SDL_GameControllerUpdate => :void,
221
290
  :SDL_GameControllerGetAxisFromString => :int,
222
291
  :SDL_GameControllerGetStringForAxis => :pointer,
223
- :SDL_GameControllerGetBindForAxis => SDL_GameControllerButtonBind,
292
+ :SDL_GameControllerGetBindForAxis => GameControllerButtonBind.by_value,
224
293
  :SDL_GameControllerHasAxis => :int,
225
294
  :SDL_GameControllerGetAxis => :short,
226
295
  :SDL_GameControllerGetButtonFromString => :int,
227
296
  :SDL_GameControllerGetStringForButton => :pointer,
228
- :SDL_GameControllerGetBindForButton => SDL_GameControllerButtonBind,
297
+ :SDL_GameControllerGetBindForButton => GameControllerButtonBind.by_value,
229
298
  :SDL_GameControllerHasButton => :int,
230
299
  :SDL_GameControllerGetButton => :uchar,
231
300
  :SDL_GameControllerGetNumTouchpads => :int,
@@ -234,18 +303,24 @@ module SDL2
234
303
  :SDL_GameControllerHasSensor => :int,
235
304
  :SDL_GameControllerSetSensorEnabled => :int,
236
305
  :SDL_GameControllerIsSensorEnabled => :int,
306
+ :SDL_GameControllerGetSensorDataRate => :float,
237
307
  :SDL_GameControllerGetSensorData => :int,
238
308
  :SDL_GameControllerRumble => :int,
239
309
  :SDL_GameControllerRumbleTriggers => :int,
240
310
  :SDL_GameControllerHasLED => :int,
311
+ :SDL_GameControllerHasRumble => :int,
312
+ :SDL_GameControllerHasRumbleTriggers => :int,
241
313
  :SDL_GameControllerSetLED => :int,
314
+ :SDL_GameControllerSendEffect => :int,
242
315
  :SDL_GameControllerClose => :void,
316
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton => :pointer,
317
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis => :pointer,
243
318
  }
244
319
  symbols.each do |sym|
245
320
  begin
246
- attach_function sym, args[sym], retvals[sym]
321
+ attach_function apis[sym], sym, args[sym], retvals[sym]
247
322
  rescue FFI::NotFoundError => error
248
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
323
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
249
324
  end
250
325
  end
251
326
  end
data/lib/sdl2_gesture.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
 
@@ -23,13 +23,19 @@ module SDL2
23
23
 
24
24
  # Function
25
25
 
26
- def self.setup_gesture_symbols()
26
+ def self.setup_gesture_symbols(output_error = false)
27
27
  symbols = [
28
28
  :SDL_RecordGesture,
29
29
  :SDL_SaveAllDollarTemplates,
30
30
  :SDL_SaveDollarTemplate,
31
31
  :SDL_LoadDollarTemplates,
32
32
  ]
33
+ apis = {
34
+ :SDL_RecordGesture => :RecordGesture,
35
+ :SDL_SaveAllDollarTemplates => :SaveAllDollarTemplates,
36
+ :SDL_SaveDollarTemplate => :SaveDollarTemplate,
37
+ :SDL_LoadDollarTemplates => :LoadDollarTemplates,
38
+ }
33
39
  args = {
34
40
  :SDL_RecordGesture => [:long_long],
35
41
  :SDL_SaveAllDollarTemplates => [:pointer],
@@ -44,9 +50,9 @@ module SDL2
44
50
  }
45
51
  symbols.each do |sym|
46
52
  begin
47
- attach_function sym, args[sym], retvals[sym]
53
+ attach_function apis[sym], sym, args[sym], retvals[sym]
48
54
  rescue FFI::NotFoundError => error
49
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
55
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
50
56
  end
51
57
  end
52
58
  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
 
@@ -25,7 +25,7 @@ module SDL2
25
25
 
26
26
  # Function
27
27
 
28
- def self.setup_gfx_primitives_symbols()
28
+ def self.setup_gfx_primitives_symbols(output_error = false)
29
29
  symbols = [
30
30
  :pixelColor,
31
31
  :pixelRGBA,
@@ -87,6 +87,67 @@ module SDL2
87
87
  :stringColor,
88
88
  :stringRGBA,
89
89
  ]
90
+ apis = {
91
+ :pixelColor => :pixelColor,
92
+ :pixelRGBA => :pixelRGBA,
93
+ :hlineColor => :hlineColor,
94
+ :hlineRGBA => :hlineRGBA,
95
+ :vlineColor => :vlineColor,
96
+ :vlineRGBA => :vlineRGBA,
97
+ :rectangleColor => :rectangleColor,
98
+ :rectangleRGBA => :rectangleRGBA,
99
+ :roundedRectangleColor => :roundedRectangleColor,
100
+ :roundedRectangleRGBA => :roundedRectangleRGBA,
101
+ :boxColor => :boxColor,
102
+ :boxRGBA => :boxRGBA,
103
+ :roundedBoxColor => :roundedBoxColor,
104
+ :roundedBoxRGBA => :roundedBoxRGBA,
105
+ :lineColor => :lineColor,
106
+ :lineRGBA => :lineRGBA,
107
+ :aalineColor => :aalineColor,
108
+ :aalineRGBA => :aalineRGBA,
109
+ :thickLineColor => :thickLineColor,
110
+ :thickLineRGBA => :thickLineRGBA,
111
+ :circleColor => :circleColor,
112
+ :circleRGBA => :circleRGBA,
113
+ :arcColor => :arcColor,
114
+ :arcRGBA => :arcRGBA,
115
+ :aacircleColor => :aacircleColor,
116
+ :aacircleRGBA => :aacircleRGBA,
117
+ :filledCircleColor => :filledCircleColor,
118
+ :filledCircleRGBA => :filledCircleRGBA,
119
+ :ellipseColor => :ellipseColor,
120
+ :ellipseRGBA => :ellipseRGBA,
121
+ :aaellipseColor => :aaellipseColor,
122
+ :aaellipseRGBA => :aaellipseRGBA,
123
+ :filledEllipseColor => :filledEllipseColor,
124
+ :filledEllipseRGBA => :filledEllipseRGBA,
125
+ :pieColor => :pieColor,
126
+ :pieRGBA => :pieRGBA,
127
+ :filledPieColor => :filledPieColor,
128
+ :filledPieRGBA => :filledPieRGBA,
129
+ :trigonColor => :trigonColor,
130
+ :trigonRGBA => :trigonRGBA,
131
+ :aatrigonColor => :aatrigonColor,
132
+ :aatrigonRGBA => :aatrigonRGBA,
133
+ :filledTrigonColor => :filledTrigonColor,
134
+ :filledTrigonRGBA => :filledTrigonRGBA,
135
+ :polygonColor => :polygonColor,
136
+ :polygonRGBA => :polygonRGBA,
137
+ :aapolygonColor => :aapolygonColor,
138
+ :aapolygonRGBA => :aapolygonRGBA,
139
+ :filledPolygonColor => :filledPolygonColor,
140
+ :filledPolygonRGBA => :filledPolygonRGBA,
141
+ :texturedPolygon => :texturedPolygon,
142
+ :bezierColor => :bezierColor,
143
+ :bezierRGBA => :bezierRGBA,
144
+ :gfxPrimitivesSetFont => :gfxPrimitivesSetFont,
145
+ :gfxPrimitivesSetFontRotation => :gfxPrimitivesSetFontRotation,
146
+ :characterColor => :characterColor,
147
+ :characterRGBA => :characterRGBA,
148
+ :stringColor => :stringColor,
149
+ :stringRGBA => :stringRGBA,
150
+ }
90
151
  args = {
91
152
  :pixelColor => [:pointer, :short, :short, :uint],
92
153
  :pixelRGBA => [:pointer, :short, :short, :uchar, :uchar, :uchar, :uchar],
@@ -211,9 +272,9 @@ module SDL2
211
272
  }
212
273
  symbols.each do |sym|
213
274
  begin
214
- attach_function sym, args[sym], retvals[sym]
275
+ attach_function apis[sym], sym, args[sym], retvals[sym]
215
276
  rescue FFI::NotFoundError => error
216
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
277
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
217
278
  end
218
279
  end
219
280
  end
data/lib/sdl2_haptic.rb CHANGED
@@ -6,31 +6,31 @@
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_HAPTIC_CONSTANT = (1 << 0)
14
- SDL_HAPTIC_SINE = (1 << 1)
15
- SDL_HAPTIC_LEFTRIGHT = (1 << 2)
16
- SDL_HAPTIC_TRIANGLE = (1 << 3)
17
- SDL_HAPTIC_SAWTOOTHUP = (1 << 4)
18
- SDL_HAPTIC_SAWTOOTHDOWN = (1 << 5)
19
- SDL_HAPTIC_RAMP = (1 << 6)
20
- SDL_HAPTIC_SPRING = (1 << 7)
21
- SDL_HAPTIC_DAMPER = (1 << 8)
22
- SDL_HAPTIC_INERTIA = (1 << 9)
23
- SDL_HAPTIC_FRICTION = (1 << 10)
24
- SDL_HAPTIC_CUSTOM = (1 << 11)
25
- SDL_HAPTIC_GAIN = (1 << 12)
26
- SDL_HAPTIC_AUTOCENTER = (1 << 13)
27
- SDL_HAPTIC_STATUS = (1 << 14)
28
- SDL_HAPTIC_PAUSE = (1 << 15)
29
- SDL_HAPTIC_POLAR = 0
30
- SDL_HAPTIC_CARTESIAN = 1
31
- SDL_HAPTIC_SPHERICAL = 2
32
- SDL_HAPTIC_STEERING_AXIS = 3
33
- SDL_HAPTIC_INFINITY = 4294967295
13
+ HAPTIC_CONSTANT = (1 << 0)
14
+ HAPTIC_SINE = (1 << 1)
15
+ HAPTIC_LEFTRIGHT = (1 << 2)
16
+ HAPTIC_TRIANGLE = (1 << 3)
17
+ HAPTIC_SAWTOOTHUP = (1 << 4)
18
+ HAPTIC_SAWTOOTHDOWN = (1 << 5)
19
+ HAPTIC_RAMP = (1 << 6)
20
+ HAPTIC_SPRING = (1 << 7)
21
+ HAPTIC_DAMPER = (1 << 8)
22
+ HAPTIC_INERTIA = (1 << 9)
23
+ HAPTIC_FRICTION = (1 << 10)
24
+ HAPTIC_CUSTOM = (1 << 11)
25
+ HAPTIC_GAIN = (1 << 12)
26
+ HAPTIC_AUTOCENTER = (1 << 13)
27
+ HAPTIC_STATUS = (1 << 14)
28
+ HAPTIC_PAUSE = (1 << 15)
29
+ HAPTIC_POLAR = 0
30
+ HAPTIC_CARTESIAN = 1
31
+ HAPTIC_SPHERICAL = 2
32
+ HAPTIC_STEERING_AXIS = 3
33
+ HAPTIC_INFINITY = 4294967295
34
34
 
35
35
  # Enum
36
36
 
@@ -40,17 +40,17 @@ module SDL2
40
40
 
41
41
  # Struct
42
42
 
43
- class SDL_HapticDirection < FFI::Struct
43
+ class HapticDirection < FFI::Struct
44
44
  layout(
45
45
  :type, :uchar,
46
46
  :dir, [:int, 3],
47
47
  )
48
48
  end
49
49
 
50
- class SDL_HapticConstant < FFI::Struct
50
+ class HapticConstant < FFI::Struct
51
51
  layout(
52
52
  :type, :ushort,
53
- :direction, SDL_HapticDirection,
53
+ :direction, HapticDirection,
54
54
  :length, :uint,
55
55
  :delay, :ushort,
56
56
  :button, :ushort,
@@ -63,10 +63,10 @@ module SDL2
63
63
  )
64
64
  end
65
65
 
66
- class SDL_HapticPeriodic < FFI::Struct
66
+ class HapticPeriodic < FFI::Struct
67
67
  layout(
68
68
  :type, :ushort,
69
- :direction, SDL_HapticDirection,
69
+ :direction, HapticDirection,
70
70
  :length, :uint,
71
71
  :delay, :ushort,
72
72
  :button, :ushort,
@@ -82,10 +82,10 @@ module SDL2
82
82
  )
83
83
  end
84
84
 
85
- class SDL_HapticCondition < FFI::Struct
85
+ class HapticCondition < FFI::Struct
86
86
  layout(
87
87
  :type, :ushort,
88
- :direction, SDL_HapticDirection,
88
+ :direction, HapticDirection,
89
89
  :length, :uint,
90
90
  :delay, :ushort,
91
91
  :button, :ushort,
@@ -99,10 +99,10 @@ module SDL2
99
99
  )
100
100
  end
101
101
 
102
- class SDL_HapticRamp < FFI::Struct
102
+ class HapticRamp < FFI::Struct
103
103
  layout(
104
104
  :type, :ushort,
105
- :direction, SDL_HapticDirection,
105
+ :direction, HapticDirection,
106
106
  :length, :uint,
107
107
  :delay, :ushort,
108
108
  :button, :ushort,
@@ -116,7 +116,7 @@ module SDL2
116
116
  )
117
117
  end
118
118
 
119
- class SDL_HapticLeftRight < FFI::Struct
119
+ class HapticLeftRight < FFI::Struct
120
120
  layout(
121
121
  :type, :ushort,
122
122
  :length, :uint,
@@ -125,10 +125,10 @@ module SDL2
125
125
  )
126
126
  end
127
127
 
128
- class SDL_HapticCustom < FFI::Struct
128
+ class HapticCustom < FFI::Struct
129
129
  layout(
130
130
  :type, :ushort,
131
- :direction, SDL_HapticDirection,
131
+ :direction, HapticDirection,
132
132
  :length, :uint,
133
133
  :delay, :ushort,
134
134
  :button, :ushort,
@@ -144,22 +144,22 @@ module SDL2
144
144
  )
145
145
  end
146
146
 
147
- class SDL_HapticEffect < FFI::Union
147
+ class HapticEffect < FFI::Union
148
148
  layout(
149
149
  :type, :ushort,
150
- :constant, SDL_HapticConstant,
151
- :periodic, SDL_HapticPeriodic,
152
- :condition, SDL_HapticCondition,
153
- :ramp, SDL_HapticRamp,
154
- :leftright, SDL_HapticLeftRight,
155
- :custom, SDL_HapticCustom,
150
+ :constant, HapticConstant,
151
+ :periodic, HapticPeriodic,
152
+ :condition, HapticCondition,
153
+ :ramp, HapticRamp,
154
+ :leftright, HapticLeftRight,
155
+ :custom, HapticCustom,
156
156
  )
157
157
  end
158
158
 
159
159
 
160
160
  # Function
161
161
 
162
- def self.setup_haptic_symbols()
162
+ def self.setup_haptic_symbols(output_error = false)
163
163
  symbols = [
164
164
  :SDL_NumHaptics,
165
165
  :SDL_HapticName,
@@ -192,6 +192,38 @@ module SDL2
192
192
  :SDL_HapticRumblePlay,
193
193
  :SDL_HapticRumbleStop,
194
194
  ]
195
+ apis = {
196
+ :SDL_NumHaptics => :NumHaptics,
197
+ :SDL_HapticName => :HapticName,
198
+ :SDL_HapticOpen => :HapticOpen,
199
+ :SDL_HapticOpened => :HapticOpened,
200
+ :SDL_HapticIndex => :HapticIndex,
201
+ :SDL_MouseIsHaptic => :MouseIsHaptic,
202
+ :SDL_HapticOpenFromMouse => :HapticOpenFromMouse,
203
+ :SDL_JoystickIsHaptic => :JoystickIsHaptic,
204
+ :SDL_HapticOpenFromJoystick => :HapticOpenFromJoystick,
205
+ :SDL_HapticClose => :HapticClose,
206
+ :SDL_HapticNumEffects => :HapticNumEffects,
207
+ :SDL_HapticNumEffectsPlaying => :HapticNumEffectsPlaying,
208
+ :SDL_HapticQuery => :HapticQuery,
209
+ :SDL_HapticNumAxes => :HapticNumAxes,
210
+ :SDL_HapticEffectSupported => :HapticEffectSupported,
211
+ :SDL_HapticNewEffect => :HapticNewEffect,
212
+ :SDL_HapticUpdateEffect => :HapticUpdateEffect,
213
+ :SDL_HapticRunEffect => :HapticRunEffect,
214
+ :SDL_HapticStopEffect => :HapticStopEffect,
215
+ :SDL_HapticDestroyEffect => :HapticDestroyEffect,
216
+ :SDL_HapticGetEffectStatus => :HapticGetEffectStatus,
217
+ :SDL_HapticSetGain => :HapticSetGain,
218
+ :SDL_HapticSetAutocenter => :HapticSetAutocenter,
219
+ :SDL_HapticPause => :HapticPause,
220
+ :SDL_HapticUnpause => :HapticUnpause,
221
+ :SDL_HapticStopAll => :HapticStopAll,
222
+ :SDL_HapticRumbleSupported => :HapticRumbleSupported,
223
+ :SDL_HapticRumbleInit => :HapticRumbleInit,
224
+ :SDL_HapticRumblePlay => :HapticRumblePlay,
225
+ :SDL_HapticRumbleStop => :HapticRumbleStop,
226
+ }
195
227
  args = {
196
228
  :SDL_NumHaptics => [],
197
229
  :SDL_HapticName => [:int],
@@ -258,9 +290,9 @@ module SDL2
258
290
  }
259
291
  symbols.each do |sym|
260
292
  begin
261
- attach_function sym, args[sym], retvals[sym]
293
+ attach_function apis[sym], sym, args[sym], retvals[sym]
262
294
  rescue FFI::NotFoundError => error
263
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
295
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
264
296
  end
265
297
  end
266
298
  end