From dc7ba0ba0d6b904a2788b01fafb840ebacdb07dd Mon Sep 17 00:00:00 2001 From: mertz Date: Thu, 2 Jan 2003 14:58:29 +0000 Subject: handles are now movable... to modify the bezier curves --- Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl | 281 +++++++++++++++------------ 1 file changed, 154 insertions(+), 127 deletions(-) (limited to 'Perl') diff --git a/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl b/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl index 0d57306..652f878 100644 --- a/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl +++ b/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl @@ -1,8 +1,8 @@ #!/usr/bin/perl -w -# $Id$ +# $Id: curve_bezier.pl,v 1.1 2002/12/20 12:28:38 # This simple demo has been developped by C. Mertz -####### This file has been inspired from svg examples +####### This file has been initially inspired from svg examples use Tk::Zinc; @@ -11,12 +11,13 @@ my $mw = MainWindow->new(); $mw->title('example of curves with cubic control points'); my $text = $mw->Text (-relief => 'sunken', -borderwidth => 2, - -setgrid => 'true', -height =>2); + -setgrid => 'true', -height =>3); $text->pack(qw/-expand yes -fill both/); $text->insert('0.0', -'6 examples of curves containig control points are displayed, - with the list of control points written just below.'); +'6 examples of curves containing control points are displayed, + with the list of control points written just below. +You can move the handles to modify the bezier curves'); my $zinc = $mw->Zinc(-width => 700, -height => 650, @@ -24,7 +25,7 @@ my $zinc = $mw->Zinc(-width => 700, -height => 650, -font => "9x15", -borderwidth => 0, -backcolor => "white", - -forecolor => "grey50", + -forecolor => "grey80", )->pack; my $group = $zinc->add('group', 1); @@ -33,107 +34,136 @@ $zinc->add('text',$group, -position => [50,20], -anchor => 'w', -text => "Examples of curve items using cubic bezier control points", -color => "grey20"); -$zinc->add('text',$group, -position => [25,270], -anchor => 'w', - -text => "[ [100, 200], [100, 100, 'c'],\n [400, 100, 'c'], [400, 200] ]"); -$zinc->add('curve',$group,[100, 200, 100, 100], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[400, 100, 400, 200], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); +## Please note: much of the following items below could be computed +$zinc->add('text',$group, -position => [25,270], -anchor => 'w', -tags => ['bezier1'], -color => "grey20"); +$zinc->add('curve',$group,[100, 200, 100, 100], -tags => ['line1', 'l1-2'], -linecolor => "#888888", -filled => 0, -linewidth => 2); +$zinc->add('curve',$group,[400, 100, 400, 200], -tags => ['line1', 'l3-4'], -linecolor => "#888888", -filled => 0, -linewidth => 2); $zinc->add('curve',$group,[[100, 200], [100, 100, 'c'], [400, 100, 'c'], [400, 200]], - -tags => ['curve_bezier'], -filled => 1, -closed => 0, -linecolor => "red", -filled => 0, -linewidth => 5); -$zinc->add('arc',$group,[90, 190, 110, 210], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('arc',$group,[90, 90, 110, 110], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[390, 90, 410, 110], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[390, 190, 410, 210], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); - -$zinc->add('text',$group, -position => [570,270], -anchor => 'w', - -text => "[ [600, 200], [675, 100, 'c'],\n [975, 100, 'c'], [900, 200] ]"); -$zinc->add('curve',$group,[600, 200, 675, 100], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[975, 100, 900, 200], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); + -tags => ['bezier1'], -closed => 0, -linecolor => "red", -linewidth => 5); +$zinc->add('arc',$group,[90, 190, 110, 210], -tags => ['handle1',"p1"], -filled => 1, -fillcolor => "#BBBBBB"); +$zinc->add('arc',$group,[90, 90, 110, 110], -tags => ['handle1',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1); +$zinc->add('arc',$group,[390, 90, 410, 110], -tags => ['handle1',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1); +$zinc->add('arc',$group,[390, 190, 410, 210], -tags => ['handle1',"p4"], -filled => 1, -fillcolor => "#BBBBBB"); + +$zinc->add('text',$group, -position => [570,270], -anchor => 'w', -tags => ['bezier2'], -color => "grey20"); +$zinc->add('curve',$group,[600, 200, 675, 100], -tags => ['line2', 'l1-2'], -linecolor => "#888888", -linewidth => 2); +$zinc->add('curve',$group,[975, 100, 900, 200], -tags => ['line2', 'l3-4'], -linecolor => "#888888", -linewidth => 2); $zinc->add('curve',$group,[[600, 200], [675, 100, 'c'], [975, 100, 'c'], [900, 200]], - -tags => ['curve_bezier'], -filled => 1, -closed => 0, -linecolor => "red", -filled => 0, -linewidth => 5); -$zinc->add('arc',$group,[590, 190, 610, 210], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('arc',$group,[665, 90, 685, 110], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[965, 90, 985, 110], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[890, 190, 910, 210], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); - -$zinc->add('text',$group, -position => [25,570], -anchor => 'w', - -text => "[ [100, 500], [25, 400, 'c'],\n [475, 400, 'c'], [400, 500] ]"); -$zinc->add('curve',$group,[100, 500, 25, 400], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[475, 400, 400, 500], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); + -tags => ['bezier2'], -closed => 0, -linecolor => "red", -linewidth => 5); +$zinc->add('arc',$group,[590, 190, 610, 210], -tags => ['handle2',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2); +$zinc->add('arc',$group,[665, 90, 685, 110], -tags => ['handle2',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80"); +$zinc->add('arc',$group,[965, 90, 985, 110], -tags => ['handle2',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80"); +$zinc->add('arc',$group,[890, 190, 910, 210], -tags => ['handle2',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2); + +$zinc->add('text',$group, -position => [25,570], -anchor => 'w', -tags => ['bezier3'], -color => "grey20"); +$zinc->add('curve',$group,[100, 500, 25, 400], -tags => ['line3', 'l1-2'], -linecolor => "#888888", -linewidth => 2); +$zinc->add('curve',$group,[475, 400, 400, 500], -tags => ['line3', 'l3-4'], -linecolor => "#888888", -linewidth => 2); $zinc->add('curve',$group,[[100, 500], [25, 400, 'c'], [475, 400, 'c'], [400, 500]], - -tags => ['curve_bezier'], -filled => 1, -closed => 0, -linecolor => "red", -filled => 0, -linewidth => 5); -$zinc->add('arc',$group,[90, 490, 110, 510], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('arc',$group,[15, 390, 35, 410], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[465, 390, 485, 410], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[390, 490, 410, 510], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); - -$zinc->add('text',$group, -position => [570,570], -tags => ['text'], -anchor => 'w', -text => "[ [600, 500], [600, 350, 'c'],\n [900, 650, 'c'], [900, 500] ]"); -$zinc->add('curve',$group,[600, 500, 600, 350], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[900, 650, 900, 500], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[[600, 500], [600, 350, 'c'], [900, 650, 'c'], [900, 500]], -tags => ['curve_bezier'], -filled => 1, -closed => 0, -linecolor => "red", -filled => 0, -linewidth => 5); -$zinc->add('arc',$group,[590, 490, 610, 510], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('arc',$group,[590, 340, 610, 360], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[890, 640, 910, 660], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[890, 490, 910, 510], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); - -$zinc->add('text',$group, -position => [25,870], -tags => ['text'], -anchor => 'w', - -text => "[ [100, 800], [175, 700, 'c'],\n [325, 700, 'c'], [400, 800] ]"); -$zinc->add('curve',$group,[100, 800, 175, 700], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[325, 700, 400, 800], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); + -tags => ['bezier3'], -closed => 0, -linecolor => "red", -linewidth => 5); +$zinc->add('arc',$group,[90, 490, 110, 510], -tags => ['handle3',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2); +$zinc->add('arc',$group,[15, 390, 35, 410], -tags => ['handle3',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", ); +$zinc->add('arc',$group,[465, 390, 485, 410], -tags => ['handle3',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", ); +$zinc->add('arc',$group,[390, 490, 410, 510], -tags => ['handle3',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2); + +$zinc->add('text',$group, -position => [570,570], -anchor => 'w', -tags => ['bezier4'], -color => "grey20"); +$zinc->add('curve',$group,[600, 500, 600, 350], -tags => ['line4', 'l1-2'], -linecolor => "#888888", -linewidth => 2); +$zinc->add('curve',$group,[900, 650, 900, 500], -tags => ['line4', 'l3-4'], -linecolor => "#888888", -linewidth => 2); +$zinc->add('curve',$group,[[600, 500], [600, 350, 'c'], [900, 650, 'c'], [900, 500]], -tags => ['bezier4'], -closed => 0, -linecolor => "red", -linewidth => 5); +$zinc->add('arc',$group,[590, 490, 610, 510], -tags => ['handle4',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2); +$zinc->add('arc',$group,[590, 340, 610, 360], -tags => ['handle4',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80"); +$zinc->add('arc',$group,[890, 640, 910, 660], -tags => ['handle4',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80"); +$zinc->add('arc',$group,[890, 490, 910, 510], -tags => ['handle4',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2); + +$zinc->add('text',$group, -position => [25,870], -anchor => 'w', -tags => ['bezier5'], -color => "grey20"); +$zinc->add('curve',$group,[100, 800, 175, 700], -tags => ['line5', 'l1-2'], -linecolor => "#888888", -filled => 0, -linewidth => 2); +$zinc->add('curve',$group,[325, 700, 400, 800], -tags => ['line5', 'l3-4'], -linecolor => "#888888", -filled => 0, -linewidth => 2); $zinc->add('curve',$group,[[100, 800], [175, 700, 'c'], [325, 700, 'c'], [400, 800]], - -tags => ['curve_bezier'], -filled => 1, -closed => 0, -linecolor => "red", -filled => 0, -linewidth => 5); -$zinc->add('arc',$group,[90, 790, 110, 810], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('arc',$group,[165, 690, 185, 710], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[315, 690, 335, 710], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[390, 790, 410, 810], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); - -$zinc->add('text',$group, -position => [570,980], -tags => ['text'], -anchor => 'w', - -text => "[ [600, 800], [625, 700, 'c'],\n [725, 700, 'c'], [750, 800],\n [775, 900, 'c'], [875, 900, 'c'],\n [900, 800] ]"); -$zinc->add('curve',$group,[600, 800, 625, 700], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[725, 700, 750, 800], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[750, 800, 775, 900], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('curve',$group,[875, 900, 900, 800], -tags => ['polyline'], -linecolor => "#888888", -filled => 0, -linewidth => 2); + -tags => ['bezier5'], -closed => 0, -linecolor => "red", -linewidth => 5); +$zinc->add('arc',$group,[90, 790, 110, 810], -tags => ['handle5',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2); +$zinc->add('arc',$group,[165, 690, 185, 710], -tags => ['handle5',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1); +$zinc->add('arc',$group,[315, 690, 335, 710], -tags => ['handle5',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80", -filled => 1); +$zinc->add('arc',$group,[390, 790, 410, 810], -tags => ['handle5',"p4"], -filled => 1, -linecolor => "grey80", -linewidth => 2); + +$zinc->add('text',$group, -position => [570,980], -anchor => 'w', -tags => ['bezier6'], -color => "grey20"); +$zinc->add('curve',$group,[600, 800, 625, 700], -tags => ['line6', 'l1-2'], -linecolor => "#888888", -linewidth => 2); +$zinc->add('curve',$group,[725, 700, 750, 800], -tags => ['line6', 'l3-4'], -linecolor => "#888888", -linewidth => 2); +$zinc->add('curve',$group,[750, 800, 775, 900], -tags => ['line6', 'l4-5'], -linecolor => "#888888", -linewidth => 2); +$zinc->add('curve',$group,[875, 900, 900, 800], -tags => ['line6', 'l6-7'], -linecolor => "#888888", -linewidth => 2); $zinc->add('curve',$group,[[600, 800], [625, 700, 'c'], [725, 700, 'c'], [750, 800], [775, 900, 'c'], [875, 900, 'c'], [900, 800]], - -tags => ['curve_bezier'], -filled => 1, -closed => 0, -linecolor => "red", -filled => 0, -linewidth => 5); -$zinc->add('arc',$group,[590, 790, 610, 810], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('arc',$group,[615, 690, 635, 710], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[715, 690, 735, 710], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[740, 790, 760, 810], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); -$zinc->add('arc',$group,[766, 891, 784, 909], -tags => ['circle'], -filled => 1, -linecolor => "blue", -filled => 0, -linewidth => 4); -$zinc->add('arc',$group,[865, 890, 885, 910], -tags => ['circle'], -filled => 1, -linewidth => 0, -fillcolor => "#888888", -filled => 1); -$zinc->add('arc',$group,[890, 790, 910, 810], -tags => ['circle'], -filled => 1, -linecolor => "#888888", -filled => 0, -linewidth => 2); + -tags => ['bezier6'], -filled => 0, -closed => 0, -linecolor => "red", -linewidth => 5); +$zinc->add('arc',$group,[590, 790, 610, 810], -tags => ['handle6',"p1"], -filled => 1, -linecolor => "grey80", -linewidth => 2); +$zinc->add('arc',$group,[615, 690, 635, 710], -tags => ['handle6',"p2"], -filled => 1, -linewidth => 0, -fillcolor => "grey80"); +$zinc->add('arc',$group,[715, 690, 735, 710], -tags => ['handle6',"p3"], -filled => 1, -linewidth => 0, -fillcolor => "grey80"); +$zinc->add('arc',$group,[740, 790, 760, 810], -tags => ['handle6',"p4"], -filled => 1, -linecolor => "blue",-fillcolor => "blue", -linewidth => 2); +$zinc->add('arc',$group,[766, 891, 784, 909], -tags => ['handle6',"p5"], -filled => 1, -linecolor => "grey80", -linewidth => 4); +$zinc->add('arc',$group,[865, 890, 885, 910], -tags => ['handle6',"p6"], -filled => 1, -linewidth => 0, -fillcolor => "grey80"); +$zinc->add('arc',$group,[890, 790, 910, 810], -tags => ['handle6',"p7"], -filled => 1, -linecolor => "grey80", -linewidth => 2); $zinc->scale($group, 0.6, 0.6); +## Set the text of the text item with a tag "tag" +## to a human-readable form of the coords of the +## corresponding curve with the same tag "tag" +sub setText { + my ($tag) = @_; + my $textItem = $zinc->find("withtype", 'text', $tag); + my $curveItem = $zinc->find("withtype", 'curve', $tag); + my @coords = $zinc->coords($curveItem); + my $count = 0; + my $text = "[ "; + while (@coords) { + $refXYc = pop @coords; + my $x=$refXYc->[0]; + my $y=$refXYc->[1]; + my $t=$refXYc->[2]; + $t = (defined $t) ? ", '".$t."'" : "" ; + $text .= "[$x, $y$t]"; + if (@coords) { $text .= ", "; } + if ($count and @coords) { + $text .= "\n "; + $count =0; + } else { + $count++; + } + } + $text .= " ]"; + $zinc->itemconfigure($textItem, -text => $text); +} +foreach my $bezierCount (1..6) { + &setText ("bezier".$bezierCount); + my $curveItem = $zinc->find("withtype", 'curve', "bezier".$bezierCount); + my @coords = $zinc->coords($curveItem); +# print "$bezierCount : ", scalar @coords, "\n"; + $zinc->bind("handle$bezierCount", '', [\&press, \&motion]); + $zinc->bind("handle$bezierCount", '', [\&release]); +} -### on ajoute quelques binding bien pratiques pour la mise au point - -$zinc->Tk::bind('', [\&press, \&motion]); -$zinc->Tk::bind('', [\&release]); -$zinc->Tk::bind('', [\&press, \&zoom]); -$zinc->Tk::bind('', [\&release]); -# $zinc->Tk::bind('', [\&press, \&mouseRotate]); -# $zinc->Tk::bind('', [\&release]); -$zinc->bind('all', '', - [ sub { my ($z)=@_; my $i=$z->find('withtag', 'current'); - my @tags = $z->gettags($i); - pop @tags; # pour enlever 'current' - print "$i (", $z->type($i), ") [@tags] -";}] ); &Tk::MainLoop; -##### bindings for moving, rotating, scaling the items -my ($cur_x, $cur_y, $cur_angle); +##### bindings for moving the handles +my ($cur_x, $cur_y,$item, $bezierNum, $ptNum); sub press { my ($zinc, $action) = @_; my $ev = $zinc->XEvent(); $cur_x = $ev->x; $cur_y = $ev->y; - $cur_angle = atan2($cur_y, $cur_x); - $zinc->Tk::bind('', [$action]); + $item = $zinc->find('withtag', 'current'); + $zinc->bind($item, '', [$action]); + foreach ( $zinc->gettags($item) ) { + ## looking for the tag "handlei" + if ( /^handle(\d+)$/ ) { + $bezierNum = $1; + } + ## looking for the tag "pj" + if ( /^p(\d+)$/ ) { + $ptNum = $1; + } + } + print "bezierNum=$bezierNum ptNum=$ptNum\n"; } sub motion { @@ -141,51 +171,48 @@ sub motion { my $ev = $zinc->XEvent(); my $lx = $ev->x; my $ly = $ev->y; - my @res = $zinc->transform($top_group, [$lx, $ly, $cur_x, $cur_y]); - $zinc->translate($top_group, $res[0] - $res[2], $res[1] - $res[3]); + my ($dx,$dy) = $zinc->transform($group, [$lx-$cur_x, $ly-$cur_y]); + &moveHandle($item,$dx,$dy); + my ($pt1,$pt2) = $zinc->coords($item); +# print "coords=",@{$pt1}, " ",@{$pt2},"\n"; $cur_x = $lx; $cur_y = $ly; } -sub zoom { - my ($zinc, $self) = @_; - my $ev = $zinc->XEvent(); - my $lx = $ev->x; - my $ly = $ev->y; - my $maxx; - my $maxy; - my $sx; - my $sy; - - if ($lx > $cur_x) { - $maxx = $lx; - } else { - $maxx = $cur_x; - } - if ($ly > $cur_y) { - $maxy = $ly - } else { - $maxy = $cur_y; - } - return if ($maxx == 0 || $maxy == 0); - $sx = 1.0 + ($lx - $cur_x)/$maxx; - $sy = 1.0 + ($ly - $cur_y)/$maxy; - $cur_x = $lx; - $cur_y = $ly; - $zinc->scale($top_group, $sx, $sx); #$sy); -} - -sub mouseRotate { +sub release { my ($zinc) = @_; - my $ev = $zinc->XEvent(); - my $lx = $ev->x; - my $ly = $ev->y; - my $langle = atan2($ly, $lx); - $zinc->rotate($top_group, -($langle - $cur_angle)); - $cur_angle = $langle; + $zinc->bind($item,'', ''); + $item = ""; } -sub release { - my ($zinc) = @_; - $zinc->Tk::bind('', ''); +sub moveHandle { + my ($item,$dx,$dy) = @_; + my ($pt1,$pt2) = $zinc->coords($item); + ## modifying the handle coords + $zinc->coords($item, [ $pt1->[0]+$dx, $pt1->[1]+$dy, $pt2->[0]+$dx, $pt2->[1]+$dy]); + my $prevPtNum = $ptNum-1; + # there should only be one such item! + my $lineA = $zinc->find("withtag", "line$bezierNum && l$prevPtNum-$ptNum"); + if (defined $lineA) { + my ($x,$y) = $zinc->coords($lineA,0,1); # to get the 2nd point coords + $zinc->coords($lineA, 0,1, [ $x+$dx, $y+$dy ]); + } + + my $nextPtNum = $ptNum+1; + # there should only be one such item: + my ($lineB) = $zinc->find("withtag", "line$bezierNum && l$ptNum-$nextPtNum"); + if (defined $lineB) { + my ($x,$y) = $zinc->coords($lineB,0,0); # to get the 1st point coords + $zinc->coords($lineB, 0,0, [ $x+$dx, $y+$dy ] ); + } + + ## correctif d'erreur (zinc 3.2.6e) + my @coords = $zinc->coords("bezier$bezierNum", 0); + $num = $#coords +1 - $ptNum; + + my ($x,$y,$control) = $zinc->coords("bezier$bezierNum", 0,$num); + $zinc->coords("bezier$bezierNum", 0,$num, [ [$x+$dx, $y+$dy, $control] ] ); + &setText ("bezier$bezierNum"); + } + -- cgit v1.1