Debian Codegraph @

DragDrop/motion_test

raw
1 #!/usr/local/bin/perl -w
2 use Tk;
3 use strict;
4 use Tk::DragDrop;
5 use Tk::DropSite;
6
7 Tk::DragDrop->import(@ARGV);
8 Tk::DropSite->import(@ARGV);
9
10 my $top = MainWindow->new();
11 $top->Button('-text' => "Quit", '-command' => ['destroy',$top])->pack;
12
13 my $f = $top->Frame->pack;
14
15 my $sun = $f->Label(-relief => 'ridge','-text' => "Sun")->pack(-side => 'left');
16 $sun->DragDrop(-event => '<B1-Motion>', -text => 'Sun', -sitetypes => [qw(Sun)]);
17
18 my $either = $f->Label(-relief => 'ridge','-text' => "Either")->pack(-side => 'left');
19 $either->DragDrop(-event => '<B1-Motion>', -text => 'Either', -sitetypes => [qw(Local Sun)]);
20
21 my $loc = $f->Label(-relief => 'ridge','-text' => "Loc")->pack(-side => 'right');
22 $loc->DragDrop(-event => '<B1-Motion>', -text => 'Local', -sitetypes => [qw(Local)]);
23
24 my $canvas = $top->Canvas(-width => 200, -height => 200,
25 -relief => 'groove', -borderwidth => 3)->pack;
26
27 my $sid = $canvas->create('oval',0,0,10,10,-fill => 'red');
28 my $lid = $canvas->create('oval',0,0,10,10,-fill => 'blue');
29
30 $canvas->DropSite(-motioncommand => [\&Motion,$canvas,"Sun",$sid],
31 -dropcommand => [\&Drop,$canvas,"Sun",$sid],
32 -droptypes => 'Sun' );
33 $canvas->DropSite(-motioncommand => [\&Motion,$canvas,"Loc",$lid],
34 -dropcommand => [\&Drop,$canvas,"Sun",$lid],
35 -droptypes => 'Local' );
36
37 MainLoop;
38
39 sub Motion
40 {
41 my ($canvas,$type,$id,$x,$y) = @_;
42 $canvas->coords($id,$x-5,$y-5,$x+5,$y+5);
43 # printf "$type x=%3d y=%3d\n",$x,$y;
44 }
45
46 sub Drop
47 {
48 my ($canvas,$type,$id,$seln,$x,$y) = @_;
49 Motion($canvas,$type,$id,$x,$y);
50 my $text = $canvas->SelectionGet(-selection => $seln);
51 my $col = $canvas->itemcget($id,'-fill');
52 $canvas->create('text',$x,$y,-text => $text, -justify => 'center', -fill => $col);
53 }
54
55
56