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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcb36c1f56cfd2a4ad4920222e9713619e23355a
4
- data.tar.gz: ef6c799ffadf4caa0d4d5a443e402f0391a47085
3
+ metadata.gz: 8dbaffe7bb73a594ee376109bd30462993f4bc57
4
+ data.tar.gz: edb658af105c6b0a5a97a2671abd027171d89d14
5
5
  SHA512:
6
- metadata.gz: 8d77dfe92939dab7ae53edb27a8b96c04941a951c0ce8aa6a9578767483becfb08c1ca85bc99c8c072cd3f034a4ebaeb929869f8fa98d2839694574986e73c59
7
- data.tar.gz: 9a5b0026a3b60ee4b95af4f6011dc81f6c68c358e254df2c55bc41b000114d09c142f86c81c05d97b8fbedaa40eda30cec7c824363797a75eb31193e2c68f305
6
+ metadata.gz: 5b232c50359ed505954197784ca922ff61ce4477ae24f8f0759af722aa7bdf095cf4101a5bc80871e008ebdbb1663be24e7b1fce26658cdfb390433317d2d0e2
7
+ data.tar.gz: 1326ddfc32e471b20c83b3730a6d8fa0166c4745bbb696227b646276aa723d0980aa7a9e472a5fc61aba89a60e0de300805357eb31adaf4c728ce17932cbeb7f
@@ -1 +1 @@
1
- ruby-2.0.0-p247
1
+ ruby-2.1.1
data/Gemfile CHANGED
@@ -2,9 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in sdl2_ffi.gemspec
4
4
  gemspec
5
-
6
- # TODO: Once SDL/Image support has been added, migrate to official
7
- # gem.
8
- group :development do
9
- gem 'approvals', git:'http://github.com/BadQuanta/approvals', branch: 'feature_binary_formats'
10
- end
data/Guardfile CHANGED
@@ -1,55 +1,10 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- #guard :minitest do
5
- # # with Minitest::Unit
6
- # watch(%r{^test/(.*)\/?test_(.*)\.rb})
7
- # watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/unit/#{m[1]}test_#{m[2]}.rb" }
8
- # watch(%r{^test/test_helper\.rb}) { 'test' }
9
- #
10
- # # with Minitest::Spec
11
- # watch(%r{^spec/(.*)_spec\.rb})
12
- # watch(%r{^lib/(.+)\.rb}) { |m| "spec/unit/#{m[1]}_spec.rb" }
13
- # watch(%r{^spec/spec_helper\.rb}) { 'spec' }
14
- #
15
- # # Rails 4
16
- # # watch(%r{^test/test_helper\.rb}) { 'test' }
17
- # # watch(%r{^test/.+_test\.rb})
18
- # # watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
19
- # # watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' }
20
- # # watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" }
21
- # # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
22
- # # watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" }
23
- #
24
- # # Rails 3.2
25
- # # watch(%r{^app/controllers/(.*)\.rb}) { |m| "test/controllers/#{m[1]}_test.rb" }
26
- # # watch(%r{^app/helpers/(.*)\.rb}) { |m| "test/helpers/#{m[1]}_test.rb" }
27
- # # watch(%r{^app/models/(.*)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
28
- #
29
- # # Rails
30
- # # watch(%r{^app/controllers/(.*)\.rb}) { |m| "test/functional/#{m[1]}_test.rb" }
31
- # # watch(%r{^app/helpers/(.*)\.rb}) { |m| "test/helpers/#{m[1]}_test.rb" }
32
- # # watch(%r{^app/models/(.*)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
33
- #end
34
4
 
35
5
  guard :rspec do
36
6
  watch(%r{^spec/.+_spec\.rb$})
37
7
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
38
8
  watch('spec/spec_helper.rb') { "spec" }
39
-
40
- # Rails example
41
- #watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
42
- #watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
43
- #watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
44
- #watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
45
- #watch('config/routes.rb') { "spec/routing" }
46
- #watch('app/controllers/application_controller.rb') { "spec/controllers" }
47
-
48
- # Capybara features specs
49
- #watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
50
-
51
- # Turnip features and steps
52
- #watch(%r{^spec/acceptance/(.+)\.feature$})
53
- #watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
54
9
  end
55
10
 
data/README.md CHANGED
@@ -1,29 +1,21 @@
1
- # sdl2_ffi
1
+ # sdl2_ffi June, 2014
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/sdl2_ffi.png)](http://badge.fury.io/rb/sdl2_ffi)
4
4
 
5
- The sdl2_ffi makes SDL2 fun and easy, eventually. This is still a new project
6
- and I am still implementing major sections of it. Check out the
7
- [approvals](https://github.com/BadQuanta/sdl2_ffi/tree/master/spec/fixtures/approvals)
8
- to get an idea of how much is working. These are screen-shots of SDL generated
9
- content. Approval testing is used to validate functionality.
10
-
11
-
12
- The "Object Oriented" part of this interface has barely started.
5
+ A Ruby interface to the SDL2 dynamic libraries, with support for SDL2_ttf, SDL2_mixer(with smpeg2), SDL2_image.
13
6
 
14
7
  # Documentation/API Reference:
15
8
 
9
+ The API's functionality [RSpecs](https://github.com/BadQuanta/sdl2_ffi/tree/master/spec) can be used as a reference.
10
+
16
11
  For the latest released gem, [rubydoc.info](http://rubydoc.info/) has the
17
12
  [automatically generated documentation](http://rubydoc.info/gems/sdl2_ffi/frames).
18
13
 
19
14
  Otherwise, you can use RDoc to generate current source documentation.
20
15
 
21
- # How to start:
22
-
23
-
24
16
  ## Testing
25
17
 
26
- Minitests are being written to validate functionality. Not SDL's functionality, but that the GEM has been linked properly and that the Object Oriented wrapper functions as intended.
18
+ Specs define the scope of what interfaces have been written and tested.
27
19
 
28
20
  Run the tests with rake:
29
21
 
@@ -35,21 +27,19 @@ Or:
35
27
 
36
28
  ### Approval Testing
37
29
 
38
- This project now uses Approval testing. At the moment, I'm using a custom
39
- 'approvals' gem which is specified in the Gemfile, as opposed to the Gemspec.
40
- This is only temporary. The approved specifications are in the repository
41
- and can act as a repository of screen shots. :)
42
-
30
+ Parts of the API are verified via "Approvals" which are PNG captures of SDL Surfaces,
31
+ on each run of an "Approved" rendering, the dumped PNGs are compared against each other.
32
+ Feel free to update these tests and "approve" the new PNGs.
43
33
 
44
34
  ### Testing Under *nix & X11
45
35
 
46
36
  If you are testing under some kind of unix system with X11 and have Xnest available,
47
- I'd recommend starting up Xnest and changing your testing terminal DISPLAY value
37
+ I'd recommend starting up Xnest or Xephyr and changing your testing terminal DISPLAY value
48
38
  so that the tests do not throw around a bunch of Windows on your screen.
49
39
 
50
40
  ## Usage
51
41
 
52
- When you `require 'sdl2'`, it should give you the same things that
42
+ When you `require 'sdl2_ffi'`, it should give you the same things that
53
43
  include 'SDL.h' would have done. See the specs for examples. There are C/C++
54
44
  tutorials that have been translated as a means of validating functionality.
55
45
 
@@ -64,4 +54,4 @@ libSDL 2.0 is licensed under the 'zlib license', listed as compatible with the G
64
54
  4. Push to the branch (`git push origin my-new-feature`)
65
55
  5. Create new Pull Request
66
56
 
67
- I specifically need help writing the minitest code.
57
+ New Issues welcome.
@@ -0,0 +1,4 @@
1
+
2
+ module BadSdl
3
+
4
+ end
@@ -1,71 +1,83 @@
1
- require 'sdl2/engine/engines'
2
-
3
- module SDL2
1
+ require 'bad_sdl'
2
+ require 'sdl2'
3
+ require 'bad_sdl/engine/engines'
4
4
 
5
+ module BadSdl
6
+ ##
5
7
  # A Top-Level SDL Application:
6
- # An application
7
-
8
-
8
+ # An application
9
+ # TODO: Review SDL2::Application for removal
9
10
  class Application < Engine::Engines
10
-
11
+
11
12
  attr_accessor :window
12
-
13
- def initialize(opts = {})
13
+
14
+ def initialize(opts = {})
14
15
  super(opts)
15
-
16
- title = opts[:title] || self.to_s
17
- x = opts[:x] || :CENTERED
18
- y = opts[:y] || :CENTERED
19
- w = opts[:w] || 640
20
- h = opts[:h] || 480
21
- flags = opts[:flags] || :SHOWN
22
-
23
- @window = Window.create(title, x, y, w, h, flags)
16
+
17
+ opts[:title] ||= self.to_s
18
+ opts[:width] ||= 640
19
+ opts[:height] ||= 480
20
+ opts[:flags] ||= :SHOWN
21
+
22
+ @window = Window.create(opts)
24
23
  @window.surface.fill_rect(@window.surface.rect, [0,0,0,SDL2::ALPHA_OPAQUE])
25
-
24
+
26
25
  # Default ON handler for :QUIT events:
27
26
  self.on({type: :QUIT}) do |event|
28
27
  @quit_loop = true
29
28
  end
30
-
29
+
31
30
  end
32
-
31
+
33
32
  def quit()
34
- @window.free
35
- super()
33
+ @window.destroy
34
+ super()
36
35
  end
37
-
36
+
38
37
  attr_accessor :poll_count_limit
39
-
38
+
40
39
  # What makes an engine an "Application" is that it takes control of event
41
40
  # polling. There should only ever be one "Application"
42
41
  def poll(cnt = poll_count_limit)
43
- puts "Poll Start" if SDL2::PrintDebug
42
+ Debug.log(self){"Poll Start"}
44
43
  times = 0
45
44
  while (event = Event.poll()) and (cnt.nil? or (times+=1 < cnt))
46
- puts "GOT: #{event.type}"if SDL2::PrintDebug
45
+ Debug.log(self){"GOT: #{event.type}"}
47
46
  handle_event(event)
48
47
  end
49
-
50
- puts "Poll End"if SDL2::PrintDebug
48
+
49
+ Debug.log(self){"Poll End"}
51
50
  end
52
-
51
+
53
52
  attr_accessor :loop_count_limit
54
-
55
- def loop(cnt = loop_count_limit, opts ={})
53
+
54
+ def loop(cnt = loop_count_limit, opts ={})
56
55
  @quit_loop = false
57
56
  times = 0
57
+
58
58
  while (cnt.nil?) or ((times+=1) <= cnt)
59
- puts ">>> Loop##{times}" if SDL2::PrintDebug
59
+ before_loop.each(&:call)
60
60
  poll # Process input
61
61
  break if @quit_loop
62
62
  # Update the surface when we are painted to
63
63
  @window.update_surface if paint_to(@window.surface)
64
- puts "<<< Loop##{times}" if SDL2::PrintDebug
65
64
  delay(opts[:delay]) if opts.has_key? :delay
65
+ after_loop.each(&:call)
66
66
  end
67
+
68
+ end
69
+
70
+ def before_loop(&block)
71
+ @before_loop ||= []
72
+ @before_loop << block unless block.nil?
73
+ @before_loop
74
+ end
75
+
76
+ def after_loop(&block)
77
+ @after_loop ||= []
78
+ @after_loop << block unless block.nil?
79
+ @after_loop
67
80
  end
68
-
69
81
  end
70
82
 
71
83
  end
@@ -1,7 +1,9 @@
1
+ require 'bad_sdl'
1
2
  require 'sdl2'
2
3
 
3
- module SDL2
4
4
 
5
+ module BadSdl
6
+
5
7
  # Input/Output engine.
6
8
  class Engine
7
9
 
@@ -40,9 +42,24 @@ module SDL2
40
42
  return false # if we get to here.
41
43
  end
42
44
 
43
- # This routine should be overriden.
45
+ # This routine should be overridden.
44
46
  def paint_to(surface)
45
- false
47
+ result = false
48
+
49
+ painter.each do |one|
50
+
51
+ result = true if one.call(surface)
52
+ end
53
+
54
+ return result
55
+ end
56
+
57
+ def painter(&block)
58
+ @painter ||= []
59
+ @painter << block unless block.nil?
60
+
61
+ @painter
62
+
46
63
  end
47
64
 
48
65
  protected
@@ -1,6 +1,6 @@
1
- require 'sdl2/engine'
1
+ require 'bad_sdl/engine'
2
2
 
3
- module SDL2
3
+ module BadSdl
4
4
 
5
5
  class Engine
6
6
 
@@ -0,0 +1,51 @@
1
+ require 'bad_sdl/engine'
2
+ require 'sdl2/debug'
3
+
4
+ module BadSdl
5
+ class Engine
6
+ # An engine multiplexor.
7
+ # Only has one focus, but that focus can change.
8
+ class Engines < Engine
9
+
10
+ def initialize(opts)
11
+ super(opts)
12
+ @engines = [] #opts[:engines] || []
13
+ @current_idx = 0
14
+ end
15
+
16
+ attr_reader :engines
17
+
18
+ def current_engine
19
+ @engines[@current_idx]
20
+ end
21
+
22
+ def handle_event(event)
23
+ return true if super(event) # self swallowed event.
24
+ if current_engine
25
+ Debug.log(self){"Passing to current engine."}
26
+ return true if current_engine.handle_event(event)
27
+ end
28
+ SDL2::Debug.log(self){"Unable to handle"}
29
+ return false # if we get to here.
30
+ end
31
+
32
+ def paint_to(surface)
33
+ result = false
34
+
35
+ result = true if super(surface)
36
+
37
+ if ce = current_engine
38
+ result = true if ce.paint_to(surface)
39
+ end
40
+ return result
41
+ end
42
+
43
+ def quit()
44
+ @engines.each(&:quit)
45
+ super()
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -77,7 +77,7 @@ module EnumerableConstants
77
77
  # Get the last defined value.
78
78
  def self.last_const_value
79
79
  if self.constants.empty?
80
- return 0
80
+ return -1
81
81
  else
82
82
  return self.const_get(self.constants.last)
83
83
  end
@@ -88,7 +88,9 @@ module EnumerableConstants
88
88
  def self.next_const_value
89
89
  last_const_value.next
90
90
  end
91
-
91
+
92
+ ##
93
+ # Set the value of undefined constants to the next constant value.
92
94
  def self.const_missing(const)
93
95
  self.const_set(const, next_const_value)
94
96
  end
@@ -2,267 +2,48 @@ require 'sdl2/sdl_module'
2
2
  require 'active_support/inflector'
3
3
  require 'enumerable_constants'
4
4
  require 'sdl2/stdinc'
5
-
6
- # libSDL2's prototypes are attached directly to this module.
7
- #
5
+ require 'sdl2/debug'
6
+ # The SDL2 Map of API Prototypes
8
7
  module SDL2
9
8
  extend FFI::Library
10
9
  extend Library
11
10
  ffi_lib SDL_MODULE
11
+
12
+ ##
13
+ # StructHelper defines a couple of handy macros, useful in structures and unions.
14
+ autoload(:StructHelper, 'sdl2/struct_helper')
12
15
 
13
- PrintDebug = false
14
-
15
- module StructHelper
16
-
17
- # Define a set of member readers
18
- # Ex1: `member_readers [:one, :two, :three]`
19
- # Ex2: `member_readers *members`
20
- def member_readers(*members_to_define)
21
- #self.class_eval do
22
- members_to_define.each do |member|
23
- define_method member do
24
- self[member]
25
- end
26
- end
27
- #end
28
- end
29
-
30
- # Define a set of member writers
31
- # Ex1: `member_writers [:one, :two, :three]`
32
- # Ex2: `member_writers *members`
33
- def member_writers(*members_to_define)
34
- members_to_define.each do |member|
35
- define_method "#{member}=".to_sym do |value|
36
- self[member]= value
37
- end
38
- end
39
- end
40
-
41
- end
42
-
43
- # Augmented for compares with anything that can be an array
16
+ ##
17
+ # FFI::Struct::InlineArray is modified to allow == operations, may not be effecient but seems to work.
44
18
  class FFI::Struct::InlineArray
45
-
46
19
  def ==(other)
47
20
  self.to_a == other.to_a
48
21
  end
49
22
  end
50
-
51
- # FFI::Struct class with some useful additions.
52
- class Struct < FFI::Struct
53
- extend StructHelper
54
-
55
- # Allows creation and use within block, automatically freeing pointer after block.
56
- def initialize(*args, &block)
57
- super(*args)
58
- if block_given?
59
- throw 'Release must be defined to use block' unless self.class.respond_to?(:release)
60
- yield self
61
- self.class.release(self.pointer)
62
- end
63
- end
64
-
65
- # Placeholder for Structs that need to initialize values.
66
- def self.create(values = {})
67
- created = self.new
68
- created.update_members(values)
69
- created
70
- end
71
-
72
- # A default release scheme is defined, but should be redefined where appropriate.
73
- def self.release(pointer)
74
- pointer.free
75
- end
76
-
77
- def free()
78
- self.pointer.free
79
- end
80
-
81
- # A human-readable representation of the struct and it's values.
82
- #def inspect
83
- # return 'nil' if self.null?
84
- #
85
- # #binding.pry
86
- # #return self.to_s
87
- #
88
- # report = "struct #{self.class.to_s}{"
89
- # report += self.class.members.collect do |field|
90
- # "#{field}->#{self[field].inspect}"
91
- # end.join(' ')
92
- # report += "}"
93
- # end
94
-
95
- # Compare two structures by class and values.
96
- # This will return true if compared to a "partial hash",
97
- # if all the keys the hash defines equal
98
- def ==(other)
99
- if PrintDebug
100
- @@rec ||= -1
101
- @@rec += 1
102
- pad = "\t"*@@rec
103
-
104
- puts
105
- puts " #{pad}COMPARING #{self} to #{other}"
106
- end
107
-
108
- result = catch(:result) do
109
- unless self.class == other.class or other.kind_of? Hash
110
- puts "Class Mismatch" if PrintDebug
111
- throw :result, false
112
- end
113
-
114
- if (other.kind_of? Hash) and (other.keys - members).any?
115
- puts "Extra Keys: #{other.keys-members}"
116
- thorw :result, false
117
- end
118
-
119
- if (other.respond_to?:null?) and (self.null? or other.null?)
120
- unless self.null? and other.null?
121
- puts "AHHHAOne is null and the other is not" if PrintDebug
122
- throw :result, false
123
- end
124
- else
125
- fields = other.kind_of?(Hash) ? members & other.keys : members
126
- fields.each do |field|
127
- print "#{pad} #{field}:#{self[field].class} = " if PrintDebug
128
-
129
- unless self[field] == other[field]
130
-
131
- puts "NO MATCH: #{self[field].to_s} #{other[field].to_s}" if PrintDebug
132
- throw :result, false
133
- end
134
- puts "MATCH" if PrintDebug
135
- end
136
- end
137
-
138
- true # Everything passed.
139
-
140
- end
141
- if PrintDebug
142
- @@rec += -1
143
- puts
144
- puts "#{pad}RESULT = #{result}"
145
- end
146
- return result
147
- end
148
-
149
- # Default cast handler
150
- def self.cast(something)
151
-
152
- if something.kind_of? self
153
-
154
- return something
155
-
156
- elsif something.kind_of? Hash
157
-
158
- return self.create(something)
159
-
160
- elsif something.nil?
161
-
162
- return something #TODO: Assume NUL is ok?
163
-
164
- else
165
-
166
- raise "#{self} can't cast #{something.insepct}"
167
-
168
- end
169
- end
170
-
171
- # Set members to values contained within hash.
172
- def update_members(values)
173
- if values.kind_of? Array
174
- raise "#{self} has less fields then #{values.inspect}" if values.count > members.count
175
- members.first(values.count).each_with_index do |field, idx|
176
- self[field] = values[idx]
177
- end
178
-
179
- elsif values.kind_of? Hash
180
- common = (self.members & values.keys)
181
- common.each do |field|
182
- self[field] = values[field]
183
- end
184
- else
185
- raise "#{self}#update_members unable to update from #{values.inspect}"
186
- end
187
- end
188
- end
189
-
190
- # FFI::ManagedStruct possibly with useful additions.
191
- class ManagedStruct < FFI::ManagedStruct
192
- extend StructHelper
193
-
194
- # Allows create and use the struct within a block.
195
- def initialize(*args, &block)
196
- super(*args)
197
- if block_given?
198
- yield self
199
- end
200
- end
201
-
202
- end
203
-
204
- class Union < FFI::Union
205
- extend StructHelper
206
- end
207
-
208
- class TypedPointer < Struct
209
-
210
- def self.type(kind)
211
- layout :value, kind
212
- end
213
-
214
- def value
215
- self[value]
216
- end
217
-
218
- alias_method :deref, :value
219
- end
220
-
221
- # Simple Type Structures to interface 'typed-pointers'
222
- # TODO: Research if this is the best way to handle 'typed-pointers'
223
- class FloatPointer < TypedPointer
224
- type :float
225
- end
226
-
227
- # Int-typed pointer
228
- class IntStruct < TypedPointer
229
- type :int
230
- end
231
-
232
- #
233
- class UInt16Struct < TypedPointer
234
- type :uint16
235
- end
236
-
237
- class UInt32Struct < TypedPointer
238
- type :uint32
239
- end
240
-
241
- class UInt8Struct < TypedPointer
242
- type :uint8
243
- end
244
-
245
- # TODO: Review if this is the best place to put it.
246
- # BlendMode is defined in a header file that is always included, so I'm
247
- # defineing again here.
248
- enum :blend_mode, [
249
- :none, 0x00000000,
250
- :blend, 0x00000001,
251
- :add, 0x00000002,
252
- :mod, 0x00000004
253
- ]
254
-
255
- class BlendModeStruct < Struct
256
- layout :value, :blend_mode
257
- end
258
-
259
- typedef :uint32, :pixel_format
23
+
24
+ ##
25
+ # Struct is locally defined, inheriting from FFI::Struct
26
+ # The original FFI::Struct is unmodified
27
+ autoload(:Struct, 'sdl2/struct')
28
+ ##
29
+ # StructArray is a helper for Pointer of Structs.
30
+ autoload(:StructArray, File.expand_path('../struct_array.rb', __FILE__))
31
+ ##
32
+ # TOOD: ManagedStruct is currently unused, and may not be.
33
+ # I have run into trouble using FFI::Struct.auto_ptr
34
+ autoload(:ManagedStruct, 'sdl2/managed_struct')
35
+ autoload(:Union, 'sdl2/union')
36
+ autoload(:TypedPointer, 'sdl2/typed_pointer')
37
+
38
+ autoload(:BLENDMODE, 'sdl2/blendmode')
39
+
260
40
 
261
41
  # Simple typedef to represent array sizes.
262
42
  typedef :int, :count
263
43
 
264
44
  end
265
45
 
46
+ require 'sdl2/blendmode'
266
47
  require 'sdl2/init'
267
48
 
268
49
  #TODO: require 'sdl2/assert'
@@ -278,8 +59,6 @@ require 'sdl2/joystick'
278
59
  require 'sdl2/gamecontroller'
279
60
  require 'sdl2/haptic'
280
61
  require 'sdl2/hints'
281
-
282
- #TODO?: require 'sdl2/loadso'
283
62
  require 'sdl2/log'
284
63
 
285
64
  #TODO: require 'sdl2/messagebox'