0
  B   ˆl–Ü4ý(!)”u( J»�3q·”Å£‘þBëÂ�fäpR>7�z7�üÿÂ„}Á>ÿÁ_ˆI|¥�+V[(ÁÀ ?÷     # floor.pl

use Tk::Trace;
use subs qw/floor_bg1 floor_bg2 floor_bg3 floor_display floor_fg1 floor_fg2
	    floor_fg3 floor_room_changed/;
use vars qw/$TOP/;

sub floor {

    # Create a top-level window containing a Canvas that displays the
    # floorplan for DEC's Western Research Laboratory.

    my($demo) = @_;
    $TOP = $MW->WidgetDemo(
	-name     => $demo,
	-text     => ['This window contains a canvas widget showing the floorplan of Digital Equipment Corporation\'s Western Research Laboratory.  It has three levels.  At any given time one of the levels is active, meaning that you can see its room structure.  To activate a level, click the left mouse button anywhere on it.  As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the "Room:" entry.  You can also type a room number in the entry and the room will light up.', qw/-wraplength 8i/],
	-title    => 'Floorplan Canvas Demonstration',
	-iconname => 'floor',
    );

    my $c = $TOP->Scrolled(qw/Canvas -width 900 -height 500 -relief sunken
			   -borderwidth 2 -scrollbars se/);
    $c->pack(qw/-expand yes -fill both/);

    # Create an Entry for displaying and typing in current room.

    $floor::current_room = '';
    my $c_entry = $c->Entry(qw/-width 10 -relief sunken -borderwidth 2
			    -textvariable/ => \$floor::current_room);

    # Choose colors, then fill in the floorplan.

    my %cinfo;                  # color information hash
    if ($TOP->depth > 1) {
	$cinfo{'floor_bg1'} = '#a9c1da';
	$cinfo{outline1} = '#77889a';
	$cinfo{'floor_bg2'} = '#9ab0c6';
	$cinfo{outline2} = '#687786';
	$cinfo{'floor_bg3'} = '#8ba0b3';
	$cinfo{outline3} = '#596673';
	$cinfo{offices} = 'Black';
	$cinfo{active} = '#c4d1df';
    } else {
	$cinfo{'floor_bg1'} = 'white';
	$cinfo{outline1} = 'black';
	$cinfo{'floor_bg2'} = 'white';
	$cinfo{outline2} = 'black';
	$cinfo{'floor_bg3'} = 'white';
	$cinfo{outline3} = 'black';
	$cinfo{offices} = 'Black';
	$cinfo{active} = 'black';
    }

    my %floor_labels = ();
    my %floor_items = ();
    my $active_floor = 0;
    floor_display $c->Subwidget('canvas'), 3, \%floor_labels, \%floor_items,
	\%cinfo, \$active_floor, $c_entry;

    # Set up event bindings for the Canvas.

    my $floor_number;
    for $floor_number (1..3) {
	$c->bind("floor${floor_number}", '<1>' =>
	    [\&floor_display, $floor_number, \%floor_labels, \%floor_items,
	    \%cinfo, \$active_floor, $c_entry],
	);
    }
    $c->bind('room', '<Enter>' => sub {
	my($c) = @_;
	my $id = $c->find('withtag' => 'current');
	$id = $id->[0] if ref($id) eq 'ARRAY';
	$floor::current_room  = $floor_labels{$id} if defined $id;
	$c->idletasks;
    });
    $c->bind('room', '<Leave>' => sub {$floor::current_room = ''});
    $c->CanvasBind('<2>' => sub {
	my($c) = @_;
	my $e = $c->XEvent;
	$c->scanMark($e->x, $e->y);
    });
    $c->CanvasBind('<B2-Motion>' => sub {
	my($c) = @_;
	my $e = $c->XEvent;
	$c->scanDragto($e->x, $e->y);
    });
    $c->CanvasBind('<Enter>', => [sub {shift; shift->focus}, $c_entry]);

    $c->traceVariable(\$floor::current_room, 'w' =>
	[sub {
	    my($index, $value, $op, $floor_items, $cinfo) = @_;
	    return if $op eq 'u';
	    $floor_current_room = $value;
	    &floor_room_changed($c->Subwidget('canvas'), $floor_items, $cinfo);
	    $value;             # always return variable's new value
	}, \%floor_items, \%cinfo],
    );

} # floor

sub floor_display {

    # The following procedure recreates the floorplan display in the
    # Canvas given by "w".  The floor given by "active" (1, 2, or 3) is
    # displayed on top, with office structure visible.  (Used as a callback
    # and a normal function.)

    my($c, $active, $floor_labels, $floor_items, $cinfo, $active_floor,
       $c_entry) = @_;

    return if $$active_floor eq $active;

    $c->delete('all');
    $$active_floor = $active;

    # First go through the three floors, displaying the backgrounds for
    # each floor.

    floor_bg1 $c, $cinfo->{'floor_bg1'}, $cin