33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'docs/hornetseye-xorg/lib/hornetseye-xorg/x11display.rb', line 33
def show( *args, &action )
options = args.last.is_a?( Hash ) ? args.pop : {}
options = { :title => 'Hornetseye', :border => true,
:output => XImageOutput }.merge options
unless action
frame, width, height = *args
width ||= frame.width
height ||= ( width.to_f * frame.height / frame.width ).round
display = options[ :display ] || new
output = options[ :output ].new
output.write frame
window = X11Window.new display, output, width, height, options
window.title = options[ :title ]
begin
window.show
display.event_loop
ensure
window.close
end
frame
else
width, height = *args
display = options[ :display ] || new
result = action.call display
width ||= result.shape[0]
height ||= ( width.to_f * result.shape[1] / result.shape[0] ).round
output = options[ :output ].new
window = X11Window.new display, output, width, height, options
window.title = options[ :title ]
begin
window.show
t = Time.new.to_f
while true
t += 1.0 / options[ :frame_rate ] if options[ :frame_rate ]
output.write result
delay = t - Time.new.to_f
if delay > 0
display.event_loop delay
else
display.process_events
end
break unless display.status?
result = action.call display
end
ensure
window.close
end
result
end
end
|