aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testshape.pl
blob: a55de42c3762e2ab869f949dd5a5e0f74a77ba41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl -w

use Tk;
use Tk::Zinc;
use Controls;

$mw = MainWindow->new();

$top = 1;
$zinc = $mw->Zinc(-render => 1,
		  -borderwidth => 0,
#		  -fullreshape => 0,
		  -relief => 'sunken');
$zinc->pack(-expand => 1, -fill => 'both');
$zinc->configure(-width => 500, -height => 500);

# $arc = $zinc->add('arc', $top, [50, 50, 200, 100],
# 		  -visible => 0);
#$zinc->itemconfigure($top, -clip => $arc);

$view = $zinc->add('group', $top, -tags => "controls");
# $cv = $zinc->add('curve', $view, [50, 50, 100, 150, 270, 70,
# 				 220, 0, 200, 20, 180, 100,
# 				 140, 40, 70, 100],
# 		 -visible => 1,
# 		 -closed => 1,
# 		 -filled => 1);

$arc = $zinc->add('arc', $view, [90,0, 160,50],
		  -visible => 0,
		  -linewidth => 0,
		  -filled => 1,
		  -fillcolor => 'brown');
# $rect = $zinc->add('rectangle', $view, [200,230, 220,250],
# 		   -visible => 1,
# 		   -linewidth => 2,
# 		   -relief => 'sunken',
# 		   -filled => 1,
# 		   -linecolor => 'white',
# 		   -fillcolor => 'tan');
$cv2 = $zinc->add('curve', $view, [],
		  -visible => 1,
		  -linewidth => 2,
		  -linecolor => 'white',
		  -fillcolor => 'tan',
		  -relief => 'sunken',
		  -closed => 1,
		  -filled => 1);
$text = $zinc->add('text', $view,
		   -visible => 1,
		   -text => 'Un Texte ICI',
		   -position => [200, 100],
		   -color => '#008000');
$zinc->contour($cv2, 'add', [[20, 20], [20, 100, 'c'], [120, 100], [120, 20]]);
$zinc->contour($cv2, 'addhole', [40, 40, 80, 40, 80, 80, 40, 80]);
$zinc->contour($cv2, 'add', [60, 50, 60, 60, 70, 60, 70, 50]);
$zinc->contour($cv2, 'addhole', [90, 70, 150, 70, 150, 150, 90, 150]);
$zinc->contour($cv2, 'add', [200, 200, 200, 220, 220, 220, 220, 200]);
$zinc->contour($cv2, 'addhole', [100, 10, 180, 10, 180, 60, 100, 60]);

$zinc->contour($cv2, 'add', $arc);
$zinc->contour($cv2, 'add', $text);

# $rect2 = $zinc->add('rectangle', $view, [40,81, 80,130],
# 		    -visible => 1,
# 		    -linewidth => 1,
# 		    -relief => 'sunken',
# 		    -filled => 1,
# 		    -linecolor => 'white',
# 		    -fillcolor => 'tan');

new Controls($zinc);

$zinc->Tk::bind('<a>', sub {print "hop\n", $zinc->contour($cv2, 'remove', 1);});
$zinc->Tk::bind('<b>', sub {my ($x,$y,$c) = $zinc->coords($cv2, 0, 1);
			    if ($c eq 'c') {
			      $zinc->coords($cv2, 0, 1, [[20, 100]]);
			    }
			    else {
			      $zinc->coords($cv2, 0, 1, [[20, 100, 'c']]);
			    }});
$zinc->Tk::bind('<1>', sub {
		  my $ev = $zinc->XEvent();
		  my $it = $zinc->find('closest', $ev->x, $ev->y);
		  my @t = $zinc->vertexat($it, $ev->x, $ev->y);
		  print "Closest: $it\n";
		  print "VertexAt: ", join(', ', @t), "\n";
		});

$zinc->focusFollowsMouse();

MainLoop();