diff options
author | mertz | 2002-03-12 17:02:49 +0000 |
---|---|---|
committer | mertz | 2002-03-12 17:02:49 +0000 |
commit | 9f9717711fed84aec81f6530266b7e97ad831ecc (patch) | |
tree | 77f81a44b9e6bead9d95f8d8836d1d1cf5fe2080 /Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl | |
parent | 9b8d0d371f494ce0059db9e0cc7d63cbcefae91d (diff) | |
download | tkzinc-9f9717711fed84aec81f6530266b7e97ad831ecc.zip tkzinc-9f9717711fed84aec81f6530266b7e97ad831ecc.tar.gz tkzinc-9f9717711fed84aec81f6530266b7e97ad831ecc.tar.bz2 tkzinc-9f9717711fed84aec81f6530266b7e97ad831ecc.tar.xz |
demos d�plac�es de examples/ vers demos/
ajout de nouvelles demos: tkZincLogo.pl window-contours.pl
Diffstat (limited to 'Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl')
-rw-r--r-- | Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl | 295 |
1 files changed, 295 insertions, 0 deletions
diff --git a/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl b/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl new file mode 100644 index 0000000..a506151 --- /dev/null +++ b/Perl/demos/Tk/demos/zinc_lib/simple_interaction_track.pl @@ -0,0 +1,295 @@ +#!/usr/bin/perl +# $Id$ +# This simple demo has been developped by C. Schlienger <celine@intuilab.com> + +use Tk; +use Tk::Zinc; +use strict; + +my $mw = MainWindow->new(); + + + +########################################### +# Text zone +########################################### + +my $text = $mw->Scrolled(qw/Text -relief sunken -borderwidth 2 -setgrid true + -height 6 -scrollbars e/); +$text->pack(qw/-expand yes -fill both/); + +$text->insert('0.0', + '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' ); + + +########################################### +# Zinc +########################################### +my $zinc_width=600; +my $zinc_height=500; +my $zinc = $mw->Zinc(-width => $zinc_width, -height => $zinc_height, + -font => "10x20", + -borderwidth => 3, -relief => 'sunken', + )->pack; + +########################################### +# Track +########################################### + +#the label format (6 formats for 6 fields)# +my $labelformat = "x80x60+0+0 x60a0^0^0 x30a0^0>1 a0a0>2>1 x30a0>3>1 a0a0^0>2"; + +#the track# +my $x=250; +my $y=200; +my $track=$zinc->add('track', 1, 6, # 6 is the number of field in the flightlabel + -labelformat => $labelformat, + -position => [$x, $y],#position of the marker + -speedvector => [30, -15],#ccords of the speed vector + -markersize => 10, + ); +# moving the track, to display past positions +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 + -filled => 0, + -bordercolor => 'DarkGreen', + -border => "contour", + ); +$zinc->itemconfigure($track, 1, + -filled => 1, + -backcolor => 'gray60', + -text => "AFR6128"); +$zinc->itemconfigure($track, 2, + -filled => 0, + -backcolor => 'gray65', + -text => "390"); +$zinc->itemconfigure($track, 3, + -filled => 0, + -backcolor => 'gray65', + -text => "/"); +$zinc->itemconfigure($track, 4, + -filled => 0, + -backcolor => 'gray65', + -text => "350"); +$zinc->itemconfigure($track, 5, + -filled => 0, + -backcolor => 'gray65', + -text => "TUR"); + + + +########################################### +# Events on the track +########################################### +#--------------------------------------------- +# Enter/Leave a field of the label of the track +#--------------------------------------------- + +foreach my $field (0..5) { + #Entering the field $field higlights it# + $zinc->bind("$track:$field", + '<Enter>', + sub { + if ($field==0){ + higlight_label_on(); + print "CP=", $zinc->currentpart, "\n"; + } + else{ + highlight_fields_on($field); + print "CP=", $zinc->currentpart, "\n"; + } + + }); + #Leaving the field cancels the highlight of $field# + $zinc->bind("$track:$field", + '<Leave>', + sub { + if($field==0){ + higlight_label_off(); + } + else{ + if ($field==1){ + highlight_field1_off(); + } + else{ + highlight_other_fields_off($field); + } + } + }); +} + +#fonction# +sub higlight_label_on{ + $zinc->itemconfigure('current', 0, + -filled => 0, + -bordercolor => 'red', + -border => "contour", + ); + +} +sub higlight_label_off{ + $zinc->itemconfigure('current', 0, + -filled => 0, + -bordercolor => 'DarkGreen', + -border => "contour", + ); + + +} + +sub highlight_fields_on{ + my $field=$_[0]; + $zinc->itemconfigure('current', $field, + -border => 'contour', + -filled => 1, + -color => 'white' + ); + +} +sub highlight_field1_off{ + $zinc->itemconfigure('current', 1, + -border => '', + -filled => 1, + -color => 'black', + -backcolor => 'gray60' + ); + +} + +sub highlight_other_fields_off{ + my $field=$_[0]; + $zinc->itemconfigure('current', $field, + -border => '', + -filled => 0, + -color => 'black', + -backcolor => 'gray65' + ); +} +#--------------------------------------------- +# Enter/Leave other parts of the track +#--------------------------------------------- +$zinc->bind("$track:position", + '<Enter>', + sub { $zinc->itemconfigure("$track", + -symbolcolor=>"red", + ); + print "CP=", $zinc->currentpart, "\n"; + }); +$zinc->bind("$track:position", + '<Leave>', + sub { $zinc->itemconfigure("$track", + -symbolcolor=>"black", + ); + }); + +$zinc->bind("$track:speedvector", + '<Enter>', + sub { $zinc->itemconfigure("$track", + -speedvectorcolor=>"red", + ); + }); +$zinc->bind("$track:speedvector", + '<Leave>', + sub { $zinc->itemconfigure("$track", + -speedvectorcolor=>"black", + ); + }); + +$zinc->bind("$track:leader", + '<Enter>', + sub { $zinc->itemconfigure("$track", + -leadercolor=>"red", + ); + }); + +$zinc->bind("$track:leader", + '<Leave>', + sub { $zinc->itemconfigure("$track", + -leadercolor=>"black", + ); + }); + +# $zinc->bind("$track:marker", +# '<Enter>', +# sub { $zinc->itemconfigure("$track", +# -markercolor=>"red", +# ); +# }); +# +# $zinc->bind("$track:marker", +# '<Leave>', +# sub { $zinc->itemconfigure("$track", +# -markercolor=>"black", +# ); +# }); + +#--------------------------------------------- +# Drag and drop the track +#--------------------------------------------- +#Binding to ButtonPress event -> "move_on" state# +$zinc -> bind("$track",'<ButtonPress-1>'=>[sub{ + select_color_on(); #change the color + move_on($_[1],$_[2]); #"move_on" state + },Ev('x'),Ev('y')]); + + +#"move_on" state# +sub move_on{ + my ($xi,$yi)=@_; + #ButtonPress event not allowed on track + $zinc -> bind("$track",'<ButtonPress-1>'=>""); + #Binding to Motion event -> move the track# + $zinc -> bind("$track",'<Motion>'=> + [sub{move($xi,$yi,$_[1],$_[2]); #move the track + $xi=$_[1]; + $yi=$_[2]; + },Ev('x'),Ev('y')]); + #Binding to ButtonRelease event -> "move_off" state# + $zinc -> bind("$track",'<ButtonRelease-1>'=>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",'<ButtonPress-1>'=>[sub{ + select_color_on(); #change the color + move_on($_[1],$_[2]); #"move_on" state + },Ev('x'),Ev('y')]); + + #Motion event not allowed on track + $zinc -> bind("$track",'<Motion>'=>""); + #ButtonRelease event not allowed on track + $zinc -> bind("$track",'<ButtonRelease-1>'=>""); +} + +#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]); +} + + +sub select_color_on{ +$zinc->itemconfigure("$track", + -speedvectorcolor=>"white", + -markercolor=>"white", + -leadercolor=>"white" ); +} + +sub select_color_off{ + $zinc->itemconfigure("$track", + -speedvectorcolor=>"black", + -markercolor=>"black", + -leadercolor=>"black" ); + } +MainLoop; |