sgl 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +16 -0
- data/README.txt +5 -0
- data/Rakefile +182 -0
- data/lib/sgl.rb +4 -0
- data/lib/sgl/version.rb +12 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/test/test_cocoa_app.rb +291 -0
- data/test/test_helper.rb +2 -0
- data/test/test_module_ruby16.rb +29 -0
- data/test/test_opengl_app.rb +148 -0
- data/test/test_opengl_basic.rb +23 -0
- data/test/test_opengl_fullscreen.rb +25 -0
- data/test/test_opengl_novice.rb +38 -0
- data/test/test_sgl.rb +32 -0
- data/website/index.html +170 -0
- data/website/index.txt +89 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +47 -0
- metadata +73 -0
@@ -0,0 +1,291 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright (C) 2004-2005 Kouichirou Eto, All rights reserved.
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
5
|
+
|
6
|
+
if /cocoa/ =~ RUBY_PLATFORM
|
7
|
+
|
8
|
+
require "sgl/cocoa-app"
|
9
|
+
require "test/unit"
|
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
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright (C) 2004-2005 Kouichirou Eto, All rights reserved.
|
2
|
+
|
3
|
+
=begin
|
4
|
+
# only for Ruby 1.6
|
5
|
+
class Array
|
6
|
+
def fetch(n)
|
7
|
+
a = self[n]
|
8
|
+
if a.nil?
|
9
|
+
a = yield
|
10
|
+
end
|
11
|
+
a
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Enumerable
|
16
|
+
def sort_by
|
17
|
+
self.collect {|i| [yield(i), i]}.
|
18
|
+
sort {|a,b| a[0] <=> b[0]}.
|
19
|
+
collect! {|i| i[1]}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
alias org_exit exit
|
24
|
+
def exit(n)
|
25
|
+
n = 0 if n == true
|
26
|
+
n = 1 if n == false
|
27
|
+
org_exit(n)
|
28
|
+
end
|
29
|
+
=end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright (C) 2004-2005 Kouichirou Eto, All rights reserved.
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
5
|
+
require "sgl/opengl-app"
|
6
|
+
require "test/unit"
|
7
|
+
|
8
|
+
class TestOpenglBasic < Test::Unit::TestCase
|
9
|
+
def test_basic
|
10
|
+
app = SGL::Application.new
|
11
|
+
app.set_setup {
|
12
|
+
app.window(100, 100)
|
13
|
+
app.runtime = 0.1
|
14
|
+
}
|
15
|
+
i = 0
|
16
|
+
app.set_display {
|
17
|
+
app.line(0, 0, 100, i*5)
|
18
|
+
i += 2
|
19
|
+
i = 0 if 20 < i
|
20
|
+
}
|
21
|
+
app.mainloop
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_window
|
25
|
+
app = SGL::Application.new
|
26
|
+
sleep 0.01; app.window(100, 100)
|
27
|
+
sleep 0.01; app.close_window
|
28
|
+
sleep 0.01; app.window(500, 500)
|
29
|
+
sleep 0.01; app.close_window
|
30
|
+
sleep 0.01; app.window(100, 100, :border=>false)
|
31
|
+
sleep 0.01; app.close_window
|
32
|
+
sleep 0.01; app.window(100, 100, :shadow=>false, :border=>false)
|
33
|
+
sleep 0.01; app.close_window
|
34
|
+
end
|
35
|
+
|
36
|
+
def nutest_color
|
37
|
+
app = SGL::Application.new
|
38
|
+
app.window(100, 100)
|
39
|
+
app.background(100)
|
40
|
+
bgcolor = app.instance_eval { @bgcolor }
|
41
|
+
assert_equal([1.0, 1.0, 1.0, 1.0], bgcolor)
|
42
|
+
app.background(10, 20, 30)
|
43
|
+
bgcolor = app.instance_eval { @bgcolor }
|
44
|
+
assert_equal([0.1, 0.2, 0.3, 1.0], bgcolor)
|
45
|
+
app.color(0)
|
46
|
+
curcolor = app.instance_eval { @curcolor }
|
47
|
+
assert_equal([0.0, 0.0, 0.0, 1.0], curcolor)
|
48
|
+
app.color(10, 20, 30)
|
49
|
+
curcolor = app.instance_eval { @curcolor }
|
50
|
+
assert_equal([0.1, 0.2, 0.3, 1.0], curcolor)
|
51
|
+
app.close_window
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_setup_and_display
|
55
|
+
app = SGL::Application.new
|
56
|
+
app.window(100, 100)
|
57
|
+
|
58
|
+
test_setup_done = false
|
59
|
+
app.set_setup { test_setup_done = true }
|
60
|
+
assert_equal(false, test_setup_done)
|
61
|
+
app.do_setup
|
62
|
+
assert_equal(true, test_setup_done)
|
63
|
+
|
64
|
+
test_display_done = false
|
65
|
+
app.set_display { test_display_done = true }
|
66
|
+
assert_equal(false, test_display_done)
|
67
|
+
app.do_display
|
68
|
+
assert_equal(true, test_display_done)
|
69
|
+
app.close_window
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_event
|
73
|
+
app = SGL::Application.new
|
74
|
+
app.window(100, 100)
|
75
|
+
|
76
|
+
test = {}
|
77
|
+
app.set_mousedown { test[:mousedown] = true }
|
78
|
+
assert_equal(nil, test[:mousedown])
|
79
|
+
app.do_mousedown
|
80
|
+
assert_equal(true, test[:mousedown])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class TestCocoaDraw < Test::Unit::TestCase
|
85
|
+
def test_commands
|
86
|
+
app = SGL::Application.new
|
87
|
+
app.set_setup {
|
88
|
+
app.window(100, 100)
|
89
|
+
app.runtime = 0.1
|
90
|
+
}
|
91
|
+
app.set_display {
|
92
|
+
app.line(0, 0, 100, 100)
|
93
|
+
app.rect(40, 40, 60, 60)
|
94
|
+
app.circle(20, 20, 10)
|
95
|
+
}
|
96
|
+
app.mainloop
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_for
|
100
|
+
app = SGL::Application.new
|
101
|
+
app.set_setup {
|
102
|
+
app.window(100, 100)
|
103
|
+
app.runtime = 0.1
|
104
|
+
}
|
105
|
+
app.set_display {
|
106
|
+
for i in 0..20
|
107
|
+
app.line(0, 0, 100, i*5)
|
108
|
+
end
|
109
|
+
}
|
110
|
+
app.mainloop
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_iterate
|
114
|
+
app = SGL::Application.new
|
115
|
+
app.set_setup {
|
116
|
+
app.window(100, 100)
|
117
|
+
app.runtime = 0.2
|
118
|
+
}
|
119
|
+
i = 0
|
120
|
+
app.set_display {
|
121
|
+
app.line(0, 0, 100, i*5)
|
122
|
+
i += 1
|
123
|
+
i = 0 if 20 < i
|
124
|
+
}
|
125
|
+
app.mainloop
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_affine
|
129
|
+
app = SGL::Application.new
|
130
|
+
app.set_setup {
|
131
|
+
app.window(300, 300)
|
132
|
+
app.runtime = 0.2
|
133
|
+
}
|
134
|
+
i = 0
|
135
|
+
app.set_display {
|
136
|
+
app.colorHSV 66, 100, 100, 50
|
137
|
+
app.lineWidth(i/10)
|
138
|
+
app.line(0, 0, 300, i)
|
139
|
+
app.translate i, i
|
140
|
+
app.rotateZ i
|
141
|
+
app.colorHSV i, 100, 100
|
142
|
+
app.rect(-10, -10, +10, +10)
|
143
|
+
i += 20
|
144
|
+
i = 0 if 300 < i
|
145
|
+
}
|
146
|
+
app.mainloop
|
147
|
+
end
|
148
|
+
end
|