require 'tk' class TkMove def initialize( canvas ) @x0, @y0 = 0, 0 @canvas = canvas @tag = 'item' end def bind @canvas.itembind( @tag, '1', proc{|x, y| plotDown x, y},"%x %y") @canvas.itembind( @tag, 'B1-Motion', proc{|x, y| plotMove x, y},"%x %y") end def unbind @canvas.itembind( @tag, '1', proc{} ) @canvas.itembind( @tag, 'B1-Motion', proc{} ) end def plotDown(x, y) @canvas.dtag 'selected' tag = @canvas.gettags('current')[-2] @canvas.addtag_withtag 'selected', tag @canvas.raise tag @x0, @y0 = x, y end def plotMove(x, y) @canvas.move 'selected', x - @x0, y - @y0 @x0, @y0 = x, y end end c = TkCanvas.new.pack m = TkMove.new( c ) m.bind x1, y1 = 100, 100 item1 = TkcRectangle.new(c, x1-15, y1-15, x1+15, y1+15, 'fill'=>'white') item1.addtag('item'); item1.addtag('g1') x2, y2 = 100, 100 item1 = TkcOval.new(c, x2-10, y2-10, x2+10, y2+10, 'fill'=>'red') item1.addtag('item'); item1.addtag('g1') x3, y3 = 150, 100 item1 = TkcOval.new(c, x3-10, y3-10, x3+10, y3+10, 'fill'=>'yellow') item1.addtag('item') x4, y4 = 200, 100 item1 = TkcOval.new(c, x4-10, y4-10, x4+10, y4+10, 'fill'=>'blue') item1.addtag('item'); item1.addtag('g2') Tk.mainloop