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.
- checksums.yaml +4 -4
- data/ChangeLog +12 -0
- data/README.md +39 -26
- data/lib/sdl2.rb +54 -99
- data/lib/sdl2_audio.rb +59 -20
- data/lib/sdl2_blendmode.rb +28 -25
- data/lib/sdl2_clipboard.rb +9 -4
- data/lib/sdl2_cpuinfo.rb +28 -5
- data/lib/sdl2_error.rb +17 -10
- data/lib/sdl2_events.rb +150 -131
- data/lib/sdl2_filesystem.rb +8 -4
- data/lib/sdl2_framerate.rb +11 -4
- data/lib/sdl2_gamecontroller.rb +112 -57
- data/lib/sdl2_gesture.rb +10 -4
- data/lib/sdl2_gfxPrimitives.rb +65 -4
- data/lib/sdl2_haptic.rb +76 -44
- data/lib/sdl2_hidapi.rb +26 -5
- data/lib/sdl2_hints.rb +146 -137
- data/lib/sdl2_image.rb +54 -7
- data/lib/sdl2_imageFilter.rb +36 -4
- data/lib/sdl2_joystick.rb +93 -38
- data/lib/sdl2_keyboard.rb +23 -5
- data/lib/sdl2_keycode.rb +6 -4
- data/lib/sdl2_log.rb +48 -32
- data/lib/sdl2_main.rb +21 -14
- data/lib/sdl2_messagebox.rb +26 -22
- data/lib/sdl2_misc.rb +7 -4
- data/lib/sdl2_mixer.rb +86 -11
- data/lib/sdl2_mouse.rb +44 -25
- data/lib/sdl2_pixels.rb +115 -99
- data/lib/sdl2_platform.rb +7 -4
- data/lib/sdl2_power.rb +12 -9
- data/lib/sdl2_rect.rb +18 -11
- data/lib/sdl2_render.rb +107 -25
- data/lib/sdl2_rotozoom.rb +14 -4
- data/lib/sdl2_rwops.rb +58 -28
- data/lib/sdl2_scancode.rb +250 -248
- data/lib/sdl2_sensor.rb +27 -9
- data/lib/sdl2_shape.rb +17 -11
- data/lib/sdl2_stdinc.rb +135 -10
- data/lib/sdl2_surface.rb +56 -15
- data/lib/sdl2_syswm.rb +47 -44
- data/lib/sdl2_timer.rb +13 -4
- data/lib/sdl2_touch.rb +18 -11
- data/lib/sdl2_ttf.rb +180 -25
- data/lib/sdl2_version.rb +13 -8
- data/lib/sdl2_video.rb +204 -110
- data/lib/sdl2_vulkan.rb +12 -4
- metadata +17 -3
data/lib/sdl2_gamecontroller.rb
CHANGED
@@ -7,81 +7,81 @@
|
|
7
7
|
require 'ffi'
|
8
8
|
require_relative 'sdl2_joystick'
|
9
9
|
|
10
|
-
module
|
10
|
+
module SDL
|
11
11
|
extend FFI::Library
|
12
12
|
# Define/Macro
|
13
13
|
|
14
14
|
|
15
15
|
# Enum
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
62
|
|
63
63
|
# Typedef
|
64
64
|
|
65
65
|
|
66
|
-
class
|
66
|
+
class GameControllerButtonBind_value_hat < FFI::Struct
|
67
67
|
layout(
|
68
68
|
:hat, :int,
|
69
69
|
:hat_mask, :int,
|
70
70
|
)
|
71
71
|
end
|
72
72
|
|
73
|
-
class
|
73
|
+
class GameControllerButtonBind_value < FFI::Struct
|
74
74
|
layout(
|
75
75
|
:button, :int,
|
76
76
|
:axis, :int,
|
77
|
-
:hat,
|
77
|
+
:hat, GameControllerButtonBind_value_hat,
|
78
78
|
)
|
79
79
|
end
|
80
80
|
|
81
|
-
class
|
81
|
+
class GameControllerButtonBind < FFI::Struct
|
82
82
|
layout(
|
83
83
|
:bindType, :int,
|
84
|
-
:value,
|
84
|
+
:value, GameControllerButtonBind_value,
|
85
85
|
)
|
86
86
|
end
|
87
87
|
|
@@ -95,7 +95,7 @@ module SDL2
|
|
95
95
|
|
96
96
|
# Function
|
97
97
|
|
98
|
-
def self.setup_gamecontroller_symbols()
|
98
|
+
def self.setup_gamecontroller_symbols(output_error = false)
|
99
99
|
symbols = [
|
100
100
|
:SDL_GameControllerAddMappingsFromRW,
|
101
101
|
:SDL_GameControllerAddMapping,
|
@@ -151,12 +151,67 @@ module SDL2
|
|
151
151
|
:SDL_GameControllerGetAppleSFSymbolsNameForButton,
|
152
152
|
:SDL_GameControllerGetAppleSFSymbolsNameForAxis,
|
153
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
|
+
}
|
154
209
|
args = {
|
155
210
|
:SDL_GameControllerAddMappingsFromRW => [:pointer, :int],
|
156
211
|
:SDL_GameControllerAddMapping => [:pointer],
|
157
212
|
:SDL_GameControllerNumMappings => [],
|
158
213
|
:SDL_GameControllerMappingForIndex => [:int],
|
159
|
-
:SDL_GameControllerMappingForGUID => [
|
214
|
+
:SDL_GameControllerMappingForGUID => [JoystickGUID.by_value],
|
160
215
|
:SDL_GameControllerMapping => [:pointer],
|
161
216
|
:SDL_IsGameController => [:int],
|
162
217
|
:SDL_GameControllerNameForIndex => [:int],
|
@@ -234,12 +289,12 @@ module SDL2
|
|
234
289
|
:SDL_GameControllerUpdate => :void,
|
235
290
|
:SDL_GameControllerGetAxisFromString => :int,
|
236
291
|
:SDL_GameControllerGetStringForAxis => :pointer,
|
237
|
-
:SDL_GameControllerGetBindForAxis =>
|
292
|
+
:SDL_GameControllerGetBindForAxis => GameControllerButtonBind.by_value,
|
238
293
|
:SDL_GameControllerHasAxis => :int,
|
239
294
|
:SDL_GameControllerGetAxis => :short,
|
240
295
|
:SDL_GameControllerGetButtonFromString => :int,
|
241
296
|
:SDL_GameControllerGetStringForButton => :pointer,
|
242
|
-
:SDL_GameControllerGetBindForButton =>
|
297
|
+
:SDL_GameControllerGetBindForButton => GameControllerButtonBind.by_value,
|
243
298
|
:SDL_GameControllerHasButton => :int,
|
244
299
|
:SDL_GameControllerGetButton => :uchar,
|
245
300
|
:SDL_GameControllerGetNumTouchpads => :int,
|
@@ -263,9 +318,9 @@ module SDL2
|
|
263
318
|
}
|
264
319
|
symbols.each do |sym|
|
265
320
|
begin
|
266
|
-
attach_function sym, args[sym], retvals[sym]
|
321
|
+
attach_function apis[sym], sym, args[sym], retvals[sym]
|
267
322
|
rescue FFI::NotFoundError => error
|
268
|
-
$stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
|
323
|
+
$stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
|
269
324
|
end
|
270
325
|
end
|
271
326
|
end
|
data/lib/sdl2_gesture.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'ffi'
|
8
8
|
|
9
|
-
module
|
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
|
data/lib/sdl2_gfxPrimitives.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'ffi'
|
8
8
|
|
9
|
-
module
|
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
|
9
|
+
module SDL
|
10
10
|
extend FFI::Library
|
11
11
|
# Define/Macro
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
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
|
50
|
+
class HapticConstant < FFI::Struct
|
51
51
|
layout(
|
52
52
|
:type, :ushort,
|
53
|
-
:direction,
|
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
|
66
|
+
class HapticPeriodic < FFI::Struct
|
67
67
|
layout(
|
68
68
|
:type, :ushort,
|
69
|
-
:direction,
|
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
|
85
|
+
class HapticCondition < FFI::Struct
|
86
86
|
layout(
|
87
87
|
:type, :ushort,
|
88
|
-
:direction,
|
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
|
102
|
+
class HapticRamp < FFI::Struct
|
103
103
|
layout(
|
104
104
|
:type, :ushort,
|
105
|
-
:direction,
|
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
|
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
|
128
|
+
class HapticCustom < FFI::Struct
|
129
129
|
layout(
|
130
130
|
:type, :ushort,
|
131
|
-
:direction,
|
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
|
147
|
+
class HapticEffect < FFI::Union
|
148
148
|
layout(
|
149
149
|
:type, :ushort,
|
150
|
-
:constant,
|
151
|
-
:periodic,
|
152
|
-
:condition,
|
153
|
-
:ramp,
|
154
|
-
:leftright,
|
155
|
-
:custom,
|
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
|
data/lib/sdl2_hidapi.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'ffi'
|
8
8
|
|
9
|
-
module
|
9
|
+
module SDL
|
10
10
|
extend FFI::Library
|
11
11
|
# Define/Macro
|
12
12
|
|
@@ -19,7 +19,7 @@ module SDL2
|
|
19
19
|
|
20
20
|
# Struct
|
21
21
|
|
22
|
-
class
|
22
|
+
class Hid_device_info < FFI::Struct
|
23
23
|
layout(
|
24
24
|
:path, :pointer,
|
25
25
|
:vendor_id, :ushort,
|
@@ -41,7 +41,7 @@ module SDL2
|
|
41
41
|
|
42
42
|
# Function
|
43
43
|
|
44
|
-
def self.setup_hidapi_symbols()
|
44
|
+
def self.setup_hidapi_symbols(output_error = false)
|
45
45
|
symbols = [
|
46
46
|
:SDL_hid_init,
|
47
47
|
:SDL_hid_exit,
|
@@ -63,6 +63,27 @@ module SDL2
|
|
63
63
|
:SDL_hid_get_indexed_string,
|
64
64
|
:SDL_hid_ble_scan,
|
65
65
|
]
|
66
|
+
apis = {
|
67
|
+
:SDL_hid_init => :hid_init,
|
68
|
+
:SDL_hid_exit => :hid_exit,
|
69
|
+
:SDL_hid_device_change_count => :hid_device_change_count,
|
70
|
+
:SDL_hid_enumerate => :hid_enumerate,
|
71
|
+
:SDL_hid_free_enumeration => :hid_free_enumeration,
|
72
|
+
:SDL_hid_open => :hid_open,
|
73
|
+
:SDL_hid_open_path => :hid_open_path,
|
74
|
+
:SDL_hid_write => :hid_write,
|
75
|
+
:SDL_hid_read_timeout => :hid_read_timeout,
|
76
|
+
:SDL_hid_read => :hid_read,
|
77
|
+
:SDL_hid_set_nonblocking => :hid_set_nonblocking,
|
78
|
+
:SDL_hid_send_feature_report => :hid_send_feature_report,
|
79
|
+
:SDL_hid_get_feature_report => :hid_get_feature_report,
|
80
|
+
:SDL_hid_close => :hid_close,
|
81
|
+
:SDL_hid_get_manufacturer_string => :hid_get_manufacturer_string,
|
82
|
+
:SDL_hid_get_product_string => :hid_get_product_string,
|
83
|
+
:SDL_hid_get_serial_number_string => :hid_get_serial_number_string,
|
84
|
+
:SDL_hid_get_indexed_string => :hid_get_indexed_string,
|
85
|
+
:SDL_hid_ble_scan => :hid_ble_scan,
|
86
|
+
}
|
66
87
|
args = {
|
67
88
|
:SDL_hid_init => [],
|
68
89
|
:SDL_hid_exit => [],
|
@@ -107,9 +128,9 @@ module SDL2
|
|
107
128
|
}
|
108
129
|
symbols.each do |sym|
|
109
130
|
begin
|
110
|
-
attach_function sym, args[sym], retvals[sym]
|
131
|
+
attach_function apis[sym], sym, args[sym], retvals[sym]
|
111
132
|
rescue FFI::NotFoundError => error
|
112
|
-
$stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
|
133
|
+
$stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
|
113
134
|
end
|
114
135
|
end
|
115
136
|
end
|