sdl2_ffi 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +33 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +7 -0
- data/bin/coderay +16 -0
- data/bin/guard +16 -0
- data/bin/pry +16 -0
- data/bin/rake +16 -0
- data/bin/thor +16 -0
- data/lib/sdl2/assert.rb +7 -0
- data/lib/sdl2/audio.rb +139 -0
- data/lib/sdl2/clipboard.rb +27 -0
- data/lib/sdl2/color.rb +12 -0
- data/lib/sdl2/cpuinfo.rb +18 -0
- data/lib/sdl2/display/mode.rb +53 -0
- data/lib/sdl2/display/modes.rb +36 -0
- data/lib/sdl2/display.rb +74 -0
- data/lib/sdl2/error.rb +9 -0
- data/lib/sdl2/events.rb +358 -0
- data/lib/sdl2/gamecontroller.rb +62 -0
- data/lib/sdl2/gem_version.rb +4 -0
- data/lib/sdl2/gesture.rb +15 -0
- data/lib/sdl2/haptic.rb +159 -0
- data/lib/sdl2/hints.rb +47 -0
- data/lib/sdl2/init.rb +54 -0
- data/lib/sdl2/joystick.rb +58 -0
- data/lib/sdl2/keyboard.rb +34 -0
- data/lib/sdl2/keycode.rb +294 -0
- data/lib/sdl2/log.rb +70 -0
- data/lib/sdl2/mouse.rb +54 -0
- data/lib/sdl2/palette.rb +15 -0
- data/lib/sdl2/pixel_format.rb +28 -0
- data/lib/sdl2/pixels.rb +35 -0
- data/lib/sdl2/point.rb +7 -0
- data/lib/sdl2/power.rb +9 -0
- data/lib/sdl2/rect.rb +38 -0
- data/lib/sdl2/render.rb +77 -0
- data/lib/sdl2/renderer.rb +34 -0
- data/lib/sdl2/renderer_info.rb +13 -0
- data/lib/sdl2/rwops.rb +127 -0
- data/lib/sdl2/scancode.rb +275 -0
- data/lib/sdl2/sdl_module.rb +8 -0
- data/lib/sdl2/surface.rb +83 -0
- data/lib/sdl2/syswm/info.rb +49 -0
- data/lib/sdl2/syswm/msg.rb +46 -0
- data/lib/sdl2/syswm.rb +20 -0
- data/lib/sdl2/texture.rb +9 -0
- data/lib/sdl2/timer.rb +17 -0
- data/lib/sdl2/touch.rb +24 -0
- data/lib/sdl2/version.rb +30 -0
- data/lib/sdl2/video.rb +154 -0
- data/lib/sdl2/window.rb +259 -0
- data/lib/sdl2.rb +99 -0
- data/lib/sdl2_ffi.rb +6 -0
- data/sdl2_ffi.gemspec +31 -0
- data/test/test_helper.rb +2 -0
- data/test/unit/sdl2/test_assert.rb +10 -0
- data/test/unit/sdl2/test_audio.rb +9 -0
- data/test/unit/sdl2/test_clipboard.rb +13 -0
- data/test/unit/sdl2/test_cpuinfo.rb +11 -0
- data/test/unit/sdl2/test_error.rb +20 -0
- data/test/unit/sdl2/test_events.rb +31 -0
- data/test/unit/sdl2/test_haptic.rb +10 -0
- data/test/unit/sdl2/test_hints.rb +50 -0
- data/test/unit/sdl2/test_init.rb +29 -0
- data/test/unit/sdl2/test_keyboard.rb +9 -0
- data/test/unit/sdl2/test_log.rb +80 -0
- data/test/unit/sdl2/test_pixels.rb +24 -0
- data/test/unit/sdl2/test_power.rb +11 -0
- data/test/unit/sdl2/test_rect.rb +19 -0
- data/test/unit/sdl2/test_render.rb +58 -0
- data/test/unit/sdl2/test_surface.rb +45 -0
- data/test/unit/sdl2/test_syswm.rb +11 -0
- data/test/unit/sdl2/test_timer.rb +9 -0
- data/test/unit/sdl2/test_version.rb +16 -0
- data/test/unit/sdl2/test_video.rb +170 -0
- data/test/unit/sdl2/test_window.rb +158 -0
- data/test/unit/test_sdl2.rb +16 -0
- metadata +280 -0
data/lib/sdl2/events.rb
ADDED
@@ -0,0 +1,358 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/error'
|
3
|
+
require 'sdl2/video'
|
4
|
+
require 'sdl2/keyboard'
|
5
|
+
require 'sdl2/mouse'
|
6
|
+
require 'sdl2/joystick'
|
7
|
+
require 'sdl2/gamecontroller'
|
8
|
+
require 'sdl2/gesture'
|
9
|
+
require 'sdl2/touch'
|
10
|
+
|
11
|
+
module SDL2
|
12
|
+
|
13
|
+
RELEASED = 0
|
14
|
+
PRESSED = 1
|
15
|
+
|
16
|
+
enum :event_type, [
|
17
|
+
:firstEvent, 0,
|
18
|
+
|
19
|
+
:quit, 0x100,
|
20
|
+
:app_terminating,
|
21
|
+
:app_lowMemory,
|
22
|
+
:app_willEnterBackground,
|
23
|
+
:app_didEnterBackground,
|
24
|
+
:app_willEnterForeground,
|
25
|
+
:app_didEnterForeground,
|
26
|
+
|
27
|
+
:windowEvent, 0x200,
|
28
|
+
:syswmEvent,
|
29
|
+
|
30
|
+
:keyDown, 0x300,
|
31
|
+
:keyUp,
|
32
|
+
:textEditing,
|
33
|
+
:textInput,
|
34
|
+
|
35
|
+
:mouseMotion, 0x400,
|
36
|
+
:mouseButtonDown,
|
37
|
+
:mouseButtonUp,
|
38
|
+
:mouseWheel,
|
39
|
+
|
40
|
+
:joyAxisMotion, 0x600,
|
41
|
+
:joyBallMotion,
|
42
|
+
:joyHatMotion,
|
43
|
+
:joyButtonDown,
|
44
|
+
:joyButtonUp,
|
45
|
+
:joyDeviceAdded,
|
46
|
+
:joyDeviceRemoved,
|
47
|
+
|
48
|
+
:controllerAxisMotion, 0x650,
|
49
|
+
:controllerButtonDown,
|
50
|
+
:controllerButtonUp,
|
51
|
+
:controllerDeviceAdded,
|
52
|
+
:controllerDeviceRemoved,
|
53
|
+
:controllerDeviceRemapped,
|
54
|
+
|
55
|
+
:fingerDown, 0x700,
|
56
|
+
:fingerUp,
|
57
|
+
:fingerMotion,
|
58
|
+
|
59
|
+
:dollarGesture, 0x800,
|
60
|
+
:dollarRecord,
|
61
|
+
:dollarMultigesture,
|
62
|
+
|
63
|
+
:clipboardUpdate, 0x900,
|
64
|
+
|
65
|
+
:dropFile, 0x1000,
|
66
|
+
|
67
|
+
:userEvent, 0x8000,
|
68
|
+
|
69
|
+
:lastEvent, 0xFFFF
|
70
|
+
|
71
|
+
]
|
72
|
+
|
73
|
+
COMMON_EVENT_LAYOUT = [:type, :uint32, :timestamp, :uint32]
|
74
|
+
|
75
|
+
class CommonEvent < Struct
|
76
|
+
layout *COMMON_EVENT_LAYOUT
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
class WindowEvent < Struct
|
81
|
+
layout *COMMON_EVENT_LAYOUT + [
|
82
|
+
:windowID, :uint32,
|
83
|
+
:event, :uint8,
|
84
|
+
:padding1, :uint8,
|
85
|
+
:padding2, :uint8,
|
86
|
+
:padding3, :uint8,
|
87
|
+
:data1, :int32,
|
88
|
+
:data2, :int32
|
89
|
+
]
|
90
|
+
end
|
91
|
+
|
92
|
+
class KeyboardEvent < Struct
|
93
|
+
layout *COMMON_EVENT_LAYOUT + [
|
94
|
+
:windowID, :uint32,
|
95
|
+
:state, :uint8,
|
96
|
+
:repeat, :uint8,
|
97
|
+
:padding2, :uint8,
|
98
|
+
:padding3, :uint8,
|
99
|
+
:keysym, Keysym
|
100
|
+
]
|
101
|
+
end
|
102
|
+
|
103
|
+
class TextEditingEvent < Struct
|
104
|
+
TEXT_SIZE = 32 # Line 188
|
105
|
+
layout *COMMON_EVENT_LAYOUT + [
|
106
|
+
:windowID, :uint32,
|
107
|
+
:char, [:char, TEXT_SIZE],
|
108
|
+
:start, :int32,
|
109
|
+
:length, :int32
|
110
|
+
]
|
111
|
+
end
|
112
|
+
|
113
|
+
class TextInputEvent < Struct
|
114
|
+
TEXT_SIZE = 32 # Line 203
|
115
|
+
layout *COMMON_EVENT_LAYOUT + [
|
116
|
+
:windowID, :uint32,
|
117
|
+
:char, [:char, TEXT_SIZE]
|
118
|
+
]
|
119
|
+
end
|
120
|
+
|
121
|
+
class MouseMotionEvent < Struct
|
122
|
+
layout *COMMON_EVENT_LAYOUT + [
|
123
|
+
:windowID, :uint32,
|
124
|
+
:which, :uint32,
|
125
|
+
:state, :uint32,
|
126
|
+
:x, :int32,
|
127
|
+
:y, :int32,
|
128
|
+
:xrel, :int32,
|
129
|
+
:yrel, :int32
|
130
|
+
]
|
131
|
+
end
|
132
|
+
|
133
|
+
class MouseButtonEvent < Struct
|
134
|
+
layout *COMMON_EVENT_LAYOUT + [
|
135
|
+
:windowID, :uint32,
|
136
|
+
:which, :uint32,
|
137
|
+
:button, :uint8,
|
138
|
+
:state, :uint8,
|
139
|
+
:padding1, :uint8,
|
140
|
+
:padding2, :uint8,
|
141
|
+
:x, :int32,
|
142
|
+
:y, :int32
|
143
|
+
]
|
144
|
+
end
|
145
|
+
|
146
|
+
class MouseWheelEvent < Struct
|
147
|
+
layout *COMMON_EVENT_LAYOUT + [
|
148
|
+
:windowID, :uint32,
|
149
|
+
:which, :uint32,
|
150
|
+
:x, :int32,
|
151
|
+
:y, :int32
|
152
|
+
]
|
153
|
+
end
|
154
|
+
|
155
|
+
class JoyAxisEvent < Struct
|
156
|
+
layout *COMMON_EVENT_LAYOUT + [
|
157
|
+
:which, :joystick_id,
|
158
|
+
:axis, :uint8,
|
159
|
+
:padding1, :uint8,
|
160
|
+
:padding2, :uint8,
|
161
|
+
:padding3, :uint8,
|
162
|
+
:value, :int16,
|
163
|
+
:padding4, :uint16
|
164
|
+
]
|
165
|
+
end
|
166
|
+
|
167
|
+
class JoyBallEvent < Struct
|
168
|
+
layout *COMMON_EVENT_LAYOUT + [
|
169
|
+
:which, :joystick_id,
|
170
|
+
:ball, :uint8,
|
171
|
+
:padding1, :uint8,
|
172
|
+
:padding2, :uint8,
|
173
|
+
:padding3, :uint8,
|
174
|
+
:xrel, :int16,
|
175
|
+
:yrel, :int16
|
176
|
+
]
|
177
|
+
end
|
178
|
+
|
179
|
+
class JoyHatEvent < Struct
|
180
|
+
layout *COMMON_EVENT_LAYOUT + [
|
181
|
+
:which, :joystick_id,
|
182
|
+
:hat, :uint8,
|
183
|
+
:value, :uint8,
|
184
|
+
:padding1, :uint8,
|
185
|
+
:padding2, :uint8
|
186
|
+
]
|
187
|
+
end
|
188
|
+
|
189
|
+
class JoyButtonEvent < Struct
|
190
|
+
layout *COMMON_EVENT_LAYOUT + [
|
191
|
+
:which, :joystick_id,
|
192
|
+
:button, :uint8,
|
193
|
+
:state, :uint8,
|
194
|
+
:padding1, :uint8,
|
195
|
+
:padding2, :uint8
|
196
|
+
]
|
197
|
+
end
|
198
|
+
|
199
|
+
class JoyDeviceEvent < Struct
|
200
|
+
layout *COMMON_EVENT_LAYOUT + [
|
201
|
+
:which, :joystick_id
|
202
|
+
]
|
203
|
+
end
|
204
|
+
|
205
|
+
class ControllerAxisEvent < Struct
|
206
|
+
layout *COMMON_EVENT_LAYOUT + [
|
207
|
+
:which, :joystick_id,
|
208
|
+
:axis, :uint8,
|
209
|
+
:padding1, :uint8,
|
210
|
+
:padding2, :uint8,
|
211
|
+
:padding3, :uint8,
|
212
|
+
:value, :int16,
|
213
|
+
:padding4, :uint16
|
214
|
+
]
|
215
|
+
end
|
216
|
+
|
217
|
+
class ControllerButtonEvent < Struct
|
218
|
+
layout *COMMON_EVENT_LAYOUT + [
|
219
|
+
:which, :joystick_id,
|
220
|
+
:button, :uint8,
|
221
|
+
:state, :uint8,
|
222
|
+
:padding1, :uint8,
|
223
|
+
:padding2, :uint8
|
224
|
+
]
|
225
|
+
end
|
226
|
+
|
227
|
+
class ControllerDeviceEvent < Struct
|
228
|
+
layout *COMMON_EVENT_LAYOUT + [
|
229
|
+
:which, :joystick_id
|
230
|
+
]
|
231
|
+
end
|
232
|
+
|
233
|
+
class TouchFingerEvent < Struct
|
234
|
+
layout *COMMON_EVENT_LAYOUT + [
|
235
|
+
:touchId, :touch_id,
|
236
|
+
:fingerId, :finger_id,
|
237
|
+
:x, :float,
|
238
|
+
:y, :float,
|
239
|
+
:dx, :float,
|
240
|
+
:dy, :float,
|
241
|
+
:pressure, :float
|
242
|
+
]
|
243
|
+
end
|
244
|
+
|
245
|
+
class MultiGestureEvent < Struct
|
246
|
+
layout *COMMON_EVENT_LAYOUT + [
|
247
|
+
:touchId, :touch_id,
|
248
|
+
:dTheta, :float,
|
249
|
+
:dDist, :float,
|
250
|
+
:x, :float,
|
251
|
+
:y, :float,
|
252
|
+
:numFingers, :uint16,
|
253
|
+
:padding, :uint16
|
254
|
+
]
|
255
|
+
end
|
256
|
+
|
257
|
+
class DollarGestureEvent < Struct
|
258
|
+
layout *COMMON_EVENT_LAYOUT + [
|
259
|
+
:touchId, :touch_id,
|
260
|
+
:gestureId, :gesture_id,
|
261
|
+
:numFingers, :uint32,
|
262
|
+
:error, :float,
|
263
|
+
:x, :float,
|
264
|
+
:y, :float
|
265
|
+
]
|
266
|
+
end
|
267
|
+
|
268
|
+
class DropEvent < Struct
|
269
|
+
layout *COMMON_EVENT_LAYOUT + [
|
270
|
+
:file, :string
|
271
|
+
]
|
272
|
+
end
|
273
|
+
|
274
|
+
class QuitEvent < Struct
|
275
|
+
layout *COMMON_EVENT_LAYOUT
|
276
|
+
end
|
277
|
+
|
278
|
+
class OSEvent < Struct
|
279
|
+
layout *COMMON_EVENT_LAYOUT
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
class UserEvent < Struct
|
284
|
+
layout *COMMON_EVENT_LAYOUT + [
|
285
|
+
:windowID, :uint32,
|
286
|
+
:code, :int32,
|
287
|
+
:data1, :pointer,
|
288
|
+
:data2, :pointer
|
289
|
+
]
|
290
|
+
end
|
291
|
+
|
292
|
+
class SysWMEvent < Struct
|
293
|
+
layout *COMMON_EVENT_LAYOUT + [
|
294
|
+
:msg, SDL2::SysWM::Msg.by_ref
|
295
|
+
]
|
296
|
+
end
|
297
|
+
|
298
|
+
class Event < FFI::Union
|
299
|
+
layout :type, :uint32,
|
300
|
+
:common, CommonEvent,
|
301
|
+
:window, WindowEvent,
|
302
|
+
:key, KeyboardEvent,
|
303
|
+
:edit, TextEditingEvent,
|
304
|
+
:text, TextInputEvent,
|
305
|
+
:motion, MouseMotionEvent,
|
306
|
+
:button, MouseButtonEvent,
|
307
|
+
:wheel, MouseWheelEvent,
|
308
|
+
:jaxis, JoyAxisEvent,
|
309
|
+
:jball, JoyBallEvent,
|
310
|
+
:jbutton, JoyButtonEvent,
|
311
|
+
:jdevice, JoyDeviceEvent,
|
312
|
+
:caxis, ControllerAxisEvent,
|
313
|
+
:cbutton, ControllerButtonEvent,
|
314
|
+
:cdevice, ControllerDeviceEvent,
|
315
|
+
:quit, QuitEvent,
|
316
|
+
:user, UserEvent,
|
317
|
+
:syswm, SysWMEvent,
|
318
|
+
:tfinger, TouchFingerEvent,
|
319
|
+
:mgesture, MultiGestureEvent,
|
320
|
+
:drop, DropEvent,
|
321
|
+
:padding, [:uint8, 56] # From SDL_events.h:529
|
322
|
+
end
|
323
|
+
|
324
|
+
enum :eventaction, [:add, :peek, :get]
|
325
|
+
|
326
|
+
attach_function :peep_events, :SDL_PeepEvents, [Event.by_ref, :count, :eventaction, :uint32, :uint32], :int
|
327
|
+
attach_function :has_event, :SDL_HasEvent, [:uint32], :bool
|
328
|
+
attach_function :has_events, :SDL_HasEvents, [:uint32, :uint32], :bool
|
329
|
+
attach_function :flush_event, :SDL_FlushEvent, [:uint32], :void
|
330
|
+
attach_function :flush_events, :SDL_FlushEvents, [:uint32, :uint32], :void
|
331
|
+
attach_function :poll_event, :SDL_PollEvent, [Event.by_ref], :int
|
332
|
+
attach_function :wait_event, :SDL_WaitEvent, [Event.by_ref], :int
|
333
|
+
attach_function :wait_event_timeout, :SDL_WaitEventTimeout, [Event.by_ref, :count], :int
|
334
|
+
attach_function :push_event, :SDL_PushEvent, [Event.by_ref, :count], :int
|
335
|
+
|
336
|
+
callback :event_filter, [:pointer, Event.by_ref], :int
|
337
|
+
class EventFilterStruct < Struct
|
338
|
+
layout :callback, :event_filter
|
339
|
+
end
|
340
|
+
|
341
|
+
attach_function :set_event_filter, :SDL_SetEventFilter, [:event_filter, :pointer], :void
|
342
|
+
attach_function :get_event_filter, :SDL_GetEventFilter, [:pointer, :pointer], :bool
|
343
|
+
attach_function :add_event_watch, :SDL_AddEventWatch, [:event_filter, :pointer], :void
|
344
|
+
attach_function :del_event_watch, :SDL_DelEventWatch, [:event_filter, :pointer], :void
|
345
|
+
attach_function :filter_events, :SDL_FilterEvents, [:event_filter, :pointer], :void
|
346
|
+
|
347
|
+
QUERY = -1
|
348
|
+
IGNORE = 0
|
349
|
+
DISABLE = 0
|
350
|
+
ENABLE = 1
|
351
|
+
|
352
|
+
attach_function :event_state, :SDL_EventState, [:uint32, :int], :uint8
|
353
|
+
def get_event_state(type)
|
354
|
+
event_state(type, QUERY)
|
355
|
+
end
|
356
|
+
|
357
|
+
attach_function :register_events, :SDL_RegisterEvents, [:count], :uint32
|
358
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/joystick'
|
3
|
+
|
4
|
+
module SDL2
|
5
|
+
enum :controller_bindtype, [:NONE, 0, :BUTTON, :AXIS, :HAT]
|
6
|
+
|
7
|
+
class GameController < Struct
|
8
|
+
|
9
|
+
class ButtonBind < Struct
|
10
|
+
|
11
|
+
class ValueUnion < FFI::Union
|
12
|
+
|
13
|
+
class HatStruct < FFI::Struct
|
14
|
+
layout :hat, :int, :hat_mask, :int
|
15
|
+
end #HatStruct
|
16
|
+
|
17
|
+
layout :button, :int,
|
18
|
+
:axis, :int,
|
19
|
+
:hat, HatStruct
|
20
|
+
end#ValueUnion
|
21
|
+
|
22
|
+
layout :bindType, :controller_bindtype,
|
23
|
+
:value, ValueUnion
|
24
|
+
end#ButtonBind
|
25
|
+
|
26
|
+
#GameController
|
27
|
+
def self.release(pointer)
|
28
|
+
SDL2.game_controller_close(pointer)
|
29
|
+
end
|
30
|
+
|
31
|
+
end#GameController
|
32
|
+
|
33
|
+
api :SDL_GameControllerAddMapping, [:string], :int
|
34
|
+
api :SDL_GameControllerMappingForGUID, [JoystickGUID], :string
|
35
|
+
api :SDL_GameControllerMapping, [GameController.by_ref], :string
|
36
|
+
api :SDL_IsGameController, [:joystick_index], :bool
|
37
|
+
api :SDL_GameControllerNameForIndex, [:joystick_index], :string
|
38
|
+
api :SDL_GameControllerOpen, [:joystick_index], :string
|
39
|
+
api :SDL_GameControllerName, [GameController.by_ref], :string
|
40
|
+
api :SDL_GameControllerGetAttached, [GameController.by_ref], :bool
|
41
|
+
api :SDL_GameControllerGetJoystick, [GameController.by_ref], Joystick.by_ref
|
42
|
+
api :SDL_GameControllerEventState, [:int], :int
|
43
|
+
api :SDL_GameControllerUpdate, [], :void
|
44
|
+
|
45
|
+
enum :game_controller_axis, [:INVALID, -1, :LEFTX, :LEFTY, :RIGHTX, :RIGHTY, :TRIGGERLEFT, :TRIGGERRIGHT, :MAX]
|
46
|
+
|
47
|
+
api :SDL_GameControllerGetAxisFromString, [:string], :game_controller_axis
|
48
|
+
api :SDL_GameControllerGetStringForAxis, [:game_controller_axis], :string
|
49
|
+
api :SDL_GameControllerGetBindForAxis, [GameController.by_ref, :game_controller_axis], GameController::ButtonBind
|
50
|
+
api :SDL_GameControllerGetAxis, [GameController.by_ref, :game_controller_axis], :int16
|
51
|
+
|
52
|
+
enum :game_controller_button, [:INVLIAD, -1,
|
53
|
+
:A, :B, :X, :Y, :BACK, :GUIDE, :START,
|
54
|
+
:LEFTSTICK, :RIGHTSTICK, :LEFTSHOULDER, :RIGHTSHOULDER,
|
55
|
+
:DPAD_UP, :DPAD_DOWN, :DPAD_LEFT, :DPAD_RIGHT]
|
56
|
+
|
57
|
+
api :SDL_GameControllerGetButtonFromString, [:string], :game_controller_button
|
58
|
+
api :SDL_GameControllerGetStringForButton, [:game_controller_button], :string
|
59
|
+
api :SDL_GameControllerGetBindForButton, [GameController.by_ref, :game_controller_button], GameController::ButtonBind
|
60
|
+
api :SDL_GameControllerGetButton, [GameController.by_ref, :game_controller_button], :uint8
|
61
|
+
api :SDL_GameControllerClose, [GameController.by_ref], :void
|
62
|
+
end
|
data/lib/sdl2/gesture.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
|
3
|
+
require 'sdl2/video'
|
4
|
+
require 'sdl2/touch'
|
5
|
+
|
6
|
+
module SDL2
|
7
|
+
|
8
|
+
typedef :int64, :gesture_id
|
9
|
+
|
10
|
+
api :SDL_RecordGesture, [:touch_id], :int
|
11
|
+
api :SDL_SaveAllDollarTemplates, [RWops.by_ref], :int
|
12
|
+
api :SDL_SaveDollarTemplate, [:gesture_id, RWops.by_ref], :int
|
13
|
+
api :SDL_LoadDollarTemplates, [:touch_id, RWops.by_ref], :int
|
14
|
+
|
15
|
+
end
|
data/lib/sdl2/haptic.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/joystick'
|
3
|
+
require 'yinum'
|
4
|
+
|
5
|
+
module SDL2
|
6
|
+
|
7
|
+
class Haptic < Struct
|
8
|
+
Features = Enum.new(:HapticFeatures, {
|
9
|
+
CONSTANT: (1<<0),
|
10
|
+
SINE: (1<<1),
|
11
|
+
LEFTRIGHT: (1<<2),
|
12
|
+
TRIANGLE: (1<<3),
|
13
|
+
SAWTOOTHUP: (1<<4),
|
14
|
+
SAWTOOTHDOWN: (1<<5),
|
15
|
+
RAMP: (1<<6),
|
16
|
+
SPRING: (1<<7),
|
17
|
+
DAMPER: (1<<8),
|
18
|
+
INERTIA: (1<<9),
|
19
|
+
FRICTION: (1<<10),
|
20
|
+
CUSTOM: (1<<11),
|
21
|
+
GAIN: (1<<12),
|
22
|
+
AUTOCENTER: (1<<13),
|
23
|
+
STATUS: (1<<14),
|
24
|
+
PAUSE: (1<<15)
|
25
|
+
})
|
26
|
+
|
27
|
+
DirectionType = Enum.new(:HapticDirectionType, {
|
28
|
+
POLAR: 0,
|
29
|
+
CARTESIAN: 1,
|
30
|
+
SPHERICAL: 2
|
31
|
+
})
|
32
|
+
|
33
|
+
|
34
|
+
RunEffect = Enum.new(:HapticRunEffect, {
|
35
|
+
INFINITY: 4294967295
|
36
|
+
})
|
37
|
+
|
38
|
+
class Direction < Struct
|
39
|
+
layout :type, :uint8,
|
40
|
+
:dir, [:int32, 3] # Magic #3 form line 442
|
41
|
+
end
|
42
|
+
|
43
|
+
COMMON_LAYOUT = [:type, :uint16,
|
44
|
+
:direction, Direction,
|
45
|
+
|
46
|
+
:length, :uint32,
|
47
|
+
:delay, :uint16,
|
48
|
+
|
49
|
+
:button, :uint16,
|
50
|
+
:interval, :uint16
|
51
|
+
]
|
52
|
+
|
53
|
+
COMMON_ENVELOPE = [
|
54
|
+
:attack_length, :uint16,
|
55
|
+
:attack_level, :uint16,
|
56
|
+
:fade_length, :uint16,
|
57
|
+
:fade_level, :uint16
|
58
|
+
]
|
59
|
+
|
60
|
+
class Constant < Struct
|
61
|
+
layout *COMMON_EVENT_LAYOUT+[
|
62
|
+
:level, :int16
|
63
|
+
] + COMMON_ENVELOPE
|
64
|
+
end
|
65
|
+
|
66
|
+
class Periodic < Struct
|
67
|
+
layout *COMMON_EVENT_LAYOUT+[
|
68
|
+
:period, :uint16,
|
69
|
+
:magnitude, :int16,
|
70
|
+
:offset, :int16,
|
71
|
+
:phase, :uint16,
|
72
|
+
]+COMMON_ENVELOPE
|
73
|
+
end
|
74
|
+
|
75
|
+
class Condition < Struct
|
76
|
+
layout *COMMON_EVENT_LAYOUT+[
|
77
|
+
:right_sat, [:uint16, 3],
|
78
|
+
:left_sat, [:uint16, 3],
|
79
|
+
:right_coeff, [:int16, 3],
|
80
|
+
:left_coeff, [:int16, 3],
|
81
|
+
:deadband, [:uint16, 3],
|
82
|
+
:center, [:int16, 3]
|
83
|
+
]
|
84
|
+
end
|
85
|
+
|
86
|
+
class Ramp < Struct
|
87
|
+
layout *COMMON_EVENT_LAYOUT+[
|
88
|
+
:start, :int16,
|
89
|
+
:'end', :int16,
|
90
|
+
]+COMMON_ENVELOPE
|
91
|
+
end
|
92
|
+
|
93
|
+
class LeftRight < Struct
|
94
|
+
layout :type, :uint16,
|
95
|
+
:length, :uint32,
|
96
|
+
:large_magnitude, :uint16,
|
97
|
+
:small_magnitude, :uint16
|
98
|
+
end
|
99
|
+
|
100
|
+
class Custom < Struct
|
101
|
+
layout *COMMON_EVENT_LAYOUT+[
|
102
|
+
:channels, :uint8,
|
103
|
+
:period, :uint16,
|
104
|
+
:samples, :uint16,
|
105
|
+
:data, :pointer,
|
106
|
+
]+COMMON_ENVELOPE
|
107
|
+
end
|
108
|
+
|
109
|
+
class Effect < FFI::Union
|
110
|
+
layout :type, :uint16,
|
111
|
+
:constant, Constant,
|
112
|
+
:periodic, Periodic,
|
113
|
+
:condition, Condition,
|
114
|
+
:ramp, Ramp,
|
115
|
+
:leftright, LeftRight,
|
116
|
+
:custom, Custom
|
117
|
+
end
|
118
|
+
|
119
|
+
# Haptic
|
120
|
+
def self.release(pointer)
|
121
|
+
SDL2.haptic_close(pointer)
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
api :SDL_NumHaptics, [], :int
|
129
|
+
api :SDL_HapticName, [:int], :string
|
130
|
+
api :SDL_HapticOpen, [:int], Haptic.auto_ptr
|
131
|
+
api :SDL_HapticOpened, [:int], :int
|
132
|
+
api :SDL_HapticIndex, [Haptic.by_ref], :int
|
133
|
+
api :SDL_MouseIsHaptic, [], :int
|
134
|
+
api :SDL_HapticOpenFromMouse, [], Haptic.auto_ptr
|
135
|
+
api :SDL_JoystickIsHaptic, [Joystick.by_ref], :int
|
136
|
+
api :SDL_HapticOpenFromJoystick, [Joystick.by_ref], Haptic.auto_ptr
|
137
|
+
api :SDL_HapticClose, [Haptic.by_ref], :void
|
138
|
+
api :SDL_HapticNumEffects, [Haptic.by_ref], :int
|
139
|
+
api :SDL_HapticNumEffectsPlaying, [Haptic.by_ref], :int
|
140
|
+
api :SDL_HapticQuery, [Haptic.by_ref], :int
|
141
|
+
api :SDL_HapticNumAxes, [Haptic.by_ref], :int
|
142
|
+
api :SDL_HapticEffectSupported, [Haptic.by_ref, Haptic::Effect.by_ref], :int
|
143
|
+
api :SDL_HapticNewEffect, [Haptic.by_ref, Haptic::Effect.by_ref], :int
|
144
|
+
api :SDL_HapticUpdateEffect, [Haptic.by_ref, :int, Haptic::Effect.by_ref], :int
|
145
|
+
api :SDL_HapticRunEffect, [Haptic.by_ref, :int, :uint32], :int
|
146
|
+
api :SDL_HapticStopEffect, [Haptic.by_ref, :int], :int
|
147
|
+
api :SDL_HapticDestroyEffect, [Haptic.by_ref, :int], :int
|
148
|
+
api :SDL_HapticGetEffectStatus, [Haptic.by_ref, :int], :int
|
149
|
+
api :SDL_HapticSetGain, [Haptic.by_ref, :int], :int
|
150
|
+
api :SDL_HapticSetAutocenter, [Haptic.by_ref, :int], :int
|
151
|
+
api :SDL_HapticPause, [Haptic.by_ref], :int
|
152
|
+
api :SDL_HapticUnpause, [Haptic.by_ref], :int
|
153
|
+
api :SDL_HapticStopAll, [Haptic.by_ref], :int
|
154
|
+
api :SDL_HapticRumbleSupported, [Haptic.by_ref], :int
|
155
|
+
api :SDL_HapticRumbleInit, [Haptic.by_ref], :int
|
156
|
+
api :SDL_HapticRumblePlay, [Haptic.by_ref], :int
|
157
|
+
api :SDL_HapticRumbleStop, [Haptic.by_ref], :int
|
158
|
+
|
159
|
+
end
|
data/lib/sdl2/hints.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
|
3
|
+
module SDL2
|
4
|
+
|
5
|
+
HINT_FRAMEBUFFER_ACCELERATION = "SDL_FRAMEBUFFER_ACCELERATION"
|
6
|
+
HINT_RENDER_DRIVER = "SDL_RENDER_DRIVER"
|
7
|
+
HINT_RENDER_OPENGL_SHADERS = "SDL_RENDER_OPENGL_SHADERS"
|
8
|
+
HINT_RENDER_SCALE_QUALITY = "SDL_RENDER_SCALE_QUALITY"
|
9
|
+
HINT_RENDER_VSYNC = "SDL_RENDER_VSYNC"
|
10
|
+
HINT_VIDEO_X11_XVIDMODE = "SDL_VIDEO_X11_XVIDMODE"
|
11
|
+
HINT_VIDEO_X11_XINERAMA = "SDL_VIDEO_X11_XINERAMA"
|
12
|
+
HINT_VIDEO_X11_XRANDR = "SDL_VIDEO_X11_XRANDR"
|
13
|
+
HINT_GRAB_KEYBOARD = "SDL_GRAB_KEYBOARD"
|
14
|
+
HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS = "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
|
15
|
+
HINT_IDLE_TIMER_DISABLED = "SDL_IOS_IDLE_TIMER_DISABLED"
|
16
|
+
HINT_ORIENTATIONS = "SDL_IOS_ORIENTATIONS"
|
17
|
+
HINT_XINPUT_ENABLED = "SDL_XINPUT_ENABLED"
|
18
|
+
|
19
|
+
HINT_GAMECONTROLLERCONFIG = "SDL_GAMECONTROLLERCONFIG"
|
20
|
+
|
21
|
+
HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS = "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
|
22
|
+
HINT_ALLOW_TOPMOST = "SDL_ALLOW_TOPMOST"
|
23
|
+
HINT_TIMER_RESOLUTION = "SDL_TIMER_RESOLUTION"
|
24
|
+
|
25
|
+
enum :hint_priority, [:default, :normal, :override]
|
26
|
+
|
27
|
+
class Hint
|
28
|
+
def self.[](name)
|
29
|
+
SDL2.get_hint(name)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sets the named Hint to Value. Returns new value on success or existing value on failure
|
33
|
+
def self.[]=(name, value)
|
34
|
+
return SDL2.set_hint(name, value) == :true ? value : self[name]
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.set_with_priority(name, value, hint_priority)
|
38
|
+
return SDL2.set_hint_with_priority(name, value, hint_priority) == :true ? value : self[name]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
api :SDL_ClearHints, [], :void
|
43
|
+
api :SDL_GetHint, [:string], :string
|
44
|
+
api :SDL_SetHint, [:string, :string], :bool
|
45
|
+
api :SDL_SetHintWithPriority, [:string, :string, :hint_priority], :bool
|
46
|
+
|
47
|
+
end
|
data/lib/sdl2/init.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/error'
|
3
|
+
|
4
|
+
module SDL2
|
5
|
+
# SDL Constants, for OR'ing them
|
6
|
+
INIT_TIMER = 0x00000001
|
7
|
+
INIT_AUDIO = 0x00000010
|
8
|
+
INIT_VIDEO = 0x00000020
|
9
|
+
INIT_JOYSTICK = 0x00000200
|
10
|
+
INIT_HAPTIC = 0x00001000
|
11
|
+
INIT_GAMECONTROLLER = 0x00002000
|
12
|
+
INIT_EVENTS = 0x00004000
|
13
|
+
INIT_NOPARACHUTE = 0x00100000
|
14
|
+
INIT_EVERYTHING = INIT_TIMER | INIT_AUDIO | INIT_VIDEO |
|
15
|
+
INIT_EVENTS | INIT_JOYSTICK | INIT_HAPTIC |
|
16
|
+
INIT_GAMECONTROLLER
|
17
|
+
|
18
|
+
enum :init_flag, [
|
19
|
+
:nothing, 0,
|
20
|
+
:timer, INIT_TIMER,
|
21
|
+
:audio, INIT_AUDIO,
|
22
|
+
:video, INIT_VIDEO,
|
23
|
+
:joystick, INIT_JOYSTICK,
|
24
|
+
:haptic, INIT_HAPTIC,
|
25
|
+
:game_controller, INIT_GAMECONTROLLER,
|
26
|
+
:events, INIT_EVENTS,
|
27
|
+
:no_parachute, INIT_NOPARACHUTE,
|
28
|
+
:everything, INIT_EVERYTHING
|
29
|
+
]
|
30
|
+
|
31
|
+
api :SDL_Init, [:init_flag], :int
|
32
|
+
|
33
|
+
def self.init!(flags)
|
34
|
+
error_code = init(flags)
|
35
|
+
if (error_code != 0)
|
36
|
+
throw get_error()
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
api :SDL_InitSubSystem, [:init_flag], :int
|
41
|
+
|
42
|
+
def init_sub_system!(flags)
|
43
|
+
error_code = init_sub_system(flags)
|
44
|
+
if (error_code != 0)
|
45
|
+
throw get_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
api :SDL_WasInit, [:init_flag], :uint32
|
50
|
+
|
51
|
+
api :SDL_Quit, [], :void
|
52
|
+
|
53
|
+
api :SDL_QuitSubSystem, [:init_flag], :void
|
54
|
+
end
|