diff options
author | mertz | 2002-12-16 13:47:12 +0000 |
---|---|---|
committer | mertz | 2002-12-16 13:47:12 +0000 |
commit | 53b02dcf0649b1a22c824f756e399df35ffdea68 (patch) | |
tree | 6691e3f379cde06bcf94ae1de90aab7ab6123770 /Perl | |
parent | b61d0a7b82507da05fe575f8b2ddde43a545cd16 (diff) | |
download | tkzinc-53b02dcf0649b1a22c824f756e399df35ffdea68.zip tkzinc-53b02dcf0649b1a22c824f756e399df35ffdea68.tar.gz tkzinc-53b02dcf0649b1a22c824f756e399df35ffdea68.tar.bz2 tkzinc-53b02dcf0649b1a22c824f756e399df35ffdea68.tar.xz |
Simplification de la d�mo, notamment avec simplification de la m�thode contour
Diffstat (limited to 'Perl')
-rw-r--r-- | Perl/demos/Tk/demos/zinc_lib/contours.pl | 90 |
1 files changed, 42 insertions, 48 deletions
diff --git a/Perl/demos/Tk/demos/zinc_lib/contours.pl b/Perl/demos/Tk/demos/zinc_lib/contours.pl index 039c159..8907dda 100644 --- a/Perl/demos/Tk/demos/zinc_lib/contours.pl +++ b/Perl/demos/Tk/demos/zinc_lib/contours.pl @@ -13,20 +13,19 @@ my $mw = MainWindow->new(); # The explanation displayed when running this demo my $text = $mw->Scrolled(qw/Text -relief sunken -borderwidth 2 -setgrid true - -height 10 -scrollbars e/); + -height 9 -scrollbars e/); $text->pack(qw/-expand yes -fill both/); $text->insert('0.0', -'All visibles items are made by combinig 2 items using contours: - - the firebrick curve1 has been holed using a diff with a circle, - - the lightblue curve2 is the intersection with a circle, - - the yellow curve3 is the union with a circle, - - the dark green curve4 has benn XORed with a circle, - - the grey curve5 is diff-ed, xor-ed and union-ed with many circle. +'All visibles items are made by combining 2 items using contours: + - the firebrick curve1 has been holed using a addhole with a circle, + - the lightblue curve2 has been "mickey-moused" by adding two circles, + - the yellow curve3 is the union with a disjoint circle, + - the grey curve4 is added to and holed with with many circle. The following operations are possible: - "Mouse Button 1" for dragging objects. - "Mouse Button 1" for dragging the black handle and - modifying the curve5 contour.'); + - "Mouse Button 1" for dragging objects. + - "Mouse Button 1" for dragging the black handle and + modifying the grey curve contour.'); # Creating the zinc widget my $zinc = $mw->Zinc(-width => 600, -height => 500, @@ -42,7 +41,7 @@ my $zinc = $mw->Zinc(-width => 600, -height => 500, my $curve0 = $zinc->add('curve', 1, [0,100 , 100,0, 300,0 , 400,100, 300,200, 100,200], -closed => 1, -visible => 0, -filled => 1, ); -my $cercle100 = $zinc->add('arc', 1, [150,50, 250,150], +my $cercle100 = $zinc->add('arc', 1, [130,30, 280,180], -visible => 0, ); @@ -57,8 +56,13 @@ my $curve2 = $zinc->clone($curve0, -visible => 1, -fillcolor => "lightblue2"); $zinc->translate($curve2,100,90); # adding an 'intersection' contour to the curve2 $zinc->contour($curve2, 'add', $cercle100); + +$zinc->translate($curve2,-200,0); +# adding an 'intersection' contour to the curve2 +$zinc->contour($curve2, 'add', $cercle100); + # ... translate to make it more visible -$zinc->translate($curve2, -10,20); +$zinc->translate($curve2, 320,20); # cloning curve0 as curve3 and moving it @@ -67,53 +71,48 @@ $zinc->translate($curve3,0,290); # adding an 'union' contour to the curve3 $zinc->contour($curve3, 'add', $cercle100); # ... translate to make it more visible -$zinc->translate($curve3, -50,-100); +$zinc->translate($curve3, -130,00); -# cloning curve0 as curve4 and moving it slightly -my $curve4 = $zinc->clone($curve0, -visible => 1, -fillcolor => "DarkGreen"); -$zinc->translate($curve4,-20,-90); -# adding an 'XOR' contour to the curve4 -$zinc->contour($curve4, 'addhole', $cercle100); -# ... translate to make it more visible -$zinc->translate($curve4, 230,130); - - -# cloning curve0 as curve5 and moving it slightly -my $curve5 = $zinc->clone($curve0, -visible => 1, -fillcolor => "grey50", +# cloning curve0 as curve4 and moving it slightly +my $curve4 = $zinc->clone($curve0, -visible => 1, -fillcolor => "grey50", -tags => ["grouped"], - # tag "grouped" of curve5 and a handle (see just below) - # is used for easily translating both + # the tag "grouped" is used for both curve4 and + # a handle (see just below) + # It is used for translating both easily ); -my ($x,$y) = $zinc->coords($curve5,0,1); +my ($x,$y) = $zinc->coords($curve4,0,1); my $handle = $zinc->add('rectangle', 1, [$x-5,$y-5,$x+5,$y+5], -fillcolor => 'black', -filled => 1, -tags => ["grouped"], ); -# adding a 'difference' contour to the curve5 -$zinc->contour($curve5, 'addhole', $cercle100); +# adding a 'difference' contour to the curve4 +$zinc->contour($curve4, 'addhole', $cercle100); $zinc->translate('grouped',110,0); -$zinc->contour($curve5, 'addhole', $cercle100); +$zinc->contour($curve4, 'addhole', $cercle100); $zinc->translate('grouped',-220,0); -$zinc->contour($curve5, 'add', $cercle100); +$zinc->contour($curve4, 'add', $cercle100); $zinc->translate('grouped',110,80); -$zinc->contour($curve5, 'add', $cercle100); +$zinc->contour($curve4, 'add', $cercle100); $zinc->translate('grouped',0,-160); -$zinc->contour($curve5, 'add', $cercle100); +$zinc->contour($curve4, 'add', $cercle100); $zinc->translate('grouped',200,80); -$zinc->contour($curve5, 'addhole', $cercle100); +$zinc->contour($curve4, 'addhole', $cercle100); $zinc->translate('grouped',-350,0); -$zinc->contour($curve5, 'add', $cercle100); +$zinc->contour($curve4, 'add', $cercle100); $zinc->translate('grouped',350,250); +#$zinc->lower('grouped'); # Deleting no more usefull items: curve0 and cercle100: $zinc->remove($curve0, $cercle100); +$zinc->raise($curve1); + # adding drag and drop callback to each visible curve! foreach my $item ($curve1, $curve2, $curve3, $curve4) { # Some bindings for dragging the items @@ -121,11 +120,11 @@ foreach my $item ($curve1, $curve2, $curve3, $curve4) { $zinc->bind($item, '<ButtonRelease-1>' => \&release); } -# adding drag and drop on curve5 which also moves handle -$zinc->bind($curve5, '<ButtonPress-1>' => [\&press, $curve5, \&motionWithHandle]); -$zinc->bind($curve5, '<ButtonRelease-1>' => \&release); +# adding drag and drop on curve4 which also moves handle +$zinc->bind($curve4, '<ButtonPress-1>' => [\&press, $curve4, \&motionWithHandle]); +$zinc->bind($curve4, '<ButtonRelease-1>' => \&release); -# adding drag and drop on handle which also modify curve5 +# adding drag and drop on handle which also modify curve4 $zinc->bind($handle, '<ButtonPress-1>' => [\&press, $handle, \&moveHandle]); $zinc->bind($handle, '<ButtonRelease-1>' => \&release); @@ -164,8 +163,7 @@ sub motionWithHandle { $y_orig = $y; } -# BUG BUG BUG -# Callback for moving the handle and modifying curve5 +# Callback for moving the handle and modifying curve4 # this code is far from being generic. Only for demonstrating how we can # modify a contour with a unique handle! sub moveHandle { @@ -175,12 +173,9 @@ sub moveHandle { my $y = $ev->y; $zinc->translate($handle, $x-$x_orig, $y-$y_orig); - print "Translating of ", $x-$x_orig, ",", $y-$y_orig, "\n"; - # LA LIGNE SUIVANTE EST OK LA 1ERE FOIS ET BUGGUE LES SUIVANTES! - # NB: CELA MARCHOTTE POUR LE CONTOUR 0, MAIS CE N'EST PAS CORRECT! - my ($vertxX,$vertxY) = $zinc->coords($curve5,0,1); - print "Vertex: $vertxX,$vertxY\n"; - $zinc->coords($curve5,0,1, [$vertxX+($x-$x_orig), $vertxY+($y-$y_orig)]); + + my ($vertxX,$vertxY) = $zinc->coords($curve4,0,1); + $zinc->coords($curve4,0,1, [$vertxX+($x-$x_orig), $vertxY+($y-$y_orig)]); $x_orig = $x; $y_orig = $y; } @@ -191,7 +186,6 @@ sub release { $zinc->Tk::bind('<Motion>', ''); } -print "1\n"; Tk::MainLoop(); |