From: Josef Wolf Date: 2009-09-08T07:20:23+09:00 Subject: Re: Zoomable TkCanvas? On Tue, Sep 08, 2009 at 04:26:32AM +0900, Joel VanderWerf wrote: > Josef Wolf wrote: >> It looks like TkCanvas has no methods for zooming in and out. For Perl, >> I have found the Tk::Worldcanvas and Tk::Abstractcanvas modules. Anybody >> knows about something like that for ruby? > > Those perl modules sound interesting--maybe it would be useful to have > them in ruby if someone hasn't done that yet. Yeah, they make life a whole lot easier. In addition to zooming, they: - maintain original coordinates at all zoom factors. Thus even after zoom operations, events as well as querying/moving/adding items are done as if the canvas is at zoom factor 1.0. So zoom is handled completely transparent to the user of the module.. - turn around the y-axis (origin is at left bottom) - handle scroll bars + panning > I've used Tk's Canvas from tcl and from ruby, and I've always had to > implement zooming myself in wrapper classes. Strange, that such a powerful widget is missing such a basic functionality. > One way to do it is tag all > canvas objects (or just the ones that zoom), and use the Canvas#scale > method on that tag. You have to keep track of the current zoom level (Tk > doesn't), and use that to calculate the arguments to #scale. You also have > to adjust the scroll bars (using 'configure :scrollregion => ...'). Then > use xview/yview to keep the current view position in sync with the zoom > level. Sounds easy enough. Is it really that easy? I think this would work only if you do not add or move any items after you have made zoom operations. Looks like above mentioned modules do a whole lot more of work. They override all of the item creation and modification methods to fix movement or addition of new items to the current zoom factor. > I think that covers it, but if you're interested, take a look at canvas.rb > in my tkar project. Tkar is a process, rather than a library, but it > abstracts out details like zooming and provides a basic user interface for > controlling zoom, pan, etc. > > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/343516 > > http://rubyforge.org/projects/tkar Sounds very interesting. Thanks, I'll check that out!