#################################
# GLOBAL VARIABLES
#
global img; 
    set img(line) {
    R0lGODdhKAAoAPUAAAAAADj4MEDsMEjkMFBQ+FDcMFjQMGDIMGjAMHB0cHC4MHikOHisMIB8
    eICAgICcOIiQOJCIOJiAOKB4OKC0yKDEyKgoGKhsOLBkOLhcOLi4uMBQOMDAwMhIOMjEwNBA
    ONg4ONh8eOAsOOC4gOgkOPAcOPC4OPgUQPiIOPj8+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAKAAoAAAG
    f8CUcEgsGo/IpHLJbDqf0Kj0CKhOo9Us4NrUerlJrxhc1KbM5yw5vRV+2e2r2t22DtFYO31f
    jj/nd3F6XICBhmCFh2xrVH5pjEaDj5BEkpOUl4qUlplrnJ1kn4mIjpWlhKd8jJ+qoamtmJGs
    sbOYtbavtLm4sb2+v8DBwsPEv0EAOw==
}
    set img(rect) {
    R0lGODdhKAAoAPUAAAAAADj4MEDsMEjkMFBQ+FDcMFjQMGDIMGjAMHB0cHC4MHikOHisMIB8
    eICAgICcOIiQOJCIOJiAOKB4OKC0yKDEyKgoGKhsOLBkOLhcOLi4uMBQOMDAwMhIOMjEwNBA
    ONg4ONh8eOAsOOC4gOgkOPAcOPC4OPgUQPiIOPj8+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAKAAoAAAG
    XsCUcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdsvtOgHgsHhMBkfLaPQZMDVD3eu4FP5lz+1Peh5f
    b/Oben1vf4J7fnKIhYOJhot3jIqAaZNha5STXpmam5ydnp+goaKjVkEAOw==
}
    set img(oval) {
    R0lGODdhKAAoAPUAAAAAADj4MEDsMEjkMFBQ+FDcMFjQMGDIMGjAMHB0cHC4MHikOHisMIB8
    eICAgICcOIiQOJCIOJiAOKB4OKC0yKDEyKgoGKhsOLBkOLhcOLi4uMBQOMDAwMhIOMjEwNBA
    ONg4ONh8eOAsOOC4gOgkOPAcOPC4OPgUQPiIOPj8+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAKAAoAAAG
    YsCUcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdstVAr5gQDcFPpax32a6Koa2pW83nC23xpf3uTqb
    N/P3aIBXfX52T4SHdVOISYyNVI5GkV6Ta4OWRGdcYZpjnp+goaKjpKWmp11BADs=
}
    set img(free) {
    R0lGODdhKAAoAPcAAAAAALi4uNh8eOC4gPC4OPj8+AEUAEAIAMg0E6D4ABT/AAi/ABA1Aa+y
    ABQBAAhAAMQsuKeppxQUFAgICMi04DL39gj//0C/vw4EwMAA9gEA/0AAv1DIbwEytQAIAQBA
    QDjIyKigoBDIEK+gr+AkvPivp/8UFL8ICDEb5v22pwIAFEAACDYEEKgArxQAFAgACGjInrSg
    vQwUAQgIQMFkG4r4AA3/AEC/AIwEDVoAABQAAEAAAADIGACgAAAUAAQIADBw/Nb4pxD/FAy/
    CDA1HNay9xAB/whAv+gETskAkhEAB1DInqigvRQUATgEG6gAAAgAAMjIDTKgAAgUAPyIGPj4
    AP//AL+/AJQ1BLWyqAQBFEBACAnQHACn9wAU/wAIvwgIgKf4khT/Bwi/CEwEyAIAoAAAFAAA
    CMjIgzIyAAgIAEBABRjIEPmgr8TIG7+gAAQUAIAkEKavABQUAAgbGae2AEwEEgIAAGS4KPn4
    9////7+/v701LnmymggBBwhACGwE8MKozwwUEwA4AQD4AAD/AAC/ANgENfkAJ/8AEb8ACLDI
    OA0y9xYI/8jIFTKgjQgUB0AICNTIrPmgzf8UE9gkhPmv/P8U/78Iv7AAOA0A+hYA/wgAv5TI
    v/mggf8UBaAQDayvAAcUAAAgAACpAAAIAAHIhAAy/AAI/wBAvygOhADA/AAB/yhSqAAB+QAA
    /wAAvwCkAAAQAAGvANyMAPn4ANgxAPn9AP8CAL9AAJSahPmp/Nz8JKz4rwf/FLAKGw0AthYA
    ACjsTwAAdgAAZQAAcihudwAAaQAFdAAHZQD5IAD/ZQC/eIQKafwAc/8AdL8AaQCgBABvyAC1
    oAABFABACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAKAAoAAAIngALCBxIsKDBgwgTKlzIsKHD
    hxAjSlQIoOLEiAAEaARw8WHGjR0bVgQZkiGAABk5lqQYoKXKlQkruoQZk0DFlzQNAiDAE2fO
    gTt7/jwY1ObQgkV9Hk16lCDTpkB5GoVa4ClVq02xZpWq9KfWpVxNdvxKdOyAAVPFTgRwtitC
    tyYterwod+5YpHWRlnzJVyfMm3hvwqVKuLDhw4gTNw0IADs=
}
global tool; set tool {free}
global widget; 
    set widget(rev,.01.02) {CANVAS}
    set widget(CANVAS) {.01.02}
    set widget(rev,.top28.fra29.can30) {CANVAS}
    set widget(rev,.tclet.01) {CANVAS}
global x; set x {224}
global y; set y {181}

#################################
# USER DEFINED PROCEDURES
#
proc init {argc argv} {
global vTcl tcl_platform tcl_version tk_strictMotif img
catch {package require unsafe}
set tk_strictMotif 1

if {$tcl_version < 7.7} {
    if {[info exists vTcl(VTCL_DIR)]} {
        set base [file join $vTcl(VTCL_DIR) demo]
    } else {
        set base [pwd]
    }
    image create photo free -file [file join $base images free.gif]
    image create photo line -file [file join $base images line.gif]
    image create photo rect -file [file join $base images rect.gif]
    image create photo oval -file [file join $base images oval.gif]
} else {
    foreach i {free line rect oval} {
        image create photo $i -data $img($i)
    }
}
}

init $argc $argv


proc button-down {sx sy} {
global tool x y obj widget

switch $tool {
    free -
    line {
        set x $sx
        set y $sy
        set obj [$widget(CANVAS) create line $x $y $x $y]
    }
    rect {
        set x $sx
        set y $sy
        set obj [$widget(CANVAS) create rectangle $x $y $x $y]
    }
    ellipse {
        set x $sx
        set y $sy
        set obj [$widget(CANVAS) create arc $x $y $x $y -start 0 -extent 359 -style arc]
    }
}
}

proc button-motion {nx ny} {
global tool x y obj widget

switch $tool {
    free {
        $widget(CANVAS) create line $x $y $nx $ny
        set x $nx
        set y $ny
    }
    line -
    rect -
    ellipse {
        $widget(CANVAS) coords $obj $x $y $nx $ny
    }
}
}

proc button-release {nx ny} {
global tool x y

switch $tool {
}
}

proc main {argc argv} {

}

proc Window {args} {
global vTcl
    set cmd [lindex $args 0]
    set name [lindex $args 1]
    set rest [lrange $args 2 end]
    if {$name == "" || $cmd == ""} {return}
    set exists [winfo exists $name]
    switch $cmd {
        show {
            if {[info procs vTclWindow(pre)$name] != ""} {
                vTclWindow(pre)$name $rest
            }
            if {[info procs vTclWindow$name] != ""} {
                vTclWindow$name
            }
            if {[info procs vTclWindow(post)$name] != ""} {
                vTclWindow(post)$name $rest
            }
        }
        hide    { if $exists {wm withdraw $name; return} }
        iconify { if $exists {wm iconify $name; return} }
        destroy { if $exists {destroy $name; return} }
    }
}

#################################
# VTCL GENERATED GUI PROCEDURES
#
frame .01 \
    -borderwidth 1 -height 30 -relief raised -width 30 
pack .01 \
    -anchor center -expand 1 -fill both -padx 5 -pady 5 -side top 
canvas .01.02 \
    -borderwidth 2 -height 246 -highlightthickness 0 -relief ridge -width 351 
grid .01.02 \
    -column 0 -row 0 -columnspan 1 -rowspan 6 -padx 5 -pady 5 -sticky nesw 
bind .01.02 <ButtonRelease-1> "
        button-release %x %y
    "
bind .01.02 <B1-Motion> "
        button-motion %x %y
    "
bind .01.02 <Button-1> "
        button-down %x %y
    "

frame .01.03 \
    -borderwidth 1 -height 30 -relief sunken -width 30 
grid .01.03 \
    -column 1 -row 0 -columnspan 1 -rowspan 1 -padx 5 -pady 5 -sticky n 
button .01.03.04 \
    -command {set tool free} \
    -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
    -highlightthickness 0 -image free -padx 11 -pady 4 -text free 
pack .01.03.04 \
    -anchor center -expand 1 -fill both -side top 

button .01.03.05 \
    -command {set tool line} \
    -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
    -highlightthickness 0 -image line -padx 11 -pady 4 -text line 
pack .01.03.05 \
    -anchor center -expand 1 -fill both -side top 

button .01.03.06 \
    -command {set tool rect} \
    -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
    -highlightthickness 0 -image rect -padx 11 -pady 4 -text rect 
pack .01.03.06 \
    -anchor center -expand 1 -fill both -side top 

button .01.03.07 \
    -command {set tool ellipse} \
    -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
    -highlightthickness 0 -image oval -padx 11 -pady 4 -text ellipse 
pack .01.03.07 \
    -anchor center -expand 1 -fill both -side top 


frame .01.08 \
    -borderwidth 2 -height 45 -relief groove -width 45 
grid .01.08 \
    -column 1 -row 1 -columnspan 1 -rowspan 1 -padx 5 -pady 5 
frame .01.08.09 \
    -background #ffffff -borderwidth 1 -height 30 -relief raised -width 30 
place .01.08.09 \
    -x 15 -y 15 -width 25 -height 25 -anchor nw -bordermode ignore 

frame .01.08.010 \
    -background #000000 -borderwidth 1 -height 30 -relief raised -width 30 
place .01.08.010 \
    -x 5 -y 5 -width 25 -height 25 -anchor nw -bordermode ignore 


label .01.011 \
    -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -text select 
grid .01.011 \
    -column 1 -row 3 -columnspan 1 -rowspan 1 

label .01.012 \
    -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -text {a tool} 
grid .01.012 \
    -column 1 -row 4 -columnspan 1 -rowspan 1 

button .01.013 \
    -command exit -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
    -highlightthickness 0 -padx 9 -pady 3 -text Quit 
grid .01.013 \
    -column 1 -row 5 -columnspan 1 -rowspan 1 -padx 5 -pady 5 -sticky ns 

grid columnconf .01 0 -weight 1
grid columnconf .01 1 -minsize 45
grid rowconf .01 5 -weight 1
grid rowconf .01 1 -minsize 45


main $argc $argv
