sgl 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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-media.rb
CHANGED
@@ -1,144 +1,144 @@
|
|
1
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
-
# License: Ruby License
|
3
|
-
|
4
|
-
require "kconv"
|
5
|
-
|
6
|
-
module SGL
|
7
|
-
def movie(*a) $__a__.movie(*a); end
|
8
|
-
def image(*a) $__a__.image(*a); end
|
9
|
-
def font(*a) $__a__.font(*a); end
|
10
|
-
def sound(*a) $__a__.sound(*a); end
|
11
|
-
|
12
|
-
class Application
|
13
|
-
def movie(u)
|
14
|
-
if /\Ahttp:\/\// =~ u || /\Artsp:\/\// =~ u
|
15
|
-
url = OSX::NSURL.URLWithString_(u)
|
16
|
-
else
|
17
|
-
url = OSX::NSURL.fileURLWithPath_(u)
|
18
|
-
end
|
19
|
-
mov = OSX::NSMovie.alloc.initWithURL(url, :byReference, true)
|
20
|
-
# Place the movie on the out of screen.
|
21
|
-
obj = NSMovieView.alloc.initWithFrame([-100.0, -100.0, 10.0, 10.0])
|
22
|
-
obj.setApp(self)
|
23
|
-
obj.setMovie(mov)
|
24
|
-
obj.showController(false, :adjustingSize, false)
|
25
|
-
view = @options[:movie] ? @movview : @bgview
|
26
|
-
# This "p" is necessary to show the movie. I don't know why.
|
27
|
-
p [@options[:movie], view]
|
28
|
-
# p view # This does not work.
|
29
|
-
# dummy = view.inspect # This does not work also.
|
30
|
-
view.addSubview(obj)
|
31
|
-
obj
|
32
|
-
end
|
33
|
-
|
34
|
-
def image(file)
|
35
|
-
img = NSImage.alloc.initWithContentsOfFile(file)
|
36
|
-
img.setApp(self)
|
37
|
-
img
|
38
|
-
end
|
39
|
-
|
40
|
-
def font(*a)
|
41
|
-
NSFont.new(self, *a)
|
42
|
-
end
|
43
|
-
|
44
|
-
def sound(file)
|
45
|
-
url = OSX::NSURL.fileURLWithPath_(file)
|
46
|
-
snd = NSSound.alloc.initWithContentsOfURL(url, :byReference, true)
|
47
|
-
snd
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class NSMovieView < OSX::NSMovieView
|
52
|
-
include FrameTranslator
|
53
|
-
|
54
|
-
def setApp(app)
|
55
|
-
@app = app
|
56
|
-
@playing = false
|
57
|
-
end
|
58
|
-
|
59
|
-
def rect(a,b,c,d)
|
60
|
-
frame(*to_xywh(a, b, c, d))
|
61
|
-
#frame(*@app.to_xywh(a, b, c, d))
|
62
|
-
end
|
63
|
-
|
64
|
-
def frame(a,b,c,d)
|
65
|
-
setFrame([a, b, c, d])
|
66
|
-
end
|
67
|
-
|
68
|
-
def play
|
69
|
-
return if @playing
|
70
|
-
@playing = true
|
71
|
-
start_
|
72
|
-
end
|
73
|
-
|
74
|
-
def stop
|
75
|
-
return if ! @playing
|
76
|
-
@playing = false
|
77
|
-
stop_
|
78
|
-
end
|
79
|
-
|
80
|
-
def goBegin() gotoBeginning_; end
|
81
|
-
def goEnd() gotoEnd_; end
|
82
|
-
def forward() stepForward_; end
|
83
|
-
def back() stepBack_; end
|
84
|
-
def loop=(a) setLoopMode(a); end
|
85
|
-
def rate=(r) setRate(r/100.0); end
|
86
|
-
def volume=(v) setVolume(v/100.0); end
|
87
|
-
end
|
88
|
-
|
89
|
-
class NSImage < OSX::NSImage
|
90
|
-
include FrameTranslator
|
91
|
-
|
92
|
-
def setApp(app) @app = app; end
|
93
|
-
|
94
|
-
def rect(a,b,c,d)
|
95
|
-
frame(*to_xywh(a, b, c, d))
|
96
|
-
end
|
97
|
-
|
98
|
-
def frame(x,y,w,h)
|
99
|
-
drawInRect([x,y,w,h],
|
100
|
-
:fromRect, [0,0,size.width,size.height],
|
101
|
-
:operation, OSX::NSCompositeSourceOver,
|
102
|
-
:fraction, @app.get_cur_color_alpha)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
class NSFont
|
107
|
-
def initialize(w, n="Helvetica", s=0.0)
|
108
|
-
@app, @name, @size = w, n, s.abs
|
109
|
-
end
|
110
|
-
attr_accessor :name
|
111
|
-
attr_reader :size
|
112
|
-
|
113
|
-
def size=(s)
|
114
|
-
@size = s.abs
|
115
|
-
end
|
116
|
-
|
117
|
-
def text(x, y, str)
|
118
|
-
return unless str.is_a? String
|
119
|
-
str = NKF.nkf("-m0 -s", str)
|
120
|
-
str = OSX::NSMutableAttributedString.alloc.initWithString(str)
|
121
|
-
str.addAttribute(OSX::NSFontAttributeName(),
|
122
|
-
:value, OSX::NSFont.fontWithName(@name, :size, @size),
|
123
|
-
:range, [0,str.length])
|
124
|
-
color = @app.make_cur_color
|
125
|
-
str.addAttribute(OSX::NSForegroundColorAttributeName(),
|
126
|
-
:value, color,
|
127
|
-
:range, [0,str.length])
|
128
|
-
str.drawAtPoint([x, y])
|
129
|
-
end
|
130
|
-
|
131
|
-
def show_fixed() show(OSX::NSFixedPitchFontMask); end
|
132
|
-
def show_all() show; end
|
133
|
-
|
134
|
-
private
|
135
|
-
def show(mask=0)
|
136
|
-
fmgr = OSX::NSFontManager.sharedFontManager
|
137
|
-
fonts = fmgr.availableFontNamesWithTraits(mask).to_a.map{|i| i.to_s }.sort
|
138
|
-
puts fonts
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
class NSSound < OSX::NSSound
|
143
|
-
end
|
144
|
-
end
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
require "kconv"
|
5
|
+
|
6
|
+
module SGL
|
7
|
+
def movie(*a) $__a__.movie(*a); end
|
8
|
+
def image(*a) $__a__.image(*a); end
|
9
|
+
def font(*a) $__a__.font(*a); end
|
10
|
+
def sound(*a) $__a__.sound(*a); end
|
11
|
+
|
12
|
+
class Application
|
13
|
+
def movie(u)
|
14
|
+
if /\Ahttp:\/\// =~ u || /\Artsp:\/\// =~ u
|
15
|
+
url = OSX::NSURL.URLWithString_(u)
|
16
|
+
else
|
17
|
+
url = OSX::NSURL.fileURLWithPath_(u)
|
18
|
+
end
|
19
|
+
mov = OSX::NSMovie.alloc.initWithURL(url, :byReference, true)
|
20
|
+
# Place the movie on the out of screen.
|
21
|
+
obj = NSMovieView.alloc.initWithFrame([-100.0, -100.0, 10.0, 10.0])
|
22
|
+
obj.setApp(self)
|
23
|
+
obj.setMovie(mov)
|
24
|
+
obj.showController(false, :adjustingSize, false)
|
25
|
+
view = @options[:movie] ? @movview : @bgview
|
26
|
+
# This "p" is necessary to show the movie. I don't know why.
|
27
|
+
p [@options[:movie], view]
|
28
|
+
# p view # This does not work.
|
29
|
+
# dummy = view.inspect # This does not work also.
|
30
|
+
view.addSubview(obj)
|
31
|
+
obj
|
32
|
+
end
|
33
|
+
|
34
|
+
def image(file)
|
35
|
+
img = NSImage.alloc.initWithContentsOfFile(file)
|
36
|
+
img.setApp(self)
|
37
|
+
img
|
38
|
+
end
|
39
|
+
|
40
|
+
def font(*a)
|
41
|
+
NSFont.new(self, *a)
|
42
|
+
end
|
43
|
+
|
44
|
+
def sound(file)
|
45
|
+
url = OSX::NSURL.fileURLWithPath_(file)
|
46
|
+
snd = NSSound.alloc.initWithContentsOfURL(url, :byReference, true)
|
47
|
+
snd
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class NSMovieView < OSX::NSMovieView
|
52
|
+
include FrameTranslator
|
53
|
+
|
54
|
+
def setApp(app)
|
55
|
+
@app = app
|
56
|
+
@playing = false
|
57
|
+
end
|
58
|
+
|
59
|
+
def rect(a,b,c,d)
|
60
|
+
frame(*to_xywh(a, b, c, d))
|
61
|
+
#frame(*@app.to_xywh(a, b, c, d))
|
62
|
+
end
|
63
|
+
|
64
|
+
def frame(a,b,c,d)
|
65
|
+
setFrame([a, b, c, d])
|
66
|
+
end
|
67
|
+
|
68
|
+
def play
|
69
|
+
return if @playing
|
70
|
+
@playing = true
|
71
|
+
start_
|
72
|
+
end
|
73
|
+
|
74
|
+
def stop
|
75
|
+
return if ! @playing
|
76
|
+
@playing = false
|
77
|
+
stop_
|
78
|
+
end
|
79
|
+
|
80
|
+
def goBegin() gotoBeginning_; end
|
81
|
+
def goEnd() gotoEnd_; end
|
82
|
+
def forward() stepForward_; end
|
83
|
+
def back() stepBack_; end
|
84
|
+
def loop=(a) setLoopMode(a); end
|
85
|
+
def rate=(r) setRate(r/100.0); end
|
86
|
+
def volume=(v) setVolume(v/100.0); end
|
87
|
+
end
|
88
|
+
|
89
|
+
class NSImage < OSX::NSImage
|
90
|
+
include FrameTranslator
|
91
|
+
|
92
|
+
def setApp(app) @app = app; end
|
93
|
+
|
94
|
+
def rect(a,b,c,d)
|
95
|
+
frame(*to_xywh(a, b, c, d))
|
96
|
+
end
|
97
|
+
|
98
|
+
def frame(x,y,w,h)
|
99
|
+
drawInRect([x,y,w,h],
|
100
|
+
:fromRect, [0,0,size.width,size.height],
|
101
|
+
:operation, OSX::NSCompositeSourceOver,
|
102
|
+
:fraction, @app.get_cur_color_alpha)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class NSFont
|
107
|
+
def initialize(w, n="Helvetica", s=0.0)
|
108
|
+
@app, @name, @size = w, n, s.abs
|
109
|
+
end
|
110
|
+
attr_accessor :name
|
111
|
+
attr_reader :size
|
112
|
+
|
113
|
+
def size=(s)
|
114
|
+
@size = s.abs
|
115
|
+
end
|
116
|
+
|
117
|
+
def text(x, y, str)
|
118
|
+
return unless str.is_a? String
|
119
|
+
str = NKF.nkf("-m0 -s", str)
|
120
|
+
str = OSX::NSMutableAttributedString.alloc.initWithString(str)
|
121
|
+
str.addAttribute(OSX::NSFontAttributeName(),
|
122
|
+
:value, OSX::NSFont.fontWithName(@name, :size, @size),
|
123
|
+
:range, [0,str.length])
|
124
|
+
color = @app.make_cur_color
|
125
|
+
str.addAttribute(OSX::NSForegroundColorAttributeName(),
|
126
|
+
:value, color,
|
127
|
+
:range, [0,str.length])
|
128
|
+
str.drawAtPoint([x, y])
|
129
|
+
end
|
130
|
+
|
131
|
+
def show_fixed() show(OSX::NSFixedPitchFontMask); end
|
132
|
+
def show_all() show; end
|
133
|
+
|
134
|
+
private
|
135
|
+
def show(mask=0)
|
136
|
+
fmgr = OSX::NSFontManager.sharedFontManager
|
137
|
+
fonts = fmgr.availableFontNamesWithTraits(mask).to_a.map{|i| i.to_s }.sort
|
138
|
+
puts fonts
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class NSSound < OSX::NSSound
|
143
|
+
end
|
144
|
+
end
|
data/lib/sgl/cocoa-notuse.rb
CHANGED
@@ -1,493 +1,493 @@
|
|
1
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
-
# License: Ruby License
|
3
|
-
# These classes are not using.
|
4
|
-
|
5
|
-
=begin
|
6
|
-
module SGL
|
7
|
-
class NuVideo
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
Thread.abort_on_exception = true
|
12
|
-
@win = Window.alloc.init
|
13
|
-
end
|
14
|
-
attr_reader :win
|
15
|
-
end
|
16
|
-
|
17
|
-
class NuWindow < OSX::NSObject
|
18
|
-
def init
|
19
|
-
OSX.ruby_thread_switcher_start(0.001, 0.01)
|
20
|
-
@app = OSX::NSApplication.sharedApplication
|
21
|
-
@app.setMainMenu(OSX::NSMenu.alloc.init)
|
22
|
-
@rgb = ColorTranslatorRGB.new(100, 100, 100, 100) # color translator
|
23
|
-
@hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
|
24
|
-
@mouseX = @mouseY = @mouseDown = 0
|
25
|
-
@keynum = 0
|
26
|
-
$windowBorder = 1
|
27
|
-
$windowShadow = 1
|
28
|
-
$windowBackground = 1
|
29
|
-
$windowDelay = 1.0/60
|
30
|
-
$windowMovie = 0
|
31
|
-
@window_initialized = false
|
32
|
-
@setup_done = false
|
33
|
-
@display_drawing = false
|
34
|
-
|
35
|
-
@bgview = @oview = nil
|
36
|
-
|
37
|
-
return self # important for RubyCocoa
|
38
|
-
end
|
39
|
-
attr_reader :mouseX, :mouseY, :mouseDown, :keynum
|
40
|
-
|
41
|
-
# generate window
|
42
|
-
def window(w, h)
|
43
|
-
return if @window_initialized
|
44
|
-
s = OSX::NSScreen.mainScreen.frame.size
|
45
|
-
x = (s.width - w)/2.0
|
46
|
-
y = (s.height - h)/2.0
|
47
|
-
@win_frame = [x.to_f, y.to_f, w.to_f, h.to_f]
|
48
|
-
window_open
|
49
|
-
end
|
50
|
-
|
51
|
-
def window_open
|
52
|
-
style = OSX::NSClosableWindowMask
|
53
|
-
style |= ($windowBorder && $windowBorder == 0) ?
|
54
|
-
OSX::NSBorderlessWindowMask : OSX::NSTitledWindowMask
|
55
|
-
@win = SglWindow.alloc.
|
56
|
-
initWithContentRect(@win_frame,
|
57
|
-
:styleMask, style,
|
58
|
-
:backing, OSX::NSBackingStoreBuffered,
|
59
|
-
:defer, true)
|
60
|
-
@win.setTitle("sgl")
|
61
|
-
@bgview = BackView.alloc.init
|
62
|
-
@bgview.myinit(self)
|
63
|
-
@win.setContentView(@bgview)
|
64
|
-
@bgcolor = @curcolor = nil
|
65
|
-
background(100) # white
|
66
|
-
color(0) # black
|
67
|
-
@win.setDelegate(self) # for handling windowShouldClose
|
68
|
-
@win.setOpaque(false) # can be transparent
|
69
|
-
@win.setHasShadow(!($windowShadow && $windowShadow == 0))
|
70
|
-
@win.setReleasedWhenClosed(false)
|
71
|
-
@win.makeKeyAndOrderFront(self)
|
72
|
-
@win.orderFrontRegardless # show the window
|
73
|
-
window_movie if $windowMovie == 1
|
74
|
-
window_overlay if defined?(displayOverlay)
|
75
|
-
@window_initialized = true
|
76
|
-
@win
|
77
|
-
end
|
78
|
-
|
79
|
-
def window_movie
|
80
|
-
o = @bgview.frame.origin
|
81
|
-
so = @win.convertBaseToScreen([o.x, o.y])
|
82
|
-
s = @bgview.frame.size
|
83
|
-
@movwin = SglWindow.alloc.
|
84
|
-
initWithContentRect([so.x, so.y, s.width, s.height],
|
85
|
-
:styleMask, OSX::NSBorderlessWindowMask,
|
86
|
-
:backing, OSX::NSBackingStoreBuffered,
|
87
|
-
:defer, true)
|
88
|
-
@movwin.setOpaque(false) # can be transparent
|
89
|
-
@movwin.setHasShadow(false)
|
90
|
-
@movwin.setIgnoresMouseEvents(true)
|
91
|
-
@movwin.setAlphaValue(1.0)
|
92
|
-
b = @bgview.bounds
|
93
|
-
bo, bs = b.origin, b.size
|
94
|
-
@movview = MovieView.alloc.initWithFrame([bo.x, bo.y, bs.width, bs.height])
|
95
|
-
@movview.myinit(self)
|
96
|
-
@movwin.contentView.addSubview(@movview)
|
97
|
-
@movwin.orderFront(self)
|
98
|
-
@win.addChildWindow(@movwin, :ordered, OSX::NSWindowAbove)
|
99
|
-
@movview.setNeedsDisplay(true)
|
100
|
-
@movewin
|
101
|
-
end
|
102
|
-
|
103
|
-
def window_overlay
|
104
|
-
o = @bgview.frame.origin
|
105
|
-
so = @win.convertBaseToScreen([o.x, o.y])
|
106
|
-
s = @bgview.frame.size
|
107
|
-
@owin = SglWindow.alloc.
|
108
|
-
initWithContentRect([so.x, so.y, s.width, s.height],
|
109
|
-
:styleMask, OSX::NSBorderlessWindowMask,
|
110
|
-
:backing, OSX::NSBackingStoreBuffered,
|
111
|
-
:defer, true)
|
112
|
-
@owin.setOpaque(false) # can be transparent
|
113
|
-
@owin.setHasShadow(false)
|
114
|
-
@owin.setIgnoresMouseEvents(true)
|
115
|
-
@owin.setAlphaValue(1.0)
|
116
|
-
b = @bgview.bounds
|
117
|
-
bo, bs = b.origin, b.size
|
118
|
-
@oview = OverView.alloc.initWithFrame([bo.x, bo.y, bs.width, bs.height])
|
119
|
-
@oview.myinit(self)
|
120
|
-
@owin.contentView.addSubview(@oview)
|
121
|
-
@owin.orderFront(self)
|
122
|
-
if $windowMovie == 1
|
123
|
-
@movwin.addChildWindow(@owin, :ordered, OSX::NSWindowAbove)
|
124
|
-
else
|
125
|
-
@win.addChildWindow(@owin, :ordered, OSX::NSWindowAbove)
|
126
|
-
end
|
127
|
-
@oview.setNeedsDisplay(true)
|
128
|
-
# timer = OSX::NSTimer.
|
129
|
-
# scheduledTimerWithTimeInterval(1.0/60,
|
130
|
-
# :target, self,
|
131
|
-
# :selector, "timerloop",
|
132
|
-
# :userInfo, nil,
|
133
|
-
# :repeats, true).retain
|
134
|
-
# OSX::NSRunLoop.currentRunLoop.
|
135
|
-
# addTimer(timer, :forMode, OSX::NSEventTrackingRunLoopMode)
|
136
|
-
@owin
|
137
|
-
end
|
138
|
-
attr_reader :bgcolor, :curcolor
|
139
|
-
|
140
|
-
def setup_post
|
141
|
-
@setup_done = true
|
142
|
-
end
|
143
|
-
|
144
|
-
def windowShouldClose(sender)
|
145
|
-
OSX.NSApp.stop(nil)
|
146
|
-
false
|
147
|
-
end
|
148
|
-
|
149
|
-
def timerloop
|
150
|
-
p "timerloop"
|
151
|
-
end
|
152
|
-
|
153
|
-
# main loop
|
154
|
-
def mainloop
|
155
|
-
@thread = Thread.start {
|
156
|
-
loop {
|
157
|
-
setNeedsDisplay
|
158
|
-
delay
|
159
|
-
}
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
def setNeedsDisplay
|
164
|
-
@bgview.setNeedsDisplay(true)
|
165
|
-
@oview.setNeedsDisplay(true) if @oview
|
166
|
-
end
|
167
|
-
|
168
|
-
def delay
|
169
|
-
sleep $windowDelay
|
170
|
-
end
|
171
|
-
|
172
|
-
def run
|
173
|
-
@app.run
|
174
|
-
end
|
175
|
-
|
176
|
-
# handle events
|
177
|
-
def winmouseDown
|
178
|
-
@mouseDown = 1
|
179
|
-
onMouseDown(@mouseX, @mouseY)
|
180
|
-
end
|
181
|
-
|
182
|
-
def winmouseUp
|
183
|
-
@mouseDown = 0
|
184
|
-
onMouseUp(@mouseX, @mouseY)
|
185
|
-
end
|
186
|
-
|
187
|
-
def winkeyDown(e)
|
188
|
-
calc_keynum(e)
|
189
|
-
p @keynum
|
190
|
-
onKeyDown(@keynum)
|
191
|
-
end
|
192
|
-
|
193
|
-
def winkeyUp(e)
|
194
|
-
calc_keynum(e)
|
195
|
-
@keynum = 0
|
196
|
-
p @keynum
|
197
|
-
onKeyUp(@keynum)
|
198
|
-
end
|
199
|
-
|
200
|
-
def calc_keynum(e)
|
201
|
-
input = event.characters
|
202
|
-
@keynum = input.to_s[0]
|
203
|
-
end
|
204
|
-
|
205
|
-
# display
|
206
|
-
def display_bg(rect)
|
207
|
-
return if $windowBackground != 1
|
208
|
-
color_set(*@bgcolor)
|
209
|
-
OSX::NSRectFill(rect)
|
210
|
-
# if @lastbgcolor && @lastbgcolor != @bgcolor
|
211
|
-
# end
|
212
|
-
# @lastbgcolor = @bgcolor.dup
|
213
|
-
end
|
214
|
-
|
215
|
-
def display_pre
|
216
|
-
pos = @win.mouseLocationOutsideOfEventStream
|
217
|
-
@mouseX, @mouseY = pos.x, pos.y
|
218
|
-
color_set(*@curcolor) # set back current color
|
219
|
-
end
|
220
|
-
|
221
|
-
def display_all(rect)
|
222
|
-
return if !@setup_done
|
223
|
-
# return if @display_drawing
|
224
|
-
return if defined?(display_drawing) && display_drawing
|
225
|
-
@display_drawing = true
|
226
|
-
display_bg(rect)
|
227
|
-
display_pre
|
228
|
-
display
|
229
|
-
display_post
|
230
|
-
@display_drawing = false
|
231
|
-
end
|
232
|
-
|
233
|
-
def display_mov(rect)
|
234
|
-
color_set(0, 0, 0, 0) # full transparent
|
235
|
-
OSX::NSRectFill(rect)
|
236
|
-
color_set(*@curcolor) # set back current color
|
237
|
-
end
|
238
|
-
|
239
|
-
def display_overlay_all(rect)
|
240
|
-
return if !@setup_done
|
241
|
-
return if @display_overlay_drawing
|
242
|
-
@display_overlay_drawing = true
|
243
|
-
color_set(0, 0, 0, 0) # display_bg
|
244
|
-
OSX::NSRectFill(rect)
|
245
|
-
color_set(*@curcolor) # set back current color
|
246
|
-
displayOverlay
|
247
|
-
@display_overlay_drawing = false
|
248
|
-
end
|
249
|
-
|
250
|
-
def display_post
|
251
|
-
end
|
252
|
-
|
253
|
-
# sgl commands
|
254
|
-
def background(x, y=nil, z=nil, a=nil)
|
255
|
-
@bgcolor = @rgb.norm(x,y,z,a)
|
256
|
-
end
|
257
|
-
|
258
|
-
def backgroundHSV(x, y=nil, z=nil, a=nil)
|
259
|
-
@bgcolor = @hsv.norm(x,y,z,a)
|
260
|
-
end
|
261
|
-
|
262
|
-
def color(x, y=nil, z=nil, a=nil)
|
263
|
-
@curcolor = @rgb.norm(x,y,z,a)
|
264
|
-
color_set(*@curcolor)
|
265
|
-
end
|
266
|
-
|
267
|
-
def colorHSV(x,y=nil,z=nil,a=nil)
|
268
|
-
@curcolor = @hsv.norm(x,y,z,a)
|
269
|
-
color_set(*@curcolor)
|
270
|
-
end
|
271
|
-
|
272
|
-
def color_set(*a)
|
273
|
-
color_make(*a).set if @window_initialized
|
274
|
-
end
|
275
|
-
|
276
|
-
def color_make(r, g, b, a)
|
277
|
-
OSX::NSColor.colorWithDeviceRed(r,:green, g, :blue, b, :alpha, a)
|
278
|
-
end
|
279
|
-
|
280
|
-
def color_cur
|
281
|
-
color_make(*@curcolor)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
class SglWindow < OSX::NSWindow
|
286
|
-
# ns_overrides :keyDown_, :keyUp_
|
287
|
-
# def keyDown(event)
|
288
|
-
# p "ho"
|
289
|
-
# end
|
290
|
-
end
|
291
|
-
|
292
|
-
class BackView < OSX::NSView
|
293
|
-
ns_overrides :drawRect_,
|
294
|
-
:mouseDown_, :mouseDragged_, :mouseUp_, :keyDown_, :keyUp_
|
295
|
-
def myinit(win) @win = win; end
|
296
|
-
def drawRect(rect) @win.display_all(rect); end
|
297
|
-
def mouseDown(event) @win.winmouseDown; end
|
298
|
-
def mouseDragged(event) end
|
299
|
-
def mouseUp(event) @win.winmouseUp; end
|
300
|
-
def keyDown(event) @win.winkeyDown(event);
|
301
|
-
p "ho"
|
302
|
-
end
|
303
|
-
def keyUp(event) @win.winkeyUp(event); end
|
304
|
-
end
|
305
|
-
|
306
|
-
class OverView < OSX::NSView
|
307
|
-
ns_overrides :drawRect_
|
308
|
-
def myinit(win) @win = win; end
|
309
|
-
def drawRect(rect) @win.display_overlay_all(rect); end
|
310
|
-
end
|
311
|
-
|
312
|
-
class MovieView < OSX::NSView
|
313
|
-
ns_overrides :drawRect_
|
314
|
-
def myinit(win) @win = win; end
|
315
|
-
def drawRect(rect) @win.display_mov(rect); end
|
316
|
-
end
|
317
|
-
|
318
|
-
class NuWindow < OSX::NSObject
|
319
|
-
def movie(u)
|
320
|
-
# if %r$^http://$ =~ u || %r$^rtsp://$ =~ u
|
321
|
-
if /\Ahttp:\/\// =~ u || /\Artsp:\/\// =~ u
|
322
|
-
url = OSX::NSURL.URLWithString_(u)
|
323
|
-
else
|
324
|
-
url = OSX::NSURL.fileURLWithPath_(u)
|
325
|
-
end
|
326
|
-
mov = OSX::NSMovie.alloc.initWithURL(url, :byReference, true)
|
327
|
-
# place it outer of the screen
|
328
|
-
obj = SglMovieView.alloc.initWithFrame([-100.0, -100.0, 10.0, 10.0])
|
329
|
-
obj.myinit(self)
|
330
|
-
obj.setMovie(mov)
|
331
|
-
obj.showController(false, :adjustingSize, false)
|
332
|
-
if $windowMovie == 1
|
333
|
-
@movview.addSubview(obj)
|
334
|
-
else
|
335
|
-
@bgview.addSubview(obj)
|
336
|
-
end
|
337
|
-
# @oview.addSubview(obj)
|
338
|
-
obj
|
339
|
-
end
|
340
|
-
|
341
|
-
def image(file)
|
342
|
-
img = SglImage.alloc.initWithContentsOfFile(file)
|
343
|
-
img.myinit(self)
|
344
|
-
img
|
345
|
-
end
|
346
|
-
|
347
|
-
def font(*a)
|
348
|
-
SglFont.new(self, *a)
|
349
|
-
end
|
350
|
-
|
351
|
-
def sound(file)
|
352
|
-
url = OSX::NSURL.fileURLWithPath_(file)
|
353
|
-
snd = SglSound.alloc.initWithContentsOfURL(url, :byReference, true)
|
354
|
-
snd
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
class SglMovieView < OSX::NSMovieView
|
359
|
-
def myinit(win)
|
360
|
-
@win = win
|
361
|
-
end
|
362
|
-
|
363
|
-
def rect(a,b,c,d)
|
364
|
-
frame(*to_xywh(a, b, c, d))
|
365
|
-
end
|
366
|
-
|
367
|
-
def frame(a,b,c,d)
|
368
|
-
setFrame([a, b, c, d])
|
369
|
-
# @win.switch_to_over
|
370
|
-
end
|
371
|
-
|
372
|
-
def play() start_; end
|
373
|
-
def stop() stop_; end
|
374
|
-
def goBegin() gotoBeginning_; end
|
375
|
-
def goEnd() gotoEnd_; end
|
376
|
-
def forward() stepForward_; end
|
377
|
-
def back() stepBack_; end
|
378
|
-
def loop=(a) setLoopMode(a); end
|
379
|
-
def rate=(r) setRate(r/100.0); end
|
380
|
-
def volume=(v) setVolume(v/100.0); end
|
381
|
-
end
|
382
|
-
|
383
|
-
class SglImage < OSX::NSImage
|
384
|
-
def myinit(win)
|
385
|
-
@win = win
|
386
|
-
end
|
387
|
-
|
388
|
-
def rect(a,b,c,d) frame(*to_xywh(a, b, c, d)); end
|
389
|
-
def frame(x,y,w,h)
|
390
|
-
drawInRect([x,y,w,h],
|
391
|
-
:fromRect, [0,0,size.width,size.height],
|
392
|
-
:operation, OSX::NSCompositeSourceOver,
|
393
|
-
:fraction, @win.curcolor[3])
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
class SglFont
|
398
|
-
def initialize(w, n="Helvetica", s=0.0)
|
399
|
-
@win, @name, @size = w, n, s.abs
|
400
|
-
end
|
401
|
-
attr_accessor :name
|
402
|
-
attr_reader :size
|
403
|
-
|
404
|
-
def size=(s)
|
405
|
-
@size = s.abs
|
406
|
-
end
|
407
|
-
|
408
|
-
def to_sjis(str)
|
409
|
-
NKF.nkf("-m0 -s", str)
|
410
|
-
end
|
411
|
-
|
412
|
-
def text(x, y, str)
|
413
|
-
return unless str.is_a? String
|
414
|
-
str = str.to_sjis
|
415
|
-
str = to_sjis(str)
|
416
|
-
str = OSX::NSMutableAttributedString.alloc.initWithString(str)
|
417
|
-
str.addAttribute(OSX::NSFontAttributeName(),
|
418
|
-
:value, OSX::NSFont.fontWithName(@name, :size, @size),
|
419
|
-
:range, [0,str.length])
|
420
|
-
str.addAttribute(OSX::NSForegroundColorAttributeName(),
|
421
|
-
:value, @win.color_cur,
|
422
|
-
:range, [0,str.length])
|
423
|
-
str.drawAtPoint([x, y])
|
424
|
-
end
|
425
|
-
|
426
|
-
def show_fixed() show(OSX::NSFixedPitchFontMask); end
|
427
|
-
def show_all() show(); end
|
428
|
-
|
429
|
-
private
|
430
|
-
def show(mask=0)
|
431
|
-
fmgr = OSX::NSFontManager.sharedFontManager
|
432
|
-
fonts = fmgr.availableFontNamesWithTraits(mask).to_a.map{|i| i.to_s }.sort
|
433
|
-
puts fonts
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
class SglSound < OSX::NSSound
|
438
|
-
# def play() play_; end
|
439
|
-
end
|
440
|
-
end
|
441
|
-
=end
|
442
|
-
|
443
|
-
=begin
|
444
|
-
# sgl commands
|
445
|
-
def point(a,b)
|
446
|
-
line(a,b,a,b)
|
447
|
-
end
|
448
|
-
|
449
|
-
def lineWidth(w)
|
450
|
-
OSX::NSBezierPath.setDefaultLineWidth(w)
|
451
|
-
end
|
452
|
-
|
453
|
-
def line(a,b,c,d)
|
454
|
-
OSX::NSBezierPath.strokeLineFromPoint(OSX::NSPoint.new(a, b),
|
455
|
-
:toPoint, OSX::NSPoint.new(c, d))
|
456
|
-
end
|
457
|
-
|
458
|
-
def rect(a,b,c,d)
|
459
|
-
rect = OSX::NSRect.new(*to_xywh(a, b, c, d))
|
460
|
-
OSX::NSBezierPath.bezierPathWithRect(rect).fill
|
461
|
-
end
|
462
|
-
|
463
|
-
def circle(x, y, r)
|
464
|
-
rect = OSX::NSRect.new(x - r, y - r, 2*r, 2*r)
|
465
|
-
OSX::NSBezierPath.bezierPathWithOvalInRect(rect).fill
|
466
|
-
end
|
467
|
-
|
468
|
-
def to_xywh(a,b,c,d)
|
469
|
-
[[a, c].min, [b, d].min, (a - c).abs, (b - d).abs]
|
470
|
-
end
|
471
|
-
|
472
|
-
def rotateZ(deg)
|
473
|
-
af = OSX::NSAffineTransform.transform
|
474
|
-
af.rotateByDegrees(deg)
|
475
|
-
af.concat
|
476
|
-
end
|
477
|
-
|
478
|
-
def translate(x, y)
|
479
|
-
af = OSX::NSAffineTransform.transform
|
480
|
-
af.translateXBy(x, :yBy, y)
|
481
|
-
af.concat
|
482
|
-
end
|
483
|
-
|
484
|
-
def scale(x, y=nil)
|
485
|
-
af = OSX::NSAffineTransform.transform
|
486
|
-
y ? af.scaleXBy(x, :yBy, y) : af.scaleBy(x)
|
487
|
-
af.concat
|
488
|
-
end
|
489
|
-
|
490
|
-
def reset()
|
491
|
-
OSX::NSAffineTransform.transform.set
|
492
|
-
end
|
493
|
-
=end
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
# These classes are not using.
|
4
|
+
|
5
|
+
=begin
|
6
|
+
module SGL
|
7
|
+
class NuVideo
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
Thread.abort_on_exception = true
|
12
|
+
@win = Window.alloc.init
|
13
|
+
end
|
14
|
+
attr_reader :win
|
15
|
+
end
|
16
|
+
|
17
|
+
class NuWindow < OSX::NSObject
|
18
|
+
def init
|
19
|
+
OSX.ruby_thread_switcher_start(0.001, 0.01)
|
20
|
+
@app = OSX::NSApplication.sharedApplication
|
21
|
+
@app.setMainMenu(OSX::NSMenu.alloc.init)
|
22
|
+
@rgb = ColorTranslatorRGB.new(100, 100, 100, 100) # color translator
|
23
|
+
@hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
|
24
|
+
@mouseX = @mouseY = @mouseDown = 0
|
25
|
+
@keynum = 0
|
26
|
+
$windowBorder = 1
|
27
|
+
$windowShadow = 1
|
28
|
+
$windowBackground = 1
|
29
|
+
$windowDelay = 1.0/60
|
30
|
+
$windowMovie = 0
|
31
|
+
@window_initialized = false
|
32
|
+
@setup_done = false
|
33
|
+
@display_drawing = false
|
34
|
+
|
35
|
+
@bgview = @oview = nil
|
36
|
+
|
37
|
+
return self # important for RubyCocoa
|
38
|
+
end
|
39
|
+
attr_reader :mouseX, :mouseY, :mouseDown, :keynum
|
40
|
+
|
41
|
+
# generate window
|
42
|
+
def window(w, h)
|
43
|
+
return if @window_initialized
|
44
|
+
s = OSX::NSScreen.mainScreen.frame.size
|
45
|
+
x = (s.width - w)/2.0
|
46
|
+
y = (s.height - h)/2.0
|
47
|
+
@win_frame = [x.to_f, y.to_f, w.to_f, h.to_f]
|
48
|
+
window_open
|
49
|
+
end
|
50
|
+
|
51
|
+
def window_open
|
52
|
+
style = OSX::NSClosableWindowMask
|
53
|
+
style |= ($windowBorder && $windowBorder == 0) ?
|
54
|
+
OSX::NSBorderlessWindowMask : OSX::NSTitledWindowMask
|
55
|
+
@win = SglWindow.alloc.
|
56
|
+
initWithContentRect(@win_frame,
|
57
|
+
:styleMask, style,
|
58
|
+
:backing, OSX::NSBackingStoreBuffered,
|
59
|
+
:defer, true)
|
60
|
+
@win.setTitle("sgl")
|
61
|
+
@bgview = BackView.alloc.init
|
62
|
+
@bgview.myinit(self)
|
63
|
+
@win.setContentView(@bgview)
|
64
|
+
@bgcolor = @curcolor = nil
|
65
|
+
background(100) # white
|
66
|
+
color(0) # black
|
67
|
+
@win.setDelegate(self) # for handling windowShouldClose
|
68
|
+
@win.setOpaque(false) # can be transparent
|
69
|
+
@win.setHasShadow(!($windowShadow && $windowShadow == 0))
|
70
|
+
@win.setReleasedWhenClosed(false)
|
71
|
+
@win.makeKeyAndOrderFront(self)
|
72
|
+
@win.orderFrontRegardless # show the window
|
73
|
+
window_movie if $windowMovie == 1
|
74
|
+
window_overlay if defined?(displayOverlay)
|
75
|
+
@window_initialized = true
|
76
|
+
@win
|
77
|
+
end
|
78
|
+
|
79
|
+
def window_movie
|
80
|
+
o = @bgview.frame.origin
|
81
|
+
so = @win.convertBaseToScreen([o.x, o.y])
|
82
|
+
s = @bgview.frame.size
|
83
|
+
@movwin = SglWindow.alloc.
|
84
|
+
initWithContentRect([so.x, so.y, s.width, s.height],
|
85
|
+
:styleMask, OSX::NSBorderlessWindowMask,
|
86
|
+
:backing, OSX::NSBackingStoreBuffered,
|
87
|
+
:defer, true)
|
88
|
+
@movwin.setOpaque(false) # can be transparent
|
89
|
+
@movwin.setHasShadow(false)
|
90
|
+
@movwin.setIgnoresMouseEvents(true)
|
91
|
+
@movwin.setAlphaValue(1.0)
|
92
|
+
b = @bgview.bounds
|
93
|
+
bo, bs = b.origin, b.size
|
94
|
+
@movview = MovieView.alloc.initWithFrame([bo.x, bo.y, bs.width, bs.height])
|
95
|
+
@movview.myinit(self)
|
96
|
+
@movwin.contentView.addSubview(@movview)
|
97
|
+
@movwin.orderFront(self)
|
98
|
+
@win.addChildWindow(@movwin, :ordered, OSX::NSWindowAbove)
|
99
|
+
@movview.setNeedsDisplay(true)
|
100
|
+
@movewin
|
101
|
+
end
|
102
|
+
|
103
|
+
def window_overlay
|
104
|
+
o = @bgview.frame.origin
|
105
|
+
so = @win.convertBaseToScreen([o.x, o.y])
|
106
|
+
s = @bgview.frame.size
|
107
|
+
@owin = SglWindow.alloc.
|
108
|
+
initWithContentRect([so.x, so.y, s.width, s.height],
|
109
|
+
:styleMask, OSX::NSBorderlessWindowMask,
|
110
|
+
:backing, OSX::NSBackingStoreBuffered,
|
111
|
+
:defer, true)
|
112
|
+
@owin.setOpaque(false) # can be transparent
|
113
|
+
@owin.setHasShadow(false)
|
114
|
+
@owin.setIgnoresMouseEvents(true)
|
115
|
+
@owin.setAlphaValue(1.0)
|
116
|
+
b = @bgview.bounds
|
117
|
+
bo, bs = b.origin, b.size
|
118
|
+
@oview = OverView.alloc.initWithFrame([bo.x, bo.y, bs.width, bs.height])
|
119
|
+
@oview.myinit(self)
|
120
|
+
@owin.contentView.addSubview(@oview)
|
121
|
+
@owin.orderFront(self)
|
122
|
+
if $windowMovie == 1
|
123
|
+
@movwin.addChildWindow(@owin, :ordered, OSX::NSWindowAbove)
|
124
|
+
else
|
125
|
+
@win.addChildWindow(@owin, :ordered, OSX::NSWindowAbove)
|
126
|
+
end
|
127
|
+
@oview.setNeedsDisplay(true)
|
128
|
+
# timer = OSX::NSTimer.
|
129
|
+
# scheduledTimerWithTimeInterval(1.0/60,
|
130
|
+
# :target, self,
|
131
|
+
# :selector, "timerloop",
|
132
|
+
# :userInfo, nil,
|
133
|
+
# :repeats, true).retain
|
134
|
+
# OSX::NSRunLoop.currentRunLoop.
|
135
|
+
# addTimer(timer, :forMode, OSX::NSEventTrackingRunLoopMode)
|
136
|
+
@owin
|
137
|
+
end
|
138
|
+
attr_reader :bgcolor, :curcolor
|
139
|
+
|
140
|
+
def setup_post
|
141
|
+
@setup_done = true
|
142
|
+
end
|
143
|
+
|
144
|
+
def windowShouldClose(sender)
|
145
|
+
OSX.NSApp.stop(nil)
|
146
|
+
false
|
147
|
+
end
|
148
|
+
|
149
|
+
def timerloop
|
150
|
+
p "timerloop"
|
151
|
+
end
|
152
|
+
|
153
|
+
# main loop
|
154
|
+
def mainloop
|
155
|
+
@thread = Thread.start {
|
156
|
+
loop {
|
157
|
+
setNeedsDisplay
|
158
|
+
delay
|
159
|
+
}
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
def setNeedsDisplay
|
164
|
+
@bgview.setNeedsDisplay(true)
|
165
|
+
@oview.setNeedsDisplay(true) if @oview
|
166
|
+
end
|
167
|
+
|
168
|
+
def delay
|
169
|
+
sleep $windowDelay
|
170
|
+
end
|
171
|
+
|
172
|
+
def run
|
173
|
+
@app.run
|
174
|
+
end
|
175
|
+
|
176
|
+
# handle events
|
177
|
+
def winmouseDown
|
178
|
+
@mouseDown = 1
|
179
|
+
onMouseDown(@mouseX, @mouseY)
|
180
|
+
end
|
181
|
+
|
182
|
+
def winmouseUp
|
183
|
+
@mouseDown = 0
|
184
|
+
onMouseUp(@mouseX, @mouseY)
|
185
|
+
end
|
186
|
+
|
187
|
+
def winkeyDown(e)
|
188
|
+
calc_keynum(e)
|
189
|
+
p @keynum
|
190
|
+
onKeyDown(@keynum)
|
191
|
+
end
|
192
|
+
|
193
|
+
def winkeyUp(e)
|
194
|
+
calc_keynum(e)
|
195
|
+
@keynum = 0
|
196
|
+
p @keynum
|
197
|
+
onKeyUp(@keynum)
|
198
|
+
end
|
199
|
+
|
200
|
+
def calc_keynum(e)
|
201
|
+
input = event.characters
|
202
|
+
@keynum = input.to_s[0]
|
203
|
+
end
|
204
|
+
|
205
|
+
# display
|
206
|
+
def display_bg(rect)
|
207
|
+
return if $windowBackground != 1
|
208
|
+
color_set(*@bgcolor)
|
209
|
+
OSX::NSRectFill(rect)
|
210
|
+
# if @lastbgcolor && @lastbgcolor != @bgcolor
|
211
|
+
# end
|
212
|
+
# @lastbgcolor = @bgcolor.dup
|
213
|
+
end
|
214
|
+
|
215
|
+
def display_pre
|
216
|
+
pos = @win.mouseLocationOutsideOfEventStream
|
217
|
+
@mouseX, @mouseY = pos.x, pos.y
|
218
|
+
color_set(*@curcolor) # set back current color
|
219
|
+
end
|
220
|
+
|
221
|
+
def display_all(rect)
|
222
|
+
return if !@setup_done
|
223
|
+
# return if @display_drawing
|
224
|
+
return if defined?(display_drawing) && display_drawing
|
225
|
+
@display_drawing = true
|
226
|
+
display_bg(rect)
|
227
|
+
display_pre
|
228
|
+
display
|
229
|
+
display_post
|
230
|
+
@display_drawing = false
|
231
|
+
end
|
232
|
+
|
233
|
+
def display_mov(rect)
|
234
|
+
color_set(0, 0, 0, 0) # full transparent
|
235
|
+
OSX::NSRectFill(rect)
|
236
|
+
color_set(*@curcolor) # set back current color
|
237
|
+
end
|
238
|
+
|
239
|
+
def display_overlay_all(rect)
|
240
|
+
return if !@setup_done
|
241
|
+
return if @display_overlay_drawing
|
242
|
+
@display_overlay_drawing = true
|
243
|
+
color_set(0, 0, 0, 0) # display_bg
|
244
|
+
OSX::NSRectFill(rect)
|
245
|
+
color_set(*@curcolor) # set back current color
|
246
|
+
displayOverlay
|
247
|
+
@display_overlay_drawing = false
|
248
|
+
end
|
249
|
+
|
250
|
+
def display_post
|
251
|
+
end
|
252
|
+
|
253
|
+
# sgl commands
|
254
|
+
def background(x, y=nil, z=nil, a=nil)
|
255
|
+
@bgcolor = @rgb.norm(x,y,z,a)
|
256
|
+
end
|
257
|
+
|
258
|
+
def backgroundHSV(x, y=nil, z=nil, a=nil)
|
259
|
+
@bgcolor = @hsv.norm(x,y,z,a)
|
260
|
+
end
|
261
|
+
|
262
|
+
def color(x, y=nil, z=nil, a=nil)
|
263
|
+
@curcolor = @rgb.norm(x,y,z,a)
|
264
|
+
color_set(*@curcolor)
|
265
|
+
end
|
266
|
+
|
267
|
+
def colorHSV(x,y=nil,z=nil,a=nil)
|
268
|
+
@curcolor = @hsv.norm(x,y,z,a)
|
269
|
+
color_set(*@curcolor)
|
270
|
+
end
|
271
|
+
|
272
|
+
def color_set(*a)
|
273
|
+
color_make(*a).set if @window_initialized
|
274
|
+
end
|
275
|
+
|
276
|
+
def color_make(r, g, b, a)
|
277
|
+
OSX::NSColor.colorWithDeviceRed(r,:green, g, :blue, b, :alpha, a)
|
278
|
+
end
|
279
|
+
|
280
|
+
def color_cur
|
281
|
+
color_make(*@curcolor)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
class SglWindow < OSX::NSWindow
|
286
|
+
# ns_overrides :keyDown_, :keyUp_
|
287
|
+
# def keyDown(event)
|
288
|
+
# p "ho"
|
289
|
+
# end
|
290
|
+
end
|
291
|
+
|
292
|
+
class BackView < OSX::NSView
|
293
|
+
ns_overrides :drawRect_,
|
294
|
+
:mouseDown_, :mouseDragged_, :mouseUp_, :keyDown_, :keyUp_
|
295
|
+
def myinit(win) @win = win; end
|
296
|
+
def drawRect(rect) @win.display_all(rect); end
|
297
|
+
def mouseDown(event) @win.winmouseDown; end
|
298
|
+
def mouseDragged(event) end
|
299
|
+
def mouseUp(event) @win.winmouseUp; end
|
300
|
+
def keyDown(event) @win.winkeyDown(event);
|
301
|
+
p "ho"
|
302
|
+
end
|
303
|
+
def keyUp(event) @win.winkeyUp(event); end
|
304
|
+
end
|
305
|
+
|
306
|
+
class OverView < OSX::NSView
|
307
|
+
ns_overrides :drawRect_
|
308
|
+
def myinit(win) @win = win; end
|
309
|
+
def drawRect(rect) @win.display_overlay_all(rect); end
|
310
|
+
end
|
311
|
+
|
312
|
+
class MovieView < OSX::NSView
|
313
|
+
ns_overrides :drawRect_
|
314
|
+
def myinit(win) @win = win; end
|
315
|
+
def drawRect(rect) @win.display_mov(rect); end
|
316
|
+
end
|
317
|
+
|
318
|
+
class NuWindow < OSX::NSObject
|
319
|
+
def movie(u)
|
320
|
+
# if %r$^http://$ =~ u || %r$^rtsp://$ =~ u
|
321
|
+
if /\Ahttp:\/\// =~ u || /\Artsp:\/\// =~ u
|
322
|
+
url = OSX::NSURL.URLWithString_(u)
|
323
|
+
else
|
324
|
+
url = OSX::NSURL.fileURLWithPath_(u)
|
325
|
+
end
|
326
|
+
mov = OSX::NSMovie.alloc.initWithURL(url, :byReference, true)
|
327
|
+
# place it outer of the screen
|
328
|
+
obj = SglMovieView.alloc.initWithFrame([-100.0, -100.0, 10.0, 10.0])
|
329
|
+
obj.myinit(self)
|
330
|
+
obj.setMovie(mov)
|
331
|
+
obj.showController(false, :adjustingSize, false)
|
332
|
+
if $windowMovie == 1
|
333
|
+
@movview.addSubview(obj)
|
334
|
+
else
|
335
|
+
@bgview.addSubview(obj)
|
336
|
+
end
|
337
|
+
# @oview.addSubview(obj)
|
338
|
+
obj
|
339
|
+
end
|
340
|
+
|
341
|
+
def image(file)
|
342
|
+
img = SglImage.alloc.initWithContentsOfFile(file)
|
343
|
+
img.myinit(self)
|
344
|
+
img
|
345
|
+
end
|
346
|
+
|
347
|
+
def font(*a)
|
348
|
+
SglFont.new(self, *a)
|
349
|
+
end
|
350
|
+
|
351
|
+
def sound(file)
|
352
|
+
url = OSX::NSURL.fileURLWithPath_(file)
|
353
|
+
snd = SglSound.alloc.initWithContentsOfURL(url, :byReference, true)
|
354
|
+
snd
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
class SglMovieView < OSX::NSMovieView
|
359
|
+
def myinit(win)
|
360
|
+
@win = win
|
361
|
+
end
|
362
|
+
|
363
|
+
def rect(a,b,c,d)
|
364
|
+
frame(*to_xywh(a, b, c, d))
|
365
|
+
end
|
366
|
+
|
367
|
+
def frame(a,b,c,d)
|
368
|
+
setFrame([a, b, c, d])
|
369
|
+
# @win.switch_to_over
|
370
|
+
end
|
371
|
+
|
372
|
+
def play() start_; end
|
373
|
+
def stop() stop_; end
|
374
|
+
def goBegin() gotoBeginning_; end
|
375
|
+
def goEnd() gotoEnd_; end
|
376
|
+
def forward() stepForward_; end
|
377
|
+
def back() stepBack_; end
|
378
|
+
def loop=(a) setLoopMode(a); end
|
379
|
+
def rate=(r) setRate(r/100.0); end
|
380
|
+
def volume=(v) setVolume(v/100.0); end
|
381
|
+
end
|
382
|
+
|
383
|
+
class SglImage < OSX::NSImage
|
384
|
+
def myinit(win)
|
385
|
+
@win = win
|
386
|
+
end
|
387
|
+
|
388
|
+
def rect(a,b,c,d) frame(*to_xywh(a, b, c, d)); end
|
389
|
+
def frame(x,y,w,h)
|
390
|
+
drawInRect([x,y,w,h],
|
391
|
+
:fromRect, [0,0,size.width,size.height],
|
392
|
+
:operation, OSX::NSCompositeSourceOver,
|
393
|
+
:fraction, @win.curcolor[3])
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
class SglFont
|
398
|
+
def initialize(w, n="Helvetica", s=0.0)
|
399
|
+
@win, @name, @size = w, n, s.abs
|
400
|
+
end
|
401
|
+
attr_accessor :name
|
402
|
+
attr_reader :size
|
403
|
+
|
404
|
+
def size=(s)
|
405
|
+
@size = s.abs
|
406
|
+
end
|
407
|
+
|
408
|
+
def to_sjis(str)
|
409
|
+
NKF.nkf("-m0 -s", str)
|
410
|
+
end
|
411
|
+
|
412
|
+
def text(x, y, str)
|
413
|
+
return unless str.is_a? String
|
414
|
+
str = str.to_sjis
|
415
|
+
str = to_sjis(str)
|
416
|
+
str = OSX::NSMutableAttributedString.alloc.initWithString(str)
|
417
|
+
str.addAttribute(OSX::NSFontAttributeName(),
|
418
|
+
:value, OSX::NSFont.fontWithName(@name, :size, @size),
|
419
|
+
:range, [0,str.length])
|
420
|
+
str.addAttribute(OSX::NSForegroundColorAttributeName(),
|
421
|
+
:value, @win.color_cur,
|
422
|
+
:range, [0,str.length])
|
423
|
+
str.drawAtPoint([x, y])
|
424
|
+
end
|
425
|
+
|
426
|
+
def show_fixed() show(OSX::NSFixedPitchFontMask); end
|
427
|
+
def show_all() show(); end
|
428
|
+
|
429
|
+
private
|
430
|
+
def show(mask=0)
|
431
|
+
fmgr = OSX::NSFontManager.sharedFontManager
|
432
|
+
fonts = fmgr.availableFontNamesWithTraits(mask).to_a.map{|i| i.to_s }.sort
|
433
|
+
puts fonts
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
class SglSound < OSX::NSSound
|
438
|
+
# def play() play_; end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
=end
|
442
|
+
|
443
|
+
=begin
|
444
|
+
# sgl commands
|
445
|
+
def point(a,b)
|
446
|
+
line(a,b,a,b)
|
447
|
+
end
|
448
|
+
|
449
|
+
def lineWidth(w)
|
450
|
+
OSX::NSBezierPath.setDefaultLineWidth(w)
|
451
|
+
end
|
452
|
+
|
453
|
+
def line(a,b,c,d)
|
454
|
+
OSX::NSBezierPath.strokeLineFromPoint(OSX::NSPoint.new(a, b),
|
455
|
+
:toPoint, OSX::NSPoint.new(c, d))
|
456
|
+
end
|
457
|
+
|
458
|
+
def rect(a,b,c,d)
|
459
|
+
rect = OSX::NSRect.new(*to_xywh(a, b, c, d))
|
460
|
+
OSX::NSBezierPath.bezierPathWithRect(rect).fill
|
461
|
+
end
|
462
|
+
|
463
|
+
def circle(x, y, r)
|
464
|
+
rect = OSX::NSRect.new(x - r, y - r, 2*r, 2*r)
|
465
|
+
OSX::NSBezierPath.bezierPathWithOvalInRect(rect).fill
|
466
|
+
end
|
467
|
+
|
468
|
+
def to_xywh(a,b,c,d)
|
469
|
+
[[a, c].min, [b, d].min, (a - c).abs, (b - d).abs]
|
470
|
+
end
|
471
|
+
|
472
|
+
def rotateZ(deg)
|
473
|
+
af = OSX::NSAffineTransform.transform
|
474
|
+
af.rotateByDegrees(deg)
|
475
|
+
af.concat
|
476
|
+
end
|
477
|
+
|
478
|
+
def translate(x, y)
|
479
|
+
af = OSX::NSAffineTransform.transform
|
480
|
+
af.translateXBy(x, :yBy, y)
|
481
|
+
af.concat
|
482
|
+
end
|
483
|
+
|
484
|
+
def scale(x, y=nil)
|
485
|
+
af = OSX::NSAffineTransform.transform
|
486
|
+
y ? af.scaleXBy(x, :yBy, y) : af.scaleBy(x)
|
487
|
+
af.concat
|
488
|
+
end
|
489
|
+
|
490
|
+
def reset()
|
491
|
+
OSX::NSAffineTransform.transform.set
|
492
|
+
end
|
493
|
+
=end
|