3
4
use subs qw/floor_bg1 floor_bg2 floor_bg3 floor_display floor_fg1 floor_fg2
4
5
floor_fg3 floor_room_changed/;
9
# Create a top-level window containing a canvas that displays the
10
# Create a top-level window containing a Canvas that displays the
10
11
# floorplan for DEC's Western Research Laboratory.
21
22
-borderwidth 2 -scrollbars se/);
22
23
$c->pack(qw/-expand yes -fill both/);
24
# Create an entry for displaying and typing in current room.
25
untie $floor::current_room;
25
# Create an Entry for displaying and typing in current room.
26
27
$floor::current_room = '';
27
28
my $c_entry = $c->Entry(qw/-width 10 -relief sunken -borderwidth 2
28
29
-textvariable/ => \$floor::current_room);
56
57
floor_display $c->Subwidget('canvas'), 3, \%floor_labels, \%floor_items,
57
58
\%cinfo, \$active_floor, $c_entry;
59
# Set up event bindings for canvas.
60
# Set up event bindings for the Canvas.
62
63
for $floor_number (1..3) {
68
69
$c->bind('room', '<Enter>' => sub {
70
71
my $id = $c->find('withtag' => 'current');
71
$floor::current_room = $floor_labels{$c->find('withtag','current')}
72
$id = $id->[0] if ref($id) eq 'ARRAY';
73
$floor::current_room = $floor_labels{$id} if defined $id;
75
76
$c->bind('room', '<Leave>' => sub {$floor::current_room = ''});
76
$c->Tk::bind('<2>' => sub {
79
$c->scan('mark', $e->x, $e->y);
81
$c->Tk::bind('<B2-Motion>' => sub {
84
$c->scan('dragto', $e->x, $e->y);
86
$c->Tk::bind('<Enter>', => [sub {shift; shift->focus}, $c_entry]);
87
tie $floor::current_room, 'floor', $c->Subwidget('canvas'), \%floor_items,
77
$c->CanvasBind('<2>' => sub {
80
$c->scanMark($e->x, $e->y);
82
$c->CanvasBind('<B2-Motion>' => sub {
85
$c->scanDragto($e->x, $e->y);
87
$c->CanvasBind('<Enter>', => [sub {shift; shift->focus}, $c_entry]);
89
$c->traceVariable(\$floor::current_room, 'w' =>
91
my($index, $value, $op, $floor_items, $cinfo) = @_;
93
$floor_current_room = $value;
94
&floor_room_changed($c->Subwidget('canvas'), $floor_items, $cinfo);
95
$value; # always return variable's new value
96
}, \%floor_items, \%cinfo],
92
101
sub floor_display {
94
103
# The following procedure recreates the floorplan display in the
95
# canvas given by "w". The floor given by "active" (1, 2, or 3) is
104
# Canvas given by "w". The floor given by "active" (1, 2, or 3) is
96
105
# displayed on top, with office structure visible. (Used as a callback
97
106
# and a normal function.)
1313
1322
} # end floor_fg3;
1317
# $current_room is tied to package "floor" for tracing purposes, thus, when
1318
# characters are typed in the Entry widget we can call floor_room_changed()
1319
# at every keystroke, and when a valid room number is found light the room up.
1321
# All other global variables are also "floor" qualified.
1323
my($class, $current_room, $canvas, $floor_items, $cinfo);
1327
# "new" method for scalars. Save reference to the floorplan canvas,
1328
# item descriptions and canvas info hash in this package's namespace.
1330
# Return a blessed reference, which is what FETCH and STORE will get.
1332
($class, $canvas, $floor_items, $cinfo) = @_;
1334
bless \$self, $class;
1340
# Method to handle reads of the tied variable: simply return it's value.
1342
my($current_room) = @_;
1343
return $$current_room;
1349
# Method to handle writes to the tied variable: simply store it's value.
1350
# Call floor_room_changed() to highlight a room, if possible.
1352
my($current_room, $value) = @_;
1353
$$current_room = $value;
1354
&::floor_room_changed($canvas, $floor_items, $cinfo);
1358
sub DESTROY { # class destructor (unused)