2
# next line is a comment in tcl \
3
exec wish "$0" ${1+"$@"}
5
package require Tkspline
7
########################################################################
8
# splinetest.tcl - a test of spline rendering using the Tkspline extension
10
# John Ellson - ellson@graphviz.org
11
########################################################################
13
# create canvas and frame for toolbar
14
pack [canvas .c -bg white -height 350] \
15
-side top -fill both -expand true
16
pack [frame .f] -side top -fill x
18
proc nextpoint {c wx wy} {
21
if {[info exists id]} {
24
set id [$c find withtag current]
25
if {[string length $id] == 0} {
29
# $id != {} so must be a Point because everything else is disabled
30
set oldx [$c canvasx $wx]
31
set oldy [$c canvasy $wy]
36
proc motion {c wx wy} {
38
set x [$c canvasx $wx]
39
set y [$c canvasy $wy]
41
foreach {items idx} [$c gettags $id] {break}
42
# update single coord in three variants of shape
43
foreach itm [split $items .] {
45
$c insert $itm $idx [list $x $y]
48
$c move $id [expr $x - $oldx] [expr $y - $oldy]
54
# itemwithcontrolpoints - create a "line" or "polygon" with
55
# straight + spline + smooth line variants and draggable
59
# item = "line" | "polygon"
60
# coords = x y x y ... list of control point locations
62
proc itemwithcontrolpoints {c item coords} {
63
if {[string equal $item "line"]} {
66
set opts {-fill {} -outline black}
68
set lid [eval $c create $item $coords $opts \
69
-state disabled -tag Line]
70
set slid [eval $c create $item $coords $opts \
71
-smooth true -state disabled -tag Smooth]
72
set bzlid [eval $c create $item $coords $opts \
73
-smooth spline -state disabled -tag Spline]
75
foreach {x y} $coords {
76
set id [$c create oval -2 -2 2 2 \
77
-fill yellow -outline black \
78
-tags [list $lid.$slid.$bzlid $idx Point]]
84
# show objects by type (from toolbar buttons)
85
proc show {typ show} {
87
if {[string equal $typ "Point"]} {
88
.c itemconfigure $typ -state normal
90
.c itemconfigure $typ -state disabled
93
.c itemconfigure $typ -state hidden
99
if {[string equal $tcl_platform(platform) "windows"]} {
100
# platform == "windows"
101
if {[catch {package require Printer}]
102
&& [catch {package require printer}]} {
103
# Can't do this--no printer package
104
puts stderr "No \"Printer\" package found"
106
# Ask the user to select a printer
107
set hdc [ printer dialog select ]
108
# Now send raw postscript output to the device
109
printer send -hdc $hdc -postscript \
110
-data [.c postscript]
113
# platform != "windows" ... then probably unix
114
set chan [open "| lpr" w]
115
.c postscript -channel $chan
121
foreach typ {Exit Print} {
122
set cmd [string tolower $typ]
123
pack [button .f.$cmd \
124
-text $typ -width 6 -command $cmd \
125
-padx 0 -pady 0 -width 6] \
129
foreach typ {Line Smooth Spline Point} {
130
pack [checkbutton .f.[string tolower $typ] \
131
-text $typ -variable var$typ -width 6 \
132
-selectcolor yellow -command "show $typ \$var$typ" \
133
-indicatoron false] \
134
-side left -fill both
138
# mouse bindings on canvas objects
139
bind .c <1> "nextpoint .c %x %y"
140
bind .c <Motion> "motion .c %x %y"
142
# populate with demo objects
143
itemwithcontrolpoints .c line \
144
{50 50 50 100 100 100 100 50 100 20 150 20 150 50}
145
itemwithcontrolpoints .c polygon \
146
{50 200 100 150 150 200 150 250 100 300 50 250}
148
set help [.c create text 10 125 \
150
-text "You can drag the points\nwith mouse button 1"]
151
after 5000 {.c delete $help}