# Canvas chapter

proc BoxInit {} {
	global c
	if {[info exists c] && ([winfo class $c] == "Canvas")} {
	    # Already set up
	} else {
	    catch {destroy .c}
	    canvas .c -bg white ; pack .c
	    set c .c
	}
	bind $c <Button-1> {BoxBegin %W %x %y}
	bind $c <B1-Motion> {BoxDrag %W %x %y}
}
proc BoxBegin { w x y } {
	global box
	set box(anchor) [list $x $y]
	catch {unset box(last)}
}
proc BoxDrag { w x y } {
	global box
	catch {$w delete $box(last)}
	set box(last) [eval {$w create rect} $box(anchor) {$x $y -tag box}]
}
BoxInit
