1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
class Screenshot
def initialize( index, view )
@index = index
@small_file = "screenshot.small.#{@index}.png"
@large_file = "screenshot.large.#{@index}.png"
view.save_image( @small_file, 80, 60 )
view.save_image( @large_file, 800, 600 )
@box = view.box
end
def box
return @box
end
def html_snippet
s = ""
l = sprintf( "%.3f", @box.left.to_s )
r = sprintf( "%.3f", @box.right.to_s )
b = sprintf( "%.3f", @box.bottom.to_s )
t = sprintf( "%.3f", @box.top.to_s )
s += "<a style=\"font-size:10px\" href=\"int:navigate?#{@index}\">#{l},#{b} <br/>"
s += "#{r},#{t}</a><br/>"
s += "<a href=\"int:enlarged?#{@large_file}\"><img src=\"file:#{@small_file}\" width=\"80\" height=\"60\"/></a>"
return s
end
end
class Browser < RBA::BrowserDialog
def initialize
@browser_source = Server.new
self.set_source( @browser_source )
self.set_home( "int:index" )
self.show
end
def add
@browser_source.add
self.show
self.load( "int:index" )
self.reload
end
end
class Server < RBA::BrowserSource
def initialize
@screenshots = []
end
def add
view = RBA::Application::instance.main_window.current_view
if view != nil
@screenshots.push( Screenshot.new( @screenshots.size, view ) )
end
end
def get( url )
url = url.sub( /^int:/, "" )
if url == "index"
return self.index
elsif url =~ /^enlarged\?(.*)/
return enlarged( $1 )
elsif url =~ /^navigate\?(.*)/
navigate( $1.to_i )
end
return ""
end
def navigate( index )
view = RBA::Application::instance.main_window.current_view
if view != nil
view.zoom_box( @screenshots[index].box )
end
end
def enlarged( img )
return "<a href=\"int:index\">Index Page</a><br/><img src=\"file:#{img}\"/>"
end
def index
r = []
r.push( "<html><h1>Screenshot gallery</h1><p><p>" )
r.push( "<table>" )
r.push( "<tr>" )
n = 0
@screenshots.each { |s|
r.push( "<td>" )
r.push( s.html_snippet )
r.push( "</td>" )
n += 1
if n % 5 == 0
r.push( "</tr><tr>" )
end
}
r.push( "</tr>" )
r.push( "</table>" )
return r.join( "" )
end
end
# ------------------------------------------------------------------
# Declare and register the menu items
app = RBA::Application::instance
mw = app.main_window
menu = mw.menu
$browser = nil
class AddScreenshot < RBA::Action
def initialize
self.title = "Add Screenshot"
end
def triggered
if $browser == nil
$browser = Browser.new
end
$browser.add
end
end
class ShowGallery < RBA::Action
def initialize
self.title = "Show Gallery"
end
def triggered
if $browser != nil
$browser.show
end
end
end
$add_screenshot_action = AddScreenshot.new
$show_gallery_action = ShowGallery.new
menu.insert_separator( "@toolbar.end", "tb_sep" )
menu.insert_item( "@toolbar.end", "add_screenshot", $add_screenshot_action )
menu.insert_item( "@toolbar.end", "show_gallery", $show_gallery_action )
app.exec
|