#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $dx;
my $dy;
my $mw = MainWindow->new;
$mw->geometry("700x600");
my $canvas = $mw->Canvas(-width => 700, -height => 565,
-bg => 'black',
-borderwidth => 3,
-relief => 'sunken',
)->pack;
my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi
+t(0)})
->pack;
$canvas->createText(100,10, -text => 'Drag Red Peg to hole',
-fill => 'white');
$canvas->create('oval', 300,300,500,500,
-fill=>'yellow',
);
my $dr = $canvas->createRectangle(0, 20, 50, 75,
-fill => 'red',
-tags => ['move','red'],
);
$canvas->bind('move', '<1>', sub {&mobileStart();});
$canvas->bind('move', '<B1-Motion>', sub {&mobileMove();});
$canvas->bind('move', '<ButtonRelease-1>', sub {&mobileStop();});
MainLoop;
sub mobileStart {
my $ev = $canvas->XEvent;
($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
$canvas->raise('current');
}
sub mobileMove {
my $ev = $canvas->XEvent;
$canvas->move('current', $ev->x + $dx, $ev->y +$dy);
($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
my @coords = $canvas->coords('current');
}
sub mobileStop{&mobileMove;}