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.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +0 -6
  4. data/Guardfile +0 -45
  5. data/README.md +11 -21
  6. data/lib/bad_sdl.rb +4 -0
  7. data/lib/{sdl2 → bad_sdl}/application.rb +47 -35
  8. data/lib/{sdl2 → bad_sdl}/engine.rb +20 -3
  9. data/lib/{sdl2 → bad_sdl}/engine/block_engine.rb +2 -2
  10. data/lib/bad_sdl/engine/engines.rb +51 -0
  11. data/lib/enumerable_constants.rb +4 -2
  12. data/lib/sdl2.rb +26 -247
  13. data/lib/sdl2/blendmode.rb +18 -0
  14. data/lib/sdl2/color.rb +1 -3
  15. data/lib/sdl2/debug.rb +58 -0
  16. data/lib/sdl2/display.rb +30 -23
  17. data/lib/sdl2/error.rb +6 -4
  18. data/lib/sdl2/event.rb +229 -0
  19. data/lib/sdl2/event/abstract.rb +11 -0
  20. data/lib/sdl2/event/action.rb +19 -0
  21. data/lib/sdl2/event/common.rb +10 -0
  22. data/lib/sdl2/event/controller_axis.rb +20 -0
  23. data/lib/sdl2/event/controller_button.rb +17 -0
  24. data/lib/sdl2/event/controller_device.rb +14 -0
  25. data/lib/sdl2/event/dollar_gesture.rb +19 -0
  26. data/lib/sdl2/event/drop.rb +18 -0
  27. data/lib/sdl2/event/joy_axis.rb +20 -0
  28. data/lib/sdl2/event/joy_ball.rb +20 -0
  29. data/lib/sdl2/event/joy_button.rb +18 -0
  30. data/lib/sdl2/event/joy_device.rb +14 -0
  31. data/lib/sdl2/event/joy_hat.rb +18 -0
  32. data/lib/sdl2/event/keyboard.rb +18 -0
  33. data/lib/sdl2/event/mouse_button.rb +21 -0
  34. data/lib/sdl2/event/mouse_motion.rb +19 -0
  35. data/lib/sdl2/event/mouse_wheel.rb +17 -0
  36. data/lib/sdl2/event/multi_gesture.rb +20 -0
  37. data/lib/sdl2/event/os.rb +12 -0
  38. data/lib/sdl2/event/quit.rb +12 -0
  39. data/lib/sdl2/event/state.rb +13 -0
  40. data/lib/sdl2/event/sys_wm.rb +15 -0
  41. data/lib/sdl2/event/text_editing.rb +17 -0
  42. data/lib/sdl2/event/text_input.rb +15 -0
  43. data/lib/sdl2/event/touch_finger.rb +20 -0
  44. data/lib/sdl2/event/type.rb +62 -0
  45. data/lib/sdl2/event/user.rb +15 -0
  46. data/lib/sdl2/event/window.rb +19 -0
  47. data/lib/sdl2/events.rb +23 -538
  48. data/lib/sdl2/gem_version.rb +1 -1
  49. data/lib/sdl2/haptic.rb +3 -3
  50. data/lib/sdl2/hints.rb +3 -1
  51. data/lib/sdl2/image.rb +20 -20
  52. data/lib/sdl2/init.rb +5 -8
  53. data/lib/sdl2/joystick.rb +104 -78
  54. data/lib/sdl2/joystick/axes.rb +22 -0
  55. data/lib/sdl2/joystick/balls.rb +24 -0
  56. data/lib/sdl2/joystick/buttons.rb +22 -0
  57. data/lib/sdl2/joystick/components.rb +23 -0
  58. data/lib/sdl2/joystick/hats.rb +22 -0
  59. data/lib/sdl2/keyboard.rb +11 -10
  60. data/lib/sdl2/keycode.rb +70 -70
  61. data/lib/sdl2/library.rb +8 -7
  62. data/lib/sdl2/log.rb +6 -0
  63. data/lib/sdl2/managed_struct.rb +17 -0
  64. data/lib/sdl2/mixer.rb +16 -12
  65. data/lib/sdl2/mixer/chunk.rb +14 -3
  66. data/lib/sdl2/mouse.rb +21 -41
  67. data/lib/sdl2/pixel_format.rb +4 -4
  68. data/lib/sdl2/pixels.rb +59 -47
  69. data/lib/sdl2/power.rb +1 -1
  70. data/lib/sdl2/rect.rb +4 -5
  71. data/lib/sdl2/render.rb +85 -170
  72. data/lib/sdl2/renderer.rb +337 -20
  73. data/lib/sdl2/rwops.rb +89 -30
  74. data/lib/sdl2/stdinc.rb +18 -21
  75. data/lib/sdl2/struct.rb +184 -0
  76. data/lib/sdl2/struct_helper.rb +32 -0
  77. data/lib/sdl2/surface.rb +15 -14
  78. data/lib/sdl2/syswm.rb +26 -10
  79. data/lib/sdl2/syswm/msg.rb +22 -4
  80. data/lib/sdl2/texture.rb +106 -0
  81. data/lib/sdl2/touch.rb +16 -20
  82. data/lib/sdl2/ttf.rb +29 -29
  83. data/lib/sdl2/ttf/sdl_ttf_module.rb +1 -1
  84. data/lib/sdl2/typed_pointer.rb +45 -0
  85. data/lib/sdl2/union.rb +7 -0
  86. data/lib/sdl2/video.rb +97 -183
  87. data/lib/sdl2/window.rb +140 -90
  88. data/lib/struct_array.rb +42 -0
  89. data/sdl2_ffi.gemspec +3 -3
  90. data/spec/fixtures/approvals/lazyfoonet_lesson_03_advanced_timers/has_a_message.approved.png +0 -0
  91. data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
  92. data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_a_message.approved.png +0 -0
  93. data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_drawn_something.approved.png +0 -0
  94. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
  95. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
  96. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
  97. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
  98. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
  99. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
  100. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
  101. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
  102. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
  103. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
  104. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
  105. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
  106. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
  107. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
  108. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
  109. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
  110. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
  111. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
  112. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
  113. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
  114. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
  115. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
  116. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
  117. data/spec/fixtures/approvals/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
  118. data/spec/fixtures/images/finger.png +0 -0
  119. data/spec/fixtures/music/beat.wav +0 -0
  120. data/spec/fixtures/sounds/high.wav +0 -0
  121. data/spec/fixtures/sounds/low.wav +0 -0
  122. data/spec/fixtures/sounds/medium.wav +0 -0
  123. data/spec/fixtures/sounds/scratch.wav +0 -0
  124. data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +4 -6
  125. data/spec/functional/lazy_foo_tutorial/lazy_foo_02_optimized_images_spec.rb +3 -4
  126. data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +2 -2
  127. data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +3 -3
  128. data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +1 -1
  129. data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +1 -1
  130. data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +3 -2
  131. data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +9 -7
  132. data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +11 -8
  133. data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +5 -4
  134. data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +17 -9
  135. data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +8 -7
  136. data/spec/functional/lazy_foo_tutorial/lazy_foo_13_advanced_timers_spec.rb +85 -0
  137. data/spec/functional/lazy_foo_tutorial/lazy_foo_14_regulating_frame_rate_spec.rb +67 -0
  138. data/spec/functional/lazy_foo_tutorial/lazy_foo_15_calculating_frame_rate_spec.rb +48 -0
  139. data/spec/functional/lazy_foo_tutorial/lazy_foo_16_motion_spec.rb +95 -0
  140. data/spec/functional/lazy_foo_tutorial/lazy_foo_helper.rb +3 -1
  141. data/spec/functional/lazy_foo_tutorial/timer.rb +55 -0
  142. data/spec/lib/bad_sdl/application_spec.rb +22 -0
  143. data/spec/{unit → lib}/sdl2/color_spec.rb +5 -1
  144. data/spec/lib/sdl2/display_spec.rb +6 -0
  145. data/spec/lib/sdl2/event_spec.rb +102 -0
  146. data/spec/lib/sdl2/events_spec.rb +12 -0
  147. data/spec/lib/sdl2/joystick_spec.rb +130 -0
  148. data/spec/lib/sdl2/keyboard_spec.rb +22 -0
  149. data/spec/lib/sdl2/mouse_spec.rb +21 -0
  150. data/spec/lib/sdl2/render_spec.rb +62 -0
  151. data/spec/lib/sdl2/renderer_spec.rb +224 -0
  152. data/spec/lib/sdl2/sdl2_helper.rb +5 -0
  153. data/spec/lib/sdl2/texture_spec.rb +65 -0
  154. data/{test/unit/sdl2/test_video.rb → spec/lib/sdl2/video_spec.rb} +82 -57
  155. data/spec/lib/sdl2/window_spec.rb +42 -0
  156. data/spec/{unit → lib}/unit_helper.rb +0 -0
  157. data/spec/png_writer.rb +9 -1
  158. data/spec/spec_helper.rb +5 -3
  159. metadata +201 -132
  160. data/lib/sdl2/engine/engines.rb +0 -46
  161. data/test/approvals/clip_blitting_and_sprite_sheets.received.bmp +0 -0
  162. data/test/approvals/color_keying_example.approved.png +0 -0
  163. data/test/approvals/hello_world_example_hello.approved.png +0 -0
  164. data/test/approvals/hello_world_example_screen.approved.png +0 -0
  165. data/test/approvals/optimized_surface_loading.approved.png +0 -0
  166. data/test/fixtures/an_example.png +0 -0
  167. data/test/fixtures/background.bmp +0 -0
  168. data/test/fixtures/background.jpg +0 -0
  169. data/test/fixtures/color_bars.jpg +0 -0
  170. data/test/fixtures/foo.jpg +0 -0
  171. data/test/fixtures/hello.bmp +0 -0
  172. data/test/fixtures/sprites.jpg +0 -0
  173. data/test/fixtures/x.png +0 -0
  174. data/test/functional/examples/lazyfoo.net_s/test_clip_blitting_and_sprite_sheets.rb +0 -50
  175. data/test/functional/examples/lazyfoo.net_s/test_color_keying.rb +0 -42
  176. data/test/functional/examples/test_lazy_foo_examples.rb +0 -195
  177. data/test/functional/examples/test_readme_examples.rb +0 -15
  178. data/test/test_helper.rb +0 -13
  179. data/test/unit/sdl2/test_assert.rb +0 -10
  180. data/test/unit/sdl2/test_audio.rb +0 -9
  181. data/test/unit/sdl2/test_clipboard.rb +0 -13
  182. data/test/unit/sdl2/test_cpuinfo.rb +0 -11
  183. data/test/unit/sdl2/test_error.rb +0 -20
  184. data/test/unit/sdl2/test_events.rb +0 -31
  185. data/test/unit/sdl2/test_haptic.rb +0 -27
  186. data/test/unit/sdl2/test_hints.rb +0 -50
  187. data/test/unit/sdl2/test_image.rb +0 -9
  188. data/test/unit/sdl2/test_init.rb +0 -29
  189. data/test/unit/sdl2/test_keyboard.rb +0 -9
  190. data/test/unit/sdl2/test_log.rb +0 -80
  191. data/test/unit/sdl2/test_palette.rb +0 -26
  192. data/test/unit/sdl2/test_pixel_format.rb +0 -38
  193. data/test/unit/sdl2/test_pixels.rb +0 -24
  194. data/test/unit/sdl2/test_power.rb +0 -11
  195. data/test/unit/sdl2/test_rect.rb +0 -19
  196. data/test/unit/sdl2/test_render.rb +0 -58
  197. data/test/unit/sdl2/test_surface.rb +0 -88
  198. data/test/unit/sdl2/test_syswm.rb +0 -11
  199. data/test/unit/sdl2/test_timer.rb +0 -9
  200. data/test/unit/sdl2/test_ttf.rb +0 -11
  201. data/test/unit/sdl2/test_version.rb +0 -16
  202. data/test/unit/sdl2/test_window.rb +0 -155
  203. data/test/unit/test_scratch.rb +0 -19
  204. data/test/unit/test_sdl2.rb +0 -16
@@ -8,14 +8,13 @@ require 'sdl2/ttf'
8
8
  describe "LazyFoo.net: Lesson 01: Hello World" do
9
9
 
10
10
  before do
11
- #expect(init(:EVERYTHING)).to eq(0)
11
+ expect(init(:EVERYTHING)).to eq(0)
12
12
 
13
- @window = Window.create(subject, :CENTERED, :CENTERED, 640, 480, :SHOWN)
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 be_false
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
- @window = Window.create(subject, :CENTERED, :CENTERED, WIDTH, HEIGHT, :SHOWN)
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.load_bmp!(file))
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, :CENTERED, :CENTERED, 640, 480)
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, :CENTERED, :CENTERED, 640, 480)
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(QuitEvent.cast(type: :QUIT))
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 be_true
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, :CENTERED, :CENTERED, 640, 480)
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, :CENTERED, :CENTERED, 640, 480)
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, :CENTERED, :CENTERED, 640, 480)
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 SDL2::TTF::Font
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
- @window = Window.create(subject, :CENTERED, :CENTERED, 640, 480)
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::KeyboardEvent.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :UP)),
27
- SDL2::KeyboardEvent.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :DOWN)),
28
- SDL2::KeyboardEvent.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :LEFT)),
29
- SDL2::KeyboardEvent.cast(type: :KEYDOWN, keysym: Keysym.cast(sym: :RIGHT)),
30
- SDL2::QuitEvent.cast(type: :QUIT)
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 'sdl2/application'
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
- puts "Mouse OVER"if SDL2::PrintDebug
27
- @clip = @clips[OVER]if SDL2::PrintDebug
27
+ SDL2::Debug.log(self){"Mouse OVER"}
28
+ @clip = @clips[OVER]
28
29
  else
29
- puts "Mouse OUT" if SDL2::PrintDebug
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
- puts "Painting"if SDL2::PrintDebug
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
- @application = Application.new()
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(1) #Prime it
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 'sdl2/application'
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 'sdl2/application'
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 < SDL2::Engine
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
- @screen = @app.window.surface
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: 100)
113
- pending "Don't know how to test this."
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 'sdl2/application'
4
+ require 'bad_sdl/application'
5
5
  #binding.pry
6
- require 'sdl2/engine/block_engine'
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: Playing sounds" do
11
+ describe "LazyFoo.net: Lesson 12: Timing" do
12
12
 
13
13
  before do
14
- @app = SDL2::Application.new()
14
+ SDL2.init!(:EVERYTHING)
15
+ @app = BadSdl::Application.new()
15
16
 
16
- @app.engines << @engine = SDL2::Engine::BlockEngine.new
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
- pending "don't know how I should test this..."
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