my $c = $w->Canvas( -relief => 'sunken', -bd => 2, -scrollregion => ['-10c', '-10c', '50c', '20c'], ); my $w_vscroll = $w->Scrollbar(-command => [$c => 'yview']); my $w_hscroll = $w->Scrollbar(-command => [$c => 'xview'], -orient => 'horiz'); $c->configure(-xscrollcommand => [$w_hscroll => 'set'], -yscrollcommand => [$w_vscroll => 'set']); $w_vscroll->pack(-side => 'right', -fill => 'y'); $w_hscroll->pack(-side => 'bottom', -fill => 'x'); $c->pack(-expand => 'yes', -fill => 'both');
$c->bind('point', '<1>' => [sub {plot_down(@ARG)}, \%pinfo]); $c->bind('point', '<ButtonRelease-1>' => sub {shift->dtag('selected')}); $c->Tk::bind('<B1-Motion>' => [sub {plot_move(@ARG)}, \%pinfo]); sub plot_down { my($w, $pinfo) = @ARG; my $e = $w->XEvent; my($x, $y) = ($e->x, $e->y); $w->dtag('selected'); $w->addtag('selected', 'withtag', 'current'); $w->raise('current'); $pinfo->{'lastX'} = $x; $pinfo->{'lastY'} = $y; } # end plot_down sub plot_move { my($w, $pinfo) = @ARG; my $e = $w->XEvent; my($x, $y) = ($e->x, $e->y); $w->move('selected', $x-$pinfo->{'lastX'}, $y-$pinfo->{'lastY'}); $pinfo->{'lastX'} = $x; $pinfo->{'lastY'} = $y; } # end plot_move