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.
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
@@ -0,0 +1,67 @@
1
+ require_relative 'lazy_foo_helper'
2
+ require_relative 'timer'
3
+ #ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson14/index.php
4
+ # Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
5
+
6
+ require 'bad_sdl/application'
7
+ require 'bad_sdl/engine/block_engine'
8
+ require 'sdl2/ttf'
9
+
10
+ FRAMES_PER_SECOND = 20
11
+
12
+ describe "LazyFoo.net: Lesson 14: Advanced Timers" do
13
+ before do
14
+ SDL2.init!(:EVERYTHING)
15
+ @app = BadSdl::Application.new
16
+ @frame = 0
17
+ @cap = true
18
+ @fps = Timer.new
19
+
20
+ TTF::init!
21
+ @font = TTF::Font.open(FONT_PATH, 32)
22
+ @message = @font.render_text_blended("Testing Frame Rate")
23
+
24
+ @app.before_loop do
25
+ puts "before loop"
26
+ @fps.start()
27
+ end
28
+
29
+ @app.on({type: :KEYDOWN, key: {keysym: {sym: :RETURN}}}) do |event|
30
+ print "CAP IS: "
31
+ @cap = !@cap
32
+ puts @cap ? "ON" : "OFF"
33
+ end
34
+
35
+ @app.after_loop do
36
+ puts "after loop"
37
+ @frame += 1
38
+ if @cap and (@fps.get_ticks() < 1000 / FRAMES_PER_SECOND)
39
+ SDL2::delay((1000 / FRAMES_PER_SECOND) - @fps.get_ticks() )
40
+ end
41
+ end
42
+
43
+ @app.painter do |surface|
44
+ puts "painter"
45
+ surface.fill_rect(surface.rect, [0,0,0])
46
+
47
+ @message.blit_out(surface, {
48
+ x: (surface.w - @message.w) / 2,
49
+ y: ((surface.h + @message.h * 2) / FRAMES_PER_SECOND) * ( @frame % FRAMES_PER_SECOND) - @message.h
50
+ })
51
+
52
+ @app.window().update_surface
53
+ true
54
+ end
55
+
56
+ end
57
+
58
+ after do
59
+ @app.quit
60
+ SDL2.quit
61
+ end
62
+
63
+ it "works" do
64
+ skip "Don't know how to test this"
65
+ @app.loop nil #, #delay: 100
66
+ end
67
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'lazy_foo_helper'
2
+ require_relative 'timer'
3
+ #ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson14/index.php
4
+ # Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
5
+
6
+ require 'bad_sdl/application'
7
+ require 'bad_sdl/engine/block_engine'
8
+ require 'sdl2/ttf'
9
+
10
+ describe "LazyFoo.net: Lesson 15: Advanced Timers" do
11
+
12
+ before do
13
+ SDL2.init(:EVERYTHING)
14
+ @app = BadSdl::Application.new(title: subject)
15
+ @frame = 0
16
+ @fps = Timer.new
17
+ @update = Timer.new
18
+ @update.start
19
+ @fps.start
20
+
21
+ @image = Image.load!(img_path('background.png'))
22
+
23
+ @app.painter do |surface|
24
+ surface.fill_rect(surface.rect, [0, 0, 0])
25
+ @image.blit_out(surface)
26
+ true
27
+ end
28
+
29
+ @app.after_loop do
30
+ @frame += 1
31
+ if @update.get_ticks() > 1000
32
+
33
+ fps = @frame./(@fps.get_ticks()./(1000.0))
34
+ @app.window.title = "Average Frames Per Second: #{fps}"
35
+ end
36
+ end
37
+ end
38
+
39
+ after do
40
+ @app.quit
41
+ SDL2.quit
42
+ end
43
+
44
+ it "works" do
45
+ @app.loop(1)
46
+ skip "don't know how to test this"
47
+ end
48
+ end
@@ -0,0 +1,95 @@
1
+ require_relative 'lazy_foo_helper'
2
+ require_relative 'timer'
3
+ #ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson16/index.php
4
+ # Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
5
+
6
+ require 'bad_sdl/application'
7
+ require 'bad_sdl/engine/block_engine'
8
+ require 'sdl2/ttf'
9
+
10
+ describe "LazyFoo.net: Lesson 16: Motion" do
11
+
12
+ class Dot
13
+
14
+ def initialize(opts)
15
+ @x = opts[:x] || 0
16
+ @y = opts[:y] || 0
17
+ @xVel = opts[:xVel] || 0
18
+ @yVel = opts[:yVel] || 0
19
+ @sprite = opts[:sprite] || SDL2::Image.load!(img_path('foo.jpg'))
20
+ end
21
+
22
+ def handle_input(event)
23
+ case event.key.keysym.sym
24
+ when :UP then @yVel -= @dot.h / 2
25
+ when :DOWN then @yVel += @dot.h / 2
26
+ when :LEFT then @xVel -= @dot.w / 2
27
+ when :RIGHT then @xVel += @dot.w / 2
28
+ end
29
+ end
30
+
31
+ def accelerate(x,y)
32
+ @xVel += x
33
+ @yVel += y
34
+ puts "New Vector: #{@xVel},#{@yVel}"
35
+ end
36
+
37
+ def move
38
+ @x += @xVel
39
+ @y += @yVel
40
+ end
41
+
42
+ def show(surface)
43
+ @sprite.blit_out(surface, [@x,@y])
44
+
45
+ end
46
+ end#class Dot
47
+
48
+ before do
49
+ SDL2.init!(:EVERYTHING)
50
+ @app = BadSdl::Application.new title: subject
51
+ @dot = Dot.new(
52
+ x: @app.window.surface.w / 2,
53
+ y: @app.window.surface.h / 2,
54
+ sprite: @app.window.surface.convert(SDL2::Image.load!(img_path('foo.jpg')))
55
+ )
56
+
57
+ @app.on(key: :KEYUP, key: {keysym: {sym: :UP}}) do
58
+ @dot.accelerate(0,-1)
59
+ end
60
+
61
+ @app.on(key: :KEYUP, key: {keysym: {sym: :DOWN}}) do
62
+ @dot.accelerate(0,1)
63
+ end
64
+
65
+ @app.on(key: :KEYUP, key: {keysym: {sym: :LEFT}}) do
66
+ @dot.accelerate(-1,0)
67
+ end
68
+
69
+ @app.on(key: :KEYUP, key: {keysym: {sym: :RIGHT}}) do
70
+ @dot.accelerate(1,0)
71
+ end
72
+
73
+ @app.after_loop do
74
+ @dot.move
75
+ delay(10)
76
+ end
77
+
78
+ @app.painter do |surface|
79
+ surface.fill_rect(surface.rect, [0,0,0])
80
+ @dot.show(surface)
81
+ true
82
+ end
83
+
84
+ end
85
+
86
+ after do
87
+ @app.quit
88
+ SDL2.quit
89
+ end
90
+
91
+ it "works" do
92
+ skip 'refine later'
93
+ @app.loop()
94
+ end
95
+ end
@@ -3,4 +3,6 @@ require_relative '../../spec_helper'
3
3
  require 'sdl2'
4
4
  require 'sdl2/image'
5
5
 
6
- include SDL2
6
+ include SDL2
7
+
8
+ FONT_PATH = fixture('fonts/GaroaHackerClubeBold.otf')
@@ -0,0 +1,55 @@
1
+ require 'sdl2'
2
+ class Timer
3
+
4
+ def initialize
5
+ @start_ticks = 0
6
+ @paused_ticks = 0
7
+ @paused = false
8
+ @started = false
9
+ end
10
+
11
+ def start
12
+ @started = true
13
+ @paused = false
14
+ @start_ticks = SDL2::get_ticks()
15
+ end
16
+
17
+ def stop
18
+ @started = false
19
+ @paused = false
20
+ end
21
+
22
+ def pause
23
+ if started? and not paused?
24
+ @paused = true
25
+ @paused_ticks = SDL2::get_ticks() - @start_ticks
26
+ end
27
+ end
28
+
29
+ def unpause
30
+ if paused?
31
+ @paused = false
32
+ @start_ticks = SDL2::get_ticks() - @paused_ticks
33
+ @paused_ticks = 0
34
+ end
35
+ end
36
+
37
+ def get_ticks
38
+ if started?
39
+ if paused?
40
+ return @paused_ticks
41
+ else
42
+ return SDL2::get_ticks() - @start_ticks
43
+ end
44
+ end
45
+ return 0
46
+ end
47
+
48
+ def paused?
49
+ @paused
50
+ end
51
+
52
+ def started?
53
+ @started
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ require 'bad_sdl/application'
4
+
5
+
6
+ describe BadSdl::Application do
7
+ before :each do
8
+ SDL2.init(:EVERYTHING)
9
+ @app = BadSdl::Application.new title: example.metadata[:example_group][:full_description]
10
+ end
11
+
12
+ after :each do
13
+ @app.quit()
14
+ SDL2.quit
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ end
@@ -3,11 +3,15 @@ require_relative '../unit_helper'
3
3
  describe SDL2::Color do
4
4
  before :each do
5
5
  SDL2.init!(:EVERYTHING)
6
- @window = SDL2::Window.create(subject.to_s, :CENTERED, :CENTERED, 100, 100)
6
+ @window = SDL2::Window.create(title: subject.to_s, width: 100, height: 100)
7
7
  @screen = @window.surface
8
8
  @color = SDL2::Color.new
9
9
  end
10
10
 
11
+ after :each do
12
+ SDL2.quit
13
+ end
14
+
11
15
  it 'looks RED when it should' do
12
16
  @color.set(255,0,0,255)
13
17
  end
@@ -0,0 +1,6 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe SDL2::Display do
4
+
5
+
6
+ end
@@ -0,0 +1,102 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe SDL2::Event do
4
+ before :each do
5
+ SDL2.init!(:VIDEO)
6
+ SDL2::Debug.enable(SDL2::Event)
7
+ end
8
+
9
+
10
+ it 'should provide event states' do
11
+ SDL2::Event.should respond_to(:state)
12
+ SDL2::Event.state(:KEYDOWN).should == true
13
+ SDL2::Event.state(:KEYDOWN, :IGNORE).should == true # Because it was true
14
+ SDL2::Event.state(:KEYDOWN).should == false # Because now it's disabled.
15
+ SDL2::Event.state(:KEYDOWN, :ENABLE).should == false #getting it?
16
+ SDL2::Event.state(:KEYDOWN).should == true
17
+ end
18
+
19
+ it 'should be able to filter events' do
20
+ SDL2::Event.should respond_to(:filter)
21
+ SDL2::Event.push(SDL2::Event.cast(SDL2::Event::Keyboard.cast({type: :KEYDOWN, keysym: {sym: :A}} )))
22
+ count = 0
23
+ SDL2::Event.filter do |data, event|
24
+ count += 1
25
+ end
26
+ count.should == 1
27
+ end
28
+
29
+ it 'should be able to flush an event type' do
30
+ SDL2::Event.push SDL2::Event.cast(SDL2::Event::Keyboard.cast({type: :KEYDOWN, keysym: {sym: :A}} ))
31
+ SDL2::Event.push SDL2::Event.cast(SDL2::Event::Keyboard.cast({type: :KEYUP, keysym: {sym: :B}} ))
32
+ SDL2::Event.has?(:KEYDOWN).should == true
33
+ SDL2::Event.has?(:KEYUP).should == true
34
+ SDL2::Event.flush(:KEYDOWN)
35
+ SDL2::Event.has?(:KEYDOWN).should == false
36
+ SDL2::Event.has?(:KEYUP).should == true
37
+ end
38
+
39
+ it 'should be able to return the event filter' do
40
+ skip 'unsure how to test right now'
41
+ my_filter = lambda do |data, event|
42
+ 0 if event.type == :KEYDOWN
43
+ 1
44
+ end
45
+
46
+ SDL2::Event.filter.should == false
47
+ SDL2::Event.filter= my_filter
48
+ SDL2::Event.filter.should == my_filter
49
+ end
50
+
51
+ it 'should be able to peep events' do
52
+ events = [
53
+ SDL2::Event.cast(SDL2::Event::Keyboard.cast({type: :KEYDOWN, keysym: {sym: :A}} )),
54
+ SDL2::Event.cast(SDL2::Event::Keyboard.cast({type: :KEYUP, keysym: {sym: :B}} )),
55
+ SDL2::Event.cast(SDL2::Event::Keyboard.cast({type: :KEYDOWN, keysym: {sym: :C}} )),
56
+ SDL2::Event.cast(SDL2::Event::Keyboard.cast({type: :KEYUP, keysym: {sym: :D}} )),
57
+ ]
58
+ events.each do |event|
59
+ SDL2::Event.push(event)
60
+ end
61
+ SDL2::Event.should respond_to(:peep)
62
+ retrieved = SDL2::Event.peep(nil, 3, :PEEK, :FIRSTEVENT, :LASTEVENT)
63
+ # The SDL2::Events won't match since they are different pointers,
64
+ # but hey, if we pull the values out we can see that they match just fine
65
+ per = lambda do |e|
66
+ [e.type, e.key.keysym.sym]
67
+ end
68
+ retrieved.map(&per).should == events.map(&per).first(3)
69
+ end
70
+
71
+ it 'should be able to pump events' do
72
+ SDL2::Event.should respond_to(:pump)
73
+ # Count the number of events pumped.
74
+ count = 0
75
+ # Setup a filter to count the events pumped.
76
+ SDL2::Event.filter= lambda do |data, event|
77
+ count += 1
78
+ end
79
+ # Create some events and push
80
+ [
81
+ SDL2::Event::Keyboard.cast({type: :KEYDOWN, keysym: {sym: :A}} ).to_event,
82
+ SDL2::Event::Keyboard.cast({type: :KEYUP, keysym: {sym: :B}} ).to_event,
83
+ SDL2::Event::Keyboard.cast({type: :KEYDOWN, keysym: {sym: :C}} ).to_event,
84
+ SDL2::Event::Keyboard.cast({type: :KEYUP, keysym: {sym: :D}} ).to_event,
85
+ ].each {|e|SDL2::Event.push(e)}
86
+ # Test the routine:
87
+ SDL2::Event.pump
88
+ count.should == 4
89
+ end
90
+
91
+ it 'should indicate if an SDL::Event::Quit is in the Que' do
92
+ SDL2::Event.should respond_to(:quit_requested?)
93
+ #
94
+ SDL2::Event.quit_requested?.should == false
95
+ SDL2::Event.push SDL2::Event::Quit.cast({type: :QUIT}).to_event
96
+ SDL2::Event.quit_requested?.should == true
97
+ end
98
+
99
+ after :each do
100
+ SDL2.quit
101
+ end
102
+ end
@@ -0,0 +1,12 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe SDL2 do
4
+ it 'should have the SDL_events.h API' do
5
+ [
6
+ :event_state?,
7
+
8
+ ].each do |function|
9
+ SDL2.should respond_to(function)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,130 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe SDL2 do
4
+ it 'should have the joystick API' do
5
+ # Joystick API
6
+ [
7
+ :joystick_close,
8
+ :joystick_event_state,
9
+ :joystick_event_state?,
10
+ :joystick_get_attached,
11
+ :joystick_get_attached?,
12
+ :num_joysticks,
13
+ :num_joysticks!,
14
+ :joystick_update,
15
+ :joystick_open,
16
+ :joystick_open!,
17
+ :joystick_num_hats,
18
+ :joystick_num_hats!,
19
+ :joystick_num_buttons,
20
+ :joystick_num_buttons!,
21
+ :joystick_num_balls,
22
+ :joystick_num_balls!,
23
+ :joystick_num_axes,
24
+ :joystick_num_axes!,
25
+ :joystick_name_for_index,
26
+ :joystick_name_for_index!,
27
+ :joystick_name,
28
+ :joystick_instance_id,
29
+ :joystick_instance_id!,
30
+ :joystick_get_hat,
31
+ # TODO: Implement Joystick GUID helpers?
32
+ :joystick_get_guid_string,
33
+ :joystick_get_guid_from_string,
34
+ :joystick_get_guid,
35
+ :joystick_get_device_guid,
36
+ :joystick_get_button,
37
+ :joystick_get_ball,
38
+ :joystick_get_axis,
39
+ :joystick_get_axis!,
40
+ ].each do |method|
41
+ SDL2.should respond_to(method)
42
+ end
43
+ end
44
+
45
+ describe SDL2::Joystick do
46
+ before :each do
47
+ SDL2.init(:JOYSTICK)
48
+ joy_count = SDL2.num_joysticks
49
+ skip "There are no Joysticks" if joy_count < 1
50
+
51
+ @joysticks = joy_count.times.map {|idx| SDL2::Joystick.open(idx)}
52
+ end
53
+
54
+
55
+ it 'should have a name' do
56
+ @joysticks.each{|j|j.name.should be_a(String)}
57
+ end
58
+
59
+ it 'should have an event state' do
60
+ @joysticks.each do |joystick|
61
+ joystick.event_state(:IGNORE)
62
+ joystick.event_state.should == false
63
+ joystick.event_state(:ENABLE)
64
+ joystick.event_state.should == true
65
+ end
66
+ end
67
+
68
+ describe SDL2::Joystick::Buttons do
69
+ it 'should return a state for each button on each joystick' do
70
+ @joysticks.delete_if{|js|js.buttons.count < 1}
71
+ skip "no buttons" if @joysticks.empty?
72
+ @joysticks.each do |joystick|
73
+ joystick.buttons.each do |button|
74
+ button.should be_a(Integer)
75
+ button.should >= 0
76
+ button.should <= 1
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe SDL2::Joystick::Axes do
83
+ it 'should return an integer for each axis' do
84
+ @joysticks.delete_if{|js|js.axes.count < 1}
85
+ skip "no axes" if @joysticks.empty?
86
+ @joysticks.each do |joystick|
87
+ joystick.axes.each do |axis|
88
+ axis.should be_a(Integer)
89
+ axis.should >= -32768
90
+ axis.should <= 32767
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ describe SDL2::Joystick::Balls do
97
+ it 'should return a delta x, delta y pair' do
98
+ @joysticks.delete_if {|js|js.balls.count < 1}
99
+ skip "no balls" if @joysticks.empty?
100
+ @joysticks.each do |joystick|
101
+ joystick.balls.each do |ball|
102
+ ball.should be_a(Array)
103
+ ball.count.should == 2
104
+ ball.each do |value|
105
+ value.should be_a(Integer)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ describe SDL2::Joystick::Hats do
113
+ it 'should return a valid SDL2::HAT value' do
114
+ @joysticks.delete_if{|js|js.hats.count < 1}
115
+ skip 'no hats' if @joysticks.empty?
116
+ @joysticks.each do |joystick|
117
+ joystick.hats.each do |hat|
118
+ hat.should be_a(Integer)
119
+ hat.should >= 0
120
+ hat.should <= 12
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ after :each do
127
+ SDL2.quit
128
+ end
129
+ end
130
+ end