#!../bltwish

source bltDemo.tcl

set graph .graph

bitmap define pattern1 { {4 4} {01 02 04 08} }
bitmap define pattern5 { {4 4} {01 01 01 01} }

set visual [winfo screenvisual .]
if { $visual != "staticgray" && $visual != "grayscale" } {
    option add *Button.Background	red
    option add *TextMarker.Foreground	black
    option add *TextMarker.Background	yellow
    option add *LineMarker.Foreground	black
    option add *LineMarker.Background	yellow
    option add *PolyMarker.Fill		yellow2
    option add *PolyMarker.Outline	""
    option add *PolyMarker.Stipple	pattern5
    option add *activeLine.Color	red4
    option add *activeLine.Fill		red2
    option add *Element.Color		purple
}

source graph2.tcl

if { [file exists testImg.jpg] } {
   image create photo someImage 
   winop readjpeg testImg.jpg someImage 
   puts stderr [time { 
     $graph marker create image -image someImage \
	-coords "-360.0 -1.0 360.0 1.0" \
 	-under yes -mapx degrees -name fred 
   }]
} 

$graph postscript configure -maxpect yes -landscape yes
$graph configure -width 5i -height 5i
set unique 0

$graph axis configure x -title "X Axis"

table . \
    0,0 $graph -fill both 

bind $graph <Control-ButtonPress-3> { MakeSnapshot }
bind $graph <Shift-ButtonPress-3> { %W print }

proc MakeSnapshot {} {
    update idletasks
    global unique
    set top ".snapshot[incr unique]"
    set im [image create photo]
    $graph snap $im 210 150

    toplevel $top
    wm title $top "Snapshot \#$unique of \"[$graph cget -title]\""
    label $top.lab -image $im 
    button $top.but -text "Dismiss" -command "DestroySnapshot $top"
    table $top $top.lab
    table $top $top.but -pady 4 
    focus $top.but
}

proc DestroySnapshot { win } {
    set im [$win.lab cget -image]
    $im write test.ppm
    image delete $im
    destroy $win
    exit
}
focus $graph
