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/bass.rb CHANGED
@@ -1,46 +1,46 @@
1
- # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
- # License: Ruby License
3
-
4
- require 'Win32API'
5
- require 'singleton'
6
- require 'sgl/bass-sample'
7
- require 'sgl/bass-api'
8
-
9
- module Bass
10
- at_exit { BASS_Free.call }
11
-
12
- class BassLib
13
- include Singleton
14
-
15
- def initialize
16
- #ret = Bass::BASS_Init.call(-1, 44100, BASS_DEVICE_OGG, 0)
17
- ret = Bass::BASS_Init.call(-1, 44100, 0, 0)
18
- ver = Bass::BASS_GetVersion.call
19
- ret = Bass::BASS_Start.call
20
- @playing_channel = []
21
- end
22
-
23
- def add_playing_channel(ch)
24
- @playing_channel << ch
25
- end
26
-
27
- def stop_all
28
- @playing_channel.each {|ch|
29
- ret = Bass::BASS_ChannelStop.call(ch)
30
- }
31
- @playing_channel = []
32
- end
33
- end
34
-
35
- # class << Bass
36
- # def init(a, b, c, d) BASS_Init.call(a, b, c, d) end
37
- # def start() BASS_Start.call() end
38
- # def errorGetCode() BASS_ErrorGetCode.call() end
39
- # def getVersion() BASS_GetVersion.call() end
40
- # def free() BASS_Free.call() end
41
- # def sampleLoad(a, b, c, d, e, f) BASS_SampleLoad.call(a, b, c, d, e, f) end
42
- # def samplePlay(a) BASS_SamplePlay.call(a) end
43
- # def samplePlayEx(a, b, c, d, e, f) BASS_SamplePlayEx.call(a, b, c, d, e, f) end
44
- # end
45
- #at_exit { Bass.free; }
46
- end
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ require 'Win32API'
5
+ require 'singleton'
6
+ require 'sgl/bass-sample'
7
+ require 'sgl/bass-api'
8
+
9
+ module Bass
10
+ at_exit { BASS_Free.call }
11
+
12
+ class BassLib
13
+ include Singleton
14
+
15
+ def initialize
16
+ #ret = Bass::BASS_Init.call(-1, 44100, BASS_DEVICE_OGG, 0)
17
+ ret = Bass::BASS_Init.call(-1, 44100, 0, 0)
18
+ ver = Bass::BASS_GetVersion.call
19
+ ret = Bass::BASS_Start.call
20
+ @playing_channel = []
21
+ end
22
+
23
+ def add_playing_channel(ch)
24
+ @playing_channel << ch
25
+ end
26
+
27
+ def stop_all
28
+ @playing_channel.each {|ch|
29
+ ret = Bass::BASS_ChannelStop.call(ch)
30
+ }
31
+ @playing_channel = []
32
+ end
33
+ end
34
+
35
+ # class << Bass
36
+ # def init(a, b, c, d) BASS_Init.call(a, b, c, d) end
37
+ # def start() BASS_Start.call() end
38
+ # def errorGetCode() BASS_ErrorGetCode.call() end
39
+ # def getVersion() BASS_GetVersion.call() end
40
+ # def free() BASS_Free.call() end
41
+ # def sampleLoad(a, b, c, d, e, f) BASS_SampleLoad.call(a, b, c, d, e, f) end
42
+ # def samplePlay(a) BASS_SamplePlay.call(a) end
43
+ # def samplePlayEx(a, b, c, d, e, f) BASS_SamplePlayEx.call(a, b, c, d, e, f) end
44
+ # end
45
+ #at_exit { Bass.free; }
46
+ end
data/lib/sgl/cocoa-app.rb CHANGED
@@ -1,43 +1,43 @@
1
- # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
- # License: Ruby License
3
-
4
- require "osx/cocoa"
5
- require "sgl/sgl-color"
6
- require "sgl/cocoa-event"
7
- require "sgl/cocoa-window"
8
- require "sgl/cocoa-draw"
9
- require "sgl/cocoa-color"
10
- require "sgl/cocoa-media"
11
-
12
- module SGL
13
- class Application
14
- def initialize
15
- initialize_cocoa
16
- initialize_window
17
- initialize_color
18
- initialize_event
19
- end
20
-
21
- def initialize_cocoa
22
- OSX.ruby_thread_switcher_start(0.001, 0.01)
23
- Thread.abort_on_exception = true
24
-
25
- @app = OSX::NSApplication.sharedApplication
26
- mainmenu = OSX::NSMenu.alloc.init
27
- @app.setMainMenu(mainmenu)
28
- end
29
- private :initialize_cocoa
30
-
31
- def run
32
- OSX.NSApp.run
33
- OSX::NSEvent.stopPeriodicEvents
34
- end
35
-
36
- def stop
37
- close_window
38
- OSX.NSApp.stop(nil)
39
- OSX::NSEvent.startPeriodicEventsAfterDelay(0.01, :withPeriod, 0.01)
40
- end
41
- end
42
- end
43
-
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ require "osx/cocoa"
5
+ require "sgl/sgl-color"
6
+ require "sgl/cocoa-event"
7
+ require "sgl/cocoa-window"
8
+ require "sgl/cocoa-draw"
9
+ require "sgl/cocoa-color"
10
+ require "sgl/cocoa-media"
11
+
12
+ module SGL
13
+ class Application
14
+ def initialize
15
+ initialize_cocoa
16
+ initialize_window
17
+ initialize_color
18
+ initialize_event
19
+ end
20
+
21
+ def initialize_cocoa
22
+ OSX.ruby_thread_switcher_start(0.001, 0.01)
23
+ Thread.abort_on_exception = true
24
+
25
+ @app = OSX::NSApplication.sharedApplication
26
+ mainmenu = OSX::NSMenu.alloc.init
27
+ @app.setMainMenu(mainmenu)
28
+ end
29
+ private :initialize_cocoa
30
+
31
+ def run
32
+ OSX.NSApp.run
33
+ OSX::NSEvent.stopPeriodicEvents
34
+ end
35
+
36
+ def stop
37
+ close_window
38
+ OSX.NSApp.stop(nil)
39
+ OSX::NSEvent.startPeriodicEventsAfterDelay(0.01, :withPeriod, 0.01)
40
+ end
41
+ end
42
+ end
43
+
@@ -1,65 +1,65 @@
1
- # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
- # License: Ruby License
3
-
4
- module SGL
5
- def background(*a) $__a__.background(*a); end
6
- def backgroundHSV(*a) $__a__.backgroundHSV(*a); end
7
- def color(*a) $__a__.color(*a); end
8
- def colorHSV(*a) $__a__.colorHSV(*a); end
9
-
10
- class Application
11
- def initialize_color
12
- @bg_color = @cur_color = nil
13
- @rgb = ColorTranslatorRGB.new(100, 100, 100, 100)
14
- @hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
15
- end
16
- private :initialize_color
17
- attr_reader :cur_color
18
-
19
- def background(x, y=nil, z=nil, a=nil)
20
- @bg_color = @rgb.norm(x,y,z,a)
21
- end
22
-
23
- def backgroundHSV(x, y=nil, z=nil, a=nil)
24
- @bg_color = @hsv.norm(x,y,z,a)
25
- end
26
-
27
- def color(x, y=nil, z=nil, a=nil)
28
- @cur_color = @rgb.norm(x,y,z,a)
29
- set_cur_color
30
- end
31
-
32
- def colorHSV(x, y=nil, z=nil, a=nil)
33
- @cur_color = @hsv.norm(x,y,z,a)
34
- set_cur_color
35
- end
36
-
37
- # called from cocoa-media
38
- # Since thie method called from NSFont, this should be public.
39
- def make_cur_color
40
- make_color(*@cur_color)
41
- end
42
-
43
- def get_cur_color_alpha
44
- @cur_color[3]
45
- end
46
-
47
- # private
48
- def set_cur_color
49
- set_color(*@cur_color)
50
- end
51
-
52
- def set_cur_bg
53
- set_color(*@bg_color)
54
- end
55
-
56
- def set_color(*a)
57
- make_color(*a).set if @win
58
- end
59
-
60
- def make_color(r, g, b, a)
61
- OSX::NSColor.colorWithDeviceRed(r, :green, g, :blue, b, :alpha, a)
62
- end
63
- private :set_cur_color, :set_cur_bg, :set_color, :make_color
64
- end
65
- end
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ module SGL
5
+ def background(*a) $__a__.background(*a); end
6
+ def backgroundHSV(*a) $__a__.backgroundHSV(*a); end
7
+ def color(*a) $__a__.color(*a); end
8
+ def colorHSV(*a) $__a__.colorHSV(*a); end
9
+
10
+ class Application
11
+ def initialize_color
12
+ @bg_color = @cur_color = nil
13
+ @rgb = ColorTranslatorRGB.new(100, 100, 100, 100)
14
+ @hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
15
+ end
16
+ private :initialize_color
17
+ attr_reader :cur_color
18
+
19
+ def background(x, y=nil, z=nil, a=nil)
20
+ @bg_color = @rgb.norm(x,y,z,a)
21
+ end
22
+
23
+ def backgroundHSV(x, y=nil, z=nil, a=nil)
24
+ @bg_color = @hsv.norm(x,y,z,a)
25
+ end
26
+
27
+ def color(x, y=nil, z=nil, a=nil)
28
+ @cur_color = @rgb.norm(x,y,z,a)
29
+ set_cur_color
30
+ end
31
+
32
+ def colorHSV(x, y=nil, z=nil, a=nil)
33
+ @cur_color = @hsv.norm(x,y,z,a)
34
+ set_cur_color
35
+ end
36
+
37
+ # called from cocoa-media
38
+ # Since thie method called from NSFont, this should be public.
39
+ def make_cur_color
40
+ make_color(*@cur_color)
41
+ end
42
+
43
+ def get_cur_color_alpha
44
+ @cur_color[3]
45
+ end
46
+
47
+ # private
48
+ def set_cur_color
49
+ set_color(*@cur_color)
50
+ end
51
+
52
+ def set_cur_bg
53
+ set_color(*@bg_color)
54
+ end
55
+
56
+ def set_color(*a)
57
+ make_color(*a).set if @win
58
+ end
59
+
60
+ def make_color(r, g, b, a)
61
+ OSX::NSColor.colorWithDeviceRed(r, :green, g, :blue, b, :alpha, a)
62
+ end
63
+ private :set_cur_color, :set_cur_bg, :set_color, :make_color
64
+ end
65
+ end
@@ -1,72 +1,72 @@
1
- # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
- # License: Ruby License
3
-
4
- module SGL
5
- module FrameTranslator
6
- def to_xywh(a,b,c,d)
7
- [[a, c].min, [b, d].min, (a - c).abs, (b - d).abs]
8
- end
9
- private :to_xywh
10
- end
11
-
12
- def point(*a) $__a__.point(*a); end
13
- def lineWidth(*a) $__a__.lineWidth(*a); end
14
- def line(*a) $__a__.line(*a); end
15
- def rect(*a) $__a__.rect(*a); end
16
- def circle(*a) $__a__.circle(*a); end
17
- def rotateZ(*a) $__a__.rotateZ(*a); end
18
- def translate(*a) $__a__.translate(*a); end
19
- def scale(*a) $__a__.scale(*a); end
20
- def reset(*a) $__a__.reset(*a); end
21
-
22
- class Application
23
- include FrameTranslator
24
-
25
- def point(a,b)
26
- line(a,b,a,b)
27
- end
28
-
29
- def lineWidth(w)
30
- OSX::NSBezierPath.setDefaultLineWidth(w)
31
- end
32
-
33
- def line(a,b,c,d)
34
- #OSX::NSBezierPath.strokeLine({:fromPoint=>OSX::NSPoint.new(a, b),
35
- # :toPoint=>OSX::NSPoint.new(c, d)})
36
- OSX::NSBezierPath.strokeLineFromPoint(OSX::NSPoint.new(a, b),
37
- :toPoint, OSX::NSPoint.new(c, d))
38
- end
39
-
40
- def rect(a,b,c,d)
41
- rect = OSX::NSRect.new(*to_xywh(a, b, c, d))
42
- OSX::NSBezierPath.bezierPathWithRect(rect).fill
43
- end
44
-
45
- def circle(x, y, r)
46
- rect = OSX::NSRect.new(x - r, y - r, 2*r, 2*r)
47
- OSX::NSBezierPath.bezierPathWithOvalInRect(rect).fill
48
- end
49
-
50
- def rotateZ(deg)
51
- af = OSX::NSAffineTransform.transform
52
- af.rotateByDegrees(deg)
53
- af.concat
54
- end
55
-
56
- def translate(x, y)
57
- af = OSX::NSAffineTransform.transform
58
- af.translateXBy(x, :yBy, y)
59
- af.concat
60
- end
61
-
62
- def scale(x, y=nil)
63
- af = OSX::NSAffineTransform.transform
64
- y ? af.scaleXBy(x, :yBy, y) : af.scaleBy(x)
65
- af.concat
66
- end
67
-
68
- def reset
69
- OSX::NSAffineTransform.transform.set
70
- end
71
- end
72
- end
1
+ # Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
2
+ # License: Ruby License
3
+
4
+ module SGL
5
+ module FrameTranslator
6
+ def to_xywh(a,b,c,d)
7
+ [[a, c].min, [b, d].min, (a - c).abs, (b - d).abs]
8
+ end
9
+ private :to_xywh
10
+ end
11
+
12
+ def point(*a) $__a__.point(*a); end
13
+ def lineWidth(*a) $__a__.lineWidth(*a); end
14
+ def line(*a) $__a__.line(*a); end
15
+ def rect(*a) $__a__.rect(*a); end
16
+ def circle(*a) $__a__.circle(*a); end
17
+ def rotateZ(*a) $__a__.rotateZ(*a); end
18
+ def translate(*a) $__a__.translate(*a); end
19
+ def scale(*a) $__a__.scale(*a); end
20
+ def reset(*a) $__a__.reset(*a); end
21
+
22
+ class Application
23
+ include FrameTranslator
24
+
25
+ def point(a,b)
26
+ line(a,b,a,b)
27
+ end
28
+
29
+ def lineWidth(w)
30
+ OSX::NSBezierPath.setDefaultLineWidth(w)
31
+ end
32
+
33
+ def line(a,b,c,d)
34
+ #OSX::NSBezierPath.strokeLine({:fromPoint=>OSX::NSPoint.new(a, b),
35
+ # :toPoint=>OSX::NSPoint.new(c, d)})
36
+ OSX::NSBezierPath.strokeLineFromPoint(OSX::NSPoint.new(a, b),
37
+ :toPoint, OSX::NSPoint.new(c, d))
38
+ end
39
+
40
+ def rect(a,b,c,d)
41
+ rect = OSX::NSRect.new(*to_xywh(a, b, c, d))
42
+ OSX::NSBezierPath.bezierPathWithRect(rect).fill
43
+ end
44
+
45
+ def circle(x, y, r)
46
+ rect = OSX::NSRect.new(x - r, y - r, 2*r, 2*r)
47
+ OSX::NSBezierPath.bezierPathWithOvalInRect(rect).fill
48
+ end
49
+
50
+ def rotateZ(deg)
51
+ af = OSX::NSAffineTransform.transform
52
+ af.rotateByDegrees(deg)
53
+ af.concat
54
+ end
55
+
56
+ def translate(x, y)
57
+ af = OSX::NSAffineTransform.transform
58
+ af.translateXBy(x, :yBy, y)
59
+ af.concat
60
+ end
61
+
62
+ def scale(x, y=nil)
63
+ af = OSX::NSAffineTransform.transform
64
+ y ? af.scaleXBy(x, :yBy, y) : af.scaleBy(x)
65
+ af.concat
66
+ end
67
+
68
+ def reset
69
+ OSX::NSAffineTransform.transform.set
70
+ end
71
+ end
72
+ end