sdl2_ffi 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/Guardfile +2 -2
- data/README.md +9 -1
- data/lib/sdl2.rb +150 -25
- data/lib/sdl2/color.rb +27 -4
- data/lib/sdl2/display.rb +3 -3
- data/lib/sdl2/gem_version.rb +1 -1
- data/lib/sdl2/image.rb +68 -0
- data/lib/sdl2/image/sdl_image_module.rb +8 -0
- data/lib/sdl2/init.rb +8 -8
- data/lib/sdl2/palette.rb +64 -6
- data/lib/sdl2/pixel_format.rb +105 -17
- data/lib/sdl2/pixels.rb +241 -18
- data/lib/sdl2/render.rb +2 -2
- data/lib/sdl2/surface.rb +137 -37
- data/lib/sdl2/ttf.rb +125 -0
- data/lib/sdl2/ttf/sdl_ttf_module.rb +5 -0
- data/lib/sdl2/version.rb +6 -0
- data/lib/sdl2/window.rb +1 -1
- data/test/fixtures/color_bars.jpg +0 -0
- data/test/test_helper.rb +2 -0
- data/test/unit/sdl2/test_hints.rb +3 -3
- data/test/unit/sdl2/test_image.rb +9 -0
- data/test/unit/sdl2/test_palette.rb +26 -0
- data/test/unit/sdl2/test_pixel_format.rb +36 -0
- data/test/unit/sdl2/test_surface.rb +43 -0
- data/test/unit/sdl2/test_ttf.rb +11 -0
- data/test/unit/sdl2/test_window.rb +29 -32
- data/test/unit/test_scratch.rb +19 -0
- data/test/unit/test_sdl2.rb +2 -2
- metadata +18 -2
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
require 'sdl2/pixels' # SDL_pixels.h defines SDL_PixelFormat
|
4
|
+
|
5
|
+
require 'sdl2/pixel_format'
|
6
|
+
|
7
|
+
describe SDL2::PixelFormat do
|
8
|
+
|
9
|
+
it 'can be created in all formats' do
|
10
|
+
|
11
|
+
SDL2::PIXELFORMAT.by_name.each do |format|
|
12
|
+
unless format == 0 # Skip "UNKOWN"
|
13
|
+
begin
|
14
|
+
pixel_format = SDL2::PixelFormat.create(format[1])
|
15
|
+
refute pixel_format.null?
|
16
|
+
assert_kind_of SDL2::PixelFormat, pixel_format
|
17
|
+
rescue RuntimeError => e
|
18
|
+
skip "Problem with SDL2::PIXELFORMAT.#{format[0]}" #TODO: Fix broken PIXELFORMATS
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
it 'can get the name of all formats' do
|
28
|
+
SDL2::PIXELFORMAT.by_name.each_pair do |k,v|
|
29
|
+
name = SDL2::PixelFormat.get_name(v)
|
30
|
+
assert_includes name, k.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
end
|
@@ -40,6 +40,49 @@ describe SDL2 do
|
|
40
40
|
].each do |function|
|
41
41
|
assert_respond_to SDL2, function
|
42
42
|
end
|
43
|
+
end
|
44
|
+
end
|
43
45
|
|
46
|
+
describe SDL2::Surface do
|
47
|
+
|
48
|
+
it 'rejects invalid pixel formats' do
|
49
|
+
assert_raises RuntimeError do
|
50
|
+
# Try to create a 64bit depth image
|
51
|
+
SDL2::Surface.create_rgb(0, 100, 100, 64)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can be created with valid arguments' do
|
56
|
+
surfaces =
|
57
|
+
[
|
58
|
+
SDL2::Surface.create_rgb(0, 100, 100, 4),
|
59
|
+
SDL2::Surface.create_rgb(0, 100, 100, 8),
|
60
|
+
SDL2::Surface.create_rgb(0,100,100,16)
|
61
|
+
]
|
62
|
+
surfaces.each do |surface|
|
63
|
+
refute surface.null?
|
64
|
+
assert_kind_of SDL2::Surface, surface
|
65
|
+
end
|
66
|
+
assert_equal 4, surfaces[0].format.bits_per_pixel
|
67
|
+
assert_equal 8, surfaces[1].format.bits_per_pixel
|
68
|
+
assert_equal 16, surfaces[2].format.bits_per_pixel
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'can be freed' do
|
72
|
+
surface = SDL2::Surface.create_rgb(0, 100, 100, 4)
|
73
|
+
surface.free
|
74
|
+
skip("Don't know how to test this")
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'can get and set the palette' do
|
78
|
+
surface = SDL2::Surface.create_rgb(0, 100, 100, 4)
|
79
|
+
surface_palette = surface.palette
|
80
|
+
assert_kind_of SDL2::Palette, surface_palette
|
81
|
+
my_palette = SDL2::Palette.create(16)
|
82
|
+
|
83
|
+
|
84
|
+
surface.palette = my_palette
|
85
|
+
|
86
|
+
assert_equal my_palette, surface.palette
|
44
87
|
end
|
45
88
|
end
|
@@ -1,18 +1,17 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
|
-
require 'sdl2/video'
|
3
|
+
require 'sdl2/video'
|
4
|
+
# Window is a part of the Video API
|
4
5
|
|
5
6
|
describe SDL2::Window do
|
6
|
-
|
7
|
+
|
7
8
|
before do
|
8
9
|
@window = SDL2::Window.create!
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
after do
|
12
13
|
SDL2.destroy_window(@window)
|
13
14
|
end
|
14
|
-
|
15
|
-
|
16
15
|
|
17
16
|
it 'can be created' do
|
18
17
|
window = SDL2::Window.create!('My Title', 10, 20, 300, 400)
|
@@ -20,7 +19,7 @@ describe SDL2::Window do
|
|
20
19
|
SDL2.destroy_window(window)
|
21
20
|
end
|
22
21
|
|
23
|
-
it 'has a title' do
|
22
|
+
it 'has a title' do
|
24
23
|
@window.title = 'Updated'
|
25
24
|
assert_equal 'Updated', @window.title
|
26
25
|
end
|
@@ -32,22 +31,22 @@ describe SDL2::Window do
|
|
32
31
|
assert_equal [640, 480], window.current_size
|
33
32
|
SDL2.destroy_window(window)
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
it 'has a maximum size' do
|
37
|
-
|
36
|
+
|
38
37
|
assert_kind_of Array, @window.maximum_size
|
39
38
|
@window.maximum_size = [800,600]
|
40
39
|
assert_equal [800,600], @window.maximum_size
|
41
|
-
|
40
|
+
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
it 'has a minimum size' do
|
45
|
-
|
44
|
+
|
46
45
|
assert_kind_of Array, @window.minimum_size
|
47
46
|
@window.minimum_size = [320,200]
|
48
47
|
assert_equal [320,200], @window.minimum_size
|
49
48
|
end
|
50
|
-
|
49
|
+
|
51
50
|
it 'has a pixel format' do
|
52
51
|
assert_kind_of Integer, @window.pixel_format
|
53
52
|
end
|
@@ -78,7 +77,7 @@ describe SDL2::Window do
|
|
78
77
|
#assert_kind_of FFI::Pointer, window.data
|
79
78
|
end
|
80
79
|
|
81
|
-
it 'has an associated display' do
|
80
|
+
it 'has an associated display' do
|
82
81
|
assert_kind_of SDL2::Display, @window.display
|
83
82
|
end
|
84
83
|
|
@@ -86,73 +85,71 @@ describe SDL2::Window do
|
|
86
85
|
assert_kind_of SDL2::Display::Mode, @window.display_mode
|
87
86
|
end
|
88
87
|
|
89
|
-
it 'has associated flags' do
|
88
|
+
it 'has associated flags' do
|
90
89
|
assert_kind_of Integer, @window.flags
|
91
90
|
end
|
92
|
-
|
91
|
+
|
93
92
|
it 'has an associated gamma ramp' do
|
94
93
|
skip('Not sure how to implement this yet.')
|
95
94
|
end
|
96
|
-
|
95
|
+
|
97
96
|
it 'has an associated id' do
|
98
97
|
assert_kind_of Integer, @window.id
|
99
98
|
end
|
100
|
-
|
99
|
+
|
101
100
|
it 'has a position' do
|
102
101
|
assert_kind_of Array, @window.position
|
103
102
|
@window.position = [123,456]
|
104
103
|
assert_equal [123,456], @window.position
|
105
104
|
end
|
106
|
-
|
105
|
+
|
107
106
|
it 'has a surface' do
|
108
107
|
assert_kind_of SDL2::Surface, @window.surface
|
109
|
-
end
|
110
|
-
|
108
|
+
end
|
109
|
+
|
111
110
|
it 'can update the window surface' do
|
112
111
|
surface = @window.surface
|
113
112
|
assert_equal 0, @window.update_surface!
|
114
113
|
end
|
115
|
-
|
114
|
+
|
116
115
|
it 'can update surface rects' do
|
117
116
|
skip('For now, I\'ll handle arrays of rects later.')
|
118
117
|
end
|
119
|
-
|
118
|
+
|
120
119
|
it 'can be hidden' do
|
121
120
|
@window.hide
|
122
121
|
skip("Not sure how to test state.")
|
123
122
|
end
|
124
|
-
|
123
|
+
|
125
124
|
it 'can be shown' do
|
126
125
|
@window.show
|
127
126
|
skip("Not sure how to test state.")
|
128
127
|
end
|
129
|
-
|
128
|
+
|
130
129
|
it 'can be maximized' do
|
131
130
|
@window.maximize
|
132
131
|
skip("Not sure how to test state.")
|
133
132
|
end
|
134
|
-
|
133
|
+
|
135
134
|
it 'can be minimized' do
|
136
135
|
@window.minimize
|
137
136
|
skip("Not sure how to test state.")
|
138
137
|
end
|
139
|
-
|
138
|
+
|
140
139
|
it 'can be restored' do
|
141
140
|
@window.restore
|
142
141
|
skip("Not sure how to test state.")
|
143
142
|
end
|
144
|
-
|
143
|
+
|
145
144
|
it 'can be raised above other windows' do
|
146
145
|
@window.raise_above
|
147
146
|
skip("Not sure how to test state.")
|
148
147
|
end
|
149
|
-
|
148
|
+
|
150
149
|
it 'can be set to fullscreen' do
|
151
150
|
assert_equal 0, @window.flags & SDL2::Window::FULLSCREEN_DESKTOP
|
152
151
|
@window.fullscreen = SDL2::Window::FULLSCREEN_DESKTOP
|
153
|
-
refute_equal 0, @window.flags & SDL2::Window::FULLSCREEN_DESKTOP
|
152
|
+
refute_equal 0, @window.flags & SDL2::Window::FULLSCREEN_DESKTOP
|
154
153
|
end
|
155
|
-
|
156
|
-
|
157
|
-
|
154
|
+
|
158
155
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
require 'sdl2'
|
4
|
+
require 'sdl2/video'
|
5
|
+
require 'sdl2/image'
|
6
|
+
|
7
|
+
class TestScratch < MiniTest::Unit::TestCase
|
8
|
+
def test_a_game
|
9
|
+
window = SDL2::Window.create!("My Window", 0, 0, 300, 300)
|
10
|
+
win_surface = window.surface
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
color_bars = SDL2::Image.load(File.expand_path('color_bars.jpg', FIXTURE_DIR))
|
15
|
+
|
16
|
+
# binding.pry
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/test/unit/test_sdl2.rb
CHANGED
@@ -9,8 +9,8 @@ describe SDL2 do
|
|
9
9
|
assert true # if we got this far without exceptions.
|
10
10
|
end
|
11
11
|
|
12
|
-
it 'has
|
13
|
-
assert defined?(SDL2::
|
12
|
+
it 'has FloatPointer for float typed pointers' do
|
13
|
+
assert defined?(SDL2::FloatPointer)
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdl2_ffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BadQuanta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -177,6 +177,8 @@ files:
|
|
177
177
|
- lib/sdl2/gesture.rb
|
178
178
|
- lib/sdl2/haptic.rb
|
179
179
|
- lib/sdl2/hints.rb
|
180
|
+
- lib/sdl2/image.rb
|
181
|
+
- lib/sdl2/image/sdl_image_module.rb
|
180
182
|
- lib/sdl2/init.rb
|
181
183
|
- lib/sdl2/joystick.rb
|
182
184
|
- lib/sdl2/keyboard.rb
|
@@ -202,11 +204,14 @@ files:
|
|
202
204
|
- lib/sdl2/texture.rb
|
203
205
|
- lib/sdl2/timer.rb
|
204
206
|
- lib/sdl2/touch.rb
|
207
|
+
- lib/sdl2/ttf.rb
|
208
|
+
- lib/sdl2/ttf/sdl_ttf_module.rb
|
205
209
|
- lib/sdl2/version.rb
|
206
210
|
- lib/sdl2/video.rb
|
207
211
|
- lib/sdl2/window.rb
|
208
212
|
- lib/sdl2_ffi.rb
|
209
213
|
- sdl2_ffi.gemspec
|
214
|
+
- test/fixtures/color_bars.jpg
|
210
215
|
- test/test_helper.rb
|
211
216
|
- test/unit/sdl2/test_assert.rb
|
212
217
|
- test/unit/sdl2/test_audio.rb
|
@@ -216,9 +221,12 @@ files:
|
|
216
221
|
- test/unit/sdl2/test_events.rb
|
217
222
|
- test/unit/sdl2/test_haptic.rb
|
218
223
|
- test/unit/sdl2/test_hints.rb
|
224
|
+
- test/unit/sdl2/test_image.rb
|
219
225
|
- test/unit/sdl2/test_init.rb
|
220
226
|
- test/unit/sdl2/test_keyboard.rb
|
221
227
|
- test/unit/sdl2/test_log.rb
|
228
|
+
- test/unit/sdl2/test_palette.rb
|
229
|
+
- test/unit/sdl2/test_pixel_format.rb
|
222
230
|
- test/unit/sdl2/test_pixels.rb
|
223
231
|
- test/unit/sdl2/test_power.rb
|
224
232
|
- test/unit/sdl2/test_rect.rb
|
@@ -226,9 +234,11 @@ files:
|
|
226
234
|
- test/unit/sdl2/test_surface.rb
|
227
235
|
- test/unit/sdl2/test_syswm.rb
|
228
236
|
- test/unit/sdl2/test_timer.rb
|
237
|
+
- test/unit/sdl2/test_ttf.rb
|
229
238
|
- test/unit/sdl2/test_version.rb
|
230
239
|
- test/unit/sdl2/test_video.rb
|
231
240
|
- test/unit/sdl2/test_window.rb
|
241
|
+
- test/unit/test_scratch.rb
|
232
242
|
- test/unit/test_sdl2.rb
|
233
243
|
homepage: https://github.com/BadQuanta/sdl2_ffi
|
234
244
|
licenses:
|
@@ -255,6 +265,7 @@ signing_key:
|
|
255
265
|
specification_version: 4
|
256
266
|
summary: Object Oriented wrapper for SDL2. Help me test & debug my interface.
|
257
267
|
test_files:
|
268
|
+
- test/fixtures/color_bars.jpg
|
258
269
|
- test/test_helper.rb
|
259
270
|
- test/unit/sdl2/test_assert.rb
|
260
271
|
- test/unit/sdl2/test_audio.rb
|
@@ -264,9 +275,12 @@ test_files:
|
|
264
275
|
- test/unit/sdl2/test_events.rb
|
265
276
|
- test/unit/sdl2/test_haptic.rb
|
266
277
|
- test/unit/sdl2/test_hints.rb
|
278
|
+
- test/unit/sdl2/test_image.rb
|
267
279
|
- test/unit/sdl2/test_init.rb
|
268
280
|
- test/unit/sdl2/test_keyboard.rb
|
269
281
|
- test/unit/sdl2/test_log.rb
|
282
|
+
- test/unit/sdl2/test_palette.rb
|
283
|
+
- test/unit/sdl2/test_pixel_format.rb
|
270
284
|
- test/unit/sdl2/test_pixels.rb
|
271
285
|
- test/unit/sdl2/test_power.rb
|
272
286
|
- test/unit/sdl2/test_rect.rb
|
@@ -274,7 +288,9 @@ test_files:
|
|
274
288
|
- test/unit/sdl2/test_surface.rb
|
275
289
|
- test/unit/sdl2/test_syswm.rb
|
276
290
|
- test/unit/sdl2/test_timer.rb
|
291
|
+
- test/unit/sdl2/test_ttf.rb
|
277
292
|
- test/unit/sdl2/test_version.rb
|
278
293
|
- test/unit/sdl2/test_video.rb
|
279
294
|
- test/unit/sdl2/test_window.rb
|
295
|
+
- test/unit/test_scratch.rb
|
280
296
|
- test/unit/test_sdl2.rb
|