Software Engineering Lecture 6/22

先週の復習



Call backのパターン

スクロール

    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

ドラッグ&ドロップ

問題

以下の仕組みを 協調図を使って表示して見よ。