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/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_render_textures.approved.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png
ADDED
Binary file
|
data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -8,14 +8,13 @@ require 'sdl2/ttf'
|
|
8
8
|
describe "LazyFoo.net: Lesson 01: Hello World" do
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
11
|
+
expect(init(:EVERYTHING)).to eq(0)
|
12
12
|
|
13
|
-
@window = Window.create(subject, :
|
13
|
+
@window = Window.create(title: subject, width: 640, height: 480, flags: :SHOWN)
|
14
14
|
|
15
15
|
@screen = @window.surface
|
16
16
|
@screen.fill_rect(@screen.rect, [0,0,0,SDL2::ALPHA_OPAQUE])
|
17
|
-
|
18
|
-
@hello = @screen.convert(SDL2.load_bmp!(img_path('hello.bmp')))
|
17
|
+
@hello = @screen.convert(SDL2::Image.load!(img_path('hello.bmp')))
|
19
18
|
@screen.blit_in(@hello)
|
20
19
|
@hello.blit_out(@screen)
|
21
20
|
@window.update_surface
|
@@ -30,7 +29,7 @@ describe "LazyFoo.net: Lesson 01: Hello World" do
|
|
30
29
|
|
31
30
|
it 'created a window surface' do
|
32
31
|
expect(@window).to be_a(Window)
|
33
|
-
expect(@window.null?).to
|
32
|
+
expect(@window.null?).to be_falsey
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'draws hello to the window surface' do
|
@@ -39,7 +38,6 @@ describe "LazyFoo.net: Lesson 01: Hello World" do
|
|
39
38
|
end
|
40
39
|
|
41
40
|
after do
|
42
|
-
@hello.free
|
43
41
|
quit()
|
44
42
|
end
|
45
43
|
|
@@ -12,11 +12,12 @@ describe "LazyFoo.net: Lesson 02: Optimized Images" do
|
|
12
12
|
HEIGHT = 480
|
13
13
|
# BPP = 32 # TODO: Is this still needed?
|
14
14
|
before do
|
15
|
-
|
15
|
+
init(:VIDEO)
|
16
|
+
@window = Window.create(title: subject, width: WIDTH, height: HEIGHT, flags: :SHOWN)
|
16
17
|
@screen = @window.surface
|
17
18
|
|
18
19
|
def load_image(file)
|
19
|
-
@screen.convert(SDL2.
|
20
|
+
@screen.convert(SDL2::Image.load!(file))
|
20
21
|
end
|
21
22
|
|
22
23
|
@background = load_image(img_path('background.bmp'))
|
@@ -33,8 +34,6 @@ describe "LazyFoo.net: Lesson 02: Optimized Images" do
|
|
33
34
|
|
34
35
|
after do
|
35
36
|
|
36
|
-
@background.free
|
37
|
-
@message.free
|
38
37
|
|
39
38
|
quit
|
40
39
|
|
@@ -8,7 +8,7 @@ describe "LazyFoo.net: Lesson 03: Extension Libraries" do
|
|
8
8
|
|
9
9
|
before do
|
10
10
|
SDL2.init!(:EVERYTHING)
|
11
|
-
@window = Window.create(subject, :
|
11
|
+
@window = Window.create(title: subject, width: 640, height: 480)
|
12
12
|
|
13
13
|
@screen = @window.surface
|
14
14
|
@screen.fill_rect(@screen.rect, [0,0,0,SDL2::ALPHA_OPAQUE])
|
@@ -26,7 +26,7 @@ describe "LazyFoo.net: Lesson 03: Extension Libraries" do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
after do
|
29
|
-
|
29
|
+
quit
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -9,7 +9,7 @@ describe "LazyFoo.net: Lesson 04: Event Driven Programming" do
|
|
9
9
|
before do
|
10
10
|
SDL2.init!(:EVERYTHING)
|
11
11
|
|
12
|
-
@window = Window.create(subject, :
|
12
|
+
@window = Window.create(title: subject, width: 640, height: 480)
|
13
13
|
|
14
14
|
@screen = @window.surface
|
15
15
|
@screen.fill_rect(@screen.rect, [0,0,0,SDL2::ALPHA_OPAQUE])
|
@@ -29,7 +29,7 @@ describe "LazyFoo.net: Lesson 04: Event Driven Programming" do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
my_quit_event = Event.cast(
|
32
|
+
my_quit_event = Event.cast(Event::Quit.cast(type: :QUIT))
|
33
33
|
|
34
34
|
|
35
35
|
SDL2.push_event!(my_quit_event)
|
@@ -45,7 +45,7 @@ describe "LazyFoo.net: Lesson 04: Event Driven Programming" do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'set the quit flag' do
|
48
|
-
expect(@quit).to
|
48
|
+
expect(@quit).to be_truthy
|
49
49
|
end
|
50
50
|
|
51
51
|
after do
|
@@ -8,7 +8,7 @@ describe "LazyFoo.net: Lesson 05: Color Keying" do
|
|
8
8
|
|
9
9
|
before do
|
10
10
|
SDL2::init!(:EVERYTHING)
|
11
|
-
@window = Window.create(subject, :
|
11
|
+
@window = Window.create(title: subject, width: 640, height: 480)
|
12
12
|
@screen = @window.surface
|
13
13
|
|
14
14
|
@background = @screen.convert(Image.load!(img_path('background.jpg')))
|
@@ -5,7 +5,7 @@ require_relative 'lazy_foo_helper'
|
|
5
5
|
describe "LazyFoo.net: Lesson 06: Clip Blitting and Sprite Sheets" do
|
6
6
|
before do
|
7
7
|
SDL2.init!(:EVERYTHING)
|
8
|
-
@window = Window.create(subject, :
|
8
|
+
@window = Window.create(title: subject, width: 640, height: 480)
|
9
9
|
@screen = @window.surface
|
10
10
|
@screen.fill_rect(@screen.rect, [0,0,0,ALPHA_OPAQUE])
|
11
11
|
|
@@ -10,7 +10,7 @@ describe "LazyFoo.net: Lesson 07: True Type Fonts" do
|
|
10
10
|
|
11
11
|
#binding.pry
|
12
12
|
SDL2.init!(:EVERYTHING)
|
13
|
-
@window = Window.create(subject, :
|
13
|
+
@window = Window.create(title: subject, width: 640, height: 480)
|
14
14
|
@screen = @window.surface
|
15
15
|
TTF.init!
|
16
16
|
|
@@ -40,11 +40,12 @@ describe "LazyFoo.net: Lesson 07: True Type Fonts" do
|
|
40
40
|
@background.free
|
41
41
|
@message.free
|
42
42
|
@font.free
|
43
|
+
TTF.quit
|
43
44
|
quit()
|
44
45
|
end
|
45
46
|
|
46
47
|
it "loads a true type font" do
|
47
|
-
expect(@font).to be_a
|
48
|
+
expect(@font).to be_a(SDL2::TTF::Font)
|
48
49
|
end
|
49
50
|
|
50
51
|
it "writes a message to a surface" do
|
@@ -8,7 +8,8 @@ describe "LazyFoo.net: Lesson 08: Key Presses" do
|
|
8
8
|
|
9
9
|
before do
|
10
10
|
SDL2.init!(:EVERYTHING)
|
11
|
-
|
11
|
+
SDL2::TTF.init
|
12
|
+
@window = Window.create(title: subject, width: 640, height: 480)
|
12
13
|
@screen = @window.surface
|
13
14
|
|
14
15
|
@background = @screen.convert(Image.load!(img_path('background.png')))
|
@@ -23,11 +24,11 @@ describe "LazyFoo.net: Lesson 08: Key Presses" do
|
|
23
24
|
|
24
25
|
# Simulated user events. If you don't want to simulate, comment line:77
|
25
26
|
@events = [
|
26
|
-
SDL2::
|
27
|
-
SDL2::
|
28
|
-
SDL2::
|
29
|
-
SDL2::
|
30
|
-
SDL2::
|
27
|
+
SDL2::Event::Keyboard.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :UP)),
|
28
|
+
SDL2::Event::Keyboard.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :DOWN)),
|
29
|
+
SDL2::Event::Keyboard.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :LEFT)),
|
30
|
+
SDL2::Event::Keyboard.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :RIGHT)),
|
31
|
+
SDL2::Event::Quit.cast(type: :QUIT)
|
31
32
|
|
32
33
|
]
|
33
34
|
|
@@ -102,7 +103,8 @@ describe "LazyFoo.net: Lesson 08: Key Presses" do
|
|
102
103
|
|
103
104
|
|
104
105
|
after do
|
105
|
-
quit()
|
106
|
+
SDL2.quit()
|
107
|
+
SDL2::TTF.quit
|
106
108
|
end
|
107
109
|
|
108
110
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require_relative 'lazy_foo_helper'
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'bad_sdl/application'
|
4
|
+
require 'bad_sdl/engine'
|
4
5
|
|
5
|
-
class ButtonEngine < Engine
|
6
|
+
class ButtonEngine < BadSdl::Engine
|
6
7
|
OVER = 0
|
7
8
|
OUT = 1
|
8
9
|
DOWN = 2
|
@@ -23,10 +24,10 @@ class ButtonEngine < Engine
|
|
23
24
|
|
24
25
|
offset = Point.cast([event.motion.x, event.motion.y])
|
25
26
|
if @box.enclose_points(offset)
|
26
|
-
|
27
|
-
@clip = @clips[OVER]
|
27
|
+
SDL2::Debug.log(self){"Mouse OVER"}
|
28
|
+
@clip = @clips[OVER]
|
28
29
|
else
|
29
|
-
|
30
|
+
SDL2::Debug.log(self){"Mouse OUT"}
|
30
31
|
@clip = @clips[OUT]
|
31
32
|
end
|
32
33
|
end#on :MOUSEMOTION
|
@@ -51,7 +52,7 @@ class ButtonEngine < Engine
|
|
51
52
|
|
52
53
|
def paint_to(surface)
|
53
54
|
if @clip
|
54
|
-
|
55
|
+
SDL2::Debug.log(self){"Painting"}
|
55
56
|
|
56
57
|
@button_sheet.blit_out(surface, @box, @clip) if @clip
|
57
58
|
@clip = nil
|
@@ -69,15 +70,17 @@ end#ButtonEngine
|
|
69
70
|
describe "LazyFoo.net: Lesson 09: Mouse Events" do
|
70
71
|
|
71
72
|
before do
|
72
|
-
|
73
|
+
SDL2.init!(:EVERYTHING)
|
74
|
+
@application = BadSdl::Application.new()
|
73
75
|
@application.window.title = subject
|
74
76
|
@button = ButtonEngine.new(x: 170, y: 120, w: 320, h: 240)
|
75
77
|
@application.engines << @button
|
76
|
-
@application.loop(
|
78
|
+
@application.loop(5) #Prime it
|
77
79
|
end
|
78
80
|
|
79
81
|
after do
|
80
82
|
@application.quit()
|
83
|
+
SDL2.quit
|
81
84
|
end
|
82
85
|
|
83
86
|
it 'has a button sheet' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'lazy_foo_helper'
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'bad_sdl/application'
|
4
4
|
|
5
5
|
#ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson10/index.php
|
6
6
|
# Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
|
@@ -8,8 +8,8 @@ require 'sdl2/application'
|
|
8
8
|
describe "LazyFoo.net: Lesson 10: Key States" do
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
12
|
-
@application = Application.new
|
11
|
+
SDL2.init!(:EVERYTHING)
|
12
|
+
@application = BadSdl::Application.new
|
13
13
|
|
14
14
|
|
15
15
|
#binding.pry
|
@@ -17,10 +17,11 @@ describe "LazyFoo.net: Lesson 10: Key States" do
|
|
17
17
|
|
18
18
|
after do
|
19
19
|
@application.quit
|
20
|
-
|
20
|
+
SDL2.quit()
|
21
21
|
end
|
22
22
|
|
23
23
|
it "can get the key states" do
|
24
|
+
skip "TODO: SDL2::Keyboard#get_state"
|
24
25
|
@state = Keyboard.get_state
|
25
26
|
expect(@state.count).to eq(512)
|
26
27
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative 'lazy_foo_helper'
|
2
2
|
|
3
3
|
require 'sdl2/mixer'
|
4
|
-
require '
|
4
|
+
require 'bad_sdl/application'
|
5
5
|
require 'sdl2/ttf'
|
6
6
|
|
7
7
|
#ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson11/index.php
|
@@ -9,7 +9,7 @@ require 'sdl2/ttf'
|
|
9
9
|
|
10
10
|
describe "LazyFoo.net: Lesson 11: Playing sounds" do
|
11
11
|
|
12
|
-
class PlayingSoundsEngine <
|
12
|
+
class PlayingSoundsEngine < BadSdl::Engine
|
13
13
|
|
14
14
|
def initialize(opts = {})
|
15
15
|
# Initialize our engine
|
@@ -24,7 +24,7 @@ describe "LazyFoo.net: Lesson 11: Playing sounds" do
|
|
24
24
|
@background = Image.load!(img_path('background.png'))
|
25
25
|
|
26
26
|
@font = TTF::Font.open(fixture('fonts/GaroaHackerClubeBold.otf'), 30)
|
27
|
-
|
27
|
+
|
28
28
|
@music = Mixer::Music.load(fixture('music/beat.wav'))
|
29
29
|
|
30
30
|
@scratch = Mixer::Chunk.load_wav(fixture('sounds/scratch.wav'))
|
@@ -77,6 +77,14 @@ describe "LazyFoo.net: Lesson 11: Playing sounds" do
|
|
77
77
|
Mix::halt_music!()
|
78
78
|
true
|
79
79
|
end
|
80
|
+
|
81
|
+
# Quit the program
|
82
|
+
on({type: :KEYDOWN, key: {keysym: {sym: :Q}}}) do |event|
|
83
|
+
puts "Quit the program."
|
84
|
+
# Emit a QUIT Signal
|
85
|
+
Event.push(SDL2::QuitEvent.cast({type: :QUIT}))
|
86
|
+
end
|
87
|
+
|
80
88
|
end#initialize
|
81
89
|
|
82
90
|
def paint_to(surface)
|
@@ -88,10 +96,10 @@ describe "LazyFoo.net: Lesson 11: Playing sounds" do
|
|
88
96
|
end
|
89
97
|
|
90
98
|
before do
|
91
|
-
|
92
|
-
@app = Application.new(title: subject)
|
99
|
+
SDL2.init!(:EVERYTHING)
|
100
|
+
@app = BadSdl::Application.new(title: subject)
|
93
101
|
@app.engines << PlayingSoundsEngine.new()
|
94
|
-
|
102
|
+
|
95
103
|
@app.window.title = "Monitor Music"
|
96
104
|
|
97
105
|
end
|
@@ -105,12 +113,12 @@ describe "LazyFoo.net: Lesson 11: Playing sounds" do
|
|
105
113
|
#TTF::quit()
|
106
114
|
|
107
115
|
#SDL2::quit()
|
108
|
-
|
116
|
+
SDL2.quit()
|
109
117
|
end
|
110
118
|
|
111
119
|
it 'loads' do
|
112
|
-
#@app.loop(nil, delay:
|
113
|
-
|
120
|
+
#@app.loop(nil, delay: 1000)
|
121
|
+
skip "Don't know how to test this."
|
114
122
|
end
|
115
123
|
|
116
124
|
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
require_relative 'lazy_foo_helper'
|
2
2
|
|
3
3
|
require 'sdl2/ttf'
|
4
|
-
require '
|
4
|
+
require 'bad_sdl/application'
|
5
5
|
#binding.pry
|
6
|
-
require '
|
6
|
+
require 'bad_sdl/engine/block_engine'
|
7
7
|
|
8
8
|
#ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson12/index.php
|
9
9
|
# Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
|
10
10
|
|
11
|
-
describe "LazyFoo.net: Lesson
|
11
|
+
describe "LazyFoo.net: Lesson 12: Timing" do
|
12
12
|
|
13
13
|
before do
|
14
|
-
|
14
|
+
SDL2.init!(:EVERYTHING)
|
15
|
+
@app = BadSdl::Application.new()
|
15
16
|
|
16
|
-
@app.engines << @engine =
|
17
|
+
@app.engines << @engine = BadSdl::Engine::BlockEngine.new
|
17
18
|
|
18
19
|
@running = true
|
19
20
|
@start = SDL2::get_ticks()
|
@@ -46,11 +47,11 @@ describe "LazyFoo.net: Lesson 11: Playing sounds" do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
after do
|
49
|
-
|
50
|
+
SDL2.quit
|
50
51
|
end
|
51
52
|
|
52
53
|
it "works" do
|
53
|
-
|
54
|
+
skip "don't know how I should test this..."
|
54
55
|
@app.loop(nil, delay: 1000)
|
55
56
|
end
|
56
57
|
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative 'lazy_foo_helper'
|
2
|
+
require_relative 'timer'
|
3
|
+
|
4
|
+
require 'bad_sdl/application'
|
5
|
+
require 'bad_sdl/engine/block_engine'
|
6
|
+
require 'sdl2/ttf'
|
7
|
+
|
8
|
+
#ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson13/index.php
|
9
|
+
# Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
|
10
|
+
|
11
|
+
|
12
|
+
describe "LazyFoo.net: Lesson 03: Advanced Timers" do
|
13
|
+
|
14
|
+
before do
|
15
|
+
SDL2.init(:EVERYTHING)
|
16
|
+
@app = BadSdl::Application.new title: subject
|
17
|
+
@engine = BadSdl::Engine::BlockEngine.new
|
18
|
+
@app.engines << @engine
|
19
|
+
|
20
|
+
TTF::init!
|
21
|
+
|
22
|
+
@font = TTF::Font.open(FONT_PATH, 18)
|
23
|
+
@big_font = TTF::Font.open(FONT_PATH, 64)
|
24
|
+
|
25
|
+
@my_timmer = Timer.new
|
26
|
+
@msg_start_stop = @font.render_text_blended("Press S to start or stop the timer.")
|
27
|
+
@msg_pause = @font.render_text_blended("Press P to pause or unpause the timer")
|
28
|
+
|
29
|
+
@my_timer = Timer.new
|
30
|
+
|
31
|
+
@my_timer.start()
|
32
|
+
|
33
|
+
@app.on({type: :KEYDOWN, key: {keysym: {sym: :S}}}) do
|
34
|
+
if @my_timer.started?
|
35
|
+
@my_timer.stop
|
36
|
+
else
|
37
|
+
@my_timer.start
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@app.on({type: :KEYDOWN, key: {keysym: {sym: :P}}}) do
|
42
|
+
if @my_timer.paused?
|
43
|
+
@my_timer.unpause
|
44
|
+
else
|
45
|
+
@my_timer.pause
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@engine.painter = Proc.new() do |surface|
|
50
|
+
time = @my_timer.get_ticks / 1000.0
|
51
|
+
@msg_seconds = @big_font.render_text_blended(time.to_s)
|
52
|
+
|
53
|
+
surface.fill_rect(surface.rect, [0,0,0])
|
54
|
+
|
55
|
+
@msg_seconds.blit_out(surface, {
|
56
|
+
x: (surface.w - @msg_seconds.w)/2,
|
57
|
+
y: 0
|
58
|
+
})
|
59
|
+
|
60
|
+
@msg_pause.blit_out(surface, {
|
61
|
+
x: 0, y: (surface.h - @msg_pause.h)
|
62
|
+
})
|
63
|
+
|
64
|
+
@msg_start_stop.blit_out(surface, {
|
65
|
+
x: (surface.w - @msg_start_stop.w),
|
66
|
+
y: (surface.h - @msg_start_stop.h)
|
67
|
+
})
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
after do
|
74
|
+
|
75
|
+
@app.quit()
|
76
|
+
SDL2.quit
|
77
|
+
end
|
78
|
+
|
79
|
+
it "works" do
|
80
|
+
skip "Don't know how to test this."
|
81
|
+
@app.loop(nil)
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|