From c51cf9b5a63bde35d57f8e69072a41fe76fbfd6c Mon Sep 17 00:00:00 2001 From: mertz Date: Tue, 19 Nov 2002 09:56:00 +0000 Subject: passage � la nouvelle m�thode contour (addhole). diverses simplifaction/correction du code des callbacks de drag&drop --- Perl/demos/Tk/demos/zinc_lib/counter.pl | 45 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/Perl/demos/Tk/demos/zinc_lib/counter.pl b/Perl/demos/Tk/demos/zinc_lib/counter.pl index 74c51aa..1ef3295 100644 --- a/Perl/demos/Tk/demos/zinc_lib/counter.pl +++ b/Perl/demos/Tk/demos/zinc_lib/counter.pl @@ -231,7 +231,7 @@ my $clipping_item2 = $zinc->add('curve', $clipped_group2, -linewidth=>0, ); -$zinc->contour($clipping_item2,"diff",[$x2,$y2,$x3,$y2,$x3,$y3,$x2,$y3,$x2,$y2]); +$zinc->contour($clipping_item2,"addhole",[$x2,$y2,$x3,$y2,$x3,$y3,$x2,$y3,$x2,$y2]); #-------------------------------- # Clipped items @@ -312,7 +312,7 @@ sub refresh { # Rotation de la fleche #--------------------------------- return if $timerIsDead; # the timer is still running when using zinc-demos! - $zinc->rotate("$fleche",$angle,$centre[0],$centre[1]); + $zinc->rotate($fleche,$angle,$centre[0],$centre[1]); $nb+=1; if (($nb==$nb_tot)&&($angle==$PI/$pas)) { @@ -332,7 +332,7 @@ sub refresh { #-------------------------------- # Centaines #--------------------------------- - $zinc->translate("$cent",0,-0.01); + $zinc->translate($cent,0,-0.01); my @coords_c1=$zinc->transform($cent,$group1,[$c_c1[0],$c_c1[1]]); if(int($coords_c1[1])==$yc-210){ @@ -351,7 +351,7 @@ sub refresh { #-------------------------------- #Dixaines #--------------------------------- - $zinc->translate("$dix",0,-0.1); + $zinc->translate($dix,0,-0.1); my @coords_d1=$zinc->transform($dix,$group1,[$c_d1[0],$c_d1[1]]); if(int($coords_d1[1])==$yd-210){ @@ -371,7 +371,7 @@ sub refresh { #-------------------------------- # Unites #--------------------------------- - $zinc->translate("$unit",0,-1); + $zinc->translate($unit,0,-1); my @coords_u1=$zinc->transform($unit,$group1,[$c_u1[0],$c_u1[1]]); if($coords_u1[1]==$yu-210){ @@ -397,38 +397,33 @@ sub refresh { # Drag and drop the counter #--------------------------------------------- -$zinc -> bind("$cercle",''=>[sub{ - move_on($_[1],$_[2]); #"move_on" state - },Ev('x'),Ev('y')]); +my ($prev_x, $prev_y); +$zinc -> bind($cercle,''=>[\&move_on] ); + #"move_on" state# sub move_on{ - my ($xi,$yi)=@_; - $zinc -> bind("$cercle",''=>""); - $zinc -> bind("$cercle",''=> - [sub{move($xi,$yi,$_[1],$_[2]); #move the counter - $xi=$_[1]; - $yi=$_[2]; - },Ev('x'),Ev('y')]); - $zinc -> bind("$cercle",''=>sub{ - move_off();}); #"move_off" state + $prev_x=$zinc->XEvent()->x; + $prev_y=$zinc->XEvent()->y; + # move the counter + $zinc -> bind($cercle,''=> [\&move]); + $zinc -> bind($cercle,''=> [\&move_off]); #"move_off" state } #"move_off" state# sub move_off{ - $zinc -> bind("$cercle",''=>[sub{ - move_on($_[1],$_[2]); #"move_on" state - },Ev('x'),Ev('y')]); - $zinc -> bind("$cercle",''=>""); - $zinc -> bind("$cercle",''=>""); + $zinc -> bind($cercle,''=>""); + $zinc -> bind($cercle,''=>""); } #move the counter# sub move{ - my ($xi,$yi,$x,$y)=@_; - $zinc->translate("$clipped_group1",$x-$xi,$y-$yi); - $zinc->translate("$clipped_group2",$x-$xi,$y-$yi); + my $x=$zinc->XEvent()->x, + my $y=$zinc->XEvent()->y; + $zinc->translate($clipped_group1,$x-$prev_x,$y-$prev_y); + $zinc->translate($clipped_group2,$x-$prev_x,$y-$prev_y); + ($prev_x,$prev_y) = ($x,$y); } Tk::MainLoop; -- cgit v1.1