use strict; use warnings; use Tk; use Tk::Canvas; use Tk::CursorControl; require Tk::PNG; my ( $X, $Y, $dx, $dy, $BNr ); my $schiebeauswahl = ""; my $mw = MainWindow->new(); my $cControl = $mw->CursorControl; my $canvas = $mw->Canvas(-width => 640, -height => 480, -background => "#c0c0c0")->grid(-row=>1, -column=>0, -columnspan=>10 ); my $image_in = $canvas->Photo( -file => 'background.png', -format => 'png' ); my $picture = $canvas->createImage(0,0,-image => $image_in, -anchor => "nw", -tags => "picture"); my $rahmen = $canvas->createRectangle(2, 2, 168, 202, -width => 2, -outline => "#0f0", -tags => "rectangle"); $canvas->Tk::bind( '', sub { $schiebeauswahl = 'rectangle'; $BNr = 1; startmove(); } ); $canvas->Tk::bind( '', sub { $schiebeauswahl = 'rectangle'; $BNr = 1; endmove(); } ); $canvas->Tk::bind( '', sub { $schiebeauswahl = 'picture'; $BNr = 3; startmove(); } ); $canvas->Tk::bind( '', sub { $schiebeauswahl = 'picture'; $BNr = 3; endmove(); } ); MainLoop; sub startmove { return unless ( $canvas->gettags('current') ); my $ev = $canvas->XEvent; ( $X, $Y ) = ( $ev->x, $ev->y ); $canvas->Tk::bind( '', \&moveit ); $canvas->raise( 'rectangle', 'all' ); } sub moveit { my $ev = $canvas->XEvent; my ( $cx, $cy ) = ( $ev->x, $ev->y ); ( $dx, $dy ) = ( $cx - $X, $cy - $Y ); $canvas->move( $schiebeauswahl, $dx, $dy ); ( $X, $Y ) = ( $cx, $cy ); } sub endmove { return unless ( $canvas->gettags('current') ); my $ev = $canvas->XEvent; my ( $cx, $cy ) = ( $ev->x, $ev->y ); ( $dx, $dy ) = ( $cx - $X, $cy - $Y ); $canvas->move( $schiebeauswahl, $dx, $dy ); undef($X); undef($Y); $canvas->Tk::bind( '', '' ); }