aboutsummaryrefslogtreecommitdiff
path: root/Perl/demos/Tk/demos/zinc_lib/zoom.pl
blob: 342627575377950c70b76d26747c76c04981bc46 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/perl
# $Id: zoom.pl 1420 2004-04-30 11:35:18Z lecoanet $
# This simple demo has been developped by C. Schlienger <celine@intuilab.com>

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision: 1420 $ =~ /(\d+)\.(\d+)/);


use Tk;
use Tk::Zinc;
use strict;


my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();

###########################################
# Text zone
###########################################

my $text = $mw->Text(-relief => 'sunken', -borderwidth => 2, -height => 4);
$text->pack(qw/-expand yes -fill both/);

$text->insert('0.0',
	      'This toy-appli shows zoom actions on waypoint and curve items.
The following operations are possible:
   Click "-" to zoom out
   Click "+" to zoom in ' );

###########################################
# Zinc
###########################################
my $zinc_width=600;
my $zinc_height=500;
my $zinc = $mw->Zinc(-width => $zinc_width, -height => $zinc_height,
		     -font => "10x20",
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

###########################################
# Waypoints and sector
###########################################

my $wp_group = $zinc->add('group', 1, -visible => 1);

my $p1=[200, 100];
my $wp1 = $zinc->add('waypoint',$wp_group, 1,
		    -position => $p1,
		    -connectioncolor => 'green',
		    -symbolcolor => 'blue',
		    -labelformat => 'x20x18+0+0',
		    -leaderwidth=>'0',
		    -labeldx=>'-20'
		   );
$zinc->itemconfigure($wp1, 0,
		     -text => "DO",
		    );

my $p2=[300, 150];
my $wp2 = $zinc->add('waypoint',$wp_group, 1,
		     -position => $p2,
		     -connecteditem => $wp1,
		     -connectioncolor => 'blue',
		     -symbolcolor => 'blue',
		     -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldx=>'-20',
		    );

$zinc->itemconfigure($wp2, 0,
		     -text => "RE",
		    );

my $p3=[400, 50];
my $wp3 = $zinc->add('waypoint', $wp_group, 2,
		     -position => $p3,
		     -connecteditem => $wp2,
		     -connectioncolor => 'blue',
		     -symbolcolor => 'blue',
		     -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldx=>'20',
		     -labeldy=>'+10'
		    );
$zinc->itemconfigure($wp3, 0,
		     -text => "MI",
		    );

my $p4=[350, 450];
my $wp4 = $zinc->add('waypoint', $wp_group, 2,
			     -position => $p4,
			     -connecteditem => $wp2,
			     -connectioncolor => 'blue',
			     -symbolcolor => 'blue',
		    -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldy=>'-15'
		    );
$zinc->itemconfigure($wp4, 0,
		     -text => "FA",
		    );

		    
my $p5=[300, 250];
my $wp5 = $zinc->add('waypoint', $wp_group, 2,
		     -position => $p5,
		     -connectioncolor => 'blue',
		     -symbolcolor => 'blue',
		     -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldy=>'-15'
		    );
$zinc->itemconfigure($wp5, 0,
		     -text => "SOL",
		    );


my $p6=[170, 240];
my $wp6 = $zinc->add('waypoint', $wp_group, 2,
		     -position => $p6,
		     -connecteditem => $wp5,
		     -connectioncolor => 'blue',
		     -symbolcolor => 'blue',
		     -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldx=>'-20'
		    );
$zinc->itemconfigure($wp6, 0,
		     -text => "LA",
		    );

my $p7=[550, 200];
my $wp7 = $zinc->add('waypoint', $wp_group, 2,
		     -position => $p7,
		     -connecteditem => $wp5,
		     -connectioncolor => 'blue',
		     -symbolcolor => 'blue',
		     -labelformat => 'x20x18+0+0',
		     -leaderwidth=>'0',
		     -labeldx=>'20'
		    );
$zinc->itemconfigure($wp7, 0,
		     -text => "SI",
		    );


my $sector = $zinc ->add('curve',$wp_group,[300,0,400,50,500,100,550,200,550,400,350,450,170,240,200,100,300,0]);

###################################################
# control panel
###################################################
my $rc = $mw->Frame()->pack();

#the reference of the scale function is top-left corner of the zinc object
#so we first translate the group to zoom in order to put its center on top-left corner
#change the scale of the group
#translate the group to put it back at the center of the zinc object 

my $minus=$rc->Button(-width => 2, 
		      -height => 2,
		      -text => '-',
		      -command=>sub{
			$zinc->translate($wp_group,-$zinc_width/2,-$zinc_height/2);
			$zinc->scale($wp_group,0.8,0.8);
			$zinc->translate($wp_group, $zinc_width/2,$zinc_height/2);
		      })->pack(-side=>'left');


my $plus=$rc->Button(-width => 2, 
		     -height => 2,
		     -text => '+',
		     -command=>sub{
		       $zinc->translate($wp_group, -$zinc_width/2,-$zinc_height/2);
		       $zinc->scale($wp_group,1.2,1.2);
		       $zinc->translate($wp_group,$zinc_width/2,$zinc_height/2);
		     })->pack(-side => 'right');



MainLoop;