From: David Bailey Date: 2006-04-03T03:12:18+09:00 Subject: Re: Ruby/Tk (X,Y) Coordinate Question David Bailey wrote: > Chris Alfeld wrote: >> Actually, what I think you are looking for is the translation from >> "real" coordinates to canvas coordinates for which you want: >> >> canvas.canvasx and canvas.canvasy >> >> also note that you can bind mouse clicks to Tkc objects, though be >> careful that if the fill is none then TkcRect's won't register clicks >> on the interior. >> >> So, in summary, see TkCanvas.canvasx, TkCanvas.canvasy, and >> TkcRectangle.bind >> (actually part of the TkcTagAccess mixin). >> >> Another command you may find useful is TkCanvas.find_overlapping which >> can translate a mouse click to a TkcObject. Thus code such as: >> >> obj_at_xy = >> @canvas.find_overlapping(@canvas.canvasx(x),@canvas.canvasy(y), >> @canvas.canvasx(x),@canvas.canvasy(y)) >> >> Here I believe x,y should be from %x,%y, that is, relative to the canvas >> widget. >> >> c. > > > Chris, > > I'm researching these canvasx and canvasy methods now. I'll let you > know how I make out. Thank you for your help. > > David Hey Chris and/or Fellow Rubyists, I bought and flipped through "Mastering Perl/Tk" by Nancy Walsh and Steve Lidie, which was purported to be "the" book on Perk/Tk. There was scant info on canvasx, canvasy and find_overlapping. I read through what was there, though. Both canvasx and canvasy take a single argument, but when I supplied various x and y arguments, the methods just returned the same argument as a result! So, I guess I just don't get it. Do you have a sense of what the argument is supposed to be and what is supposed to happen to it? Also, where can I get some inormation about find_overlapping, real quick. I spent all day yesterday fighting with widget placement (see my earlier post "Placing Sets of Ruby/Tk Widgets"), and that pooped me out. What week-end brain power I have left, I will apply toward continuing to explore this problem. Thanks, David P.S. BTW, my use of root_x and root_y coordinates did not work because they appear to be relative to the desktop and not the application window. (Unless I did something drastically wrong!) So, if I calculate an offset but the user then moves the application window, the offset becomes no longer valid. Rats! -- Posted via http://www.ruby-forum.com/.