ray 0.0.1 → 0.1.0.pre1

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 (188) hide show
  1. data/.gemtest +0 -0
  2. data/.yardopts +4 -0
  3. data/README.md +17 -21
  4. data/Rakefile +18 -139
  5. data/VERSION +1 -1
  6. data/ext/audio.cpp +723 -0
  7. data/ext/{color.c → color.cpp} +25 -13
  8. data/ext/drawable.cpp +91 -0
  9. data/ext/event.cpp +460 -0
  10. data/ext/extconf.rb +5 -104
  11. data/ext/font.cpp +190 -0
  12. data/ext/image.cpp +733 -0
  13. data/ext/input.cpp +74 -0
  14. data/ext/ray.cpp +168 -0
  15. data/ext/ray.hpp +356 -0
  16. data/ext/{rect.c → rect.cpp} +51 -37
  17. data/ext/shader.cpp +169 -0
  18. data/ext/shape.cpp +409 -0
  19. data/ext/sprite.cpp +306 -0
  20. data/ext/text.cpp +181 -0
  21. data/ext/vector.cpp +215 -0
  22. data/guide.md +619 -0
  23. data/lib/ray/audio.rb +0 -41
  24. data/lib/ray/color.rb +32 -10
  25. data/lib/ray/drawable.rb +16 -0
  26. data/lib/ray/dsl/event_listener.rb +25 -2
  27. data/lib/ray/dsl/event_runner.rb +33 -5
  28. data/lib/ray/dsl/event_translator.rb +66 -30
  29. data/lib/ray/dsl/handler.rb +3 -2
  30. data/lib/ray/dsl/matcher.rb +58 -14
  31. data/lib/ray/font.rb +38 -96
  32. data/lib/ray/font_set.rb +8 -8
  33. data/lib/ray/game.rb +87 -66
  34. data/lib/ray/helper.rb +105 -10
  35. data/lib/ray/image.rb +150 -24
  36. data/lib/ray/image_set.rb +3 -1
  37. data/lib/ray/input.rb +10 -0
  38. data/lib/ray/music_set.rb +5 -3
  39. data/lib/ray/ray.rb +21 -9
  40. data/lib/ray/rect.rb +48 -7
  41. data/lib/ray/rmagick.rb +41 -0
  42. data/lib/ray/scene.rb +99 -43
  43. data/lib/ray/scene_list.rb +67 -0
  44. data/lib/ray/shape.rb +132 -0
  45. data/lib/ray/sound_set.rb +4 -2
  46. data/lib/ray/sprite.rb +49 -111
  47. data/lib/ray/text.rb +101 -0
  48. data/lib/ray/text_helper.rb +37 -0
  49. data/lib/ray/turtle.rb +215 -0
  50. data/lib/ray/vector.rb +226 -0
  51. data/samples/audio/spacial.rb +44 -0
  52. data/samples/hello_world/hello.rb +9 -13
  53. data/samples/hello_world/hello_dsl.rb +8 -12
  54. data/samples/hello_world/text.rb +15 -0
  55. data/samples/opengl/binding.rb +38 -0
  56. data/samples/opengl/image.rb +32 -0
  57. data/samples/opengl/opengl.rb +34 -0
  58. data/samples/opengl/shader.rb +42 -0
  59. data/samples/pong/pong.rb +14 -10
  60. data/samples/run_scene.rb +53 -0
  61. data/samples/shaders/scene.rb +40 -0
  62. data/samples/shaders/shaders.rb +42 -0
  63. data/samples/shaders/shape.rb +34 -0
  64. data/samples/sokoban/sokoban.rb +18 -18
  65. data/samples/test/actual_scene.rb +41 -0
  66. data/samples/test/scene_riot.rb +39 -0
  67. data/samples/test/scene_spec.rb +32 -0
  68. data/samples/test/scene_test_unit.rb +25 -0
  69. data/samples/turtle/byzantium.rb +45 -0
  70. data/samples/turtle/hilbert.rb +48 -0
  71. data/samples/turtle/koch.rb +55 -0
  72. data/samples/turtle/mandala.rb +61 -0
  73. data/samples/turtle/tree.rb +57 -0
  74. data/test/audio_test.rb +69 -0
  75. data/test/color_test.rb +77 -0
  76. data/test/drawable_test.rb +19 -0
  77. data/test/dsl_test.rb +93 -0
  78. data/test/font_test.rb +57 -0
  79. data/test/helpers.rb +94 -0
  80. data/test/image_test.rb +82 -0
  81. data/test/ray_test.rb +25 -0
  82. data/test/rect_test.rb +121 -0
  83. data/{spec → test}/res/VeraMono.ttf +0 -0
  84. data/{spec → test}/res/aqua.bmp +0 -0
  85. data/{spec → test}/res/aqua.png +0 -0
  86. data/{spec → test}/res/aqua2.bmp +0 -0
  87. data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
  88. data/{spec → test}/res/pop.wav +0 -0
  89. data/test/resource_set_test.rb +99 -0
  90. data/test/run_all.rb +7 -0
  91. data/test/shape_test.rb +101 -0
  92. data/test/sprite_test.rb +89 -0
  93. data/test/text_test.rb +78 -0
  94. data/test/turtle_test.rb +176 -0
  95. data/test/vector_test.rb +111 -0
  96. data/yard_ext.rb +0 -28
  97. metadata +95 -139
  98. data/.gitignore +0 -23
  99. data/.gitmodules +0 -3
  100. data/.rspec +0 -3
  101. data/ext/audio.c +0 -473
  102. data/ext/event.c +0 -557
  103. data/ext/font.c +0 -287
  104. data/ext/image.c +0 -933
  105. data/ext/joystick.c +0 -145
  106. data/ext/ray.c +0 -489
  107. data/ext/ray.h +0 -245
  108. data/ext/ray_osx.m +0 -161
  109. data/lib/ray/joystick.rb +0 -30
  110. data/psp/SDL_psp_main.c +0 -84
  111. data/psp/bigdecimal/README +0 -60
  112. data/psp/bigdecimal/bigdecimal.c +0 -4697
  113. data/psp/bigdecimal/bigdecimal.h +0 -216
  114. data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
  115. data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
  116. data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
  117. data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
  118. data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
  119. data/psp/digest/bubblebabble/bubblebabble.c +0 -142
  120. data/psp/digest/defs.h +0 -20
  121. data/psp/digest/digest.c +0 -643
  122. data/psp/digest/digest.h +0 -32
  123. data/psp/digest/lib/digest.rb +0 -50
  124. data/psp/digest/lib/md5.rb +0 -27
  125. data/psp/digest/lib/sha1.rb +0 -27
  126. data/psp/digest/md5/md5.c +0 -420
  127. data/psp/digest/md5/md5.h +0 -80
  128. data/psp/digest/md5/md5init.c +0 -40
  129. data/psp/digest/rmd160/rmd160.c +0 -457
  130. data/psp/digest/rmd160/rmd160.h +0 -56
  131. data/psp/digest/rmd160/rmd160init.c +0 -40
  132. data/psp/digest/sha1/sha1.c +0 -269
  133. data/psp/digest/sha1/sha1.h +0 -39
  134. data/psp/digest/sha1/sha1init.c +0 -40
  135. data/psp/digest/sha2/lib/sha2.rb +0 -73
  136. data/psp/digest/sha2/sha2.c +0 -919
  137. data/psp/digest/sha2/sha2.h +0 -109
  138. data/psp/digest/sha2/sha2init.c +0 -52
  139. data/psp/enumerator/enumerator.c +0 -298
  140. data/psp/etc/etc.c +0 -559
  141. data/psp/ext.c +0 -289
  142. data/psp/fcntl/fcntl.c +0 -187
  143. data/psp/lib/rbconfig.rb +0 -178
  144. data/psp/nkf/lib/kconv.rb +0 -367
  145. data/psp/nkf/nkf-utf8/config.h +0 -88
  146. data/psp/nkf/nkf-utf8/nkf.c +0 -6040
  147. data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
  148. data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
  149. data/psp/nkf/nkf.c +0 -654
  150. data/psp/socket/addrinfo.h +0 -173
  151. data/psp/socket/getaddrinfo.c +0 -676
  152. data/psp/socket/getnameinfo.c +0 -270
  153. data/psp/socket/pspsocket.c +0 -71
  154. data/psp/socket/pspsocket.h +0 -28
  155. data/psp/socket/socket.c +0 -4662
  156. data/psp/socket/sockport.h +0 -76
  157. data/psp/stringio/stringio.c +0 -1306
  158. data/psp/strscan/strscan.c +0 -1320
  159. data/psp/syck/bytecode.c +0 -1166
  160. data/psp/syck/emitter.c +0 -1242
  161. data/psp/syck/gram.c +0 -1894
  162. data/psp/syck/gram.h +0 -79
  163. data/psp/syck/handler.c +0 -174
  164. data/psp/syck/implicit.c +0 -2990
  165. data/psp/syck/node.c +0 -408
  166. data/psp/syck/rubyext.c +0 -2367
  167. data/psp/syck/syck.c +0 -504
  168. data/psp/syck/syck.h +0 -456
  169. data/psp/syck/token.c +0 -2725
  170. data/psp/syck/yaml2byte.c +0 -257
  171. data/psp/syck/yamlbyte.h +0 -170
  172. data/psp/thread/thread.c +0 -1175
  173. data/psp/zlib/zlib.c +0 -3547
  174. data/script.rb +0 -10
  175. data/spec/ray/audio_spec.rb +0 -146
  176. data/spec/ray/color_spec.rb +0 -57
  177. data/spec/ray/event_spec.rb +0 -80
  178. data/spec/ray/font_spec.rb +0 -93
  179. data/spec/ray/image_set_spec.rb +0 -48
  180. data/spec/ray/image_spec.rb +0 -162
  181. data/spec/ray/joystick_spec.rb +0 -21
  182. data/spec/ray/matcher_spec.rb +0 -50
  183. data/spec/ray/ray_spec.rb +0 -88
  184. data/spec/ray/rect_spec.rb +0 -154
  185. data/spec/ray/resource_set_spec.rb +0 -105
  186. data/spec/ray/sprite_spec.rb +0 -163
  187. data/spec/spec.opts +0 -4
  188. data/spec/spec_helper.rb +0 -8
data/script.rb DELETED
@@ -1,10 +0,0 @@
1
- $: << "./lib" << "./rspec/lib" << "./ruby_stdlib/lib" << "./psp/lib"
2
-
3
- def path_of(res)
4
- File.expand_path(File.join(File.dirname(__FILE__), "spec", "res", res))
5
- end
6
-
7
- require 'ray'
8
- require 'spec'
9
- Dir["spec/**/*_spec.rb"].each { |file| load file }
10
- Spec::Runner.run
@@ -1,146 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- if Ray.has_audio_support?
4
- describe Ray::Audio do
5
- it "should allow to set and get audio parameters" do
6
- Ray.init(:mono => true,
7
- :format => Ray::Audio::FORMAT_S8,
8
- :frequency => 44100)
9
-
10
- Ray::Audio.frequency.should == 44100
11
- Ray::Audio.should be_mono
12
- Ray::Audio.format.should == Ray::Audio::FORMAT_S8
13
-
14
- Ray.stop
15
- end
16
-
17
- it "should allow to change the volume" do
18
- Ray.init(:mono => true,
19
- :format => Ray::Audio::FORMAT_S8,
20
- :frequency => 44100)
21
-
22
- Ray::Audio.volume = 50
23
- Ray::Audio.volume.should be_close(50, 0.1)
24
-
25
- Ray.stop
26
- end
27
- end
28
-
29
- describe Ray::Sound do
30
- before :all do
31
- Ray.init
32
- end
33
-
34
- it "should allow to load sounds" do
35
- lambda {
36
- Ray::Sound.new(path_of("pop.wav"))
37
- }.should_not raise_exception
38
- end
39
-
40
- it "should allow to load sounds from IO objects" do
41
- lambda {
42
- open(path_of("pop.wav")) do |io|
43
- Ray::Sound.new(io)
44
- end
45
- }.should_not raise_exception
46
- end
47
-
48
- it "should allow to change the volume" do
49
- sound = Ray::Sound.new(path_of("pop.wav"))
50
- sound.volume = 50
51
- sound.volume.should be_close(50, 0.1)
52
- end
53
-
54
- it "should make Ray play" do
55
- sound = Ray::Sound.new(path_of("pop.wav"))
56
-
57
- lambda { sound.play(1) }.should change {
58
- Ray::Audio.playing?(1) && !Ray::Audio.paused?(1)
59
- }.from(false).to(true)
60
-
61
- Ray::Audio.stop(1)
62
- end
63
-
64
- it "can be paused" do
65
- sound = Ray::Sound.new(path_of("pop.wav"))
66
- sound.play(1)
67
-
68
- lambda { Ray::Audio.pause(1) }.should change {
69
- Ray::Audio.playing?(1) && !Ray::Audio.paused?(1)
70
- }.from(true).to(false)
71
- end
72
-
73
- it "can be resumed" do
74
- sound = Ray::Sound.new(path_of("pop.wav"))
75
- sound.play(1)
76
- Ray::Audio.pause(1)
77
-
78
- lambda { Ray::Audio.resume(1) }.should change {
79
- Ray::Audio.playing?(1) && !Ray::Audio.paused?(1)
80
- }.from(false).to(true)
81
-
82
- Ray::Audio.stop(1)
83
- end
84
-
85
- after :all do
86
- Ray.stop
87
- end
88
- end
89
-
90
- describe Ray::Music do
91
- before :all do
92
- Ray.init
93
- end
94
-
95
- it "should be able to create object from valid files" do
96
- lambda {
97
- Ray::Music.new(path_of("pop.wav"))
98
- }.should_not raise_exception
99
- end
100
-
101
- it "should be able to create object from IO objects" do
102
- lambda {
103
- open(path_of("pop.wav")) { |io| Ray::Music.new(io) }
104
- }.should_not raise_exception
105
- end
106
-
107
- it "should make Ray play" do
108
- music = Ray::Music.new(path_of("pop.wav"))
109
- music.play
110
-
111
- Ray::Audio.should be_playing
112
- Ray::Audio.stop
113
- end
114
-
115
- it "can be paused" do
116
- music = Ray::Music.new(path_of("pop.wav"))
117
- music.play
118
- Ray::Audio.pause
119
-
120
- Ray::Audio.should be_paused
121
- end
122
-
123
- it "can be resumed" do
124
- music = Ray::Music.new(path_of("pop.wav"))
125
- music.play
126
-
127
- Ray::Audio.pause
128
- Ray::Audio.resume
129
-
130
- Ray::Audio.should_not be_paused
131
- Ray::Audio.stop
132
- end
133
-
134
- it "can be stopped" do
135
- music = Ray::Music.new(path_of("pop.wav"))
136
- music.play
137
-
138
- Ray::Audio.stop
139
- Ray::Audio.should_not be_playing
140
- end
141
-
142
- after :all do
143
- Ray.stop
144
- end
145
- end
146
- end
@@ -1,57 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Ray::Color do
4
- describe "#initialize" do
5
- it "should accept 3 integers" do
6
- lambda {
7
- Ray::Color.new(10, 20, 30)
8
- }.should_not raise_exception(ArgumentError)
9
- end
10
-
11
- it "should accept 4 integers" do
12
- lambda {
13
- Ray::Color.new(10, 20, 30, 40)
14
- }.should_not raise_exception(ArgumentError)
15
- end
16
-
17
- it "should only work with numerics" do
18
- [Ray, "string", Ray::Color].each do |obj|
19
- lambda {
20
- Ray::Color.new(obj, 0, 0, obj)
21
- }.should raise_exception(TypeError)
22
- end
23
- end
24
- end
25
-
26
- [:r, :g, :b, :a].each do |meth|
27
- describe "#{meth}=" do
28
- it "should only work with numerics" do
29
- color = Ray::Color.new(0, 0, 0, 0)
30
- [Ray, "string", Ray::Color].each do |obj|
31
- lambda {
32
- color.send("#{meth}=", obj)
33
- }.should raise_exception(TypeError)
34
- end
35
- end
36
-
37
- it "should set a new value" do
38
- color = Ray::Color.new(0, 0, 0, 0)
39
-
40
- lambda {
41
- color.send("#{meth}=", 30)
42
- }.should change(color, meth).from(0).to(30)
43
- end
44
- end
45
- end
46
-
47
- describe "#==" do
48
- it "should return true if both colors are identical" do
49
- Ray::Color.new(10, 15, 20, 30).should == Ray::Color.new(10, 15, 20, 30)
50
- Ray::Color.new(10, 15, 20, 30).should_not == Ray::Color.new(1, 15, 2, 3)
51
- end
52
-
53
- it "should not raise an exception if the argument isn't a color" do
54
- Ray::Color.new(1, 1, 1, 1).should_not == 1
55
- end
56
- end
57
- end
@@ -1,80 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Ray::DSL do
4
- before :each do
5
- @runner = Ray::DSL::EventRunner.new
6
-
7
- @obj = Object.new
8
- @obj.extend Ray::DSL::EventListener
9
- @obj.extend Ray::DSL::EventRaiser
10
- @obj.extend Ray::Matchers
11
-
12
- @obj.listener_runner = @runner
13
- @obj.raiser_runner = @runner
14
- end
15
-
16
- it "should send events with the same arguments and name as in #on" do
17
- count = 0
18
- @obj.on :right_event, "danger", "bar" do |*args|
19
- args.should == ["danger", "bar"]
20
- count += 1
21
- end
22
-
23
- [:right_event, :wrong_event].each do |name|
24
- @obj.raise_event(name)
25
- @obj.raise_event(name, "bar")
26
- @obj.raise_event(name, "danger")
27
- @obj.raise_event(name, "danger", "bar")
28
- end
29
-
30
- @runner.run
31
- count.should == 1
32
- end
33
-
34
- it "should use === to see if an event can be raised" do
35
- true_matcher = mock('true_matcher')
36
- true_matcher.should_receive(:===).and_return(true)
37
-
38
- false_matcher = mock('false_matcher')
39
- false_matcher.should_receive(:===).and_return(false)
40
-
41
- worked = nil
42
-
43
- @obj.on :event, true_matcher do
44
- worked.should_not == false
45
- worked = true
46
- end
47
-
48
- @obj.on :event, false_matcher do
49
- worked = false
50
- end
51
-
52
- @obj.raise_event(:event, :argument)
53
- @runner.run
54
-
55
- worked.should be_true
56
- end
57
-
58
- it "should pass the arguments of the event to the block" do
59
- @obj.on :foo do |*args|
60
- args.should == ["a", "b", "c"]
61
- end
62
-
63
- @obj.raise_event(:foo, "a", "b", "c")
64
- @runner.run
65
- end
66
-
67
- it "should send events with more arguments than #on if they match" do
68
- count = 0
69
- @obj.on :foo do
70
- count += 1
71
- end
72
-
73
- @obj.raise_event(:foo, "blabla")
74
- @obj.raise_event(:foo)
75
- @obj.raise_event(:foo, :error, 3, "read")
76
-
77
- @runner.run
78
- count.should == 3
79
- end
80
- end
@@ -1,93 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- if Ray.has_font_support?
4
- describe Ray::Font do
5
- before :all do
6
- Ray.init
7
- end
8
-
9
- it "should be able to load fonts from a file" do
10
- lambda {
11
- Ray::Font.new(path_of("VeraMono.ttf"), 12)
12
- }.should_not raise_exception
13
- end
14
-
15
- it "should be able to load fonts from IO objects" do
16
- lambda {
17
- open(path_of("VeraMono.ttf")) { |io| Ray::Font.new(io, 12) }
18
- }.should_not raise_exception
19
- end
20
-
21
- it "should create normal font" do
22
- Ray::Font.new(path_of("VeraMono.ttf"), 12).should be_normal
23
- end
24
-
25
- it "should allow to change its style" do
26
- font = Ray::Font.new(path_of("VeraMono.ttf"), 12)
27
- font.style = Ray::Font::STYLE_BOLD | Ray::Font::STYLE_ITALIC
28
-
29
- font.should be_italic
30
- font.should be_bold
31
- end
32
-
33
- describe "#draw" do
34
- before :all do
35
- @win = Ray.create_window(:w => 100, :h => 100)
36
- @font = Ray::Font.new(path_of("VeraMono.ttf"), 12)
37
- end
38
-
39
- it "should return an image when we don't say where to draw" do
40
- @font.draw("Something").should be_a(Ray::Image)
41
- end
42
-
43
- it "should return the surface it drew on if it did" do
44
- @font.draw("Something", :on => @win, :at => [0, 0]).should == @win
45
- end
46
- end
47
-
48
- after :all do
49
- Ray.stop
50
- end
51
- end
52
-
53
- describe "String#draw" do
54
- before :all do
55
- Ray.init
56
-
57
- @win = Ray.create_window(:w => 100, :h => 100)
58
- @font = Ray::Font.new(path_of("VeraMono.ttf"), 12)
59
- end
60
-
61
- it "should be able to guess the size" do
62
- lambda {
63
- "Hello world!".draw(:font => @font)
64
- }.should_not raise_exception
65
- end
66
-
67
- it "should use the specified width unless :on is specified" do
68
- img = "Hello world!".draw(:font => @font, :w => 40)
69
- img.w.should == 40
70
- end
71
-
72
- it "should require the font to be specified" do
73
- lambda {
74
- "Hello world".draw(:on => @win)
75
- }.should raise_exception
76
- end
77
-
78
- it "should draw on multiple lines" do
79
- img = "Hello\nworld".draw(:font => @font, :w => 100)
80
- img.height.should == @font.line_skip * 2
81
- end
82
-
83
- it "should allow to specify an explicit size" do
84
- img = "Hello\nworld".draw(:font => @font, :h => 100, :w => 50)
85
- img.width.should == 50
86
- img.height.should == 100
87
- end
88
-
89
- after :all do
90
- Ray.stop
91
- end
92
- end
93
- end
@@ -1,48 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- Ray.image_set(/^test:(red|green|blue)$/) do |col|
4
- %w(red green blue).include?(col).should == true
5
- Ray::Image.new(:w => 50, :h => 50).fill(Ray::Color.send(col))
6
- end
7
-
8
- describe Ray::ImageSet do
9
- before :all do
10
- Ray.init
11
- end
12
-
13
- describe ".[]" do
14
- it "should return a new image" do
15
- Ray::ImageSet["test:red"].should be_a(Ray::Image)
16
- end
17
-
18
- it "should always return the same image" do
19
- obj = Ray::ImageSet["test:green"]
20
- obj.object_id.should == Ray::ImageSet["test:green"].object_id
21
- end
22
- end
23
-
24
- it "should allow to remove images from cache" do
25
- obj = Ray::ImageSet["test:red"]
26
- other = Ray::ImageSet["test:blue"]
27
- Ray::ImageSet.delete_if { |name, img| name == "test:red" }
28
- obj.object_id.should_not == Ray::ImageSet["test:red"].object_id
29
- other.object_id.should == Ray::ImageSet["test:blue"].object_id
30
- end
31
-
32
- it "should also use Ray::Image's cache" do
33
- img = Ray::ImageSet[path_of("aqua.bmp")]
34
- img.should == Ray::Image[path_of("aqua.bmp")]
35
- end
36
-
37
- it "should also handle Ray::Image's cache" do
38
- img = Ray::ImageSet[path_of("aqua.bmp")]
39
-
40
- Ray::ImageSet.delete_if { |name, img| name == path_of("aqua.bmp") }
41
- img.should_not == Ray::Image[path_of("aqua.bmp")]
42
- img.should_not == Ray::ImageSet[path_of("aqua.bmp")]
43
- end
44
-
45
- after :all do
46
- Ray.stop
47
- end
48
- end
@@ -1,162 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Ray::Image do
4
- before :all do
5
- Ray.init
6
- @win = Ray.create_window(:w => 100, :h => 100)
7
- end
8
-
9
- it "should raise a type error when blitting on something that isn't an image" do
10
- img = Ray::Image.new(:w => 50, :h => 50)
11
- lambda {
12
- img.blit(:on => Ray::Color.new(10, 20, 30))
13
- }.should raise_exception(TypeError)
14
- end
15
-
16
- describe "#initialize" do
17
- it "should raise a type error if the argument isn't a hash or a string " do
18
- lambda {
19
- Ray::Image.new(3)
20
- }.should raise_exception(TypeError)
21
- end
22
-
23
- it "should not raise an error when loading an existing image" do
24
- lambda {
25
- Ray::Image.new(path_of("aqua.bmp"))
26
- }.should_not raise_exception
27
- end
28
-
29
- it "should raise an error when loading an unexisting file " do
30
- lambda {
31
- Ray::Image.new("does_not_exist.bmp")
32
- }.should raise_exception
33
- end
34
-
35
- it "should be able to load a file from an IO" do
36
- File.open(path_of("aqua.bmp")) do |io|
37
- lambda {
38
- img = Ray::Image.new(io)
39
- }.should_not raise_exception
40
- end
41
- end
42
-
43
- if Ray.has_image_support?
44
- it "should be able to load other kind of images" do
45
- lambda {
46
- Ray::Image.new(path_of("aqua.png"))
47
- }.should_not raise_exception
48
- end
49
-
50
- it "should be able to load other kind of images from an IO" do
51
- File.open(path_of("aqua.png")) do |io|
52
- lambda {
53
- Ray::Image.new(io)
54
- }.should_not raise_exception
55
- end
56
- end
57
-
58
- it "should load images even if the extension is incorrect" do
59
- lambda {
60
- Ray::Image.new(path_of("not_a_jpeg.jpeg"))
61
- }.should_not raise_exception
62
- end
63
- end
64
- end
65
-
66
- describe ".[]" do
67
- it "should return a new image" do
68
- Ray::Image[path_of("aqua.bmp")].should be_a(Ray::Image)
69
- end
70
-
71
- it "should always return the same image" do
72
- obj = Ray::Image[path_of("aqua2.bmp")]
73
- obj.object_id.should == Ray::Image[path_of("aqua2.bmp")].object_id
74
- end
75
- end
76
-
77
- describe "#==" do
78
- it "should be true if the parameter uses the same surface" do
79
- @win.should == Ray.screen
80
-
81
- first = Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.red)
82
- sec = Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.red)
83
-
84
- first.should_not == sec
85
- end
86
-
87
- it "should not raise an exception for non-images" do
88
- lambda {
89
- @win == 3
90
- }.should_not raise_exception
91
- end
92
- end
93
-
94
- describe "#dup" do
95
- it "should create a new surface" do
96
- first = Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.red)
97
- sec = first.dup
98
-
99
- first.should_not == sec
100
- end
101
- end
102
-
103
- describe "#[]" do
104
- it "should return nil for pixels outside the image" do
105
- Ray::Image.new(:w => 10, :h => 10)[10, 10].should be_nil
106
- end
107
-
108
- it "should return a color for pixels inside the image" do
109
- Ray::Image.new(:w => 10, :h => 10)[5, 5].should be_a(Ray::Color)
110
- end
111
- end
112
-
113
- describe "#[]=" do
114
- it "should change the color of the pixel" do
115
- img = Ray::Image.new(:w => 10, :h => 10)
116
- img.lock { img[5, 5] = Ray::Color.new(10, 15, 20) }
117
-
118
- col = img[5, 5]
119
- col.r.should == 10
120
- col.g.should == 15
121
- col.b.should == 20
122
- end
123
-
124
- it "should raise an error for pixels outside the image" do
125
- img = Ray::Image.new(:w => 10, :h => 10)
126
- lambda {
127
- img.lock { img[11, 11] = Ray::Color.new(10, 15, 20) }
128
- }.should raise_exception
129
- end
130
- end
131
-
132
- describe "#clip" do
133
- it "should return the clipping rect if there are no arguments" do
134
- img = Ray::Image.new(:w => 10, :h => 10)
135
- img.clip.should == Ray::Rect.new(0, 0, 10, 10)
136
- end
137
-
138
- it "should change the clip rect when called with a rect" do
139
- img = Ray::Image.new(:w => 10, :h => 10)
140
- img.clip([5, 5, 3, 3])
141
- img.clip.should == Ray::Rect.new(5, 5, 3, 3)
142
- end
143
-
144
- it "should return the new rect" do
145
- img = Ray::Image.new(:w => 10, :h => 10)
146
- img.clip([5, 5, 3, 3]).should == Ray::Rect.new(5, 5, 3, 3)
147
- end
148
-
149
- it "should change the clipping rect only within a block" do
150
- img = Ray::Image.new(:w => 10, :h => 10)
151
- img.clip([5, 5, 3, 3]) do
152
- img.clip.should == Ray::Rect.new(5, 5, 3, 3)
153
- end
154
-
155
- img.clip.should == Ray::Rect.new(0, 0, 10, 10)
156
- end
157
- end
158
-
159
- after :all do
160
- Ray.stop
161
- end
162
- end