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
|
#!/usr/bin/perl
#
# This short script tries to demonstrate with a simple example what you can
# do with Tk Zinc widget, in particular how to use group item, clipping, and
# transformations.
# $Id$
# this demo has been developped by D. Etienne etienne@cena.fr
#
use Tk;
# Zinc module is loaded...
use Tk::Zinc;
# to find the Wheel class. Should be included in this source file!
use lib Tk->findINC('demos/zinc_pm');
# my Wheel object class too. See below...
use Wheel;
# We create a classical root widget called MainWindow; then we create Zinc
# widget child with size, color and relief attributes, and we display it using
# the geometry manager called 'pack'.
my $mw = MainWindow->new;
$mw->geometry("320x565");
$mw->resizable(0,0);
my $zinc = $mw->Zinc(-width => 300, -height => 500, -backcolor => 'gray70',
-borderwidth => 3, -relief => 'sunken');
$zinc->pack;
# Then we create a gray filled rectangle, in which we will display explain text.
$zinc->add('rectangle', 1 , [10, 400, 290, 490],
-linewidth => 0,
-filled => 1,
-fillcolor => 'gray80',
);
my $text = $zinc->add('text', 1,
-position => [150, 445],
-anchor => 'center',
);
# Create the Wheel object (see Wheel.pm)
my $wheel = Wheel->new($zinc, 150, 500, 100);
# Display comment
&comment("Strike any key to begin");
# Create Tk binding
$mw->Tk::bind('<Key>', \&openmode);
MainLoop;
# Callback bound to '<Key>' event when wheel is unmapped
sub openmode {
return if $wheel->ismoving;
# set binding to unmap the wheel
$mw->Tk::bind('<Key>', \&closemode);
# set binding to rotate the hand
$zinc->bind($wheel, '<1>', sub {$wheel->rotatehand(300)});
# map the wheel
$wheel->show(150, 150);
# and then inform user
&comment("Click on the wheel to rotate the hand.\n".
"Strike any other key to hide the wheel.");
}
# Callback bound to '<Key>' event when wheel is already mapped
sub closemode {
return if $wheel->ismoving;
# set binding to map the wheel
$mw->Tk::bind('<Key>', \&openmode);
# unmap the wheel
$wheel->hide(150, 400);
# and then inform user
&comment("Strike any key to show the wheel");
}
# Just display comment
sub comment {
my $string = shift;
$zinc->itemconfigure($text, -text => $string);
}
|