sdl2_ffi 0.0.4 → 0.0.5

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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile +6 -0
  4. data/Guardfile +47 -25
  5. data/Rakefile +6 -0
  6. data/bin/approvals +16 -0
  7. data/bin/autospec +16 -0
  8. data/bin/htmldiff +16 -0
  9. data/bin/ldiff +16 -0
  10. data/bin/nokogiri +16 -0
  11. data/bin/rspec +16 -0
  12. data/lib/enumerable_constants.rb +23 -8
  13. data/lib/sdl2.rb +116 -39
  14. data/lib/sdl2/color.rb +19 -7
  15. data/lib/sdl2/events.rb +184 -85
  16. data/lib/sdl2/gamecontroller.rb +1 -1
  17. data/lib/sdl2/gem_version.rb +1 -1
  18. data/lib/sdl2/joystick.rb +1 -1
  19. data/lib/sdl2/keyboard.rb +3 -0
  20. data/lib/sdl2/mouse.rb +5 -5
  21. data/lib/sdl2/pixel_format.rb +11 -3
  22. data/lib/sdl2/pixels.rb +40 -40
  23. data/lib/sdl2/point.rb +17 -1
  24. data/lib/sdl2/power.rb +12 -3
  25. data/lib/sdl2/rect.rb +19 -0
  26. data/lib/sdl2/render.rb +3 -3
  27. data/lib/sdl2/scancode.rb +7 -0
  28. data/lib/sdl2/stdinc.rb +2 -0
  29. data/lib/sdl2/surface.rb +64 -12
  30. data/lib/sdl2/ttf.rb +52 -66
  31. data/lib/sdl2/ttf/font.rb +115 -0
  32. data/lib/sdl2/video.rb +23 -23
  33. data/lib/sdl2/window.rb +15 -15
  34. data/sdl2_ffi.gemspec +5 -2
  35. data/spec/fixtures/approvals/lazyfoonet_lesson_01_hello_world/draws_hello_to_the_window_surface.approved.png +0 -0
  36. data/spec/fixtures/approvals/lazyfoonet_lesson_01_hello_world/loaded_and_optimizes_hello_bitmap.approved.png +0 -0
  37. data/spec/fixtures/approvals/lazyfoonet_lesson_02_optimized_images/draws_the_message_and_background.approved.png +0 -0
  38. data/spec/fixtures/approvals/lazyfoonet_lesson_03_extension_libraries/should_blit_a_png_to_screen.approved.png +0 -0
  39. data/spec/fixtures/approvals/lazyfoonet_lesson_04_event_driven_programming/draws_something_to_the_screen.approved.png +0 -0
  40. data/spec/fixtures/approvals/lazyfoonet_lesson_05_color_keying/draws_the_sprite_using_a_color_key.approved.png +0 -0
  41. data/spec/fixtures/approvals/lazyfoonet_lesson_06_clip_blitting_and_sprite_sheets/draws_the_clipped_sprites_to_the_screen.approved.png +0 -0
  42. data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
  43. data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/writes_a_message_to_a_surface.approved.png +0 -0
  44. data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_down_message.approved.png +0 -0
  45. data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_left_message.approved.png +0 -0
  46. data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_right_message.approved.png +0 -0
  47. data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_up_message.approved.png +0 -0
  48. data/spec/fixtures/approvals/sdl2_color/looks_blue_when_it_should.approved.png +0 -0
  49. data/spec/fixtures/approvals/sdl2_color/looks_green_when_it_should.approved.png +0 -0
  50. data/spec/fixtures/approvals/sdl2_color/looks_red_when_it_should.approved.png +0 -0
  51. data/spec/fixtures/approvals/sdl2_color/should_cast_arrays_properly.approved.png +0 -0
  52. data/spec/fixtures/approvals/sdl2_color/should_cast_hashes_properly.approved.png +0 -0
  53. data/spec/fixtures/fonts/FreeMono.ttf +0 -0
  54. data/spec/fixtures/fonts/GaroaHackerClubeBold.otf +0 -0
  55. data/spec/fixtures/fonts/GaroaHackerClubeBold.otf.credits.yaml +4 -0
  56. data/spec/fixtures/images/an_example.png +0 -0
  57. data/spec/fixtures/images/background.bmp +0 -0
  58. data/spec/fixtures/images/background.jpg +0 -0
  59. data/spec/fixtures/images/background.png +0 -0
  60. data/spec/fixtures/images/foo.jpg +0 -0
  61. data/spec/fixtures/images/hello.bmp +0 -0
  62. data/spec/fixtures/images/sprites.jpg +0 -0
  63. data/spec/fixtures/images/tile.png +0 -0
  64. data/spec/fixtures/images/x.png +0 -0
  65. data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +39 -0
  66. data/spec/functional/lazy_foo_tutorial/lazy_foo_02_optimized_images_spec.rb +51 -0
  67. data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +31 -0
  68. data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +55 -0
  69. data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +41 -0
  70. data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +41 -0
  71. data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +56 -0
  72. data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +120 -0
  73. data/spec/functional/lazy_foo_tutorial/lazy_foo_helper.rb +6 -0
  74. data/spec/png_writer.rb +21 -0
  75. data/spec/spec_helper.rb +23 -0
  76. data/spec/unit/sdl2/color_spec.rb +46 -0
  77. data/spec/unit/unit_helper.rb +3 -0
  78. data/test/approvals/clip_blitting_and_sprite_sheets.received.bmp +0 -0
  79. data/test/approvals/color_keying_example.approved.png +0 -0
  80. data/test/approvals/hello_world_example_hello.approved.png +0 -0
  81. data/test/approvals/hello_world_example_screen.approved.png +0 -0
  82. data/test/approvals/optimized_surface_loading.approved.png +0 -0
  83. data/test/fixtures/background.jpg +0 -0
  84. data/test/fixtures/foo.jpg +0 -0
  85. data/test/fixtures/sprites.jpg +0 -0
  86. data/test/fixtures/x.png +0 -0
  87. data/test/functional/examples/lazyfoo.net_s/test_clip_blitting_and_sprite_sheets.rb +50 -0
  88. data/test/functional/examples/lazyfoo.net_s/test_color_keying.rb +42 -0
  89. data/test/functional/examples/test_lazy_foo_examples.rb +120 -48
  90. data/test/test_helper.rb +9 -0
  91. metadata +138 -4
  92. data/graph +0 -566
@@ -0,0 +1,115 @@
1
+ module SDL2
2
+
3
+ module TTF
4
+
5
+ # Internal structure containing font information
6
+ class Font < Struct
7
+
8
+ class FT_Bitmap < Struct
9
+ layout :rows, :int,
10
+ :width, :int,
11
+ :pitch, :int,
12
+ :buffer, :string,
13
+ :num_grays, :short,
14
+ :pixel_mode, :char,
15
+ :palette_mode, :char,
16
+ :palette, :pointer
17
+ end
18
+
19
+ class FT_Open_Args < Struct
20
+ layout :flags, :uint,
21
+ :memory_base, :uint8,
22
+ :memory_size, :long,
23
+ :pathname, :string,
24
+ :stream, :pointer,
25
+ :module, :pointer,
26
+ :num_params, :int,
27
+ :params, :pointer
28
+ end
29
+
30
+ class CachedGlyph < Struct
31
+ layout :stored, :int,
32
+ :index, :uint,
33
+ :bitmap, FT_Bitmap,
34
+ :pixmap, FT_Bitmap,
35
+ :minx, :int,
36
+ :maxx, :int,
37
+ :miny, :int,
38
+ :maxy, :int,
39
+ :yoffset, :int,
40
+ :advance, :int,
41
+ :cached, :uint16
42
+ end
43
+
44
+ layout :face, :pointer,
45
+
46
+ :height, :int,
47
+ :ascent, :int,
48
+ :descent, :int,
49
+ :lineskip, :int,
50
+
51
+ :face_style, :int,
52
+ :style, :int,
53
+ :outline, :int,
54
+
55
+ :kerning, :int,
56
+
57
+ :glyph_overhang, :int,
58
+ :glyph_italics, :float,
59
+
60
+ :underline_offset, :int,
61
+ :underline_height, :int,
62
+
63
+ :current, CachedGlyph.by_ref,
64
+ :cache, [CachedGlyph, 257], # SDL_ttf.c: Line 95
65
+
66
+ :src, SDL2::RWops.by_ref,
67
+ :freesrc, :int,
68
+ :args, FT_Open_Args,
69
+
70
+ :font_size_family, :int,
71
+
72
+ :hinting, :int
73
+
74
+ def self.open(file, pt_size)
75
+ TTF.open_font!(file, pt_size)
76
+ end
77
+
78
+ def self.release(pointer)
79
+ TTF.close_font(pointer)
80
+ end
81
+
82
+ def close()
83
+ TTF.close_font(self)
84
+ end
85
+
86
+ alias_method :free, :close
87
+
88
+ def render_text_solid(text, color = [255,255,255])
89
+ color = Color.cast(color)
90
+ TTF.render_text_solid!(self, text, color)
91
+ end
92
+
93
+ def render_text_shaded(text, fg = [255,255,255,255], bg = [0,0,0,0] )
94
+ fg = Color.cast(fg)
95
+ bg = Color.cast(bg)
96
+ TTF.render_text_shaded!(self, text, fg, bg)
97
+ end
98
+
99
+ def render_text_blended(text, fg = [255, 255, 255, 255])
100
+ #binding.pry
101
+ fg = Color.cast(fg)
102
+ #binding.pry
103
+ TTF.render_text_blended!(self, text, fg)
104
+ end
105
+
106
+ def render_text_blended_wrapped(text, width, fg = [255,255,255,255])
107
+ fg = Color.cast(fg)
108
+ TTF.render_text_blended_wrapped!(self, text, fg, width)
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
115
+ end
@@ -22,29 +22,29 @@ module SDL2
22
22
  # OpenGL configuration attributes
23
23
  module GLattr
24
24
  include EnumerableConstants
25
- RED_SIZE = next_const_value
26
- GREEN_SIZE = next_const_value
27
- BLUE_SIZE = next_const_value
28
- ALPHA_SIZE = next_const_value
29
- BUFFER_SIZE = next_const_value
30
- DOUBLEBUFFER = next_const_value
31
- DEPTH_SIZE = next_const_value
32
- STENCIL_SIZE = next_const_value
33
- ACCUM_RED_SIZE = next_const_value
34
- ACCUM_GREEN_SIZE = next_const_value
35
- ACCUM_BLUE_SIZE = next_const_value
36
- ACCUM_ALPHA_SIZE = next_const_value
37
- STEREO = next_const_value
38
- MULTISAMPLEBUFFERS = next_const_value
39
- MULTISAMPLESAMPLES = next_const_value
40
- ACCELERATED_VISUAL = next_const_value
41
- RETAINED_BACKING = next_const_value
42
- CONTEXT_MAJOR_VERSION = next_const_value
43
- CONTEXT_MINOR_VERSION = next_const_value
44
- CONTEXT_EGL = next_const_value
45
- CONTEXT_FLAGS = next_const_value
46
- CONTEXT_PROFILE_MASK = next_const_value
47
- SHARE_WITH_CURRENT_CONTEXT = next_const_value
25
+ RED_SIZE
26
+ GREEN_SIZE
27
+ BLUE_SIZE
28
+ ALPHA_SIZE
29
+ BUFFER_SIZE
30
+ DOUBLEBUFFER
31
+ DEPTH_SIZE
32
+ STENCIL_SIZE
33
+ ACCUM_RED_SIZE
34
+ ACCUM_GREEN_SIZE
35
+ ACCUM_BLUE_SIZE
36
+ ACCUM_ALPHA_SIZE
37
+ STEREO
38
+ MULTISAMPLEBUFFERS
39
+ MULTISAMPLESAMPLES
40
+ ACCELERATED_VISUAL
41
+ RETAINED_BACKING
42
+ CONTEXT_MAJOR_VERSION
43
+ CONTEXT_MINOR_VERSION
44
+ CONTEXT_EGL
45
+ CONTEXT_FLAGS
46
+ CONTEXT_PROFILE_MASK
47
+ SHARE_WITH_CURRENT_CONTEXT
48
48
  end
49
49
 
50
50
  # lines 165~190
@@ -62,21 +62,21 @@ module SDL2
62
62
  # Event subtype for window events
63
63
  module WINDOWEVENT
64
64
  include EnumerableConstants
65
- NONE = next_const_value
66
- SHOWN = next_const_value
67
- HIDDEN = next_const_value
68
- EXPOSED = next_const_value
69
- MOVED = next_const_value
70
- RESIZED = next_const_value
71
- SIZE_CHANGED = next_const_value
72
- MINIMIZED = next_const_value
73
- MAXIMIZED = next_const_value
74
- RESTORED = next_const_value
75
- ENTER = next_const_value
76
- LEAVE = next_const_value
77
- FOCUS_GAINED = next_const_value
78
- FOCUS_LOST = next_const_value
79
- CLOSE = next_const_value
65
+ NONE
66
+ SHOWN
67
+ HIDDEN
68
+ EXPOSED
69
+ MOVED
70
+ RESIZED
71
+ SIZE_CHANGED
72
+ MINIMIZED
73
+ MAXIMIZED
74
+ RESTORED
75
+ ENTER
76
+ LEAVE
77
+ FOCUS_GAINED
78
+ FOCUS_LOST
79
+ CLOSE
80
80
  end
81
81
 
82
82
  # System Window
@@ -22,12 +22,15 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'activesupport'
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.3'
25
- spec.add_development_dependency 'minitest', '~> 5.0.7'
25
+ spec.add_development_dependency 'minitest', '~> 5.0.7' # TODO: Remove Minitest?
26
+ spec.add_development_dependency 'rspec', '~> 2.0'
26
27
  spec.add_development_dependency 'rake'
27
28
  spec.add_development_dependency 'pry'
28
29
  spec.add_development_dependency 'guard'
29
- spec.add_development_dependency 'guard-minitest'
30
+ #spec.add_development_dependency 'guard-minitest'
31
+ spec.add_development_dependency 'guard-rspec'
30
32
  spec.add_development_dependency 'yard'
31
33
 
32
34
 
35
+
33
36
  end
@@ -0,0 +1,4 @@
1
+ authors:
2
+ - Tony de Marco
3
+ - Diego Maldonado
4
+ href: http://openfontlibrary.org/en/font/garoa-hacker-clube-bold
@@ -0,0 +1,39 @@
1
+ require_relative 'lazy_foo_helper'
2
+
3
+ # ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson01/index2.php
4
+ # Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
5
+ describe "LazyFoo.net: Lesson 01: Hello World" do
6
+
7
+ before do
8
+ expect(init(:EVERYTHING)).to eq(0)
9
+
10
+ @window = Window.create(subject, :CENTERED, :CENTERED, 640, 480, :SHOWN)
11
+
12
+ @screen = @window.surface
13
+
14
+ @hello = @screen.convert(SDL2.load_bmp!(img_path('hello.bmp')))
15
+ @screen.blit_in(@hello)
16
+ @window.update_surface
17
+ # If you want to see it, uncomment the following:
18
+ #delay(2000)
19
+ end
20
+
21
+ it 'loaded and optimizes hello bitmap' do
22
+ verify(){@hello}
23
+ end
24
+
25
+ it 'created a window surface' do
26
+ expect(@window).to be_a(Window)
27
+ expect(@window.null?).to be_false
28
+ end
29
+
30
+ it 'draws hello to the window surface' do
31
+ verify(format: :png){@screen}
32
+ end
33
+
34
+ after do
35
+ @hello.free
36
+ quit()
37
+ end
38
+
39
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ require 'sdl2'
4
+
5
+ include SDL2
6
+
7
+ # ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson02/index2.php
8
+ # Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
9
+
10
+ describe "LazyFoo.net: Lesson 02: Optimized Images" do
11
+ WIDTH = 640
12
+ HEIGHT = 480
13
+ # BPP = 32 # TODO: Is this still needed?
14
+ before do
15
+ @window = Window.create(subject, :CENTERED, :CENTERED, WIDTH, HEIGHT, :SHOWN)
16
+ @screen = @window.surface
17
+
18
+ def load_image(file)
19
+ @screen.convert(SDL2.load_bmp!(file))
20
+ end
21
+
22
+ @background = load_image(img_path('background.bmp'))
23
+ @message = load_image(img_path('hello.bmp'))
24
+ @background.blit_out(@screen, [0, 0])
25
+ @background.blit_out(@screen, [320, 0])
26
+ @background.blit_out(@screen, [0, 240])
27
+ @background.blit_out(@screen, [320, 240])
28
+ @message.blit_out(@screen, [180, 140])
29
+
30
+ @window.update_surface
31
+
32
+ end
33
+
34
+ after do
35
+
36
+ @background.free
37
+ @message.free
38
+
39
+ quit
40
+
41
+ end
42
+
43
+ it "optimized the background and message" do
44
+ expect(@background.format).to eq(@screen.format)
45
+ expect(@message.format).to eq(@screen.format)
46
+ end
47
+
48
+ it 'draws the message and background' do
49
+ verify(format: :png){@screen}
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'lazy_foo_helper'
2
+
3
+ require 'sdl2/image'
4
+
5
+ #ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson03/index.php
6
+ # Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
7
+ describe "LazyFoo.net: Lesson 03: Extension Libraries" do
8
+
9
+ before do
10
+ SDL2.init!(:EVERYTHING)
11
+ @window = Window.create(subject, :CENTERED, :CENTERED, 640, 480)
12
+
13
+ @screen = @window.surface
14
+
15
+ a_png = @screen.convert(Image.load!(img_path('an_example.png')))
16
+
17
+ a_png.blit_out(@screen)
18
+
19
+ @window.update_surface
20
+
21
+ end
22
+
23
+ it 'should blit a_png to screen' do
24
+ verify(format: :png){@screen}
25
+ end
26
+
27
+ after do
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,55 @@
1
+ require_relative 'lazy_foo_helper'
2
+
3
+ require 'sdl2/image'
4
+
5
+ #ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson04/index.php
6
+ # Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
7
+ describe "LazyFoo.net: Lesson 04: Event Driven Programming" do
8
+
9
+ before do
10
+ SDL2.init!(:EVERYTHING)
11
+
12
+ @window = Window.create(subject, :CENTERED, :CENTERED, 640, 480)
13
+
14
+ @screen = @window.surface
15
+
16
+ @image = @screen.convert(Image.load!(img_path('x.png')))
17
+
18
+ @image.blit_out(@screen, [0, 0])
19
+
20
+ @window.update_surface()
21
+
22
+ until @quit do
23
+
24
+ while event = Event.poll()
25
+ puts "GOT EVENT TYPE: #{event.type_symbol}"
26
+ if (event.type == :QUIT)
27
+ @quit = true
28
+ end
29
+ end
30
+
31
+ my_quit_event = SDL2::Event.new
32
+ my_quit_event.type = SDL2::EVENTTYPE::QUIT
33
+
34
+ SDL2.push_event!(my_quit_event)
35
+
36
+ end
37
+
38
+ end
39
+
40
+ it 'Draws something to the screen' do
41
+ verify(format: :png) do
42
+ @screen
43
+ end
44
+ end
45
+
46
+ it 'set the quit flag' do
47
+ expect(@quit).to be_true
48
+ end
49
+
50
+ after do
51
+ @image.free
52
+ quit()
53
+ end
54
+
55
+ end