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
@@ -1,46 +0,0 @@
1
- require 'sdl2/engine'
2
-
3
- module SDL2
4
-
5
- # An engine multiplexor.
6
- # Only has one focus, but that focus can change.
7
- class Engine::Engines < Engine
8
-
9
- def initialize(opts)
10
- super(opts)
11
- @engines = [] #opts[:engines] || []
12
- @current_idx = 0
13
- end
14
-
15
- attr_reader :engines
16
-
17
- def current_engine
18
- @engines[@current_idx]
19
- end
20
-
21
- def handle_event(event)
22
- return true if super(event) # self swallowed event.
23
- if current_engine
24
- puts "Passing to current engine."if SDL2::PrintDebug
25
- return true if current_engine.handle_event(event)
26
- end
27
- puts "Unable to handle"if SDL2::PrintDebug
28
- return false # if we get to here.
29
- end
30
-
31
- def paint_to(surface)
32
- if ce = current_engine
33
- return ce.paint_to(surface)
34
- else
35
- return false
36
- end
37
- end
38
-
39
- def quit()
40
- @engines.each(&:quit)
41
- super()
42
- end
43
-
44
- end
45
-
46
- end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,50 +0,0 @@
1
- require_relative '../../../test_helper'
2
-
3
- describe "LazyFoo.net's Examples" do
4
-
5
- it "runs the clip blitting and sprite sheets example" do
6
-
7
- require 'sdl2'
8
- require 'sdl2/image'
9
- SDL2.init(:EVERYTHING)
10
-
11
- @window = SDL2::Window.create('Clip blitting and sprite sheets',
12
- :CENTERED,:CENTERED,640,480)
13
-
14
- @screen = @window.surface
15
-
16
- clip = Array.new{SDL2::Rect.new}
17
-
18
- sprite_rect = Array.new(4)do |idx|
19
- s = SDL2::Rect.new
20
- s.x= (idx % 2)* 100
21
- s.y= (idx / 2) *100
22
- s.w= 100
23
- s.h= 100
24
- s
25
- end
26
-
27
- puts sprite_rect[0]
28
- puts sprite_rect[1]
29
- puts sprite_rect[2]
30
- puts sprite_rect[3]
31
-
32
- dots = @screen.convert(SDL2::Image.load(fixture('sprites.jpg')))
33
-
34
- @screen.fill_rect(@screen.clip_rect, [0xFF, 0xFF, 0xFF])
35
-
36
- #binding.pry
37
- @screen.blit_in(dots, [0,0], sprite_rect[0])
38
- @screen.blit_in(dots, [540,0], sprite_rect[1])
39
- @screen.blit_in(dots, [0, 380], sprite_rect[2])
40
- @screen.blit_in(dots, [540, 380], sprite_rect[3])
41
-
42
- @window.update_surface
43
-
44
- Approvals.verify(@screen, format: :bmp, name: "clip blitting and sprite sheets")
45
-
46
- SDL2.quit()
47
-
48
- end
49
-
50
- end
@@ -1,42 +0,0 @@
1
- require_relative '../../../test_helper'
2
-
3
- def path_for(something)
4
- File.expand_path(something, FIXTURE_DIR)
5
- end
6
-
7
- describe "Color Keying" do
8
- it "runs LazyFoo.net's Color Keying example" do
9
- require 'sdl2'
10
- require 'sdl2/image'
11
-
12
- def load_image(filename)
13
- loadedImage = SDL2::Image.load!(path_for(filename))
14
- optimizedImage = @screen.convert(loadedImage)
15
- loadedImage.free
16
-
17
- return optimizedImage
18
- end
19
-
20
- @window = SDL2::Window.create("Color Keying",:CENTERED,:CENTERED,640,480)
21
- @screen = @window.surface
22
-
23
- background = load_image('background.jpg')
24
-
25
- foo = load_image('foo.jpg')
26
-
27
- foo.color_key = foo.format.map_rgb([0, 0xFF, 0xFF])
28
-
29
- @screen.blit_in(background)
30
- @screen.blit_in(foo)
31
-
32
- @window.update_surface
33
-
34
- Approvals.verify(@screen, format: :png, name: "Color Keying Example")
35
-
36
- background.free
37
- foo.free
38
-
39
- SDL2.quit()
40
- end
41
-
42
- end
@@ -1,195 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe "Hello World example translated from: http://lazyfoo.net/SDL_tutorials/lesson01/index2.php" do
4
-
5
- BMP = Hash.new(){ | bmps, key | bmps[key] = File.expand_path("#{key}.bmp", FIXTURE_DIR) }
6
- PNG = Hash.new(){ | bmps, key | bmps[key] = File.expand_path("#{key}.png", FIXTURE_DIR) }
7
-
8
- # Functional Translated from:
9
- # http://lazyfoo.net/SDL_tutorials/lesson01/index2.php
10
- it "runs LazyFoo.net's Hello World example" do
11
-
12
- require 'sdl2'
13
-
14
- hello = nil
15
- window = nil
16
- screen = nil
17
-
18
- # BANG(!) versions of methods Raise RuntimeErrors if needed.
19
- SDL2.init!(:EVERYTHING)
20
-
21
- window = SDL2::Window.create('Hello World', :UNDEFINED, :UNDEFINED, 640, 480, :SHOWN)
22
-
23
- screen = window.surface
24
-
25
- #binding.pry
26
-
27
- hello = SDL2::Surface.load_bmp(BMP[:hello])
28
-
29
- Approvals.verify(hello, format: :png, name: 'hello world example: hello')
30
-
31
- screen.blit_in(hello)
32
-
33
- Approvals.verify(screen, format: :png, name: 'hello world example: screen')
34
-
35
- window.update_surface
36
-
37
- #SDL2::delay(2000)
38
-
39
- SDL2::quit() # Since the Quit function can't fail, there is no BANG(!) version.
40
-
41
- end
42
-
43
- # Functional Example Translated from:
44
- # http://lazyfoo.net/SDL_tutorials/lesson02/index.php
45
- it "runs LazyFoo.net's Optimized Surface Loading and Blitting " do
46
-
47
- width = 640
48
- height = 480
49
-
50
- message = nil
51
- background = nil
52
- SDL2.init!(:EVERYTHING)
53
-
54
- window = SDL2::Window.create("Optimized Images!", :CENTERED, :CENTERED, width, height)
55
- @screen = window.surface
56
-
57
- def load_image(filename)
58
- loadedImage = SDL2.load_bmp!(filename)
59
- optimizedImage = @screen.convert(loadedImage)
60
- loadedImage.free
61
- return optimizedImage
62
- end
63
-
64
- def apply_surface(x, y, source, dest)
65
- offset = SDL2::Rect.new
66
- offset.x, offset.y = x,y
67
- offset.w, offset.h = source.w, source.h
68
- source.blit_out(dest, offset)
69
- end
70
-
71
- message = load_image(BMP[:hello])
72
- background = load_image(BMP[:background])
73
-
74
- apply_surface(0,0, background, @screen)
75
- apply_surface(320,0, background, @screen)
76
- apply_surface(0,240, background, @screen)
77
- apply_surface(320,240, background, @screen)
78
-
79
- apply_surface(180, 140, message, @screen)
80
-
81
- Approvals.verify(@screen, format: :png, name: 'Optimized Surface Loading')
82
-
83
- window.update_surface
84
-
85
- # SDL2.delay(2000) # Watch it for a sec.
86
-
87
- message.free
88
- background.free
89
-
90
- SDL2.quit()
91
-
92
- end
93
-
94
- it "runs LazyFoo.net's SDL Extension Libraries" do
95
- require 'sdl2/image'
96
-
97
- SDL2.init! :EVERYTHING
98
-
99
- @window = SDL2::Window.create("Extension Libraries", :CENTERED, :CENTERED, 640, 480)
100
- @screen = @window.surface
101
-
102
- # We can load more now, not just BMPs!
103
- def load_image(filename)
104
- loadedImage = SDL2::Image.load!(filename)
105
- optimizedImage = @screen.convert(loadedImage)
106
- loadedImage.free
107
- return optimizedImage
108
- end
109
-
110
- a_png = load_image(PNG[:an_example])
111
-
112
- a_png.blit_out(@screen)
113
-
114
- @window.update_surface
115
-
116
- # SDL2.delay(2000) # sleep 1
117
-
118
- a_png.free
119
-
120
- SDL2.quit()
121
-
122
- end
123
-
124
- it "runs LazyFoo.net's Event Driven Programming" do
125
- require 'sdl2/image'
126
- require 'sdl2'
127
-
128
- def init()
129
- SDL2.init!(:EVERYTHING)
130
-
131
- width = 640
132
- height = 480
133
- @window = SDL2::Window.create("Event Driven Programming",
134
- :CENTERED, :CENTERED, width, height)
135
-
136
- @screen = @window.surface
137
- end
138
-
139
- def clean_up()
140
- @image.free unless @image.nil?
141
- SDL2.quit()
142
- end
143
-
144
- def load_image(filename)
145
- loadedImage = SDL2::Image.load!(filename)
146
- optimizedImage = @screen.convert(loadedImage)
147
- loadedImage.free
148
- return optimizedImage
149
- end
150
-
151
- def apply_surface(x, y, source, destination)
152
- offset = SDL2::Rect.new
153
- offset.x, offset.y = x,y
154
- source.blit_out(destination, offset)
155
- end
156
-
157
- def load_files()
158
- @image = load_image(PNG[:x])
159
- end
160
-
161
- # Main start:
162
-
163
- quit = false
164
-
165
- init()
166
-
167
- load_files()
168
-
169
- apply_surface(0,0, @image, @screen)
170
-
171
- @window.update_surface()
172
-
173
- until @quit do
174
- # Pre-Events
175
-
176
- # Event Processing
177
- while event = SDL2::Event.poll()
178
- puts "GOT EVENT TYPE: #{event.type_symbol}"
179
- if (event.type == SDL2::EVENTTYPE::QUIT)
180
- @quit = true
181
- end
182
- end
183
-
184
- # Post - Events
185
- # Lets insert an SDL QUIT event.
186
- my_quit_event = SDL2::Event.new
187
- my_quit_event.type = SDL2::EVENTTYPE::QUIT
188
-
189
- SDL2::push_event! my_quit_event
190
-
191
- end
192
-
193
- end
194
-
195
- end
@@ -1,15 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe "README.md" do
4
-
5
- it "'How to start:' Example" do
6
-
7
- require 'sdl2'
8
-
9
- SDL2.init! :EVERYTHING
10
-
11
- assert SDL2.was_init?(:VIDEO)
12
-
13
- end
14
-
15
- end
@@ -1,13 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'pry'
3
- require 'approvals'
4
-
5
-
6
- FIXTURE_DIR = File.expand_path('../fixtures/',__FILE__)
7
- def fixture(file)
8
- File.expand_path(file, FIXTURE_DIR)
9
- end
10
-
11
- Approvals.configure do |c|
12
- c.approvals_path = File.expand_path('../approvals/',__FILE__)+'/'
13
- end
@@ -1,10 +0,0 @@
1
- require_relative '../../test_helper'
2
- require 'sdl2/assert'
3
-
4
- describe 'SDL2' do
5
-
6
- it 'has the SDL_assert.h API' do
7
- skip 'Not yet implemented'
8
- end
9
-
10
- end
@@ -1,9 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- require 'sdl2/audio'
4
-
5
- describe SDL2 do
6
- it 'has the SDL_audio.h API' do
7
- skip('Not Yet Implemented')
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- require 'sdl2/clipboard'
4
-
5
- describe SDL2 do
6
-
7
- it 'has the SDL_clipboard.h API' do
8
- [:set_clipboard_text, :get_clipboard_text, :has_clipboard_text].each do|func|
9
- assert_respond_to SDL2, func
10
- end
11
- end
12
-
13
- end
@@ -1,11 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- require 'sdl2/cpuinfo'
4
-
5
- describe SDL2 do
6
-
7
- it 'should have the SDL_cpuinfo.h API' do
8
- skip "Not yet implemented."
9
- end
10
-
11
- end
@@ -1,20 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- require 'sdl2/error'
4
-
5
- describe SDL2 do
6
-
7
- it 'deals with errors' do
8
-
9
- assert SDL2.respond_to?(:clear_error)
10
- assert SDL2.respond_to?(:get_error)
11
- assert SDL2.respond_to?(:set_error)
12
-
13
- SDL2.clear_error()
14
- assert_equal '', SDL2.get_error()
15
- assert_equal -1, SDL2.set_error('My Error String %d', :int, 6384)
16
- assert_equal 'My Error String 6384', SDL2.get_error()
17
-
18
- end
19
-
20
- end