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.
- data/ChangeLog +254 -234
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/Rakefile +27 -7
- data/examples/cocoa1-basic.rb +14 -14
- data/examples/cocoa10-transparent.rb +26 -26
- data/examples/cocoa11-application.rb +13 -13
- data/examples/cocoa2-draw.rb +23 -23
- data/examples/cocoa3-affine.rb +29 -29
- data/examples/cocoa4-font.rb +24 -24
- data/examples/cocoa5-image.rb +22 -22
- data/examples/cocoa6-sound.rb +24 -24
- data/examples/cocoa7-movie.rb +40 -40
- data/examples/cocoa8-movieoverlay.rb +42 -42
- data/examples/cocoa9-streaming.rb +40 -40
- data/examples/opengl1-basic.rb +14 -14
- data/examples/opengl11-application.rb +13 -13
- data/examples/opengl2-draw.rb +23 -23
- data/examples/opengl3-affine.rb +29 -29
- data/examples/sample1.rb +11 -11
- data/examples/sample10.rb +16 -16
- data/examples/sample11.rb +22 -22
- data/examples/sample11a.rb +33 -33
- data/examples/sample12.rb +30 -30
- data/examples/sample12a.rb +35 -35
- data/examples/sample13.rb +116 -116
- data/examples/sample15.rb +24 -24
- data/examples/sample16.rb +31 -31
- data/examples/sample16a.rb +35 -35
- data/examples/sample6.rb +18 -18
- data/examples/sample7.rb +16 -16
- data/examples/sample9.rb +20 -20
- data/examples/testgl.rb +169 -169
- data/lib/sgl/bass.rb +46 -46
- data/lib/sgl/cocoa-app.rb +43 -43
- data/lib/sgl/cocoa-color.rb +65 -65
- data/lib/sgl/cocoa-draw.rb +72 -72
- data/lib/sgl/cocoa-event.rb +229 -229
- data/lib/sgl/cocoa-media.rb +144 -144
- data/lib/sgl/cocoa-notuse.rb +493 -493
- data/lib/sgl/cocoa-window.rb +203 -203
- data/lib/sgl/cocoa.rb +8 -8
- data/lib/sgl/opengl-app.rb +38 -38
- data/lib/sgl/opengl-color.rb +44 -44
- data/lib/sgl/opengl-draw.rb +260 -260
- data/lib/sgl/opengl-event.rb +325 -325
- data/lib/sgl/opengl-modules.rb +22 -22
- data/lib/sgl/opengl-window.rb +224 -224
- data/lib/sgl/opengl.rb +7 -7
- data/lib/sgl/sgl-button.rb +135 -135
- data/lib/sgl/sgl-client.rb +21 -21
- data/lib/sgl/sgl-color.rb +68 -82
- data/lib/sgl/sgl-connect.rb +9 -9
- data/lib/sgl/sgl-server.rb +58 -58
- data/lib/sgl/sgl-spring.rb +216 -216
- data/lib/sgl/version.rb +2 -2
- data/scripts/lib-txt2html.rb +130 -0
- data/scripts/txt2html +2 -63
- data/spec/sgl_spec.rb +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +1 -0
- data/test/test_cocoa_app.rb +291 -291
- data/test/test_module_ruby16.rb +30 -30
- data/test/test_opengl_app.rb +147 -147
- data/test/test_opengl_basic.rb +22 -22
- data/test/test_opengl_fullscreen.rb +23 -23
- data/test/test_opengl_novice.rb +35 -35
- data/website/challenge1.html +91 -91
- data/website/challenge1.txt +3 -3
- data/website/challenge2.html +143 -144
- data/website/challenge2.txt +13 -14
- data/website/challenge3.html +66 -63
- data/website/challenge3.txt +7 -7
- data/website/cocoa.html +85 -88
- data/website/cocoa.txt +2 -4
- data/website/description.html +138 -138
- data/website/description.txt +1 -1
- data/website/exercise1.html +262 -264
- data/website/exercise1.txt +58 -53
- data/website/exercise2.html +241 -683
- data/website/exercise2.txt +11 -427
- data/website/exercise3.html +206 -0
- data/website/exercise3.txt +155 -0
- data/website/exercise4.html +198 -0
- data/website/exercise4.txt +151 -0
- data/website/exercise5.html +162 -0
- data/website/exercise5.txt +113 -0
- data/website/exhibition.html +84 -84
- data/website/howto.html +146 -134
- data/website/howto.txt +9 -0
- data/website/index.html +178 -178
- data/website/index.txt +20 -19
- data/website/sound.html +141 -141
- metadata +16 -3
data/lib/sgl/cocoa-event.rb
CHANGED
@@ -1,229 +1,229 @@
|
|
1
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
-
# License: Ruby License
|
3
|
-
|
4
|
-
module SGL
|
5
|
-
# callback functions
|
6
|
-
def setup() end
|
7
|
-
def onMouseDown(x,y) end
|
8
|
-
def onMouseUp(x,y) end
|
9
|
-
def onKeyDown(k) end
|
10
|
-
def onKeyUp(k) end
|
11
|
-
def display() end
|
12
|
-
|
13
|
-
# mainloop
|
14
|
-
def mainloop
|
15
|
-
$__a__.set_setup { setup }
|
16
|
-
$__a__.set_mousedown {|x, y| onMouseDown(x, y) }
|
17
|
-
$__a__.set_mouseup {|x, y| onMouseUp(x, y) }
|
18
|
-
$__a__.set_keydown {|k| onKeyDown(k) }
|
19
|
-
$__a__.set_keyup {|k| onKeyUp(k) }
|
20
|
-
$__a__.set_display { display }
|
21
|
-
$__a__.mainloop
|
22
|
-
end
|
23
|
-
|
24
|
-
# get status functions
|
25
|
-
def mouseX() $__a__.mouseX; end
|
26
|
-
def mouseY() $__a__.mouseY; end
|
27
|
-
def mouseDown() $__a__.mouseDown; end
|
28
|
-
def keynum() $__a__.keynum; end
|
29
|
-
|
30
|
-
class Application
|
31
|
-
def initialize_event
|
32
|
-
# block setting
|
33
|
-
@setup_done = nil
|
34
|
-
@display_drawing = nil
|
35
|
-
@display_overlay_drawing = nil
|
36
|
-
@block = {}
|
37
|
-
@delay_time = 1.0/60
|
38
|
-
@runtime = nil
|
39
|
-
|
40
|
-
# status setting
|
41
|
-
@mouseX, @mouseY = 0, 0
|
42
|
-
@mouseDown = 0
|
43
|
-
@keynum = 0
|
44
|
-
end
|
45
|
-
attr_accessor :runtime # for test
|
46
|
-
|
47
|
-
# get status
|
48
|
-
attr_reader :mouseX, :mouseY
|
49
|
-
attr_reader :mouseDown
|
50
|
-
attr_reader :keynum
|
51
|
-
|
52
|
-
# setup
|
53
|
-
def set_setup(&b)
|
54
|
-
return unless block_given?
|
55
|
-
@block[:setup] = Proc.new
|
56
|
-
end
|
57
|
-
|
58
|
-
def do_setup
|
59
|
-
setup_pre
|
60
|
-
@block[:setup].call if @block[:setup]
|
61
|
-
setup_post
|
62
|
-
end
|
63
|
-
|
64
|
-
def setup_pre
|
65
|
-
# do nothing
|
66
|
-
end
|
67
|
-
|
68
|
-
def setup_post
|
69
|
-
@setup_done = true
|
70
|
-
end
|
71
|
-
private :setup_pre, :setup_post
|
72
|
-
|
73
|
-
# display
|
74
|
-
def display_all(rect) # callback
|
75
|
-
return if @win.nil?
|
76
|
-
return if @setup_done.nil?
|
77
|
-
return if @display_drawing
|
78
|
-
@display_drawing = true
|
79
|
-
display_bg(rect)
|
80
|
-
display_pre
|
81
|
-
do_display
|
82
|
-
display_post
|
83
|
-
@display_drawing = nil
|
84
|
-
end
|
85
|
-
|
86
|
-
def set_display(&b)
|
87
|
-
return unless block_given?
|
88
|
-
@block[:display] = Proc.new
|
89
|
-
end
|
90
|
-
|
91
|
-
def set_display_overlay(&b)
|
92
|
-
return unless block_given?
|
93
|
-
@block[:display_overlay] = Proc.new
|
94
|
-
end
|
95
|
-
|
96
|
-
def do_display
|
97
|
-
return if @win.nil?
|
98
|
-
display_pre
|
99
|
-
@block[:display].call if @block[:display]
|
100
|
-
display_post
|
101
|
-
end
|
102
|
-
|
103
|
-
def display_pre
|
104
|
-
return if @win.nil?
|
105
|
-
pos = @win.mouseLocationOutsideOfEventStream
|
106
|
-
@mouseX, @mouseY = pos.x.to_i, pos.y.to_i
|
107
|
-
set_cur_color # set back current color
|
108
|
-
end
|
109
|
-
|
110
|
-
def display_bg(rect)
|
111
|
-
set_cur_bg
|
112
|
-
OSX::NSRectFill(rect)
|
113
|
-
end
|
114
|
-
|
115
|
-
def display_clear_bg(rect)
|
116
|
-
set_color(0, 0, 0, 0) # full transparent
|
117
|
-
OSX::NSRectFill(rect)
|
118
|
-
end
|
119
|
-
|
120
|
-
def display_post
|
121
|
-
# do nothing
|
122
|
-
end
|
123
|
-
private :display_pre, :display_bg, :display_clear_bg, :display_post
|
124
|
-
|
125
|
-
# sub view
|
126
|
-
def display_mov(rect)
|
127
|
-
display_clear_bg(rect)
|
128
|
-
set_cur_color # set back current color
|
129
|
-
end
|
130
|
-
|
131
|
-
def display_overlay_all(rect)
|
132
|
-
return if @win.nil?
|
133
|
-
return if @setup_done.nil?
|
134
|
-
return if @display_overlay_drawing
|
135
|
-
@display_overlay_drawing = true
|
136
|
-
display_clear_bg(rect)
|
137
|
-
set_cur_color # set back current color
|
138
|
-
@block[:display_overlay].call if @block[:display_overlay]
|
139
|
-
@display_overlay_drawing = nil
|
140
|
-
end
|
141
|
-
|
142
|
-
# mainloop
|
143
|
-
def mainloop
|
144
|
-
starttime = Time.now
|
145
|
-
|
146
|
-
do_setup
|
147
|
-
|
148
|
-
@thread = Thread.start {
|
149
|
-
loop {
|
150
|
-
need_display
|
151
|
-
delay
|
152
|
-
|
153
|
-
if check_runtime_finished(starttime)
|
154
|
-
stop
|
155
|
-
break
|
156
|
-
end
|
157
|
-
}
|
158
|
-
}
|
159
|
-
|
160
|
-
run
|
161
|
-
end
|
162
|
-
|
163
|
-
def check_runtime_finished(starttime)
|
164
|
-
diff = Time.now - starttime
|
165
|
-
return (@runtime && @runtime < diff)
|
166
|
-
end
|
167
|
-
|
168
|
-
def need_display
|
169
|
-
return if @app.nil?
|
170
|
-
@bgview.setNeedsDisplay(true) if @bgview
|
171
|
-
@oview.setNeedsDisplay(true) if @oview
|
172
|
-
end
|
173
|
-
|
174
|
-
def delay
|
175
|
-
sleep @delay_time
|
176
|
-
end
|
177
|
-
private :need_display, :delay
|
178
|
-
|
179
|
-
# mouse events
|
180
|
-
def set_mousedown(&b)
|
181
|
-
return unless block_given?
|
182
|
-
@block[:mousedown] = Proc.new
|
183
|
-
end
|
184
|
-
|
185
|
-
def do_mousedown
|
186
|
-
@mouseDown = 1
|
187
|
-
@block[:mousedown].call(@mouseX, @mouseY) if @block[:mousedown]
|
188
|
-
end
|
189
|
-
|
190
|
-
def set_mouseup(&b)
|
191
|
-
return unless block_given?
|
192
|
-
@block[:mouseup] = Proc.new
|
193
|
-
end
|
194
|
-
|
195
|
-
def do_mouseup
|
196
|
-
@mouseDown = 0
|
197
|
-
@block[:mouseup].call(@mouseX, @mouseY) if @block[:mouseup]
|
198
|
-
end
|
199
|
-
|
200
|
-
# key events
|
201
|
-
def set_keydown(&b)
|
202
|
-
return unless block_given?
|
203
|
-
@block[:keydown] = Proc.new
|
204
|
-
end
|
205
|
-
|
206
|
-
def do_keydown(e)
|
207
|
-
calc_keynum(e)
|
208
|
-
@block[:keydown].call(@keynum) if @block[:keydown]
|
209
|
-
end
|
210
|
-
|
211
|
-
def set_keyup(&b)
|
212
|
-
return unless block_given?
|
213
|
-
@block[:keyup] = Proc.new
|
214
|
-
end
|
215
|
-
|
216
|
-
def do_keyup(e)
|
217
|
-
calc_keynum(e)
|
218
|
-
@keynum = 0
|
219
|
-
@block[:keyup].call(@keynum) if @block[:keyup]
|
220
|
-
end
|
221
|
-
|
222
|
-
def calc_keynum(e)
|
223
|
-
#input = event.characters
|
224
|
-
input = e.characters
|
225
|
-
@keynum = input.to_s[0]
|
226
|
-
end
|
227
|
-
private :calc_keynum
|
228
|
-
end
|
229
|
-
end
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
module SGL
|
5
|
+
# callback functions
|
6
|
+
def setup() end
|
7
|
+
def onMouseDown(x,y) end
|
8
|
+
def onMouseUp(x,y) end
|
9
|
+
def onKeyDown(k) end
|
10
|
+
def onKeyUp(k) end
|
11
|
+
def display() end
|
12
|
+
|
13
|
+
# mainloop
|
14
|
+
def mainloop
|
15
|
+
$__a__.set_setup { setup }
|
16
|
+
$__a__.set_mousedown {|x, y| onMouseDown(x, y) }
|
17
|
+
$__a__.set_mouseup {|x, y| onMouseUp(x, y) }
|
18
|
+
$__a__.set_keydown {|k| onKeyDown(k) }
|
19
|
+
$__a__.set_keyup {|k| onKeyUp(k) }
|
20
|
+
$__a__.set_display { display }
|
21
|
+
$__a__.mainloop
|
22
|
+
end
|
23
|
+
|
24
|
+
# get status functions
|
25
|
+
def mouseX() $__a__.mouseX; end
|
26
|
+
def mouseY() $__a__.mouseY; end
|
27
|
+
def mouseDown() $__a__.mouseDown; end
|
28
|
+
def keynum() $__a__.keynum; end
|
29
|
+
|
30
|
+
class Application
|
31
|
+
def initialize_event
|
32
|
+
# block setting
|
33
|
+
@setup_done = nil
|
34
|
+
@display_drawing = nil
|
35
|
+
@display_overlay_drawing = nil
|
36
|
+
@block = {}
|
37
|
+
@delay_time = 1.0/60
|
38
|
+
@runtime = nil
|
39
|
+
|
40
|
+
# status setting
|
41
|
+
@mouseX, @mouseY = 0, 0
|
42
|
+
@mouseDown = 0
|
43
|
+
@keynum = 0
|
44
|
+
end
|
45
|
+
attr_accessor :runtime # for test
|
46
|
+
|
47
|
+
# get status
|
48
|
+
attr_reader :mouseX, :mouseY
|
49
|
+
attr_reader :mouseDown
|
50
|
+
attr_reader :keynum
|
51
|
+
|
52
|
+
# setup
|
53
|
+
def set_setup(&b)
|
54
|
+
return unless block_given?
|
55
|
+
@block[:setup] = Proc.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def do_setup
|
59
|
+
setup_pre
|
60
|
+
@block[:setup].call if @block[:setup]
|
61
|
+
setup_post
|
62
|
+
end
|
63
|
+
|
64
|
+
def setup_pre
|
65
|
+
# do nothing
|
66
|
+
end
|
67
|
+
|
68
|
+
def setup_post
|
69
|
+
@setup_done = true
|
70
|
+
end
|
71
|
+
private :setup_pre, :setup_post
|
72
|
+
|
73
|
+
# display
|
74
|
+
def display_all(rect) # callback
|
75
|
+
return if @win.nil?
|
76
|
+
return if @setup_done.nil?
|
77
|
+
return if @display_drawing
|
78
|
+
@display_drawing = true
|
79
|
+
display_bg(rect)
|
80
|
+
display_pre
|
81
|
+
do_display
|
82
|
+
display_post
|
83
|
+
@display_drawing = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_display(&b)
|
87
|
+
return unless block_given?
|
88
|
+
@block[:display] = Proc.new
|
89
|
+
end
|
90
|
+
|
91
|
+
def set_display_overlay(&b)
|
92
|
+
return unless block_given?
|
93
|
+
@block[:display_overlay] = Proc.new
|
94
|
+
end
|
95
|
+
|
96
|
+
def do_display
|
97
|
+
return if @win.nil?
|
98
|
+
display_pre
|
99
|
+
@block[:display].call if @block[:display]
|
100
|
+
display_post
|
101
|
+
end
|
102
|
+
|
103
|
+
def display_pre
|
104
|
+
return if @win.nil?
|
105
|
+
pos = @win.mouseLocationOutsideOfEventStream
|
106
|
+
@mouseX, @mouseY = pos.x.to_i, pos.y.to_i
|
107
|
+
set_cur_color # set back current color
|
108
|
+
end
|
109
|
+
|
110
|
+
def display_bg(rect)
|
111
|
+
set_cur_bg
|
112
|
+
OSX::NSRectFill(rect)
|
113
|
+
end
|
114
|
+
|
115
|
+
def display_clear_bg(rect)
|
116
|
+
set_color(0, 0, 0, 0) # full transparent
|
117
|
+
OSX::NSRectFill(rect)
|
118
|
+
end
|
119
|
+
|
120
|
+
def display_post
|
121
|
+
# do nothing
|
122
|
+
end
|
123
|
+
private :display_pre, :display_bg, :display_clear_bg, :display_post
|
124
|
+
|
125
|
+
# sub view
|
126
|
+
def display_mov(rect)
|
127
|
+
display_clear_bg(rect)
|
128
|
+
set_cur_color # set back current color
|
129
|
+
end
|
130
|
+
|
131
|
+
def display_overlay_all(rect)
|
132
|
+
return if @win.nil?
|
133
|
+
return if @setup_done.nil?
|
134
|
+
return if @display_overlay_drawing
|
135
|
+
@display_overlay_drawing = true
|
136
|
+
display_clear_bg(rect)
|
137
|
+
set_cur_color # set back current color
|
138
|
+
@block[:display_overlay].call if @block[:display_overlay]
|
139
|
+
@display_overlay_drawing = nil
|
140
|
+
end
|
141
|
+
|
142
|
+
# mainloop
|
143
|
+
def mainloop
|
144
|
+
starttime = Time.now
|
145
|
+
|
146
|
+
do_setup
|
147
|
+
|
148
|
+
@thread = Thread.start {
|
149
|
+
loop {
|
150
|
+
need_display
|
151
|
+
delay
|
152
|
+
|
153
|
+
if check_runtime_finished(starttime)
|
154
|
+
stop
|
155
|
+
break
|
156
|
+
end
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
run
|
161
|
+
end
|
162
|
+
|
163
|
+
def check_runtime_finished(starttime)
|
164
|
+
diff = Time.now - starttime
|
165
|
+
return (@runtime && @runtime < diff)
|
166
|
+
end
|
167
|
+
|
168
|
+
def need_display
|
169
|
+
return if @app.nil?
|
170
|
+
@bgview.setNeedsDisplay(true) if @bgview
|
171
|
+
@oview.setNeedsDisplay(true) if @oview
|
172
|
+
end
|
173
|
+
|
174
|
+
def delay
|
175
|
+
sleep @delay_time
|
176
|
+
end
|
177
|
+
private :need_display, :delay
|
178
|
+
|
179
|
+
# mouse events
|
180
|
+
def set_mousedown(&b)
|
181
|
+
return unless block_given?
|
182
|
+
@block[:mousedown] = Proc.new
|
183
|
+
end
|
184
|
+
|
185
|
+
def do_mousedown
|
186
|
+
@mouseDown = 1
|
187
|
+
@block[:mousedown].call(@mouseX, @mouseY) if @block[:mousedown]
|
188
|
+
end
|
189
|
+
|
190
|
+
def set_mouseup(&b)
|
191
|
+
return unless block_given?
|
192
|
+
@block[:mouseup] = Proc.new
|
193
|
+
end
|
194
|
+
|
195
|
+
def do_mouseup
|
196
|
+
@mouseDown = 0
|
197
|
+
@block[:mouseup].call(@mouseX, @mouseY) if @block[:mouseup]
|
198
|
+
end
|
199
|
+
|
200
|
+
# key events
|
201
|
+
def set_keydown(&b)
|
202
|
+
return unless block_given?
|
203
|
+
@block[:keydown] = Proc.new
|
204
|
+
end
|
205
|
+
|
206
|
+
def do_keydown(e)
|
207
|
+
calc_keynum(e)
|
208
|
+
@block[:keydown].call(@keynum) if @block[:keydown]
|
209
|
+
end
|
210
|
+
|
211
|
+
def set_keyup(&b)
|
212
|
+
return unless block_given?
|
213
|
+
@block[:keyup] = Proc.new
|
214
|
+
end
|
215
|
+
|
216
|
+
def do_keyup(e)
|
217
|
+
calc_keynum(e)
|
218
|
+
@keynum = 0
|
219
|
+
@block[:keyup].call(@keynum) if @block[:keyup]
|
220
|
+
end
|
221
|
+
|
222
|
+
def calc_keynum(e)
|
223
|
+
#input = event.characters
|
224
|
+
input = e.characters
|
225
|
+
@keynum = input.to_s[0]
|
226
|
+
end
|
227
|
+
private :calc_keynum
|
228
|
+
end
|
229
|
+
end
|