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
@@ -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