#!/usr/bin/perl -- use strict; use warnings; use Tk; use Tk::AbstractCanvas; { my $mwin = my $mw = tkinit; my $acnv = $mwin->AbstractCanvas()->pack(-expand => 1, -fill => 'both'); $acnv->controlNav(1); # advanced CtrlKey+MouseDrag Navigation $acnv->rectToPoly(1); $acnv->ovalToPoly(1); my $rect = $acnv->createRectangle( 7, 8, 24, 23, -fill => 'red'); my $oval = $acnv->createOval( 23, 24, 32, 27, -fill => 'green'); my $line = $acnv->createLine( 0, 1, 31, 32, -fill => 'blue', -arrow => 'last'); my $labl = $mwin->Label(-text => 'Hello AbstractCanvas! =)'); my $wind = $acnv->createWindow(15, 16, -window => $labl); $acnv->CanvasBind('' => \&exit); $acnv->CanvasFocus(); $acnv->viewAll(); my $c2 = $mwin->Canvas( -background => 'black', #~ -width => 100, #~ -height => 100, #~ -width => 20, #~ -height => 20, -width => 30, -height => 30, ); $c2->createOval(0, 0, 5, 5, -fill => 'white',-tags => ['shabba'] ); $mw->bind( $c2, '' => [ \&shabba , $acnv ]); $c2->place( qw/ -x 10 -y 10 / ); } MainLoop; sub shabba { my( $c2, $acnv ) = @_; #~ my $c2 = $Tk::event->W; my $x = $Tk::event->x; my $y = $Tk::event->y; #~ use Data::Dump; #~ dd [ $c2->configure ], [ $c2->itemconfigure( 'shabba' )] ; $c2->coords( 'shabba', $x, $y , $x+5, $y+5); # size is 5 my $width = $c2->cget('-width'); my $height = $c2->cget('-height'); my $xview = $x / $width; my $yview = $y / $height; $acnv->xviewMoveto( $xview ); $acnv->yviewMoveto( $yview ); }