sgl 0.4.0 → 1.0.0

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 (94) hide show
  1. data/ChangeLog +254 -234
  2. data/History.txt +6 -0
  3. data/Manifest.txt +10 -0
  4. data/Rakefile +27 -7
  5. data/examples/cocoa1-basic.rb +14 -14
  6. data/examples/cocoa10-transparent.rb +26 -26
  7. data/examples/cocoa11-application.rb +13 -13
  8. data/examples/cocoa2-draw.rb +23 -23
  9. data/examples/cocoa3-affine.rb +29 -29
  10. data/examples/cocoa4-font.rb +24 -24
  11. data/examples/cocoa5-image.rb +22 -22
  12. data/examples/cocoa6-sound.rb +24 -24
  13. data/examples/cocoa7-movie.rb +40 -40
  14. data/examples/cocoa8-movieoverlay.rb +42 -42
  15. data/examples/cocoa9-streaming.rb +40 -40
  16. data/examples/opengl1-basic.rb +14 -14
  17. data/examples/opengl11-application.rb +13 -13
  18. data/examples/opengl2-draw.rb +23 -23
  19. data/examples/opengl3-affine.rb +29 -29
  20. data/examples/sample1.rb +11 -11
  21. data/examples/sample10.rb +16 -16
  22. data/examples/sample11.rb +22 -22
  23. data/examples/sample11a.rb +33 -33
  24. data/examples/sample12.rb +30 -30
  25. data/examples/sample12a.rb +35 -35
  26. data/examples/sample13.rb +116 -116
  27. data/examples/sample15.rb +24 -24
  28. data/examples/sample16.rb +31 -31
  29. data/examples/sample16a.rb +35 -35
  30. data/examples/sample6.rb +18 -18
  31. data/examples/sample7.rb +16 -16
  32. data/examples/sample9.rb +20 -20
  33. data/examples/testgl.rb +169 -169
  34. data/lib/sgl/bass.rb +46 -46
  35. data/lib/sgl/cocoa-app.rb +43 -43
  36. data/lib/sgl/cocoa-color.rb +65 -65
  37. data/lib/sgl/cocoa-draw.rb +72 -72
  38. data/lib/sgl/cocoa-event.rb +229 -229
  39. data/lib/sgl/cocoa-media.rb +144 -144
  40. data/lib/sgl/cocoa-notuse.rb +493 -493
  41. data/lib/sgl/cocoa-window.rb +203 -203
  42. data/lib/sgl/cocoa.rb +8 -8
  43. data/lib/sgl/opengl-app.rb +38 -38
  44. data/lib/sgl/opengl-color.rb +44 -44
  45. data/lib/sgl/opengl-draw.rb +260 -260
  46. data/lib/sgl/opengl-event.rb +325 -325
  47. data/lib/sgl/opengl-modules.rb +22 -22
  48. data/lib/sgl/opengl-window.rb +224 -224
  49. data/lib/sgl/opengl.rb +7 -7
  50. data/lib/sgl/sgl-button.rb +135 -135
  51. data/lib/sgl/sgl-client.rb +21 -21
  52. data/lib/sgl/sgl-color.rb +68 -82
  53. data/lib/sgl/sgl-connect.rb +9 -9
  54. data/lib/sgl/sgl-server.rb +58 -58
  55. data/lib/sgl/sgl-spring.rb +216 -216
  56. data/lib/sgl/version.rb +2 -2
  57. data/scripts/lib-txt2html.rb +130 -0
  58. data/scripts/txt2html +2 -63
  59. data/spec/sgl_spec.rb +13 -0
  60. data/spec/spec.opts +1 -0
  61. data/spec/spec_helper.rb +1 -0
  62. data/test/test_cocoa_app.rb +291 -291
  63. data/test/test_module_ruby16.rb +30 -30
  64. data/test/test_opengl_app.rb +147 -147
  65. data/test/test_opengl_basic.rb +22 -22
  66. data/test/test_opengl_fullscreen.rb +23 -23
  67. data/test/test_opengl_novice.rb +35 -35
  68. data/website/challenge1.html +91 -91
  69. data/website/challenge1.txt +3 -3
  70. data/website/challenge2.html +143 -144
  71. data/website/challenge2.txt +13 -14
  72. data/website/challenge3.html +66 -63
  73. data/website/challenge3.txt +7 -7
  74. data/website/cocoa.html +85 -88
  75. data/website/cocoa.txt +2 -4
  76. data/website/description.html +138 -138
  77. data/website/description.txt +1 -1
  78. data/website/exercise1.html +262 -264
  79. data/website/exercise1.txt +58 -53
  80. data/website/exercise2.html +241 -683
  81. data/website/exercise2.txt +11 -427
  82. data/website/exercise3.html +206 -0
  83. data/website/exercise3.txt +155 -0
  84. data/website/exercise4.html +198 -0
  85. data/website/exercise4.txt +151 -0
  86. data/website/exercise5.html +162 -0
  87. data/website/exercise5.txt +113 -0
  88. data/website/exhibition.html +84 -84
  89. data/website/howto.html +146 -134
  90. data/website/howto.txt +9 -0
  91. data/website/index.html +178 -178
  92. data/website/index.txt +20 -19
  93. data/website/sound.html +141 -141
  94. metadata +16 -3
data/lib/sgl/version.rb CHANGED
@@ -3,8 +3,8 @@
3
3
 
4
4
  module SGL #:nodoc:
5
5
  module VERSION #:nodoc:
6
- MAJOR = 0
7
- MINOR = 4
6
+ MAJOR = 1
7
+ MINOR = 0
8
8
  TINY = 0
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+
8
+ class Fixnum
9
+ def ordinal
10
+ # teens
11
+ return 'th' if (10..19).include?(self % 100)
12
+ # others
13
+ case self % 10
14
+ when 1: return 'st'
15
+ when 2: return 'nd'
16
+ when 3: return 'rd'
17
+ else return 'th'
18
+ end
19
+ end
20
+ end
21
+
22
+ class Time
23
+ def pretty
24
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
25
+ end
26
+ end
27
+
28
+ class Txt2Html
29
+ def self.main(argv)
30
+ self.new.main(argv)
31
+ end
32
+
33
+ def main(argv)
34
+ if argv.length >= 1
35
+ src, template = argv
36
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
37
+ else
38
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
39
+ exit!
40
+ end
41
+
42
+ template_text = File.open(template).read
43
+ src_text = File.open(src) {|fsrc| fsrc.read }
44
+ modified = File.stat(src).mtime
45
+ result = generate(template_text, src_text, modified)
46
+ $stdout << result
47
+ end
48
+
49
+ def translate(src, dest)
50
+ template = File.dirname(__FILE__) + '/../website/template.rhtml'
51
+ template_text = File.open(template).read
52
+ src_text = File.open(src) {|fsrc| fsrc.read }
53
+ modified = File.stat(src).mtime
54
+ result = generate(template_text, src_text, modified)
55
+ File.open(dest, 'wb') {|f| f.print result }
56
+ end
57
+
58
+ def generate(template_text, src_text, modified)
59
+ version = SGL::VERSION::STRING
60
+ download = 'http://rubyforge.org/projects/sgl'
61
+
62
+ title_text, body_text = parse_title_body(src_text)
63
+ title = create_title(title_text)
64
+ body = create_body(body_text)
65
+ template = ERB.new(template_text)
66
+ result = template.result(binding)
67
+ return result
68
+ end
69
+
70
+ def parse_title_body(str)
71
+ /\A(.*?)\n(.*)/m =~ str
72
+ return $1, $2
73
+ end
74
+
75
+ def create_title(title_text)
76
+ return RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
77
+ end
78
+
79
+ def create_body(body_text)
80
+ syntax_items = []
81
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m) {
82
+ ident = syntax_items.length
83
+ element, syntax, source = $1, $2, $3
84
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
85
+ "syntax-temp-#{ident}"
86
+ }
87
+ body = RedCloth.new(body_text).to_html
88
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
89
+ return body
90
+ end
91
+
92
+ def convert_syntax(syntax, source)
93
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!, '')
94
+ end
95
+
96
+ end
97
+
98
+ if $0 == __FILE__
99
+ require "test/unit"
100
+ $__test_txt2html__ = true
101
+ end
102
+
103
+ if defined?($__test_txt2html__) && $__test_txt2html__
104
+ class TestTxt2Html < Test::Unit::TestCase #:nodoc:
105
+ def test_all
106
+ # test_fixnum_ordinal
107
+ assert_equal 'st', 1.ordinal
108
+
109
+ # test_time_pretty
110
+ assert_equal '1st January 1970', Time.at(0).pretty
111
+
112
+ # test_txt2html
113
+ t2h = Txt2Html.new
114
+
115
+ # test_parse_title_body
116
+ assert_equal ["title", "body\n"], t2h.parse_title_body("title\nbody\n")
117
+ assert_equal ["title", "b\nb\n"], t2h.parse_title_body("title\nb\nb\n")
118
+
119
+ # test_create_title
120
+ assert_equal 'title', t2h.create_title('h1. title')
121
+
122
+ # test_create_body
123
+ assert_equal '<h2>body</h2>', t2h.create_body('h2. body')
124
+
125
+ # test_convert_syntax
126
+ assert_equal '<span class="number">0</span>',
127
+ t2h.convert_syntax('ruby', '0')
128
+ end
129
+ end
130
+ end
data/scripts/txt2html CHANGED
@@ -1,67 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'redcloth'
5
- require 'syntax/convertors/html'
6
- require 'erb'
7
3
  require File.dirname(__FILE__) + '/../lib/sgl/version.rb'
4
+ require 'scripts/lib-txt2html'
8
5
 
9
- version = SGL::VERSION::STRING
10
- download = 'http://rubyforge.org/projects/sgl'
11
-
12
- class Fixnum
13
- def ordinal
14
- # teens
15
- return 'th' if (10..19).include?(self % 100)
16
- # others
17
- case self % 10
18
- when 1: return 'st'
19
- when 2: return 'nd'
20
- when 3: return 'rd'
21
- else return 'th'
22
- end
23
- end
24
- end
25
-
26
- class Time
27
- def pretty
28
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
- end
30
- end
31
-
32
- def convert_syntax(syntax, source)
33
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
- end
35
-
36
- if ARGV.length >= 1
37
- src, template = ARGV
38
- template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
-
40
- else
41
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
- exit!
43
- end
44
-
45
- template = ERB.new(File.open(template).read)
46
-
47
- title = nil
48
- body = nil
49
- File.open(src) do |fsrc|
50
- title_text = fsrc.readline
51
- body_text = fsrc.read
52
- syntax_items = []
53
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
- ident = syntax_items.length
55
- element, syntax, source = $1, $2, $3
56
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
- "syntax-temp-#{ident}"
58
- }
59
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
- body = RedCloth.new(body_text).to_html
61
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
- end
63
- stat = File.stat(src)
64
- created = stat.ctime
65
- modified = stat.mtime
66
-
67
- $stdout << template.result(binding)
6
+ Txt2Html.main(ARGV)
data/spec/sgl_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'sgl'
3
+
4
+ describe SGL do
5
+ it "should return" do
6
+ t = SGL::ColorTranslatorRGB.new(100, 100, 100, 100)
7
+ t.norm(100, 100, 100).should == [1.0, 1.0, 1.0, 1.0]
8
+ t.norm(100, 0, 0).should == [1.0, 0.0, 0.0, 1.0]
9
+
10
+ t = SGL::ColorTranslatorHSV.new(100, 100, 100, 100)
11
+ t.norm(100, 100, 100).should == [1.0, 0.0, 0.0, 1.0]
12
+ end
13
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1 @@
1
+ require 'spec'
@@ -1,291 +1,291 @@
1
- #!/usr/bin/env ruby -w
2
- # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
3
- # License: Ruby License
4
-
5
- require File.dirname(__FILE__) + '/test_helper.rb'
6
-
7
- if /osx/ =~ RUBY_PLATFORM
8
-
9
- require "sgl/cocoa-app"
10
-
11
- class TestCocoaBasic < Test::Unit::TestCase
12
- def test_basic
13
- app = SGL::Application.new
14
- app.set_setup {
15
- app.window(100, 100)
16
- app.runtime = 0.5
17
- }
18
- i = 0
19
- app.set_display {
20
- app.line(0, 0, 100, i*5)
21
- i += 2
22
- i = 0 if 20 < i
23
- }
24
- app.mainloop
25
- end
26
-
27
- def test_window
28
- app = SGL::Application.new
29
- sleep 0.01; app.window(100, 100)
30
- sleep 0.01; app.close_window
31
- sleep 0.01; app.window(500, 500)
32
- sleep 0.01; app.close_window
33
- sleep 0.01; app.window(100, 100, :border=>false)
34
- sleep 0.01; app.close_window
35
- sleep 0.01; app.window(100, 100, :shadow=>false, :border=>false)
36
- sleep 0.01; app.close_window
37
- end
38
-
39
- def test_color
40
- app = SGL::Application.new
41
- app.window(100, 100)
42
- app.background(100)
43
- bgcolor = app.instance_eval { @bgcolor }
44
- assert_equal([1.0, 1.0, 1.0, 1.0], bgcolor)
45
- app.background(10, 20, 30)
46
- bgcolor = app.instance_eval { @bgcolor }
47
- assert_equal([0.1, 0.2, 0.3, 1.0], bgcolor)
48
- app.color(0)
49
- curcolor = app.instance_eval { @curcolor }
50
- assert_equal([0.0, 0.0, 0.0, 1.0], curcolor)
51
- app.color(10, 20, 30)
52
- curcolor = app.instance_eval { @curcolor }
53
- assert_equal([0.1, 0.2, 0.3, 1.0], curcolor)
54
- app.close_window
55
- end
56
-
57
- def test_setup_and_display
58
- app = SGL::Application.new
59
- app.window(100, 100)
60
-
61
- test_setup_done = false
62
- app.set_setup { test_setup_done = true }
63
- assert_equal(false, test_setup_done)
64
- app.do_setup
65
- assert_equal(true, test_setup_done)
66
-
67
- test_display_done = false
68
- app.set_display { test_display_done = true }
69
- assert_equal(false, test_display_done)
70
- app.do_display
71
- assert_equal(true, test_display_done)
72
- app.close_window
73
- end
74
-
75
- def test_event
76
- app = SGL::Application.new
77
- app.window(100, 100)
78
-
79
- test = {}
80
- app.set_mousedown { test[:mousedown] = true }
81
- assert_equal(nil, test[:mousedown])
82
- app.do_mousedown
83
- assert_equal(true, test[:mousedown])
84
- end
85
- end
86
-
87
- class TestCocoaDraw < Test::Unit::TestCase
88
- def test_commands
89
- app = SGL::Application.new
90
- app.set_setup {
91
- app.window(100, 100)
92
- app.runtime = 0.1
93
- }
94
- app.set_display {
95
- app.line(0, 0, 100, 100)
96
- app.rect(40, 40, 60, 60)
97
- app.circle(20, 20, 10)
98
- }
99
- app.mainloop
100
- end
101
-
102
- def test_for
103
- app = SGL::Application.new
104
- app.set_setup {
105
- app.window(100, 100)
106
- app.runtime = 0.1
107
- }
108
- app.set_display {
109
- for i in 0..20
110
- app.line(0, 0, 100, i*5)
111
- end
112
- }
113
- app.mainloop
114
- end
115
-
116
- def test_iterate
117
- app = SGL::Application.new
118
- app.set_setup {
119
- app.window(100, 100)
120
- app.runtime = 0.5
121
- }
122
- i = 0
123
- app.set_display {
124
- app.line(0, 0, 100, i*5)
125
- i += 1
126
- i = 0 if 20 < i
127
- }
128
- app.mainloop
129
- end
130
-
131
- def test_font
132
- app = SGL::Application.new
133
- app.set_setup {
134
- app.window(100, 100)
135
- app.runtime = 0.1
136
- }
137
- font = app.font("Helvetica")
138
- app.set_display {
139
- font.text(50, 50, "hello")
140
- }
141
- app.mainloop
142
- end
143
-
144
- def test_font_iterate
145
- app = SGL::Application.new
146
- app.set_setup {
147
- app.window(100, 100)
148
- app.runtime = 0.5
149
- }
150
- i = 10
151
- app.set_display {
152
- font = app.font("Helvetica", i)
153
- font.text(0, 0, "hello")
154
- i += 5
155
- i = 0 if 200 < i
156
- }
157
- app.mainloop
158
- end
159
-
160
- def test_affine
161
- app = SGL::Application.new
162
- app.set_setup {
163
- app.window(300, 300)
164
- app.runtime = 0.5
165
- @font = app.font("Helvetica", 20)
166
- }
167
- i = 0
168
- app.set_display {
169
- app.colorHSV 66, 100, 100, 50
170
- app.lineWidth(i/10)
171
- app.line(0, 0, 300, i)
172
- app.translate i, i
173
- app.rotateZ i
174
- app.colorHSV i, 100, 100
175
- @font.text(0, 0, "rotate")
176
- app.rect(-10, -10, +10, +10)
177
- i += 20
178
- i = 0 if 300 < i
179
- }
180
- app.mainloop
181
- end
182
- end
183
-
184
- class TestCocoaMedia < Test::Unit::TestCase
185
- def test_image
186
- app = SGL::Application.new
187
- app.set_setup {
188
- app.window(200, 200)
189
- app.runtime = 0.5
190
- }
191
- image = app.image("../media/balls.png")
192
- i = 10
193
- app.set_display {
194
- app.background 100-i
195
- image.rect(0, i, 100, i+50)
196
- i += 5
197
- i = 0 if 100 < i
198
- }
199
- app.mainloop
200
- end
201
-
202
- def nutest_sound
203
- app = SGL::Application.new
204
- app.set_setup {
205
- app.window(100, 100)
206
- app.runtime = 1.5
207
- @sound = app.sound("../media/Pop.aiff")
208
- @first = true
209
- }
210
- app.set_display {
211
- if @first
212
- @sound.play
213
- @first = false
214
- end
215
- }
216
- app.mainloop
217
- end
218
- end
219
-
220
- #class TestCocoaMovie < Test::Unit::TestCase
221
- class TestCocoaMovie
222
- TEST_MOVIE = "/Applications/iDVD 3/Tutorial/Media/Background Movie.mov"
223
-
224
- def test_movie
225
- app = SGL::Application.new
226
- app.set_setup {
227
- app.window(500, 500)
228
- app.runtime = 2.0
229
- @movie = app.movie(TEST_MOVIE)
230
- @movie.play
231
- }
232
- i = 100
233
- app.set_display {
234
- app.background 100-i
235
- @movie.rect(i, i, 200+i, 150+i)
236
- i += 5
237
- i = 0 if 500 < i
238
- }
239
- app.mainloop
240
- end
241
-
242
- def test_movie_view
243
- app = SGL::Application.new
244
- app.set_setup {
245
- app.window(500, 500, :movie=>true, :overlay=>true)
246
- app.runtime = 3.0
247
- @movie = app.movie(TEST_MOVIE)
248
- @movie.play
249
- }
250
- i = 100
251
- app.set_display {
252
- app.background 100-i/5
253
- app.colorHSV(66, 100, 100, 50)
254
- app.circle(500-i, i, 100)
255
- i += 20
256
- i = 0 if 400 < i
257
- @movie.rect(i+100, i+100, i+400, i+300)
258
- }
259
- app.set_display_overlay {
260
- app.colorHSV(33, 100, 100, 50)
261
- app.circle(i, i, 100)
262
- }
263
- app.mainloop
264
- end
265
-
266
- def test_movie_overlay
267
- app = SGL::Application.new
268
- app.set_setup {
269
- app.window(500, 500, :overlay=>true)
270
- app.runtime = 3.0
271
- @movie = app.movie(TEST_MOVIE)
272
- @movie.play
273
- }
274
- i = 100
275
- app.set_display {
276
- app.background 100-i/5
277
- @movie.rect(100, 100, 400, 300)
278
- app.colorHSV(66, 100, 100, 50)
279
- app.circle(500-i, i, 100)
280
- i += 20
281
- i = 0 if 400 < i
282
- }
283
- app.set_display_overlay {
284
- app.colorHSV(33, 100, 100, 50)
285
- app.circle(i, i, 100)
286
- }
287
- app.mainloop
288
- end
289
- end
290
-
291
- end
1
+ #!/usr/bin/env ruby -w
2
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
3
+ # License: Ruby License
4
+
5
+ require File.dirname(__FILE__) + '/test_helper.rb'
6
+
7
+ if /osx/ =~ RUBY_PLATFORM
8
+
9
+ require "sgl/cocoa-app"
10
+
11
+ class TestCocoaBasic < Test::Unit::TestCase
12
+ def test_basic
13
+ app = SGL::Application.new
14
+ app.set_setup {
15
+ app.window(100, 100)
16
+ app.runtime = 0.5
17
+ }
18
+ i = 0
19
+ app.set_display {
20
+ app.line(0, 0, 100, i*5)
21
+ i += 2
22
+ i = 0 if 20 < i
23
+ }
24
+ app.mainloop
25
+ end
26
+
27
+ def test_window
28
+ app = SGL::Application.new
29
+ sleep 0.01; app.window(100, 100)
30
+ sleep 0.01; app.close_window
31
+ sleep 0.01; app.window(500, 500)
32
+ sleep 0.01; app.close_window
33
+ sleep 0.01; app.window(100, 100, :border=>false)
34
+ sleep 0.01; app.close_window
35
+ sleep 0.01; app.window(100, 100, :shadow=>false, :border=>false)
36
+ sleep 0.01; app.close_window
37
+ end
38
+
39
+ def test_color
40
+ app = SGL::Application.new
41
+ app.window(100, 100)
42
+ app.background(100)
43
+ bgcolor = app.instance_eval { @bgcolor }
44
+ assert_equal([1.0, 1.0, 1.0, 1.0], bgcolor)
45
+ app.background(10, 20, 30)
46
+ bgcolor = app.instance_eval { @bgcolor }
47
+ assert_equal([0.1, 0.2, 0.3, 1.0], bgcolor)
48
+ app.color(0)
49
+ curcolor = app.instance_eval { @curcolor }
50
+ assert_equal([0.0, 0.0, 0.0, 1.0], curcolor)
51
+ app.color(10, 20, 30)
52
+ curcolor = app.instance_eval { @curcolor }
53
+ assert_equal([0.1, 0.2, 0.3, 1.0], curcolor)
54
+ app.close_window
55
+ end
56
+
57
+ def test_setup_and_display
58
+ app = SGL::Application.new
59
+ app.window(100, 100)
60
+
61
+ test_setup_done = false
62
+ app.set_setup { test_setup_done = true }
63
+ assert_equal(false, test_setup_done)
64
+ app.do_setup
65
+ assert_equal(true, test_setup_done)
66
+
67
+ test_display_done = false
68
+ app.set_display { test_display_done = true }
69
+ assert_equal(false, test_display_done)
70
+ app.do_display
71
+ assert_equal(true, test_display_done)
72
+ app.close_window
73
+ end
74
+
75
+ def test_event
76
+ app = SGL::Application.new
77
+ app.window(100, 100)
78
+
79
+ test = {}
80
+ app.set_mousedown { test[:mousedown] = true }
81
+ assert_equal(nil, test[:mousedown])
82
+ app.do_mousedown
83
+ assert_equal(true, test[:mousedown])
84
+ end
85
+ end
86
+
87
+ class TestCocoaDraw < Test::Unit::TestCase
88
+ def test_commands
89
+ app = SGL::Application.new
90
+ app.set_setup {
91
+ app.window(100, 100)
92
+ app.runtime = 0.1
93
+ }
94
+ app.set_display {
95
+ app.line(0, 0, 100, 100)
96
+ app.rect(40, 40, 60, 60)
97
+ app.circle(20, 20, 10)
98
+ }
99
+ app.mainloop
100
+ end
101
+
102
+ def test_for
103
+ app = SGL::Application.new
104
+ app.set_setup {
105
+ app.window(100, 100)
106
+ app.runtime = 0.1
107
+ }
108
+ app.set_display {
109
+ for i in 0..20
110
+ app.line(0, 0, 100, i*5)
111
+ end
112
+ }
113
+ app.mainloop
114
+ end
115
+
116
+ def test_iterate
117
+ app = SGL::Application.new
118
+ app.set_setup {
119
+ app.window(100, 100)
120
+ app.runtime = 0.5
121
+ }
122
+ i = 0
123
+ app.set_display {
124
+ app.line(0, 0, 100, i*5)
125
+ i += 1
126
+ i = 0 if 20 < i
127
+ }
128
+ app.mainloop
129
+ end
130
+
131
+ def test_font
132
+ app = SGL::Application.new
133
+ app.set_setup {
134
+ app.window(100, 100)
135
+ app.runtime = 0.1
136
+ }
137
+ font = app.font("Helvetica")
138
+ app.set_display {
139
+ font.text(50, 50, "hello")
140
+ }
141
+ app.mainloop
142
+ end
143
+
144
+ def test_font_iterate
145
+ app = SGL::Application.new
146
+ app.set_setup {
147
+ app.window(100, 100)
148
+ app.runtime = 0.5
149
+ }
150
+ i = 10
151
+ app.set_display {
152
+ font = app.font("Helvetica", i)
153
+ font.text(0, 0, "hello")
154
+ i += 5
155
+ i = 0 if 200 < i
156
+ }
157
+ app.mainloop
158
+ end
159
+
160
+ def test_affine
161
+ app = SGL::Application.new
162
+ app.set_setup {
163
+ app.window(300, 300)
164
+ app.runtime = 0.5
165
+ @font = app.font("Helvetica", 20)
166
+ }
167
+ i = 0
168
+ app.set_display {
169
+ app.colorHSV 66, 100, 100, 50
170
+ app.lineWidth(i/10)
171
+ app.line(0, 0, 300, i)
172
+ app.translate i, i
173
+ app.rotateZ i
174
+ app.colorHSV i, 100, 100
175
+ @font.text(0, 0, "rotate")
176
+ app.rect(-10, -10, +10, +10)
177
+ i += 20
178
+ i = 0 if 300 < i
179
+ }
180
+ app.mainloop
181
+ end
182
+ end
183
+
184
+ class TestCocoaMedia < Test::Unit::TestCase
185
+ def test_image
186
+ app = SGL::Application.new
187
+ app.set_setup {
188
+ app.window(200, 200)
189
+ app.runtime = 0.5
190
+ }
191
+ image = app.image("../media/balls.png")
192
+ i = 10
193
+ app.set_display {
194
+ app.background 100-i
195
+ image.rect(0, i, 100, i+50)
196
+ i += 5
197
+ i = 0 if 100 < i
198
+ }
199
+ app.mainloop
200
+ end
201
+
202
+ def nutest_sound
203
+ app = SGL::Application.new
204
+ app.set_setup {
205
+ app.window(100, 100)
206
+ app.runtime = 1.5
207
+ @sound = app.sound("../media/Pop.aiff")
208
+ @first = true
209
+ }
210
+ app.set_display {
211
+ if @first
212
+ @sound.play
213
+ @first = false
214
+ end
215
+ }
216
+ app.mainloop
217
+ end
218
+ end
219
+
220
+ #class TestCocoaMovie < Test::Unit::TestCase
221
+ class TestCocoaMovie
222
+ TEST_MOVIE = "/Applications/iDVD 3/Tutorial/Media/Background Movie.mov"
223
+
224
+ def test_movie
225
+ app = SGL::Application.new
226
+ app.set_setup {
227
+ app.window(500, 500)
228
+ app.runtime = 2.0
229
+ @movie = app.movie(TEST_MOVIE)
230
+ @movie.play
231
+ }
232
+ i = 100
233
+ app.set_display {
234
+ app.background 100-i
235
+ @movie.rect(i, i, 200+i, 150+i)
236
+ i += 5
237
+ i = 0 if 500 < i
238
+ }
239
+ app.mainloop
240
+ end
241
+
242
+ def test_movie_view
243
+ app = SGL::Application.new
244
+ app.set_setup {
245
+ app.window(500, 500, :movie=>true, :overlay=>true)
246
+ app.runtime = 3.0
247
+ @movie = app.movie(TEST_MOVIE)
248
+ @movie.play
249
+ }
250
+ i = 100
251
+ app.set_display {
252
+ app.background 100-i/5
253
+ app.colorHSV(66, 100, 100, 50)
254
+ app.circle(500-i, i, 100)
255
+ i += 20
256
+ i = 0 if 400 < i
257
+ @movie.rect(i+100, i+100, i+400, i+300)
258
+ }
259
+ app.set_display_overlay {
260
+ app.colorHSV(33, 100, 100, 50)
261
+ app.circle(i, i, 100)
262
+ }
263
+ app.mainloop
264
+ end
265
+
266
+ def test_movie_overlay
267
+ app = SGL::Application.new
268
+ app.set_setup {
269
+ app.window(500, 500, :overlay=>true)
270
+ app.runtime = 3.0
271
+ @movie = app.movie(TEST_MOVIE)
272
+ @movie.play
273
+ }
274
+ i = 100
275
+ app.set_display {
276
+ app.background 100-i/5
277
+ @movie.rect(100, 100, 400, 300)
278
+ app.colorHSV(66, 100, 100, 50)
279
+ app.circle(500-i, i, 100)
280
+ i += 20
281
+ i = 0 if 400 < i
282
+ }
283
+ app.set_display_overlay {
284
+ app.colorHSV(33, 100, 100, 50)
285
+ app.circle(i, i, 100)
286
+ }
287
+ app.mainloop
288
+ end
289
+ end
290
+
291
+ end