sdl2_ffi 0.0.6 → 0.0.7
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 +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +0 -6
- data/Guardfile +0 -45
- data/README.md +11 -21
- data/lib/bad_sdl.rb +4 -0
- data/lib/{sdl2 → bad_sdl}/application.rb +47 -35
- data/lib/{sdl2 → bad_sdl}/engine.rb +20 -3
- data/lib/{sdl2 → bad_sdl}/engine/block_engine.rb +2 -2
- data/lib/bad_sdl/engine/engines.rb +51 -0
- data/lib/enumerable_constants.rb +4 -2
- data/lib/sdl2.rb +26 -247
- data/lib/sdl2/blendmode.rb +18 -0
- data/lib/sdl2/color.rb +1 -3
- data/lib/sdl2/debug.rb +58 -0
- data/lib/sdl2/display.rb +30 -23
- data/lib/sdl2/error.rb +6 -4
- data/lib/sdl2/event.rb +229 -0
- data/lib/sdl2/event/abstract.rb +11 -0
- data/lib/sdl2/event/action.rb +19 -0
- data/lib/sdl2/event/common.rb +10 -0
- data/lib/sdl2/event/controller_axis.rb +20 -0
- data/lib/sdl2/event/controller_button.rb +17 -0
- data/lib/sdl2/event/controller_device.rb +14 -0
- data/lib/sdl2/event/dollar_gesture.rb +19 -0
- data/lib/sdl2/event/drop.rb +18 -0
- data/lib/sdl2/event/joy_axis.rb +20 -0
- data/lib/sdl2/event/joy_ball.rb +20 -0
- data/lib/sdl2/event/joy_button.rb +18 -0
- data/lib/sdl2/event/joy_device.rb +14 -0
- data/lib/sdl2/event/joy_hat.rb +18 -0
- data/lib/sdl2/event/keyboard.rb +18 -0
- data/lib/sdl2/event/mouse_button.rb +21 -0
- data/lib/sdl2/event/mouse_motion.rb +19 -0
- data/lib/sdl2/event/mouse_wheel.rb +17 -0
- data/lib/sdl2/event/multi_gesture.rb +20 -0
- data/lib/sdl2/event/os.rb +12 -0
- data/lib/sdl2/event/quit.rb +12 -0
- data/lib/sdl2/event/state.rb +13 -0
- data/lib/sdl2/event/sys_wm.rb +15 -0
- data/lib/sdl2/event/text_editing.rb +17 -0
- data/lib/sdl2/event/text_input.rb +15 -0
- data/lib/sdl2/event/touch_finger.rb +20 -0
- data/lib/sdl2/event/type.rb +62 -0
- data/lib/sdl2/event/user.rb +15 -0
- data/lib/sdl2/event/window.rb +19 -0
- data/lib/sdl2/events.rb +23 -538
- data/lib/sdl2/gem_version.rb +1 -1
- data/lib/sdl2/haptic.rb +3 -3
- data/lib/sdl2/hints.rb +3 -1
- data/lib/sdl2/image.rb +20 -20
- data/lib/sdl2/init.rb +5 -8
- data/lib/sdl2/joystick.rb +104 -78
- data/lib/sdl2/joystick/axes.rb +22 -0
- data/lib/sdl2/joystick/balls.rb +24 -0
- data/lib/sdl2/joystick/buttons.rb +22 -0
- data/lib/sdl2/joystick/components.rb +23 -0
- data/lib/sdl2/joystick/hats.rb +22 -0
- data/lib/sdl2/keyboard.rb +11 -10
- data/lib/sdl2/keycode.rb +70 -70
- data/lib/sdl2/library.rb +8 -7
- data/lib/sdl2/log.rb +6 -0
- data/lib/sdl2/managed_struct.rb +17 -0
- data/lib/sdl2/mixer.rb +16 -12
- data/lib/sdl2/mixer/chunk.rb +14 -3
- data/lib/sdl2/mouse.rb +21 -41
- data/lib/sdl2/pixel_format.rb +4 -4
- data/lib/sdl2/pixels.rb +59 -47
- data/lib/sdl2/power.rb +1 -1
- data/lib/sdl2/rect.rb +4 -5
- data/lib/sdl2/render.rb +85 -170
- data/lib/sdl2/renderer.rb +337 -20
- data/lib/sdl2/rwops.rb +89 -30
- data/lib/sdl2/stdinc.rb +18 -21
- data/lib/sdl2/struct.rb +184 -0
- data/lib/sdl2/struct_helper.rb +32 -0
- data/lib/sdl2/surface.rb +15 -14
- data/lib/sdl2/syswm.rb +26 -10
- data/lib/sdl2/syswm/msg.rb +22 -4
- data/lib/sdl2/texture.rb +106 -0
- data/lib/sdl2/touch.rb +16 -20
- data/lib/sdl2/ttf.rb +29 -29
- data/lib/sdl2/ttf/sdl_ttf_module.rb +1 -1
- data/lib/sdl2/typed_pointer.rb +45 -0
- data/lib/sdl2/union.rb +7 -0
- data/lib/sdl2/video.rb +97 -183
- data/lib/sdl2/window.rb +140 -90
- data/lib/struct_array.rb +42 -0
- data/sdl2_ffi.gemspec +3 -3
- data/spec/fixtures/approvals/lazyfoonet_lesson_03_advanced_timers/has_a_message.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_a_message.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_drawn_something.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
- data/spec/fixtures/images/finger.png +0 -0
- data/spec/fixtures/music/beat.wav +0 -0
- data/spec/fixtures/sounds/high.wav +0 -0
- data/spec/fixtures/sounds/low.wav +0 -0
- data/spec/fixtures/sounds/medium.wav +0 -0
- data/spec/fixtures/sounds/scratch.wav +0 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +4 -6
- data/spec/functional/lazy_foo_tutorial/lazy_foo_02_optimized_images_spec.rb +3 -4
- data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +2 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +3 -3
- data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +1 -1
- data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +1 -1
- data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +3 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +9 -7
- data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +11 -8
- data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +5 -4
- data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +17 -9
- data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +8 -7
- data/spec/functional/lazy_foo_tutorial/lazy_foo_13_advanced_timers_spec.rb +85 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_14_regulating_frame_rate_spec.rb +67 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_15_calculating_frame_rate_spec.rb +48 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_16_motion_spec.rb +95 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_helper.rb +3 -1
- data/spec/functional/lazy_foo_tutorial/timer.rb +55 -0
- data/spec/lib/bad_sdl/application_spec.rb +22 -0
- data/spec/{unit → lib}/sdl2/color_spec.rb +5 -1
- data/spec/lib/sdl2/display_spec.rb +6 -0
- data/spec/lib/sdl2/event_spec.rb +102 -0
- data/spec/lib/sdl2/events_spec.rb +12 -0
- data/spec/lib/sdl2/joystick_spec.rb +130 -0
- data/spec/lib/sdl2/keyboard_spec.rb +22 -0
- data/spec/lib/sdl2/mouse_spec.rb +21 -0
- data/spec/lib/sdl2/render_spec.rb +62 -0
- data/spec/lib/sdl2/renderer_spec.rb +224 -0
- data/spec/lib/sdl2/sdl2_helper.rb +5 -0
- data/spec/lib/sdl2/texture_spec.rb +65 -0
- data/{test/unit/sdl2/test_video.rb → spec/lib/sdl2/video_spec.rb} +82 -57
- data/spec/lib/sdl2/window_spec.rb +42 -0
- data/spec/{unit → lib}/unit_helper.rb +0 -0
- data/spec/png_writer.rb +9 -1
- data/spec/spec_helper.rb +5 -3
- metadata +201 -132
- data/lib/sdl2/engine/engines.rb +0 -46
- data/test/approvals/clip_blitting_and_sprite_sheets.received.bmp +0 -0
- data/test/approvals/color_keying_example.approved.png +0 -0
- data/test/approvals/hello_world_example_hello.approved.png +0 -0
- data/test/approvals/hello_world_example_screen.approved.png +0 -0
- data/test/approvals/optimized_surface_loading.approved.png +0 -0
- data/test/fixtures/an_example.png +0 -0
- data/test/fixtures/background.bmp +0 -0
- data/test/fixtures/background.jpg +0 -0
- data/test/fixtures/color_bars.jpg +0 -0
- data/test/fixtures/foo.jpg +0 -0
- data/test/fixtures/hello.bmp +0 -0
- data/test/fixtures/sprites.jpg +0 -0
- data/test/fixtures/x.png +0 -0
- data/test/functional/examples/lazyfoo.net_s/test_clip_blitting_and_sprite_sheets.rb +0 -50
- data/test/functional/examples/lazyfoo.net_s/test_color_keying.rb +0 -42
- data/test/functional/examples/test_lazy_foo_examples.rb +0 -195
- data/test/functional/examples/test_readme_examples.rb +0 -15
- data/test/test_helper.rb +0 -13
- data/test/unit/sdl2/test_assert.rb +0 -10
- data/test/unit/sdl2/test_audio.rb +0 -9
- data/test/unit/sdl2/test_clipboard.rb +0 -13
- data/test/unit/sdl2/test_cpuinfo.rb +0 -11
- data/test/unit/sdl2/test_error.rb +0 -20
- data/test/unit/sdl2/test_events.rb +0 -31
- data/test/unit/sdl2/test_haptic.rb +0 -27
- data/test/unit/sdl2/test_hints.rb +0 -50
- data/test/unit/sdl2/test_image.rb +0 -9
- data/test/unit/sdl2/test_init.rb +0 -29
- data/test/unit/sdl2/test_keyboard.rb +0 -9
- data/test/unit/sdl2/test_log.rb +0 -80
- data/test/unit/sdl2/test_palette.rb +0 -26
- data/test/unit/sdl2/test_pixel_format.rb +0 -38
- data/test/unit/sdl2/test_pixels.rb +0 -24
- data/test/unit/sdl2/test_power.rb +0 -11
- data/test/unit/sdl2/test_rect.rb +0 -19
- data/test/unit/sdl2/test_render.rb +0 -58
- data/test/unit/sdl2/test_surface.rb +0 -88
- data/test/unit/sdl2/test_syswm.rb +0 -11
- data/test/unit/sdl2/test_timer.rb +0 -9
- data/test/unit/sdl2/test_ttf.rb +0 -11
- data/test/unit/sdl2/test_version.rb +0 -16
- data/test/unit/sdl2/test_window.rb +0 -155
- data/test/unit/test_scratch.rb +0 -19
- data/test/unit/test_sdl2.rb +0 -16
data/lib/sdl2/gem_version.rb
CHANGED
data/lib/sdl2/haptic.rb
CHANGED
@@ -444,7 +444,7 @@ module SDL2
|
|
444
444
|
api :SDL_HapticName, [:int], :string
|
445
445
|
##
|
446
446
|
#
|
447
|
-
api :SDL_HapticOpen, [:int], Haptic.
|
447
|
+
api :SDL_HapticOpen, [:int], Haptic.ptr
|
448
448
|
##
|
449
449
|
#
|
450
450
|
api :SDL_HapticOpened, [:int], :int
|
@@ -456,13 +456,13 @@ module SDL2
|
|
456
456
|
api :SDL_MouseIsHaptic, [], :int
|
457
457
|
##
|
458
458
|
#
|
459
|
-
api :SDL_HapticOpenFromMouse, [], Haptic.
|
459
|
+
api :SDL_HapticOpenFromMouse, [], Haptic.ptr
|
460
460
|
##
|
461
461
|
#
|
462
462
|
api :SDL_JoystickIsHaptic, [Joystick.by_ref], :int
|
463
463
|
##
|
464
464
|
#
|
465
|
-
api :SDL_HapticOpenFromJoystick, [Joystick.by_ref], Haptic.
|
465
|
+
api :SDL_HapticOpenFromJoystick, [Joystick.by_ref], Haptic.ptr
|
466
466
|
##
|
467
467
|
#
|
468
468
|
api :SDL_HapticClose, [Haptic.by_ref], :void
|
data/lib/sdl2/hints.rb
CHANGED
@@ -7,6 +7,7 @@ module SDL2
|
|
7
7
|
FRAMEBUFFER_ACCELERATION = "SDL_FRAMEBUFFER_ACCELERATION"
|
8
8
|
RENDER_DRIVER = "SDL_RENDER_DRIVER"
|
9
9
|
RENDER_OPENGL_SHADERS = "SDL_RENDER_OPENGL_SHADERS"
|
10
|
+
RENDER_DIRECT3D_THREADSAFE = "SDL_RENDER_DIRECT3D_THREADSAFE"
|
10
11
|
RENDER_SCALE_QUALITY = "SDL_RENDER_SCALE_QUALITY"
|
11
12
|
RENDER_VSYNC = "SDL_RENDER_VSYNC"
|
12
13
|
VIDEO_X11_XVIDMODE = "SDL_VIDEO_X11_XVIDMODE"
|
@@ -23,6 +24,7 @@ module SDL2
|
|
23
24
|
JOYSTICK_ALLOW_BACKGROUND_EVENTS = "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
|
24
25
|
ALLOW_TOPMOST = "SDL_ALLOW_TOPMOST"
|
25
26
|
TIMER_RESOLUTION = "SDL_TIMER_RESOLUTION"
|
27
|
+
VIDEO_HIGHDPI_DISABLED = "SDL_VIDEO_HIGHDPI_DISABLED"
|
26
28
|
end
|
27
29
|
|
28
30
|
enum :hint_priority, [:default, :normal, :override]
|
@@ -64,4 +66,4 @@ module SDL2
|
|
64
66
|
#
|
65
67
|
api :SDL_SetHintWithPriority, [:string, :string, :hint_priority], :bool
|
66
68
|
|
67
|
-
end
|
69
|
+
end
|
data/lib/sdl2/image.rb
CHANGED
@@ -23,19 +23,19 @@ module SDL2
|
|
23
23
|
# Loads dynamic libraries and prepares them for use. Flags should be
|
24
24
|
# one or more flags from IMG_InitFlags OR'd together.
|
25
25
|
# It returns the flags successfully initialized, or 0 on failure.
|
26
|
-
api :IMG_Init, [:init_flags], :int, {error: true, filter:
|
26
|
+
api :IMG_Init, [:init_flags], :int, {error: true, filter: OK_WHEN_NOT_ZERO}
|
27
27
|
##
|
28
28
|
#
|
29
29
|
api :IMG_Quit, [], :void
|
30
30
|
##
|
31
31
|
#
|
32
|
-
api :IMG_LoadTyped_RW, [RWops.by_ref, :int, :string], Surface.
|
32
|
+
api :IMG_LoadTyped_RW, [RWops.by_ref, :int, :string], Surface.ptr
|
33
33
|
##
|
34
34
|
#
|
35
|
-
api :IMG_Load, [:string], Surface.
|
35
|
+
api :IMG_Load, [:string], Surface.ptr, {error: true, filter: OK_WHEN_NOT_NULL }
|
36
36
|
##
|
37
37
|
#
|
38
|
-
api :IMG_Load_RW, [RWops.by_ref, :int], Surface.
|
38
|
+
api :IMG_Load_RW, [RWops.by_ref, :int], Surface.ptr
|
39
39
|
|
40
40
|
##
|
41
41
|
#
|
@@ -82,53 +82,53 @@ module SDL2
|
|
82
82
|
|
83
83
|
##
|
84
84
|
#
|
85
|
-
api :IMG_LoadICO_RW, [RWops.by_ref], Surface.
|
85
|
+
api :IMG_LoadICO_RW, [RWops.by_ref], Surface.ptr
|
86
86
|
##
|
87
87
|
#
|
88
|
-
api :IMG_LoadCUR_RW, [RWops.by_ref], Surface.
|
88
|
+
api :IMG_LoadCUR_RW, [RWops.by_ref], Surface.ptr
|
89
89
|
##
|
90
90
|
#
|
91
|
-
api :IMG_LoadBMP_RW, [RWops.by_ref], Surface.
|
91
|
+
api :IMG_LoadBMP_RW, [RWops.by_ref], Surface.ptr
|
92
92
|
##
|
93
93
|
#
|
94
|
-
api :IMG_LoadGIF_RW, [RWops.by_ref], Surface.
|
94
|
+
api :IMG_LoadGIF_RW, [RWops.by_ref], Surface.ptr
|
95
95
|
##
|
96
96
|
#
|
97
|
-
api :IMG_LoadJPG_RW, [RWops.by_ref], Surface.
|
97
|
+
api :IMG_LoadJPG_RW, [RWops.by_ref], Surface.ptr
|
98
98
|
##
|
99
99
|
#
|
100
|
-
api :IMG_LoadLBM_RW, [RWops.by_ref], Surface.
|
100
|
+
api :IMG_LoadLBM_RW, [RWops.by_ref], Surface.ptr
|
101
101
|
##
|
102
102
|
#
|
103
|
-
api :IMG_LoadPCX_RW, [RWops.by_ref], Surface.
|
103
|
+
api :IMG_LoadPCX_RW, [RWops.by_ref], Surface.ptr
|
104
104
|
##
|
105
105
|
#
|
106
|
-
api :IMG_LoadPNG_RW, [RWops.by_ref], Surface.
|
106
|
+
api :IMG_LoadPNG_RW, [RWops.by_ref], Surface.ptr
|
107
107
|
##
|
108
108
|
#
|
109
|
-
api :IMG_LoadPNM_RW, [RWops.by_ref], Surface.
|
109
|
+
api :IMG_LoadPNM_RW, [RWops.by_ref], Surface.ptr
|
110
110
|
##
|
111
111
|
#
|
112
|
-
api :IMG_LoadTGA_RW, [RWops.by_ref], Surface.
|
112
|
+
api :IMG_LoadTGA_RW, [RWops.by_ref], Surface.ptr
|
113
113
|
##
|
114
114
|
#
|
115
|
-
api :IMG_LoadTIF_RW, [RWops.by_ref], Surface.
|
115
|
+
api :IMG_LoadTIF_RW, [RWops.by_ref], Surface.ptr, method_name: :load_TIF_rw
|
116
116
|
##
|
117
117
|
#
|
118
|
-
api :IMG_LoadXCF_RW, [RWops.by_ref], Surface.
|
118
|
+
api :IMG_LoadXCF_RW, [RWops.by_ref], Surface.ptr, method_name: :load_XCF_rw
|
119
119
|
##
|
120
120
|
#
|
121
|
-
api :IMG_LoadXPM_RW, [RWops.by_ref], Surface.
|
121
|
+
api :IMG_LoadXPM_RW, [RWops.by_ref], Surface.ptr, method_name: :load_XPM_rw
|
122
122
|
##
|
123
123
|
#
|
124
|
-
api :IMG_LoadXV_RW, [RWops.by_ref], Surface.
|
124
|
+
api :IMG_LoadXV_RW, [RWops.by_ref], Surface.ptr, method_name: :load_XV_rw
|
125
125
|
##
|
126
126
|
#
|
127
|
-
api :IMG_LoadWEBP_RW, [RWops.by_ref], Surface.
|
127
|
+
api :IMG_LoadWEBP_RW, [RWops.by_ref], Surface.ptr
|
128
128
|
|
129
129
|
##
|
130
130
|
#
|
131
|
-
api :IMG_ReadXPMFromArray, [:pointer], Surface.
|
131
|
+
api :IMG_ReadXPMFromArray, [:pointer], Surface.ptr
|
132
132
|
|
133
133
|
##
|
134
134
|
#
|
data/lib/sdl2/init.rb
CHANGED
@@ -2,7 +2,6 @@ require 'sdl2'
|
|
2
2
|
require 'sdl2/error'
|
3
3
|
|
4
4
|
module SDL2
|
5
|
-
|
6
5
|
# Enumeration of valid initialization flags.
|
7
6
|
module INIT
|
8
7
|
include EnumerableConstants
|
@@ -17,14 +16,12 @@ module SDL2
|
|
17
16
|
NOPARACHUTE = 0x00100000
|
18
17
|
EVERYTHING = TIMER | AUDIO | VIDEO | EVENTS | JOYSTICK | HAPTIC | GAMECONTROLLER
|
19
18
|
|
20
|
-
end
|
21
|
-
|
19
|
+
end
|
22
20
|
enum :init_flag, INIT.flatten_consts
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
api :SDL_Init, [:init_flag], :int, {error: true}
|
22
|
+
|
23
|
+
|
24
|
+
api :SDL_Init, [:init_flag], :int, {error: true}
|
28
25
|
|
29
26
|
|
30
27
|
##
|
@@ -42,7 +39,7 @@ module SDL2
|
|
42
39
|
#
|
43
40
|
api :SDL_WasInit, [:init_flag], :uint32
|
44
41
|
|
45
|
-
boolean? :was_init,
|
42
|
+
boolean? :was_init, OK_WHEN_NOT_ZERO
|
46
43
|
|
47
44
|
##
|
48
45
|
#
|
data/lib/sdl2/joystick.rb
CHANGED
@@ -1,17 +1,85 @@
|
|
1
1
|
require 'sdl2'
|
2
2
|
|
3
3
|
module SDL2
|
4
|
-
|
5
|
-
#
|
6
|
-
class Joystick < Struct
|
7
|
-
|
4
|
+
##
|
5
|
+
# TODO: == Joystick Overview ==
|
6
|
+
class Joystick < Struct
|
8
7
|
# TODO: Review if the Joystick layout should be hidden.
|
9
8
|
layout :hidden, :uint8
|
10
|
-
|
11
9
|
def self.release(pointer)
|
12
10
|
SDL2.joystick_close(pointer)
|
11
|
+
end
|
12
|
+
##
|
13
|
+
# Returns the number of attached joysticks on success or a
|
14
|
+
# exception on failure
|
15
|
+
def self.num
|
16
|
+
SDL2.num_joysticks!
|
17
|
+
end
|
18
|
+
##
|
19
|
+
# Returns a joystick identifier or raises exception on error
|
20
|
+
def self.open(idx)
|
21
|
+
SDL2.joystick_open!(idx)
|
13
22
|
end
|
14
|
-
|
23
|
+
##
|
24
|
+
# Returns the name of a joystick
|
25
|
+
def self.name(idx)
|
26
|
+
SDL2.joystick_name_for_index!(idx)
|
27
|
+
end
|
28
|
+
##
|
29
|
+
# update the current state of open joysticks
|
30
|
+
def self.update()
|
31
|
+
SDL2.joystick_update()
|
32
|
+
end
|
33
|
+
##
|
34
|
+
# Returns the name of the joystick
|
35
|
+
def name()
|
36
|
+
SDL2.joystick_name(self)
|
37
|
+
end
|
38
|
+
##
|
39
|
+
# Enumerator for Axes
|
40
|
+
def axes
|
41
|
+
@axes ||= Axes.new(self)
|
42
|
+
end
|
43
|
+
autoload(:Axes, 'sdl2/joystick/axes')
|
44
|
+
##
|
45
|
+
# Enumerator for balls
|
46
|
+
def balls
|
47
|
+
@balls ||= Balls.new(self)
|
48
|
+
end
|
49
|
+
autoload(:Balls, 'sdl2/joystick/balls')
|
50
|
+
##
|
51
|
+
# Enumerator for buttons
|
52
|
+
def buttons
|
53
|
+
@buttons ||= Buttons.new(self)
|
54
|
+
end
|
55
|
+
autoload(:Buttons, 'sdl2/joystick/buttons')
|
56
|
+
##
|
57
|
+
# Enumerator for hats
|
58
|
+
def hats
|
59
|
+
@hats ||= Hats.new(self)
|
60
|
+
end
|
61
|
+
autoload(:Hats, 'sdl2/joystick/hats')
|
62
|
+
##
|
63
|
+
# Get the device index of an opened joystick
|
64
|
+
def instance_id()
|
65
|
+
SDL2.joystick_instance_id!(self)
|
66
|
+
end
|
67
|
+
##
|
68
|
+
# Get the GUID
|
69
|
+
def get_guid()
|
70
|
+
SDL2.joystick_get_guid!(self)
|
71
|
+
end
|
72
|
+
##
|
73
|
+
# Event state
|
74
|
+
# @param - state
|
75
|
+
# == SDL2::Event::STATE::QUERY [default]: Returns current state
|
76
|
+
# == SDL2::Event::STATE::IGNORE : Disables event dispatching
|
77
|
+
# == SDL2::Event::STATE::ENABLE : Enables event dispatching
|
78
|
+
# @returns - true if events enabled
|
79
|
+
def event_state(state = SDL2::Event::STATE::QUERY)
|
80
|
+
SDL2.joystick_event_state(state)
|
81
|
+
end
|
82
|
+
|
15
83
|
end
|
16
84
|
|
17
85
|
# A structure that encodes the stable unique id for a joystick device
|
@@ -22,82 +90,40 @@ module SDL2
|
|
22
90
|
typedef :int32, :joystick_id
|
23
91
|
typedef :int32, :joystick_index # Dunno
|
24
92
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
api :SDL_JoystickGetGUID, [Joystick.by_ref], JoystickGUID
|
43
|
-
##
|
44
|
-
#
|
45
|
-
api :SDL_JoystickGetGUIDString, [JoystickGUID.by_value, :pointer, :int], :void
|
46
|
-
##
|
47
|
-
#
|
48
|
-
api :SDL_JoystickGetGUIDFromString, [:string], JoystickGUID
|
49
|
-
##
|
50
|
-
#
|
51
|
-
api :SDL_JoystickGetAttached, [Joystick.by_ref], :bool
|
52
|
-
##
|
53
|
-
#
|
54
|
-
api :SDL_JoystickInstanceID, [Joystick.by_ref], :joystick_id
|
55
|
-
##
|
56
|
-
#
|
57
|
-
api :SDL_JoystickNumAxes, [Joystick.by_ref], :int
|
58
|
-
##
|
59
|
-
#
|
60
|
-
api :SDL_JoystickNumBalls, [Joystick.by_ref], :int
|
61
|
-
##
|
62
|
-
#
|
63
|
-
api :SDL_JoystickNumHats, [Joystick.by_ref], :int
|
64
|
-
##
|
65
|
-
#
|
66
|
-
api :SDL_JoystickNumButtons, [Joystick.by_ref], :int
|
67
|
-
##
|
68
|
-
#
|
69
|
-
api :SDL_JoystickUpdate, [], :void
|
70
|
-
##
|
71
|
-
#
|
72
|
-
api :SDL_JoystickEventState, [:int], :int
|
73
|
-
##
|
74
|
-
#
|
75
|
-
api :SDL_JoystickGetAxis, [Joystick.by_ref, :int], :int16
|
93
|
+
api :SDL_NumJoysticks, [], :int, {error: true, filter: OK_WHEN_GTE_ZERO}
|
94
|
+
api :SDL_JoystickNameForIndex, [:int], :string, {error: true, filter: OK_WHEN_NOT_NULL}
|
95
|
+
api :SDL_JoystickOpen, [:int], Joystick.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
96
|
+
api :SDL_JoystickName, [Joystick.by_ref], :string
|
97
|
+
api :SDL_JoystickGetDeviceGUID, [:int], JoystickGUID.ptr
|
98
|
+
api :SDL_JoystickGetGUID, [Joystick.by_ref], JoystickGUID.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
99
|
+
api :SDL_JoystickGetGUIDString, [JoystickGUID.by_value, :pointer, :int], :void
|
100
|
+
api :SDL_JoystickGetGUIDFromString, [:string], JoystickGUID.ptr
|
101
|
+
api :SDL_JoystickGetAttached, [Joystick.by_ref], :bool
|
102
|
+
api :SDL_JoystickInstanceID, [Joystick.by_ref], :joystick_id, {error: true, filter: OK_WHEN_GTE_ZERO}
|
103
|
+
api :SDL_JoystickNumAxes, [Joystick.by_ref], :int, {error: true, filter: OK_WHEN_GTE_ZERO}
|
104
|
+
api :SDL_JoystickNumBalls, [Joystick.by_ref], :int, {error: true, filter: OK_WHEN_GTE_ZERO}
|
105
|
+
api :SDL_JoystickNumHats, [Joystick.by_ref], :int, {error: true, filter: OK_WHEN_GTE_ZERO}
|
106
|
+
api :SDL_JoystickNumButtons, [Joystick.by_ref], :int, {error: true, filter: OK_WHEN_GTE_ZERO}
|
107
|
+
api :SDL_JoystickUpdate, [], :void
|
108
|
+
api :SDL_JoystickEventState, [:int], :bool
|
109
|
+
api :SDL_JoystickGetAxis, [Joystick.by_ref, :int], :int16, {error: true, filter: OK_WHEN_NOT_ZERO}
|
76
110
|
|
77
111
|
# Hat positions
|
78
112
|
module HAT
|
79
113
|
include EnumerableConstants
|
80
|
-
CENTERED
|
81
|
-
UP
|
82
|
-
RIGHT
|
83
|
-
DOWN
|
84
|
-
LEFT
|
85
|
-
RIGHTUP
|
86
|
-
RIGHTDOWN
|
87
|
-
LEFTUP
|
88
|
-
LEFTDOWN
|
114
|
+
CENTERED = 0x00
|
115
|
+
UP = 0x01
|
116
|
+
RIGHT = 0x02
|
117
|
+
DOWN = 0x04
|
118
|
+
LEFT = 0x08
|
119
|
+
RIGHTUP = RIGHT | UP
|
120
|
+
RIGHTDOWN = RIGHT | DOWN
|
121
|
+
LEFTUP = LEFT | UP
|
122
|
+
LEFTDOWN = LEFT | DOWN
|
89
123
|
end
|
90
124
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
#
|
96
|
-
api :SDL_JoystickGetBall, [Joystick.by_ref, :int, IntStruct.by_ref, IntStruct.by_ref], :int
|
97
|
-
##
|
98
|
-
#
|
99
|
-
api :SDL_JoystickGetButton, [Joystick.by_ref, :int], :uint8
|
100
|
-
##
|
101
|
-
#
|
102
|
-
api :SDL_JoystickClose, [Joystick.by_ref], :void
|
125
|
+
api :SDL_JoystickGetHat, [Joystick.by_ref, :int], :uint8
|
126
|
+
api :SDL_JoystickGetBall, [Joystick.by_ref, :int, TypedPointer::Int.by_ref, TypedPointer::Int.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
|
127
|
+
api :SDL_JoystickGetButton, [Joystick.by_ref, :int], :uint8
|
128
|
+
api :SDL_JoystickClose, [Joystick.by_ref], :void
|
103
129
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'sdl2/joystick/components'
|
2
|
+
module SDL2
|
3
|
+
##
|
4
|
+
# A joystick may have many Axes
|
5
|
+
class Joystick
|
6
|
+
##
|
7
|
+
# Enumerates axes on a joystick.
|
8
|
+
class Axes < Components
|
9
|
+
##
|
10
|
+
# How many Axes are there?
|
11
|
+
def count
|
12
|
+
SDL2::joystick_num_axes(@joystick)
|
13
|
+
end
|
14
|
+
##
|
15
|
+
# Axis accessor via index
|
16
|
+
# @returns Integer -32768...32767
|
17
|
+
def [](idx)
|
18
|
+
SDL2::joystick_get_axis(@joystick,idx)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sdl2/joystick/components'
|
2
|
+
module SDL2
|
3
|
+
##
|
4
|
+
# A Joystick may have many balls.
|
5
|
+
class Joystick
|
6
|
+
##
|
7
|
+
# Enumerates buttons on a joystick.
|
8
|
+
class Balls < Components
|
9
|
+
##
|
10
|
+
# How many buttons are there?
|
11
|
+
def count
|
12
|
+
SDL2::joystick_num_balls(@joystick)
|
13
|
+
end
|
14
|
+
##
|
15
|
+
# Button accessor via index
|
16
|
+
# @returns [DeltaX, DeltaY] integers
|
17
|
+
def [](idx)
|
18
|
+
dx, dy = SDL2::TypedPointer::Int.new, SDL2::TypedPointer::Int.new
|
19
|
+
SDL2::joystick_get_ball(@joystick,idx, dx, dy)
|
20
|
+
[dx.value, dy.value]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'sdl2/joystick/components'
|
2
|
+
module SDL2
|
3
|
+
##
|
4
|
+
# A Joystick may have many buttons.
|
5
|
+
class Joystick
|
6
|
+
##
|
7
|
+
# Enumerates buttons on a joystick.
|
8
|
+
class Buttons < Components
|
9
|
+
##
|
10
|
+
# How many buttons are there?
|
11
|
+
def count
|
12
|
+
SDL2::joystick_num_buttons(@joystick)
|
13
|
+
end
|
14
|
+
##
|
15
|
+
# Button accessor via index
|
16
|
+
# @returns Integer {0=>RELEASED,1=>PRESSED}
|
17
|
+
def [](idx)
|
18
|
+
SDL2::joystick_get_button(@joystick,idx)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|