home *** CD-ROM | disk | FTP | other *** search
- # Test of the w_draw diagram facilities
- # Unlike the text test we will have different diagrams in each window,
- # so we will need the tagging facilities so that we can have different
- # variables for each diagram.
-
- # A global variable to hold the diagram number. Diagrams will be named d1,d2,...
-
- set number 0
-
- # A menu structure for the diagram windows.
-
- set diagmenu\
- { Diagram
- {Path -tag -tick p}
- {Text -tag -tick t}
- {Sprite -tag -tick s}
- {Group -tag -tick g}
- {Save -dbox saveBox -click {saveMclick %w} }
- }
-
- #The following traces and procedure onetick ensure that at most one of the
- # Path, Text, Sprite and Group options are ticked
-
- trace variable p w onetick
- trace variable t w onetick
- trace variable s w onetick
- trace variable g w onetick
-
- proc onetick {name element op}\
- { set full ${name}($element)
- upvar $full x
- if ($x==1)\
- { foreach f {p t s g}\
- { if {$f!=$name}\
- { set full ${f}($element)
- upvar $full x
- set x 0
- }
- }
- }
- }
-
- #This first increments number. For diagram p1 it sets p(d1) so that the
- # "Path" entry on the menu is initially ticked.
- #It creates the diagram setting a number of options.
- #It opens a window on the diagram.
- # When the window is clicked on procedure diagclick is called with parameters
- # the diagram name, the x and y coordinates of the click and a string
- # representing the button used and modifier keys.
- #Array xnumber is use to hold the object number of the X shaped path, so
- # that it can be deleted later.
-
- proc drawopen {}\
- { global number diagmenu p dname xnumber
- incr number
- set p(d$number) 1
- set dname(d$number) DTest$number
- w_draw d$number create\
- -title "Diagram d$number"\
- -bg yellow\
- -menu $diagmenu\
- -click {diagclick %w %x %y %b}\
- -close {expr ![w_error "The diagram will be discarded" -ok -cancel] }\
- -page A6l\
- -xscale 1.2i\
- -yscale 2c
- set xnumber(d$number) [w_draw d$number path (1,2)-(2,1).(1,1)-(2,2) -t.1i ]
- w_draw d$number open
- }
-
-
- #This puts objects on the diagram
- #Clicking alter moves the X shaped path, by deleting the old X and putting
- # a new one at the front of the diagram.
- #The menu can be used to chose which of the path, text ,sprite or group
- # examples are placed where select is clicked.
-
- proc diagclick {w x y button}\
- { global p t s g xnumber
- set x1 [expr $x+1]
- set y1 [expr $y+1]
- if {$button=="a"}\
- { w_draw $w delete $xnumber($w)
- set xnumber($w)\
- [w_draw $w above -1 path ($x,$y)-($x1,$y1).($x,$y1)-($x1,$y) -t.1i]
- return
- }
- if {$p($w)==1}\
- {w_draw $w path ($x,$y)-($x,$y1)-($x1,$y1)-($x1,$y). -t.1i -icyan -r}
- if {$t($w)==1} {w_draw $w text ($x,$y) $button}
- if {$s($w)==1} {w_draw $w sprite file_037 ($x,$y)}
- if {$g($w)==1}\
- { w_draw $w group "text ($x,$y) Group -cred"\
- "path ($x,$y)<($x1,$y)($x,$y1)>($x,$y) -cblue -t.05i"
- }
- }
-
-
- # Create a "Save As" dialog box template called "saveBox"
-
- w_box saveBox create "Save as:"\
- { vlist {save DrawFile dname {savedrag $w_file %d}}
- {hlist {action Cancel} {default Save {saveclick %d}}}
- } -tag
-
-
- #These commands handle saving from the diagram menu
- #The three procedures handle dragging from the dialog box, clicking "OK"
- # on the dialog box and clicking on the menu.
- #The actual save is performed by the "w_draw $w save ..." line.
-
- proc savedrag {f w}\
- { global dname
- w_draw $w save $f
- set dname($w) $f
- return 0
- }
-
- proc saveclick {w}\
- { global dname
- if [string match *.* $dname($w)] \
- { w_draw $w save $dname($w)
- return 0
- }
- w_error "To save, drag the icon to a directory display"
- return 0
- }
-
- proc saveMclick {w}\
- { global dname
- if [string match *.* $dname($w)] \
- { w_draw $w save $dname($w)
- } \
- else \
- { w_box saveBox open $w
- }
- }