texplay 0.3.1 → 0.3.3pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/Rakefile +37 -13
- data/ext/texplay/graphics_utils.c +95 -26
- data/ext/texplay/texplay.h +62 -57
- data/lib/texplay-contrib.rb +111 -118
- data/lib/texplay.rb +36 -14
- data/lib/texplay/alone.rb +20 -0
- data/lib/texplay/c_function_docs.rb +3 -2
- data/lib/texplay/version.rb +1 -1
- data/live/live.rb +85 -0
- data/test/image_spec.rb +45 -0
- data/test/texplay_spec.rb +141 -0
- metadata +36 -13
- data/spec/image_spec.rb +0 -7
- data/spec/texplay_spec.rb +0 -80
data/spec/image_spec.rb
DELETED
data/spec/texplay_spec.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..', 'lib','texplay')
|
2
|
-
|
3
|
-
require 'texplay'
|
4
|
-
|
5
|
-
describe TexPlay do
|
6
|
-
before :each do
|
7
|
-
@window = Gosu::Window.new(640, 480, false)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#create_image" do
|
11
|
-
it "should create a blank image of the correct size" do
|
12
|
-
width, height = 30, 10
|
13
|
-
image = described_class.create_image(@window, width, height)
|
14
|
-
|
15
|
-
image.width.should == width
|
16
|
-
image.height.should == height
|
17
|
-
|
18
|
-
width.times do |x|
|
19
|
-
height.times do |y|
|
20
|
-
image.get_pixel(x, y).should == [0.0, 0.0, 0.0, 0.0]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should create a coloured image of the correct size" do
|
26
|
-
width, height = 10, 30
|
27
|
-
color = [1.0, 1.0, 0.0, 1.0]
|
28
|
-
image = described_class.create_image(@window, width, height, :color => color)
|
29
|
-
|
30
|
-
image.width.should == width
|
31
|
-
image.height.should == height
|
32
|
-
|
33
|
-
width.times do |x|
|
34
|
-
height.times do |y|
|
35
|
-
image.get_pixel(x, y).should == color
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should raise an error if an image dimension is 0 or less" do
|
41
|
-
lambda { described_class.create_image(@window, 0, 0)}.should raise_error ArgumentError
|
42
|
-
end
|
43
|
-
|
44
|
-
# TODO: Should probably be an ArgumentError.
|
45
|
-
it "should raise an error if the image would be too large" do
|
46
|
-
too_big = TexPlay::TP_MAX_QUAD_SIZE + 1
|
47
|
-
[[too_big, 5], [10, too_big], [too_big, too_big]].each do |width, height|
|
48
|
-
lambda { described_class.create_image(@window, width, height)}.should raise_error Exception
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#from_blob" do
|
54
|
-
it "should create an image with the requested pixel data and size" do
|
55
|
-
# 4 x 3, with columns of red, blue, green, transparent.
|
56
|
-
gosu_colors = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], [0, 0, 0, 0]]
|
57
|
-
texplay_colors = gosu_colors.map {|a| a.map {|c| c / 255.0 } }
|
58
|
-
width, height = gosu_colors.size, 3
|
59
|
-
|
60
|
-
image = described_class.from_blob(@window, (gosu_colors * height).flatten.pack('C*'), width, height)
|
61
|
-
|
62
|
-
image.width.should == width
|
63
|
-
image.height.should == height
|
64
|
-
|
65
|
-
texplay_colors.each_with_index do |color, x|
|
66
|
-
3.times do |y|
|
67
|
-
image.get_pixel(x, y).should == color
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should raise an error if the image size is not correct for the blob data" do
|
73
|
-
lambda { described_class.from_blob(@window, [1, 1, 1, 1].pack("C*"), 2, 1) }.should raise_error ArgumentError
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should raise an error if an image dimension is 0 or less" do
|
77
|
-
lambda { described_class.from_blob(@window, '', 0, 0) }.should raise_error ArgumentError
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|