views:

26

answers:

0

I'm writing a video game mapping program in Ruby that has uses Tk for GUI. To give you some background, the level map ($Map) is a large TkCanvas covered with TkcImages - one for each tile in the level. I wanted to set it up so that the user could edit the level by clicking and dragging the mouse around to paint tiles.

So I figured I could do this in the method that generates the TkcImages.

require 'tk'
...
...
class Tile
    ...
    def createImage()
        @vsg ||= TkcImage.new($Map,dispX,dispY,:image=>img,:anchor=>"nw")
        @vsg.bind("B1-Enter") { $LEVEL.paintxy(@x,@y) }
    end
    ...
end

But it turns out Enter events don't fire as a mouse button is held (at least not in Linux), making B1-Enter effectively useless. It behaves exactly the same as a basic 1 event, firing once on the thing I click, and not on anything else I drag over.
In order for my program to allow dragging to paint multiple tiles, I need an event that will fire on everything I drag over.

So what event will allow me to capture when the mouse travels over a tile with the left mouse button held down?

Update: I just tried capturing B1-Motion and using the x/y values it provides. That's no good, either; even when I have the event bound to the individual Tkc images, the xy coordinates it gives always seems to be relative to the same point on the window - not the image I clicked, or even the canvas. Meaning I can't even use it to attempt to calculate anything, since $Map has scrollbars.