aboutsummaryrefslogtreecommitdiff
path: root/Perl/demos
diff options
context:
space:
mode:
Diffstat (limited to 'Perl/demos')
-rw-r--r--Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl191
-rw-r--r--Perl/demos/zinc-demos1
2 files changed, 192 insertions, 0 deletions
diff --git a/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl b/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl
new file mode 100644
index 0000000..0d57306
--- /dev/null
+++ b/Perl/demos/Tk/demos/zinc_lib/curve_bezier.pl
@@ -0,0 +1,191 @@
+#!/usr/bin/perl -w
+# $Id$
+# This simple demo has been developped by C. Mertz <mertz@cena.fr>
+
+####### This file has been inspired from svg examples
+
+use Tk::Zinc;
+
+
+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);
+$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.');
+
+
+my $zinc = $mw->Zinc(-width => 700, -height => 650,
+ -font => "10x20",
+ -font => "9x15",
+ -borderwidth => 0,
+ -backcolor => "white",
+ -forecolor => "grey50",
+ )->pack;
+
+my $group = $zinc->add('group', 1);
+
+$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);
+$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);
+$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);
+$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);
+$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);
+$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);
+
+$zinc->scale($group, 0.6, 0.6);
+
+
+
+### on ajoute quelques binding bien pratiques pour la mise au point
+
+$zinc->Tk::bind('<ButtonPress-1>', [\&press, \&motion]);
+$zinc->Tk::bind('<ButtonRelease-1>', [\&release]);
+$zinc->Tk::bind('<ButtonPress-2>', [\&press, \&zoom]);
+$zinc->Tk::bind('<ButtonRelease-2>', [\&release]);
+
+# $zinc->Tk::bind('<ButtonPress-3>', [\&press, \&mouseRotate]);
+# $zinc->Tk::bind('<ButtonRelease-3>', [\&release]);
+$zinc->bind('all', '<Enter>',
+ [ 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);
+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('<Motion>', [$action]);
+}
+
+sub motion {
+ my ($zinc) = @_;
+ 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]);
+ $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 {
+ 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;
+}
+
+sub release {
+ my ($zinc) = @_;
+ $zinc->Tk::bind('<Motion>', '');
+}
diff --git a/Perl/demos/zinc-demos b/Perl/demos/zinc-demos
index 8d0c5e1..f1d58ed 100644
--- a/Perl/demos/zinc-demos
+++ b/Perl/demos/zinc-demos
@@ -156,6 +156,7 @@ $T->insert('end', "3. Examples of line style and line termination.\n", [qw/demo
$T->insert('end', "4. Curves with multiple contours.\n", [qw/demo demo-contours/]);
$T->insert('end', "5. Examples of labelformat.\n", [qw/demo demo-labelformat/]);
$T->insert('end', "6. Use of mapinfos.\n", [qw/demo demo-mapinfo/]);
+$T->insert('end', "7. Example of curves with cubic bezier control points.\n", [qw/demo demo-curve_bezier/]);
$T->insert('end', "\n", '', "Groups, Priority and Clipping\n", 'title');