home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / tcl / tcl_1 / !wtest_drawtest < prev    next >
Encoding:
Text File  |  1996-02-05  |  3.7 KB  |  137 lines

  1. # Test of the w_draw diagram facilities
  2. # Unlike the text test we will have different diagrams in each window,
  3. # so we will need the tagging facilities so that we can have different
  4. # variables for each diagram.
  5.  
  6. # A global variable to hold the diagram number. Diagrams will be named d1,d2,...
  7.  
  8. set number 0
  9.  
  10. # A menu structure for the diagram windows.
  11.  
  12. set diagmenu\
  13.  { Diagram
  14.    {Path -tag -tick p}
  15.    {Text -tag -tick t}
  16.    {Sprite -tag -tick s}
  17.    {Group -tag -tick g}
  18.    {Save -dbox saveBox -click {saveMclick %w} }
  19.  }
  20.  
  21. #The following traces and procedure onetick ensure that at most one of the
  22. # Path, Text, Sprite and Group options are ticked
  23.  
  24. trace variable p w onetick
  25. trace variable t w onetick
  26. trace variable s w onetick
  27. trace variable g w onetick
  28.  
  29. proc onetick {name element op}\
  30.  { set full ${name}($element)
  31.    upvar $full x
  32.    if ($x==1)\
  33.    { foreach f {p t s g}\
  34.      { if {$f!=$name}\
  35.        { set full ${f}($element)
  36.          upvar $full x
  37.          set x 0
  38.        }
  39.      }
  40.    }
  41.  }
  42.  
  43. #This first increments number. For diagram p1 it sets p(d1) so that the
  44. # "Path" entry on the menu is initially ticked.
  45. #It creates the diagram setting a number of options.
  46. #It opens a window on the diagram.
  47. # When the window is clicked on procedure diagclick is called with parameters
  48. # the diagram name, the x and y coordinates of the click and a string
  49. # representing the button used and modifier keys.
  50. #Array xnumber is use to hold the object number of the X shaped path, so
  51. # that it can be deleted later.
  52.  
  53. proc drawopen {}\
  54.  { global number diagmenu p dname xnumber
  55.    incr number
  56.    set p(d$number) 1
  57.    set dname(d$number) DTest$number
  58.    w_draw d$number create\
  59.      -title "Diagram d$number"\
  60.      -bg yellow\
  61.      -menu $diagmenu\
  62.      -click {diagclick %w %x %y %b}\
  63.      -close {expr ![w_error "The diagram will be discarded" -ok -cancel] }\
  64.      -page A6l\
  65.      -xscale 1.2i\
  66.      -yscale 2c
  67.    set xnumber(d$number) [w_draw d$number path (1,2)-(2,1).(1,1)-(2,2) -t.1i ]
  68.    w_draw d$number open
  69.  }
  70.  
  71.  
  72. #This puts objects on the diagram
  73. #Clicking alter moves the X shaped path, by deleting the old X and putting
  74. # a new one at the front of the diagram.
  75. #The menu can be used to chose which of the path, text ,sprite or group
  76. # examples are placed where select is clicked. 
  77.  
  78. proc diagclick {w x y button}\
  79.  { global p t s g xnumber
  80.    set x1 [expr $x+1]
  81.    set y1 [expr $y+1]
  82.    if {$button=="a"}\
  83.    { w_draw $w delete $xnumber($w)
  84.      set xnumber($w)\
  85.      [w_draw $w above -1 path ($x,$y)-($x1,$y1).($x,$y1)-($x1,$y) -t.1i]
  86.      return
  87.    }
  88.    if {$p($w)==1}\
  89.    {w_draw $w path ($x,$y)-($x,$y1)-($x1,$y1)-($x1,$y). -t.1i -icyan -r}
  90.    if {$t($w)==1} {w_draw $w text ($x,$y) $button}
  91.    if {$s($w)==1} {w_draw $w sprite file_037 ($x,$y)}
  92.    if {$g($w)==1}\
  93.    { w_draw $w group "text ($x,$y) Group -cred"\
  94.                      "path ($x,$y)<($x1,$y)($x,$y1)>($x,$y) -cblue -t.05i"
  95.    }
  96.  }
  97.  
  98.  
  99. # Create a "Save As" dialog box template called "saveBox"
  100.  
  101. w_box saveBox create "Save as:"\
  102.  { vlist {save DrawFile dname {savedrag $w_file %d}}
  103.          {hlist {action Cancel} {default Save {saveclick %d}}}
  104.  } -tag
  105.  
  106.  
  107. #These commands handle saving from the diagram menu
  108. #The three procedures handle dragging from the dialog box, clicking "OK"
  109. # on the dialog box and clicking on the menu.
  110. #The actual save is performed by the "w_draw $w save ..." line.
  111.  
  112. proc savedrag {f w}\
  113.  { global dname
  114.    w_draw $w save $f
  115.    set dname($w) $f
  116.    return 0
  117.  }
  118.  
  119. proc saveclick {w}\
  120.  { global dname
  121.    if [string match *.* $dname($w)] \
  122.    { w_draw $w save $dname($w)
  123.      return 0
  124.    }
  125.    w_error "To save, drag the icon to a directory display"
  126.    return 0
  127.  }
  128.  
  129. proc saveMclick {w}\
  130.  { global dname
  131.    if [string match *.* $dname($w)] \
  132.    { w_draw $w save $dname($w)
  133.    } \
  134.    else \
  135.    { w_box saveBox open $w
  136.    }
  137.  }