sdl2_ffi 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe SDL2::Keyboard do
|
4
|
+
before :each do
|
5
|
+
SDL2.init(:VIDEO)
|
6
|
+
@window = SDL2::Window.create()
|
7
|
+
SDL2.pump_events
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return a focused window' do
|
11
|
+
SDL2::Keyboard.get_focus.should be_a(SDL2::Window)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return an array of integers' do
|
15
|
+
skip 'TODO: Keyboard#get_state'
|
16
|
+
#binding.pry
|
17
|
+
end
|
18
|
+
|
19
|
+
after :each do
|
20
|
+
SDL2.quit
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe SDL2 do
|
4
|
+
it 'should have the SDL_mouse.h API' do
|
5
|
+
[
|
6
|
+
:create_color_cursor!,
|
7
|
+
].each do |function|
|
8
|
+
SDL2.should respond_to(function)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe SDL2::Cursor do
|
14
|
+
it 'can create color cursors' do
|
15
|
+
skip 'supported yet?' do
|
16
|
+
SDL2::Cursor.should respond_to(:create_color_cursor)
|
17
|
+
finger = SDL2::Image.load(img_path('finger.png'))
|
18
|
+
@cursor = SDL2::Cursor.create_color_cursor(finger,finger.w/2,finger.h/2)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe SDL2 do
|
4
|
+
it 'should have the renderer api' do
|
5
|
+
[
|
6
|
+
:create_renderer!,
|
7
|
+
:create_software_renderer!,
|
8
|
+
:create_texture!,
|
9
|
+
:create_texture_from_surface!,
|
10
|
+
:create_window_and_renderer!,
|
11
|
+
:destroy_renderer,
|
12
|
+
:destroy_texture,
|
13
|
+
:get_num_render_drivers!,
|
14
|
+
:get_render_draw_blend_mode!,
|
15
|
+
:get_render_draw_color!,
|
16
|
+
:get_render_driver_info!,
|
17
|
+
:get_render_target,
|
18
|
+
:get_renderer!,
|
19
|
+
:get_renderer_info!,
|
20
|
+
:get_renderer_output_size!,
|
21
|
+
:get_texture_alpha_mod!,
|
22
|
+
:get_texture_color_mod!,
|
23
|
+
:get_texture_blend_mode!,
|
24
|
+
:lock_texture!,
|
25
|
+
:query_texture!,
|
26
|
+
:render_clear!,
|
27
|
+
:render_copy!,
|
28
|
+
:render_copy_ex!,
|
29
|
+
:render_draw_line!,
|
30
|
+
:render_draw_lines!,
|
31
|
+
:render_draw_point!,
|
32
|
+
:render_draw_points!,
|
33
|
+
:render_draw_rect!,
|
34
|
+
:render_draw_rects!,
|
35
|
+
:render_fill_rect!,
|
36
|
+
:render_fill_rects!,
|
37
|
+
:render_get_clip_rect,
|
38
|
+
:render_get_logical_size,
|
39
|
+
:render_get_scale,
|
40
|
+
:render_get_viewport,
|
41
|
+
:render_present,
|
42
|
+
:render_read_pixels!,
|
43
|
+
:render_set_clip_rect!,
|
44
|
+
:render_set_logical_size!,
|
45
|
+
:render_set_scale!,
|
46
|
+
:render_set_viewport!,
|
47
|
+
:render_target_supported?,
|
48
|
+
:set_render_draw_blend_mode!,
|
49
|
+
:set_render_draw_color!,
|
50
|
+
:set_render_target!,
|
51
|
+
:render_set_clip_rect!,
|
52
|
+
:set_texture_alpha_mod!,
|
53
|
+
:set_texture_blend_mode!,
|
54
|
+
:set_texture_color_mod!,
|
55
|
+
:unlock_texture,
|
56
|
+
:update_texture!,
|
57
|
+
].each do |method|
|
58
|
+
SDL2.should respond_to(method)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
module SDL2
|
4
|
+
|
5
|
+
describe Renderer do
|
6
|
+
before :each do
|
7
|
+
SDL2.init(:VIDEO)
|
8
|
+
@window = SDL2::Window.create()
|
9
|
+
@renderer = SDL2::Renderer.create(@window)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'could have many drivers' do
|
13
|
+
SDL2::Renderer::Drivers.count.should be_a(Integer)
|
14
|
+
SDL2::Renderer::Drivers.count.should >= 0
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have a draw_color' do
|
18
|
+
@renderer.draw_color.should be_a(SDL2::Color)
|
19
|
+
@renderer.draw_color = SDL2::Color.create(r: 255)
|
20
|
+
@renderer.draw_color.r.should == 255
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have a draw blend mode' do
|
24
|
+
@renderer.should respond_to(:draw_blend_mode)
|
25
|
+
@renderer.draw_blend_mode= :BLEND
|
26
|
+
@renderer.draw_blend_mode.should == :BLEND
|
27
|
+
@renderer.draw_blend_mode= :NONE
|
28
|
+
@renderer.draw_blend_mode.should == :NONE
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have an info' do
|
32
|
+
@renderer.should respond_to(:info)
|
33
|
+
@renderer.info.should be_a(SDL2::RendererInfo)
|
34
|
+
@renderer.info.should_not be_null
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have an output size' do
|
38
|
+
@renderer.should respond_to(:output_size)
|
39
|
+
@renderer.output_size.count.should == 2
|
40
|
+
@renderer.output_size.should == @window.current_size
|
41
|
+
@renderer.output_size.each{|val|val.should be_a(Integer)}
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should have a target' do
|
45
|
+
@renderer.should respond_to(:target)
|
46
|
+
@renderer.should respond_to(:target=)
|
47
|
+
@renderer.target.should be_nil
|
48
|
+
skip "TODO: SDL Error: glFramebufferTexture2DEXT() failed" #TODO: Investigate SDL Error: glFramebufferTexture2DEXT() failed
|
49
|
+
binding.pry
|
50
|
+
texture = SDL2::Texture.create(@renderer, :RGBA8888, :TARGET, 128, 128)
|
51
|
+
@renderer.target=texture
|
52
|
+
@renderer.target.should == texture
|
53
|
+
@renderer.target=nil
|
54
|
+
@renderer.target.should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should be able to clear' do
|
58
|
+
@renderer.should respond_to(:clear)
|
59
|
+
@renderer.draw_color = SDL2::Color.create(g: 255)
|
60
|
+
@renderer.clear
|
61
|
+
SDL2.render_present(@renderer)
|
62
|
+
|
63
|
+
verify(format: :png){@window.renderer_to_surface}
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should be able to create textures from surfaces' do
|
67
|
+
@renderer.should respond_to(:texture_from_surface)
|
68
|
+
sur_hello = @window.surface.convert(SDL2::Image.load!(img_path('hello.bmp')))
|
69
|
+
@renderer.texture_from_surface(sur_hello).should be_a(SDL2::Texture)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should be able to render textures' do
|
73
|
+
@renderer.should respond_to(:copy)
|
74
|
+
txt_hello = @renderer.texture_from_surface(@window.surface.convert(SDL2::Image.load!(img_path('hello.bmp'))))
|
75
|
+
@renderer.copy(txt_hello, {w: 200, h: 200}, {x: 100, y: 100, w: 100, h: 100})
|
76
|
+
SDL2.render_present(@renderer)
|
77
|
+
verify(){@window.renderer_to_surface}
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should be able to rotate and flip while rendering textures' do
|
81
|
+
@renderer.should respond_to(:copy_ex)
|
82
|
+
txt_hello = @renderer.texture_from_surface(@window.surface.convert(SDL2::Image.load!(img_path('hello.bmp'))))
|
83
|
+
@renderer.copy_ex(txt_hello, nil, nil, 12, {x: 12, y: 12}, :BOTH )
|
84
|
+
verify(){@window.renderer_to_surface}
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should be able to draw a single pixel line' do
|
88
|
+
@renderer.should respond_to(:draw_line)
|
89
|
+
@renderer.draw_color = SDL2::Color.create(r: 255,g: 255,b: 255)
|
90
|
+
@renderer.draw_line(100,100,200,200)
|
91
|
+
SDL2.render_present(@renderer)
|
92
|
+
verify(){@window.renderer_to_surface}
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should be able to draw a line connecting many points' do
|
96
|
+
@renderer.should respond_to(:draw_lines)
|
97
|
+
points = [[5,5],[1,123],[290,33],[27,222]]
|
98
|
+
@renderer.draw_color = SDL2::Color.create(g: 255)
|
99
|
+
# draw lines expects each point to be specified as an argument,
|
100
|
+
# no limit to the number of points that can be specified at once
|
101
|
+
# that I know of using this method.
|
102
|
+
@renderer.draw_lines(*points)
|
103
|
+
SDL2.render_present(@renderer)
|
104
|
+
|
105
|
+
verify(){@window.renderer_to_surface}
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should be able to draw a point' do
|
109
|
+
@renderer.should respond_to(:draw_point)
|
110
|
+
@renderer.draw_color = SDL2::Color.create(r: 255)
|
111
|
+
@renderer.draw_point(160,120)
|
112
|
+
SDL2.render_present(@renderer)
|
113
|
+
verify(){@window.renderer_to_surface}
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should be able to draw points' do
|
117
|
+
# You can pass many kinds of points.
|
118
|
+
points = [[88,44],SDL2::Point.cast([128,40]),{x: 300, y: 444}]
|
119
|
+
@renderer.draw_color = SDL2::Color.create(b: 255)
|
120
|
+
@renderer.draw_points(*points)
|
121
|
+
SDL2.render_present(@renderer)
|
122
|
+
verify(){@window.renderer_to_surface}
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should be able to draw a single rectangle' do
|
126
|
+
@renderer.should respond_to(:draw_rect)
|
127
|
+
@renderer.draw_color = {r: 255}
|
128
|
+
@renderer.draw_rect([10,10,100,100])
|
129
|
+
@renderer.draw_color = {g: 255}
|
130
|
+
@renderer.draw_rect({x: 40, y: 40, w: 64, h: 128})
|
131
|
+
@renderer.draw_color = {b: 255}
|
132
|
+
@renderer.draw_rect(SDL2::Rect.cast({x: 100, y: 100, w: 128, h: 64}))
|
133
|
+
SDL2.render_present(@renderer)
|
134
|
+
verify(){@window.renderer_to_surface}
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
it 'should be able to draw many rectangles at once' do
|
139
|
+
@renderer.should respond_to(:draw_rects)
|
140
|
+
# Should be able to handle many kinds of cords.
|
141
|
+
cords = [[10,10,100,100],{x: 40, y: 40, w: 64, h: 128},SDL2::Rect.cast({x: 100, y: 100, w: 128, h: 64})]
|
142
|
+
@renderer.draw_color = {r: 255, g: 255, b: 255}
|
143
|
+
@renderer.draw_rects(*cords)
|
144
|
+
SDL2.render_present(@renderer)
|
145
|
+
verify(){@window.renderer_to_surface}
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should be able to draw a single filled rectangle' do
|
149
|
+
@renderer.should respond_to(:fill_rect)
|
150
|
+
rect = {x: 123, y: 132, w: 200, h: 200}
|
151
|
+
@renderer.fill_rect(rect)
|
152
|
+
@renderer.present
|
153
|
+
verify(){@window.renderer_to_surface}
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should be able to draw many filled rectangles' do
|
157
|
+
rects = [
|
158
|
+
[21,32,124,200],
|
159
|
+
[64,11,15,66],
|
160
|
+
[222,100,80,100]
|
161
|
+
]
|
162
|
+
@renderer.fill_rects(*rects)
|
163
|
+
@renderer.present
|
164
|
+
verify(){@window.renderer_to_surface}
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should have a clip rect' do
|
168
|
+
@renderer.should respond_to(:clip_rect)
|
169
|
+
@renderer.should respond_to(:clip_rect=)
|
170
|
+
@renderer.clip_rect.should be_a(SDL2::Rect)
|
171
|
+
@renderer.clip_rect.x.should == 0
|
172
|
+
@renderer.clip_rect.y.should == 0
|
173
|
+
@renderer.clip_rect.w.should == 0
|
174
|
+
@renderer.clip_rect.h.should == 0
|
175
|
+
@renderer.clip_rect = {x: 128, y: 128, w: 64, h: 32}
|
176
|
+
|
177
|
+
@renderer.clip_rect.x.should == 128
|
178
|
+
@renderer.clip_rect.y.should == 128
|
179
|
+
@renderer.clip_rect.w.should == 64
|
180
|
+
@renderer.clip_rect.h.should == 32
|
181
|
+
@renderer.fill_rect x: 100, y: 100, w: 100, h: 100
|
182
|
+
@renderer.present
|
183
|
+
verify(){@window.renderer_to_surface}
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should have a logical size' do
|
187
|
+
@renderer.should respond_to(:logical_size)
|
188
|
+
@renderer.should respond_to(:logical_size=)
|
189
|
+
@renderer.logical_size.should == [0, 0]
|
190
|
+
@renderer.logical_size = [128, 128]
|
191
|
+
@renderer.logical_size.should == [128, 128]
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should have a scale' do
|
195
|
+
@renderer.should respond_to(:scale)
|
196
|
+
@renderer.should respond_to(:scale=)
|
197
|
+
@renderer.scale.should == [1.0, 1.0]
|
198
|
+
@renderer.scale = [2.0, 3.0]
|
199
|
+
@renderer.scale.should == [2.0, 3.0]
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should have a viewport' do
|
203
|
+
@renderer.should respond_to(:viewport)
|
204
|
+
@renderer.should respond_to(:viewport=)
|
205
|
+
@renderer.viewport.should == SDL2::Rect.cast([0,0,*@window.current_size])
|
206
|
+
@renderer.viewport = {x: 20, y: 20, w: 128, h: 128}
|
207
|
+
@renderer.viewport.x.should == 20
|
208
|
+
@renderer.viewport.y.should == 20
|
209
|
+
@renderer.viewport.w.should == 128
|
210
|
+
@renderer.viewport.h.should == 128
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should signal if target rendering is supported' do
|
214
|
+
@renderer.should respond_to(:target_supported?)
|
215
|
+
# TODO: How else should we test this?
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
after :each do
|
220
|
+
SDL2.quit
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
module SDL2
|
4
|
+
|
5
|
+
describe Texture do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
SDL2.init!(:VIDEO)
|
9
|
+
@window = SDL2::Window.create()
|
10
|
+
@renderer = SDL2::Renderer.create(@window)
|
11
|
+
@texture = @renderer.texture_from_surface(SDL2::Image.load(img_path('hello.bmp')))
|
12
|
+
#@texture = SDL2::Texture.create(@renderer, :RGBA8888, :STATIC, 64,64)
|
13
|
+
#@renderer.present
|
14
|
+
#binding.pry
|
15
|
+
#SDL2::Debug.enable(SDL2::Struct)
|
16
|
+
#SDL2::Debug.enable(SDL2)
|
17
|
+
end
|
18
|
+
|
19
|
+
after :each do
|
20
|
+
#@texture.destroy
|
21
|
+
#@renderer.destroy
|
22
|
+
SDL2.quit
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has an alpha_mod' do
|
26
|
+
@texture.should respond_to(:alpha_mod)
|
27
|
+
@texture.should respond_to(:alpha_mod=)
|
28
|
+
@texture.alpha_mod.should == 255
|
29
|
+
@texture.alpha_mod = 128
|
30
|
+
@texture.alpha_mod.should == 128
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has a blend_mode' do
|
34
|
+
@texture.should respond_to(:blend_mode)
|
35
|
+
@texture.should respond_to(:blend_mode=)
|
36
|
+
@texture.blend_mode.should == :BLEND
|
37
|
+
@texture.blend_mode = SDL2::BLENDMODE::ADD
|
38
|
+
@texture.blend_mode.should == :ADD
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'has a color_mod' do
|
42
|
+
@texture.should respond_to(:color_mod)
|
43
|
+
@texture.should respond_to(:color_mod=)
|
44
|
+
@texture.color_mod.should == [255,255,255]
|
45
|
+
@texture.color_mod = [32,64,128]
|
46
|
+
@texture.color_mod.should == [32,64,128]
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can be locked' do
|
50
|
+
@texture.should respond_to(:lock)
|
51
|
+
@texture.should respond_to(:unlock)
|
52
|
+
skip 'need to mess with streaming textures'
|
53
|
+
@texture.lock
|
54
|
+
@texture.unlock
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can be queried' do
|
58
|
+
query = @texture.query
|
59
|
+
query.length.should == 4
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '../../
|
1
|
+
require_relative '../../spec_helper'
|
2
2
|
|
3
3
|
require 'sdl2/init'
|
4
4
|
require 'sdl2/video'
|
@@ -9,15 +9,15 @@ require 'sdl2/video'
|
|
9
9
|
# What the Ruby version of the SDL_video.h API should look like
|
10
10
|
#
|
11
11
|
VIDEO_API = [
|
12
|
-
:get_num_video_drivers
|
12
|
+
:get_num_video_drivers!,
|
13
13
|
:get_video_driver,
|
14
14
|
:video_init,
|
15
15
|
:video_quit,
|
16
16
|
:get_current_video_driver,
|
17
|
-
:get_num_video_displays
|
17
|
+
:get_num_video_displays!,
|
18
18
|
:get_display_name,
|
19
19
|
:get_display_bounds,
|
20
|
-
:get_num_display_modes
|
20
|
+
:get_num_display_modes!,
|
21
21
|
:get_display_mode,
|
22
22
|
:get_desktop_display_mode,
|
23
23
|
:get_current_display_mode,
|
@@ -83,88 +83,113 @@ VIDEO_API = [
|
|
83
83
|
]
|
84
84
|
|
85
85
|
describe SDL2 do
|
86
|
-
before do
|
87
|
-
assert(SDL2.init(SDL2::INIT::VIDEO) == 0, 'Video initialized.')
|
88
|
-
end
|
89
|
-
|
90
|
-
after do
|
91
|
-
SDL2.quit()
|
92
|
-
end
|
93
|
-
|
94
86
|
it 'has the video API' do
|
95
|
-
|
87
|
+
VIDEO_API.count.should == 70
|
96
88
|
VIDEO_API.each do |function|
|
97
|
-
|
89
|
+
SDL2.should respond_to(function)
|
98
90
|
end
|
99
91
|
end
|
92
|
+
end
|
100
93
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
SDL2.
|
105
|
-
assert SDL2.is_screen_saver_enabled
|
94
|
+
describe SDL2::Video do
|
95
|
+
before do
|
96
|
+
SDL2::Debug.enable(SDL2::Struct)
|
97
|
+
SDL2.init(:VIDEO)
|
106
98
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
99
|
+
after do
|
100
|
+
SDL2.quit
|
110
101
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
102
|
+
it 'can be initialized and shut down with default drivers' do
|
103
|
+
SDL2::Video.init("x11")
|
104
|
+
SDL2::Video.quit
|
114
105
|
end
|
115
106
|
|
116
|
-
it 'can
|
117
|
-
skip 'for
|
107
|
+
it 'can initialize each of the video drivers' do
|
108
|
+
skip 'Fails on dummy driver right now for me'
|
109
|
+
SDL2::Video::Drivers.each do |driver|
|
110
|
+
SDL2::Video.init(driver)
|
111
|
+
SDL2::Video.current_driver.should == driver
|
112
|
+
SDL2::Video.quit
|
113
|
+
end
|
118
114
|
end
|
115
|
+
end
|
119
116
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
117
|
+
describe SDL2::Video::Drivers do
|
118
|
+
before do
|
119
|
+
SDL2.init(:VIDEO)
|
120
|
+
end
|
121
|
+
after do
|
122
|
+
SDL2.quit
|
123
|
+
end
|
124
|
+
it 'can list the video drivers' do
|
125
|
+
SDL2::Video::Drivers.num.should >= 1
|
126
|
+
SDL2::Video::Drivers.each do |driver|
|
127
|
+
driver.should be_a(String)
|
124
128
|
end
|
129
|
+
end
|
125
130
|
|
126
|
-
|
127
|
-
assert_kind_of SDL2::Display, SDL2::Display.first
|
128
|
-
end
|
131
|
+
end
|
129
132
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
+
describe SDL2::ScreenSaver do
|
134
|
+
before do
|
135
|
+
SDL2.init(:VIDEO)
|
136
|
+
end
|
137
|
+
after do
|
138
|
+
SDL2.quit()
|
139
|
+
end
|
140
|
+
before :each do
|
141
|
+
SDL2::Video.init
|
142
|
+
end
|
143
|
+
after :each do
|
144
|
+
SDL2::Video.quit
|
145
|
+
end
|
146
|
+
it 'can manage the screen saver' do
|
147
|
+
SDL2::ScreenSaver.disable
|
148
|
+
SDL2::ScreenSaver.enabled?.should == false
|
149
|
+
SDL2::ScreenSaver.enable
|
150
|
+
SDL2::ScreenSaver.enabled?.should == true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe SDL2::Display do
|
155
|
+
before(:each){SDL2.init!(:VIDEO)}
|
156
|
+
after(:each){SDL2.quit}
|
157
|
+
it 'can count the displays attached' do
|
158
|
+
sdl_count = SDL2.get_num_video_displays()
|
159
|
+
SDL2::Display.count.should == sdl_count
|
160
|
+
end
|
133
161
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
162
|
+
it 'can get the first display' do
|
163
|
+
SDL2::Display.first.should be_a(SDL2::Display)
|
164
|
+
end
|
138
165
|
|
166
|
+
it 'can get the display bounds' do
|
167
|
+
SDL2::Display.first.bounds!.should be_a(SDL2::Rect)
|
139
168
|
end
|
140
169
|
|
170
|
+
it 'has many display modes' do
|
171
|
+
SDL2::Display.first.modes.count.should > 0
|
172
|
+
SDL2::Display.first().modes.first.should be_a(SDL2::Display::Mode)
|
173
|
+
end
|
141
174
|
it 'can get the closest display mode' do
|
142
175
|
closest_display_mode_found = nil # for now
|
143
176
|
|
144
177
|
SDL2::Display::Mode.new do |wanted|
|
145
|
-
|
146
178
|
wanted.format = 0 #SDL2::PIXELFORMAT_RGBA8888 #TODO: Import PIXELFORMAT
|
147
179
|
# constants?
|
148
180
|
wanted.w = 640
|
149
181
|
wanted.h = 480
|
150
182
|
wanted.refresh_rate = 60
|
151
183
|
wanted.driverdata = nil
|
152
|
-
|
153
|
-
closest_display_mode_found = SDL2::Display.first.closest_display_mode!(wanted)
|
184
|
+
closest_display_mode_found = SDL2::Display.first.closest_display_mode(wanted)
|
154
185
|
end # This should automatically dispose of the display_mode struct we created
|
155
186
|
# as wanted
|
156
|
-
|
187
|
+
closest_display_mode_found.should be_a(SDL2::Display::Mode)
|
157
188
|
|
158
189
|
end
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
# assert_kind_of SDL2::GLContext, context
|
166
|
-
# end
|
167
|
-
#
|
168
|
-
# end
|
169
|
-
|
170
|
-
end
|
190
|
+
|
191
|
+
it 'can list the current display mode' do
|
192
|
+
SDL2::Display.first.current_display_mode.should be_a(SDL2::Display::Mode)
|
193
|
+
#binding.pry
|
194
|
+
end
|
195
|
+
end
|