It sounds like an easy job for one of the Canvas modules....Tk::Canvas, Tk::Zinc, Gnome2::Canvas, Goo::Canvas, etc. The advantage of the canvas widgets over SDL, is that they give you persistence of items ( sort of as objects) on the screen, whearas SDL requires you to do that yourself.
See Tk Patio/Office layout designer as a good example of tagging items on a canvas.
For a simple
example of mouse position and the use of tags, this moves lines individually, or as a group if you move the red oval
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $dx;
my $dy;
my $grouptag;
my $mw = MainWindow->new;
$mw->geometry("700x600");
my $x1 = 50;
my $x2 = 100;
my $y1 = 50;
my $y2 = 200;
my $c = $mw->Canvas(-width => 700, -height => 565,
-bg => 'black',
)->pack;
my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi
+t(0)})
->pack;
my $parent = $c->createOval($x1, $y1, $x2, $y2,
-fill => 'red',
-tags => ['mover','group1'],
);
my @children;
for (1..4) {
push @children, $c->createLine(($x1 + $x2)/2,$y1, (2 * $x2), (2 *
+$y2),
# -state =>'disabled',
-fill => 'white',
-activefill => 'green',
-disabledfill => 'white',
-tags => ['mover','group1','line','line'.$_],
);
$x1 += 15; $x2 += 15;
}
$c->bind('mover', '<1>', sub {&mobileStart();});
$c->bind('mover', '<B1-Motion>', sub {&mobileMove();});
$c->bind('mover', '<ButtonRelease>', sub {&mobileStop();});
MainLoop;
sub mobileStart {
my $ev = $c->XEvent;
($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
my $curr_object = $c->find('withtag','current');
print "curr->",@$curr_object,"\n"; #array dereference
my (@list) = $c->gettags($curr_object);
print "movelist->@list\n";
# if( grep /line/, @list){
# ($grouptag) = grep /(line\d+)/, @list;
# } else {($grouptag) = grep /(group\d+)/, @list; }
# JKrahn correctly observes:
#You are grep()ing through @list twice! and using capturing parenthese
+s!
#this is better
unless ( ( $grouptag ) = grep /line\d/, @list ) {
( $grouptag ) = grep /group\d/, @list;
}
# print "grouptag-> $grouptag\n";
# print "START MOVE-> $dx $dy\n";
}
sub mobileMove {
my $ev = $c->XEvent;
$c->move($grouptag, $ev->x + $dx, $ev->y +$dy);
($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
# print "MOVING-> $dx $dy\n";
}
sub mobileStop{&mobileMove;}
__END__
If you are more specific in your question, like showing a sample text file, and exactly what you want to do, we might be able to give you a head start on setting up your tags and mouse bindings.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.