From dc52b76e565ab6d780e65860eeb34dced5be1f1a Mon Sep 17 00:00:00 2001 From: mertz Date: Fri, 21 Mar 2003 09:43:34 +0000 Subject: Corrections (le d�placement de la piste ne fonctionait plus) et simplification du code --- .../Tk/demos/zinc_lib/simple_interaction_track.pl | 121 +++++++++------------ 1 file changed, 54 insertions(+), 67 deletions(-) (limited to 'Perl/demos/Tk') diff --git a/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl b/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl index 6b4e86a..08d25b1 100644 --- a/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl +++ b/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl @@ -25,12 +25,13 @@ my $zinc = $mw->Zinc(-width => $zinc_width, -height => $zinc_height, # The explanation displayed when running this demo $zinc->add('text', 1, -position=> [10,10], - -text => 'This toy-appli shows some interactions on different parts of a flight track item. -The following operations are possible: - - Drag Button 1 on the track to move it. - Please Note the position history (past positions) - - Enter/Leave flight label fields - - Enter/Leave the speedvector, symbol (i.e. current position), label leader', + -text => 'This toy-appli shows some interactions on different parts +of a flight track item. The following operations are possible: + - Drag Button 1 on the track to move it. + Please Note the position history (past positions) + - Enter/Leave flight label fields + - Enter/Leave the speedvector, symbol (i.e. current position), + label, or leader', -font => "9x15", ); @@ -51,7 +52,7 @@ my $track=$zinc->add('track', 1, 6, # 6 is the number of field in the flightlabe -markersize => 10, ); # moving the track, to display past positions -foreach my $i (0..5) { $zinc->coords("$track",[$x+$i*10,$y-$i*5]); } +foreach my $i (0..5) { $zinc->coords($track,[$x+$i*10,$y-$i*5]); } #fields of the label# $zinc->itemconfigure($track, 0,#configuration of field 0 of the label @@ -96,11 +97,11 @@ foreach my $field (0..5) { sub { if ($field==0){ higlight_label_on(); - print "CP=", $zinc->currentpart, "\n"; +# print "CP=", $zinc->currentpart, "\n"; } else{ highlight_fields_on($field); - print "CP=", $zinc->currentpart, "\n"; +# print "CP=", $zinc->currentpart, "\n"; } }); @@ -174,105 +175,91 @@ sub highlight_other_fields_off{ #--------------------------------------------- $zinc->bind("$track:position", '', - sub { $zinc->itemconfigure("$track", + sub { $zinc->itemconfigure($track, -symbolcolor=>"red", ); - print "CP=", $zinc->currentpart, "\n"; +# print "CP=", $zinc->currentpart, "\n"; }); $zinc->bind("$track:position", '', - sub { $zinc->itemconfigure("$track", + sub { $zinc->itemconfigure($track, -symbolcolor=>"black", ); }); $zinc->bind("$track:speedvector", '', - sub { $zinc->itemconfigure("$track", + sub { $zinc->itemconfigure($track, -speedvectorcolor=>"red", ); }); -$zinc->bind("$track:speedvector", - '', - sub { $zinc->itemconfigure("$track", - -speedvectorcolor=>"black", - ); - }); +$zinc->bind("$track:speedvector", '', + sub { $zinc->itemconfigure($track, + -speedvectorcolor=>"black", + ); + }); -$zinc->bind("$track:leader", - '', - sub { $zinc->itemconfigure("$track", - -leadercolor=>"red", - ); - }); +$zinc->bind("$track:leader", '', + sub { $zinc->itemconfigure($track, + -leadercolor=>"red", + ); + }); -$zinc->bind("$track:leader", - '', - sub { $zinc->itemconfigure("$track", - -leadercolor=>"black", - ); - }); +$zinc->bind("$track:leader", '', + sub { $zinc->itemconfigure($track, + -leadercolor=>"black", + ); + }); #--------------------------------------------- # Drag and drop the track #--------------------------------------------- #Binding to ButtonPress event -> "move_on" state# -$zinc -> bind("$track",''=>[ sub { select_color_on(); #change the color - move_on(Tk::Ev('x'),Tk::Ev('y')); #"move_on" state - } - ]); +$zinc -> bind($track,''=>[ sub { &select_color_on(); #change the color + &move_on($_[1],$_[2]); #"move_on" state + }, Tk::Ev('x'),Tk::Ev('y') ]); +#Binding to ButtonRelease event -> "move_off" state# +$zinc -> bind($track,''=>sub{&select_color_off(); #change the color + &move_off();}); #"move_off" state #"move_on" state# sub move_on{ - my ($xi,$yi)=@_; - #ButtonPress event not allowed on track - $zinc -> bind("$track",''=>""); - #Binding to Motion event -> move the track# - $zinc -> bind("$track",''=> - [sub{move($xi,$yi,$_[1],$_[2]); #move the track - $xi=$_[1]; - $yi=$_[2]; + my ($xi,$yi)=@_; + #Binding to Motion event -> move the track# + $zinc -> bind($track,''=> + [sub{move($xi,$yi,$_[1],$_[2]); #move the track + $xi=$_[1]; + $yi=$_[2]; },Tk::Ev('x'),Tk::Ev('y')]); - #Binding to ButtonRelease event -> "move_off" state# - $zinc -> bind("$track",''=>sub{select_color_off(); #change the color - move_off();}); #"move_off" state } #"move_off" state# sub move_off{ - #Binding to ButtonPress event -> "move_on" state# - $zinc -> bind("$track",''=>[sub { select_color_on(); #change the color - move_on(Tk::Ev('x'),Tk::Ev('y')) - } - ]); - - #Motion event not allowed on track - $zinc -> bind("$track",''=>""); - #ButtonRelease event not allowed on track - $zinc -> bind("$track",''=>""); + #Motion event not allowed on track + $zinc -> bind($track,''=>""); } #move the track# sub move{ - my ($xi,$yi,$x,$y)=@_; - select_color_on(); - my @coords=$zinc->coords("$track"); - $zinc->coords("$track",[$coords[0]+$x-$xi,$coords[1]+$y-$yi]); + my ($xi,$yi,$x,$y)=@_; + select_color_on(); + my @coords=$zinc->coords($track); + $zinc->coords($track,[$coords[0]+$x-$xi,$coords[1]+$y-$yi]); } sub select_color_on{ -$zinc->itemconfigure("$track", - -speedvectorcolor=>"white", - -markercolor=>"white", - -leadercolor=>"white" ); + $zinc->itemconfigure($track, + -speedvectorcolor=>"white", + -markercolor=>"white", + -leadercolor=>"white" ); } sub select_color_off{ - $zinc->itemconfigure("$track", + $zinc->itemconfigure($track, -speedvectorcolor=>"black", -markercolor=>"black", -leadercolor=>"black" ); - } -Tk::MainLoop; +} + Tk::MainLoop; -- cgit v1.1