sdl2-bindings 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +140 -124
  3. data/LICENSE.txt +0 -0
  4. data/README.md +93 -77
  5. data/lib/sdl2.rb +131 -131
  6. data/lib/sdl2_audio.rb +265 -261
  7. data/lib/sdl2_blendmode.rb +72 -72
  8. data/lib/sdl2_clipboard.rb +56 -56
  9. data/lib/sdl2_cpuinfo.rb +137 -129
  10. data/lib/sdl2_error.rb +71 -71
  11. data/lib/sdl2_events.rb +575 -564
  12. data/lib/sdl2_filesystem.rb +52 -52
  13. data/lib/sdl2_framerate.rb +74 -74
  14. data/lib/sdl2_gamecontroller.rb +345 -329
  15. data/lib/sdl2_gesture.rb +61 -61
  16. data/lib/sdl2_gfxPrimitives.rb +283 -283
  17. data/lib/sdl2_guid.rb +58 -0
  18. data/lib/sdl2_haptic.rb +301 -301
  19. data/lib/sdl2_hidapi.rb +139 -139
  20. data/lib/sdl2_hints.rb +240 -221
  21. data/lib/sdl2_image.rb +296 -232
  22. data/lib/sdl2_imageFilter.rb +164 -164
  23. data/lib/sdl2_joystick.rb +332 -294
  24. data/lib/sdl2_keyboard.rb +129 -125
  25. data/lib/sdl2_keycode.rb +311 -307
  26. data/lib/sdl2_log.rb +131 -131
  27. data/lib/sdl2_main.rb +74 -74
  28. data/lib/sdl2_messagebox.rb +102 -102
  29. data/lib/sdl2_misc.rb +48 -48
  30. data/lib/sdl2_mixer.rb +464 -392
  31. data/lib/sdl2_mouse.rb +136 -136
  32. data/lib/sdl2_pixels.rb +240 -240
  33. data/lib/sdl2_platform.rb +48 -48
  34. data/lib/sdl2_power.rb +54 -54
  35. data/lib/sdl2_rect.rb +145 -145
  36. data/lib/sdl2_render.rb +408 -408
  37. data/lib/sdl2_rotozoom.rb +76 -76
  38. data/lib/sdl2_rwops.rb +242 -238
  39. data/lib/sdl2_scancode.rb +293 -289
  40. data/lib/sdl2_sensor.rb +115 -115
  41. data/lib/sdl2_shape.rb +83 -83
  42. data/lib/sdl2_sound.rb +154 -154
  43. data/lib/sdl2_stdinc.rb +564 -556
  44. data/lib/sdl2_surface.rb +229 -229
  45. data/lib/sdl2_syswm.rb +160 -160
  46. data/lib/sdl2_timer.rb +74 -74
  47. data/lib/sdl2_touch.rb +86 -86
  48. data/lib/sdl2_ttf.rb +414 -358
  49. data/lib/sdl2_version.rb +67 -67
  50. data/lib/sdl2_video.rb +549 -540
  51. data/lib/sdl2_vulkan.rb +72 -72
  52. metadata +4 -3
@@ -1,329 +1,345 @@
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_joystick'
9
-
10
- module SDL
11
- extend FFI::Library
12
- # Define/Macro
13
-
14
-
15
- # Enum
16
-
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
62
-
63
- # Typedef
64
-
65
-
66
- class GameControllerButtonBind_value_hat < FFI::Struct
67
- layout(
68
- :hat, :int,
69
- :hat_mask, :int,
70
- )
71
- end
72
-
73
- class GameControllerButtonBind_value < FFI::Struct
74
- layout(
75
- :button, :int,
76
- :axis, :int,
77
- :hat, GameControllerButtonBind_value_hat,
78
- )
79
- end
80
-
81
- class GameControllerButtonBind < FFI::Struct
82
- layout(
83
- :bindType, :int,
84
- :value, GameControllerButtonBind_value,
85
- )
86
- end
87
-
88
- typedef :int, :SDL_GameControllerType
89
- typedef :int, :SDL_GameControllerBindType
90
- typedef :int, :SDL_GameControllerAxis
91
- typedef :int, :SDL_GameControllerButton
92
-
93
- # Struct
94
-
95
-
96
- # Function
97
-
98
- def self.setup_gamecontroller_symbols(output_error = false)
99
- symbols = [
100
- :SDL_GameControllerAddMappingsFromRW,
101
- :SDL_GameControllerAddMapping,
102
- :SDL_GameControllerNumMappings,
103
- :SDL_GameControllerMappingForIndex,
104
- :SDL_GameControllerMappingForGUID,
105
- :SDL_GameControllerMapping,
106
- :SDL_IsGameController,
107
- :SDL_GameControllerNameForIndex,
108
- :SDL_GameControllerTypeForIndex,
109
- :SDL_GameControllerMappingForDeviceIndex,
110
- :SDL_GameControllerOpen,
111
- :SDL_GameControllerFromInstanceID,
112
- :SDL_GameControllerFromPlayerIndex,
113
- :SDL_GameControllerName,
114
- :SDL_GameControllerGetType,
115
- :SDL_GameControllerGetPlayerIndex,
116
- :SDL_GameControllerSetPlayerIndex,
117
- :SDL_GameControllerGetVendor,
118
- :SDL_GameControllerGetProduct,
119
- :SDL_GameControllerGetProductVersion,
120
- :SDL_GameControllerGetSerial,
121
- :SDL_GameControllerGetAttached,
122
- :SDL_GameControllerGetJoystick,
123
- :SDL_GameControllerEventState,
124
- :SDL_GameControllerUpdate,
125
- :SDL_GameControllerGetAxisFromString,
126
- :SDL_GameControllerGetStringForAxis,
127
- :SDL_GameControllerGetBindForAxis,
128
- :SDL_GameControllerHasAxis,
129
- :SDL_GameControllerGetAxis,
130
- :SDL_GameControllerGetButtonFromString,
131
- :SDL_GameControllerGetStringForButton,
132
- :SDL_GameControllerGetBindForButton,
133
- :SDL_GameControllerHasButton,
134
- :SDL_GameControllerGetButton,
135
- :SDL_GameControllerGetNumTouchpads,
136
- :SDL_GameControllerGetNumTouchpadFingers,
137
- :SDL_GameControllerGetTouchpadFinger,
138
- :SDL_GameControllerHasSensor,
139
- :SDL_GameControllerSetSensorEnabled,
140
- :SDL_GameControllerIsSensorEnabled,
141
- :SDL_GameControllerGetSensorDataRate,
142
- :SDL_GameControllerGetSensorData,
143
- :SDL_GameControllerRumble,
144
- :SDL_GameControllerRumbleTriggers,
145
- :SDL_GameControllerHasLED,
146
- :SDL_GameControllerHasRumble,
147
- :SDL_GameControllerHasRumbleTriggers,
148
- :SDL_GameControllerSetLED,
149
- :SDL_GameControllerSendEffect,
150
- :SDL_GameControllerClose,
151
- :SDL_GameControllerGetAppleSFSymbolsNameForButton,
152
- :SDL_GameControllerGetAppleSFSymbolsNameForAxis,
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
- }
209
- args = {
210
- :SDL_GameControllerAddMappingsFromRW => [:pointer, :int],
211
- :SDL_GameControllerAddMapping => [:pointer],
212
- :SDL_GameControllerNumMappings => [],
213
- :SDL_GameControllerMappingForIndex => [:int],
214
- :SDL_GameControllerMappingForGUID => [JoystickGUID.by_value],
215
- :SDL_GameControllerMapping => [:pointer],
216
- :SDL_IsGameController => [:int],
217
- :SDL_GameControllerNameForIndex => [:int],
218
- :SDL_GameControllerTypeForIndex => [:int],
219
- :SDL_GameControllerMappingForDeviceIndex => [:int],
220
- :SDL_GameControllerOpen => [:int],
221
- :SDL_GameControllerFromInstanceID => [:int],
222
- :SDL_GameControllerFromPlayerIndex => [:int],
223
- :SDL_GameControllerName => [:pointer],
224
- :SDL_GameControllerGetType => [:pointer],
225
- :SDL_GameControllerGetPlayerIndex => [:pointer],
226
- :SDL_GameControllerSetPlayerIndex => [:pointer, :int],
227
- :SDL_GameControllerGetVendor => [:pointer],
228
- :SDL_GameControllerGetProduct => [:pointer],
229
- :SDL_GameControllerGetProductVersion => [:pointer],
230
- :SDL_GameControllerGetSerial => [:pointer],
231
- :SDL_GameControllerGetAttached => [:pointer],
232
- :SDL_GameControllerGetJoystick => [:pointer],
233
- :SDL_GameControllerEventState => [:int],
234
- :SDL_GameControllerUpdate => [],
235
- :SDL_GameControllerGetAxisFromString => [:pointer],
236
- :SDL_GameControllerGetStringForAxis => [:int],
237
- :SDL_GameControllerGetBindForAxis => [:pointer, :int],
238
- :SDL_GameControllerHasAxis => [:pointer, :int],
239
- :SDL_GameControllerGetAxis => [:pointer, :int],
240
- :SDL_GameControllerGetButtonFromString => [:pointer],
241
- :SDL_GameControllerGetStringForButton => [:int],
242
- :SDL_GameControllerGetBindForButton => [:pointer, :int],
243
- :SDL_GameControllerHasButton => [:pointer, :int],
244
- :SDL_GameControllerGetButton => [:pointer, :int],
245
- :SDL_GameControllerGetNumTouchpads => [:pointer],
246
- :SDL_GameControllerGetNumTouchpadFingers => [:pointer, :int],
247
- :SDL_GameControllerGetTouchpadFinger => [:pointer, :int, :int, :pointer, :pointer, :pointer, :pointer],
248
- :SDL_GameControllerHasSensor => [:pointer, :int],
249
- :SDL_GameControllerSetSensorEnabled => [:pointer, :int, :int],
250
- :SDL_GameControllerIsSensorEnabled => [:pointer, :int],
251
- :SDL_GameControllerGetSensorDataRate => [:pointer, :int],
252
- :SDL_GameControllerGetSensorData => [:pointer, :int, :pointer, :int],
253
- :SDL_GameControllerRumble => [:pointer, :ushort, :ushort, :uint],
254
- :SDL_GameControllerRumbleTriggers => [:pointer, :ushort, :ushort, :uint],
255
- :SDL_GameControllerHasLED => [:pointer],
256
- :SDL_GameControllerHasRumble => [:pointer],
257
- :SDL_GameControllerHasRumbleTriggers => [:pointer],
258
- :SDL_GameControllerSetLED => [:pointer, :uchar, :uchar, :uchar],
259
- :SDL_GameControllerSendEffect => [:pointer, :pointer, :int],
260
- :SDL_GameControllerClose => [:pointer],
261
- :SDL_GameControllerGetAppleSFSymbolsNameForButton => [:pointer, :int],
262
- :SDL_GameControllerGetAppleSFSymbolsNameForAxis => [:pointer, :int],
263
- }
264
- retvals = {
265
- :SDL_GameControllerAddMappingsFromRW => :int,
266
- :SDL_GameControllerAddMapping => :int,
267
- :SDL_GameControllerNumMappings => :int,
268
- :SDL_GameControllerMappingForIndex => :pointer,
269
- :SDL_GameControllerMappingForGUID => :pointer,
270
- :SDL_GameControllerMapping => :pointer,
271
- :SDL_IsGameController => :int,
272
- :SDL_GameControllerNameForIndex => :pointer,
273
- :SDL_GameControllerTypeForIndex => :int,
274
- :SDL_GameControllerMappingForDeviceIndex => :pointer,
275
- :SDL_GameControllerOpen => :pointer,
276
- :SDL_GameControllerFromInstanceID => :pointer,
277
- :SDL_GameControllerFromPlayerIndex => :pointer,
278
- :SDL_GameControllerName => :pointer,
279
- :SDL_GameControllerGetType => :int,
280
- :SDL_GameControllerGetPlayerIndex => :int,
281
- :SDL_GameControllerSetPlayerIndex => :void,
282
- :SDL_GameControllerGetVendor => :ushort,
283
- :SDL_GameControllerGetProduct => :ushort,
284
- :SDL_GameControllerGetProductVersion => :ushort,
285
- :SDL_GameControllerGetSerial => :pointer,
286
- :SDL_GameControllerGetAttached => :int,
287
- :SDL_GameControllerGetJoystick => :pointer,
288
- :SDL_GameControllerEventState => :int,
289
- :SDL_GameControllerUpdate => :void,
290
- :SDL_GameControllerGetAxisFromString => :int,
291
- :SDL_GameControllerGetStringForAxis => :pointer,
292
- :SDL_GameControllerGetBindForAxis => GameControllerButtonBind.by_value,
293
- :SDL_GameControllerHasAxis => :int,
294
- :SDL_GameControllerGetAxis => :short,
295
- :SDL_GameControllerGetButtonFromString => :int,
296
- :SDL_GameControllerGetStringForButton => :pointer,
297
- :SDL_GameControllerGetBindForButton => GameControllerButtonBind.by_value,
298
- :SDL_GameControllerHasButton => :int,
299
- :SDL_GameControllerGetButton => :uchar,
300
- :SDL_GameControllerGetNumTouchpads => :int,
301
- :SDL_GameControllerGetNumTouchpadFingers => :int,
302
- :SDL_GameControllerGetTouchpadFinger => :int,
303
- :SDL_GameControllerHasSensor => :int,
304
- :SDL_GameControllerSetSensorEnabled => :int,
305
- :SDL_GameControllerIsSensorEnabled => :int,
306
- :SDL_GameControllerGetSensorDataRate => :float,
307
- :SDL_GameControllerGetSensorData => :int,
308
- :SDL_GameControllerRumble => :int,
309
- :SDL_GameControllerRumbleTriggers => :int,
310
- :SDL_GameControllerHasLED => :int,
311
- :SDL_GameControllerHasRumble => :int,
312
- :SDL_GameControllerHasRumbleTriggers => :int,
313
- :SDL_GameControllerSetLED => :int,
314
- :SDL_GameControllerSendEffect => :int,
315
- :SDL_GameControllerClose => :void,
316
- :SDL_GameControllerGetAppleSFSymbolsNameForButton => :pointer,
317
- :SDL_GameControllerGetAppleSFSymbolsNameForAxis => :pointer,
318
- }
319
- symbols.each do |sym|
320
- begin
321
- attach_function apis[sym], sym, args[sym], retvals[sym]
322
- rescue FFI::NotFoundError => error
323
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
324
- end
325
- end
326
- end
327
-
328
- end
329
-
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_joystick'
9
+
10
+ module SDL
11
+ extend FFI::Library
12
+ # Define/Macro
13
+
14
+
15
+ # Enum
16
+
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_TYPE_NVIDIA_SHIELD = 10
28
+ CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT = 11
29
+ CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT = 12
30
+ CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR = 13
31
+ CONTROLLER_BINDTYPE_NONE = 0
32
+ CONTROLLER_BINDTYPE_BUTTON = 1
33
+ CONTROLLER_BINDTYPE_AXIS = 2
34
+ CONTROLLER_BINDTYPE_HAT = 3
35
+ CONTROLLER_AXIS_INVALID = -1
36
+ CONTROLLER_AXIS_LEFTX = 0
37
+ CONTROLLER_AXIS_LEFTY = 1
38
+ CONTROLLER_AXIS_RIGHTX = 2
39
+ CONTROLLER_AXIS_RIGHTY = 3
40
+ CONTROLLER_AXIS_TRIGGERLEFT = 4
41
+ CONTROLLER_AXIS_TRIGGERRIGHT = 5
42
+ CONTROLLER_AXIS_MAX = 6
43
+ CONTROLLER_BUTTON_INVALID = -1
44
+ CONTROLLER_BUTTON_A = 0
45
+ CONTROLLER_BUTTON_B = 1
46
+ CONTROLLER_BUTTON_X = 2
47
+ CONTROLLER_BUTTON_Y = 3
48
+ CONTROLLER_BUTTON_BACK = 4
49
+ CONTROLLER_BUTTON_GUIDE = 5
50
+ CONTROLLER_BUTTON_START = 6
51
+ CONTROLLER_BUTTON_LEFTSTICK = 7
52
+ CONTROLLER_BUTTON_RIGHTSTICK = 8
53
+ CONTROLLER_BUTTON_LEFTSHOULDER = 9
54
+ CONTROLLER_BUTTON_RIGHTSHOULDER = 10
55
+ CONTROLLER_BUTTON_DPAD_UP = 11
56
+ CONTROLLER_BUTTON_DPAD_DOWN = 12
57
+ CONTROLLER_BUTTON_DPAD_LEFT = 13
58
+ CONTROLLER_BUTTON_DPAD_RIGHT = 14
59
+ CONTROLLER_BUTTON_MISC1 = 15
60
+ CONTROLLER_BUTTON_PADDLE1 = 16
61
+ CONTROLLER_BUTTON_PADDLE2 = 17
62
+ CONTROLLER_BUTTON_PADDLE3 = 18
63
+ CONTROLLER_BUTTON_PADDLE4 = 19
64
+ CONTROLLER_BUTTON_TOUCHPAD = 20
65
+ CONTROLLER_BUTTON_MAX = 21
66
+
67
+ # Typedef
68
+
69
+
70
+ class GameControllerButtonBind_value_hat < FFI::Struct
71
+ layout(
72
+ :hat, :int,
73
+ :hat_mask, :int,
74
+ )
75
+ end
76
+
77
+ class GameControllerButtonBind_value < FFI::Struct
78
+ layout(
79
+ :button, :int,
80
+ :axis, :int,
81
+ :hat, GameControllerButtonBind_value_hat,
82
+ )
83
+ end
84
+
85
+ class GameControllerButtonBind < FFI::Struct
86
+ layout(
87
+ :bindType, :int,
88
+ :value, GameControllerButtonBind_value,
89
+ )
90
+ end
91
+
92
+ typedef :int, :SDL_GameControllerType
93
+ typedef :int, :SDL_GameControllerBindType
94
+ typedef :int, :SDL_GameControllerAxis
95
+ typedef :int, :SDL_GameControllerButton
96
+
97
+ # Struct
98
+
99
+
100
+ # Function
101
+
102
+ def self.setup_gamecontroller_symbols(output_error = false)
103
+ symbols = [
104
+ :SDL_GameControllerAddMappingsFromRW,
105
+ :SDL_GameControllerAddMapping,
106
+ :SDL_GameControllerNumMappings,
107
+ :SDL_GameControllerMappingForIndex,
108
+ :SDL_GameControllerMappingForGUID,
109
+ :SDL_GameControllerMapping,
110
+ :SDL_IsGameController,
111
+ :SDL_GameControllerNameForIndex,
112
+ :SDL_GameControllerPathForIndex,
113
+ :SDL_GameControllerTypeForIndex,
114
+ :SDL_GameControllerMappingForDeviceIndex,
115
+ :SDL_GameControllerOpen,
116
+ :SDL_GameControllerFromInstanceID,
117
+ :SDL_GameControllerFromPlayerIndex,
118
+ :SDL_GameControllerName,
119
+ :SDL_GameControllerPath,
120
+ :SDL_GameControllerGetType,
121
+ :SDL_GameControllerGetPlayerIndex,
122
+ :SDL_GameControllerSetPlayerIndex,
123
+ :SDL_GameControllerGetVendor,
124
+ :SDL_GameControllerGetProduct,
125
+ :SDL_GameControllerGetProductVersion,
126
+ :SDL_GameControllerGetFirmwareVersion,
127
+ :SDL_GameControllerGetSerial,
128
+ :SDL_GameControllerGetAttached,
129
+ :SDL_GameControllerGetJoystick,
130
+ :SDL_GameControllerEventState,
131
+ :SDL_GameControllerUpdate,
132
+ :SDL_GameControllerGetAxisFromString,
133
+ :SDL_GameControllerGetStringForAxis,
134
+ :SDL_GameControllerGetBindForAxis,
135
+ :SDL_GameControllerHasAxis,
136
+ :SDL_GameControllerGetAxis,
137
+ :SDL_GameControllerGetButtonFromString,
138
+ :SDL_GameControllerGetStringForButton,
139
+ :SDL_GameControllerGetBindForButton,
140
+ :SDL_GameControllerHasButton,
141
+ :SDL_GameControllerGetButton,
142
+ :SDL_GameControllerGetNumTouchpads,
143
+ :SDL_GameControllerGetNumTouchpadFingers,
144
+ :SDL_GameControllerGetTouchpadFinger,
145
+ :SDL_GameControllerHasSensor,
146
+ :SDL_GameControllerSetSensorEnabled,
147
+ :SDL_GameControllerIsSensorEnabled,
148
+ :SDL_GameControllerGetSensorDataRate,
149
+ :SDL_GameControllerGetSensorData,
150
+ :SDL_GameControllerRumble,
151
+ :SDL_GameControllerRumbleTriggers,
152
+ :SDL_GameControllerHasLED,
153
+ :SDL_GameControllerHasRumble,
154
+ :SDL_GameControllerHasRumbleTriggers,
155
+ :SDL_GameControllerSetLED,
156
+ :SDL_GameControllerSendEffect,
157
+ :SDL_GameControllerClose,
158
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton,
159
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis,
160
+ ]
161
+ apis = {
162
+ :SDL_GameControllerAddMappingsFromRW => :GameControllerAddMappingsFromRW,
163
+ :SDL_GameControllerAddMapping => :GameControllerAddMapping,
164
+ :SDL_GameControllerNumMappings => :GameControllerNumMappings,
165
+ :SDL_GameControllerMappingForIndex => :GameControllerMappingForIndex,
166
+ :SDL_GameControllerMappingForGUID => :GameControllerMappingForGUID,
167
+ :SDL_GameControllerMapping => :GameControllerMapping,
168
+ :SDL_IsGameController => :IsGameController,
169
+ :SDL_GameControllerNameForIndex => :GameControllerNameForIndex,
170
+ :SDL_GameControllerPathForIndex => :GameControllerPathForIndex,
171
+ :SDL_GameControllerTypeForIndex => :GameControllerTypeForIndex,
172
+ :SDL_GameControllerMappingForDeviceIndex => :GameControllerMappingForDeviceIndex,
173
+ :SDL_GameControllerOpen => :GameControllerOpen,
174
+ :SDL_GameControllerFromInstanceID => :GameControllerFromInstanceID,
175
+ :SDL_GameControllerFromPlayerIndex => :GameControllerFromPlayerIndex,
176
+ :SDL_GameControllerName => :GameControllerName,
177
+ :SDL_GameControllerPath => :GameControllerPath,
178
+ :SDL_GameControllerGetType => :GameControllerGetType,
179
+ :SDL_GameControllerGetPlayerIndex => :GameControllerGetPlayerIndex,
180
+ :SDL_GameControllerSetPlayerIndex => :GameControllerSetPlayerIndex,
181
+ :SDL_GameControllerGetVendor => :GameControllerGetVendor,
182
+ :SDL_GameControllerGetProduct => :GameControllerGetProduct,
183
+ :SDL_GameControllerGetProductVersion => :GameControllerGetProductVersion,
184
+ :SDL_GameControllerGetFirmwareVersion => :GameControllerGetFirmwareVersion,
185
+ :SDL_GameControllerGetSerial => :GameControllerGetSerial,
186
+ :SDL_GameControllerGetAttached => :GameControllerGetAttached,
187
+ :SDL_GameControllerGetJoystick => :GameControllerGetJoystick,
188
+ :SDL_GameControllerEventState => :GameControllerEventState,
189
+ :SDL_GameControllerUpdate => :GameControllerUpdate,
190
+ :SDL_GameControllerGetAxisFromString => :GameControllerGetAxisFromString,
191
+ :SDL_GameControllerGetStringForAxis => :GameControllerGetStringForAxis,
192
+ :SDL_GameControllerGetBindForAxis => :GameControllerGetBindForAxis,
193
+ :SDL_GameControllerHasAxis => :GameControllerHasAxis,
194
+ :SDL_GameControllerGetAxis => :GameControllerGetAxis,
195
+ :SDL_GameControllerGetButtonFromString => :GameControllerGetButtonFromString,
196
+ :SDL_GameControllerGetStringForButton => :GameControllerGetStringForButton,
197
+ :SDL_GameControllerGetBindForButton => :GameControllerGetBindForButton,
198
+ :SDL_GameControllerHasButton => :GameControllerHasButton,
199
+ :SDL_GameControllerGetButton => :GameControllerGetButton,
200
+ :SDL_GameControllerGetNumTouchpads => :GameControllerGetNumTouchpads,
201
+ :SDL_GameControllerGetNumTouchpadFingers => :GameControllerGetNumTouchpadFingers,
202
+ :SDL_GameControllerGetTouchpadFinger => :GameControllerGetTouchpadFinger,
203
+ :SDL_GameControllerHasSensor => :GameControllerHasSensor,
204
+ :SDL_GameControllerSetSensorEnabled => :GameControllerSetSensorEnabled,
205
+ :SDL_GameControllerIsSensorEnabled => :GameControllerIsSensorEnabled,
206
+ :SDL_GameControllerGetSensorDataRate => :GameControllerGetSensorDataRate,
207
+ :SDL_GameControllerGetSensorData => :GameControllerGetSensorData,
208
+ :SDL_GameControllerRumble => :GameControllerRumble,
209
+ :SDL_GameControllerRumbleTriggers => :GameControllerRumbleTriggers,
210
+ :SDL_GameControllerHasLED => :GameControllerHasLED,
211
+ :SDL_GameControllerHasRumble => :GameControllerHasRumble,
212
+ :SDL_GameControllerHasRumbleTriggers => :GameControllerHasRumbleTriggers,
213
+ :SDL_GameControllerSetLED => :GameControllerSetLED,
214
+ :SDL_GameControllerSendEffect => :GameControllerSendEffect,
215
+ :SDL_GameControllerClose => :GameControllerClose,
216
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton => :GameControllerGetAppleSFSymbolsNameForButton,
217
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis => :GameControllerGetAppleSFSymbolsNameForAxis,
218
+ }
219
+ args = {
220
+ :SDL_GameControllerAddMappingsFromRW => [:pointer, :int],
221
+ :SDL_GameControllerAddMapping => [:pointer],
222
+ :SDL_GameControllerNumMappings => [],
223
+ :SDL_GameControllerMappingForIndex => [:int],
224
+ :SDL_GameControllerMappingForGUID => [JoystickGUID.by_value],
225
+ :SDL_GameControllerMapping => [:pointer],
226
+ :SDL_IsGameController => [:int],
227
+ :SDL_GameControllerNameForIndex => [:int],
228
+ :SDL_GameControllerPathForIndex => [:int],
229
+ :SDL_GameControllerTypeForIndex => [:int],
230
+ :SDL_GameControllerMappingForDeviceIndex => [:int],
231
+ :SDL_GameControllerOpen => [:int],
232
+ :SDL_GameControllerFromInstanceID => [:int],
233
+ :SDL_GameControllerFromPlayerIndex => [:int],
234
+ :SDL_GameControllerName => [:pointer],
235
+ :SDL_GameControllerPath => [:pointer],
236
+ :SDL_GameControllerGetType => [:pointer],
237
+ :SDL_GameControllerGetPlayerIndex => [:pointer],
238
+ :SDL_GameControllerSetPlayerIndex => [:pointer, :int],
239
+ :SDL_GameControllerGetVendor => [:pointer],
240
+ :SDL_GameControllerGetProduct => [:pointer],
241
+ :SDL_GameControllerGetProductVersion => [:pointer],
242
+ :SDL_GameControllerGetFirmwareVersion => [:pointer],
243
+ :SDL_GameControllerGetSerial => [:pointer],
244
+ :SDL_GameControllerGetAttached => [:pointer],
245
+ :SDL_GameControllerGetJoystick => [:pointer],
246
+ :SDL_GameControllerEventState => [:int],
247
+ :SDL_GameControllerUpdate => [],
248
+ :SDL_GameControllerGetAxisFromString => [:pointer],
249
+ :SDL_GameControllerGetStringForAxis => [:int],
250
+ :SDL_GameControllerGetBindForAxis => [:pointer, :int],
251
+ :SDL_GameControllerHasAxis => [:pointer, :int],
252
+ :SDL_GameControllerGetAxis => [:pointer, :int],
253
+ :SDL_GameControllerGetButtonFromString => [:pointer],
254
+ :SDL_GameControllerGetStringForButton => [:int],
255
+ :SDL_GameControllerGetBindForButton => [:pointer, :int],
256
+ :SDL_GameControllerHasButton => [:pointer, :int],
257
+ :SDL_GameControllerGetButton => [:pointer, :int],
258
+ :SDL_GameControllerGetNumTouchpads => [:pointer],
259
+ :SDL_GameControllerGetNumTouchpadFingers => [:pointer, :int],
260
+ :SDL_GameControllerGetTouchpadFinger => [:pointer, :int, :int, :pointer, :pointer, :pointer, :pointer],
261
+ :SDL_GameControllerHasSensor => [:pointer, :int],
262
+ :SDL_GameControllerSetSensorEnabled => [:pointer, :int, :int],
263
+ :SDL_GameControllerIsSensorEnabled => [:pointer, :int],
264
+ :SDL_GameControllerGetSensorDataRate => [:pointer, :int],
265
+ :SDL_GameControllerGetSensorData => [:pointer, :int, :pointer, :int],
266
+ :SDL_GameControllerRumble => [:pointer, :ushort, :ushort, :uint],
267
+ :SDL_GameControllerRumbleTriggers => [:pointer, :ushort, :ushort, :uint],
268
+ :SDL_GameControllerHasLED => [:pointer],
269
+ :SDL_GameControllerHasRumble => [:pointer],
270
+ :SDL_GameControllerHasRumbleTriggers => [:pointer],
271
+ :SDL_GameControllerSetLED => [:pointer, :uchar, :uchar, :uchar],
272
+ :SDL_GameControllerSendEffect => [:pointer, :pointer, :int],
273
+ :SDL_GameControllerClose => [:pointer],
274
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton => [:pointer, :int],
275
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis => [:pointer, :int],
276
+ }
277
+ retvals = {
278
+ :SDL_GameControllerAddMappingsFromRW => :int,
279
+ :SDL_GameControllerAddMapping => :int,
280
+ :SDL_GameControllerNumMappings => :int,
281
+ :SDL_GameControllerMappingForIndex => :pointer,
282
+ :SDL_GameControllerMappingForGUID => :pointer,
283
+ :SDL_GameControllerMapping => :pointer,
284
+ :SDL_IsGameController => :int,
285
+ :SDL_GameControllerNameForIndex => :pointer,
286
+ :SDL_GameControllerPathForIndex => :pointer,
287
+ :SDL_GameControllerTypeForIndex => :int,
288
+ :SDL_GameControllerMappingForDeviceIndex => :pointer,
289
+ :SDL_GameControllerOpen => :pointer,
290
+ :SDL_GameControllerFromInstanceID => :pointer,
291
+ :SDL_GameControllerFromPlayerIndex => :pointer,
292
+ :SDL_GameControllerName => :pointer,
293
+ :SDL_GameControllerPath => :pointer,
294
+ :SDL_GameControllerGetType => :int,
295
+ :SDL_GameControllerGetPlayerIndex => :int,
296
+ :SDL_GameControllerSetPlayerIndex => :void,
297
+ :SDL_GameControllerGetVendor => :ushort,
298
+ :SDL_GameControllerGetProduct => :ushort,
299
+ :SDL_GameControllerGetProductVersion => :ushort,
300
+ :SDL_GameControllerGetFirmwareVersion => :ushort,
301
+ :SDL_GameControllerGetSerial => :pointer,
302
+ :SDL_GameControllerGetAttached => :int,
303
+ :SDL_GameControllerGetJoystick => :pointer,
304
+ :SDL_GameControllerEventState => :int,
305
+ :SDL_GameControllerUpdate => :void,
306
+ :SDL_GameControllerGetAxisFromString => :int,
307
+ :SDL_GameControllerGetStringForAxis => :pointer,
308
+ :SDL_GameControllerGetBindForAxis => GameControllerButtonBind.by_value,
309
+ :SDL_GameControllerHasAxis => :int,
310
+ :SDL_GameControllerGetAxis => :short,
311
+ :SDL_GameControllerGetButtonFromString => :int,
312
+ :SDL_GameControllerGetStringForButton => :pointer,
313
+ :SDL_GameControllerGetBindForButton => GameControllerButtonBind.by_value,
314
+ :SDL_GameControllerHasButton => :int,
315
+ :SDL_GameControllerGetButton => :uchar,
316
+ :SDL_GameControllerGetNumTouchpads => :int,
317
+ :SDL_GameControllerGetNumTouchpadFingers => :int,
318
+ :SDL_GameControllerGetTouchpadFinger => :int,
319
+ :SDL_GameControllerHasSensor => :int,
320
+ :SDL_GameControllerSetSensorEnabled => :int,
321
+ :SDL_GameControllerIsSensorEnabled => :int,
322
+ :SDL_GameControllerGetSensorDataRate => :float,
323
+ :SDL_GameControllerGetSensorData => :int,
324
+ :SDL_GameControllerRumble => :int,
325
+ :SDL_GameControllerRumbleTriggers => :int,
326
+ :SDL_GameControllerHasLED => :int,
327
+ :SDL_GameControllerHasRumble => :int,
328
+ :SDL_GameControllerHasRumbleTriggers => :int,
329
+ :SDL_GameControllerSetLED => :int,
330
+ :SDL_GameControllerSendEffect => :int,
331
+ :SDL_GameControllerClose => :void,
332
+ :SDL_GameControllerGetAppleSFSymbolsNameForButton => :pointer,
333
+ :SDL_GameControllerGetAppleSFSymbolsNameForAxis => :pointer,
334
+ }
335
+ symbols.each do |sym|
336
+ begin
337
+ attach_function apis[sym], sym, args[sym], retvals[sym]
338
+ rescue FFI::NotFoundError => error
339
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
340
+ end
341
+ end
342
+ end
343
+
344
+ end
345
+