diff options
author | lecoanet | 2003-03-30 09:09:44 +0000 |
---|---|---|
committer | lecoanet | 2003-03-30 09:09:44 +0000 |
commit | 839c6cd06b3fccc2e6dc227746e58b3544a70b22 (patch) | |
tree | 9a1ca213fcdf9dc4e4dfa93d6b52698f1b0cf28b /demos/contours.tcl | |
parent | d6a7dbb3a6090cc7d8007237f0b4f75c1d3f0112 (diff) | |
download | tkzinc-839c6cd06b3fccc2e6dc227746e58b3544a70b22.zip tkzinc-839c6cd06b3fccc2e6dc227746e58b3544a70b22.tar.gz tkzinc-839c6cd06b3fccc2e6dc227746e58b3544a70b22.tar.bz2 tkzinc-839c6cd06b3fccc2e6dc227746e58b3544a70b22.tar.xz |
Mise � jour interm�diaire
Diffstat (limited to 'demos/contours.tcl')
-rw-r--r-- | demos/contours.tcl | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/demos/contours.tcl b/demos/contours.tcl index 07fa3c3..ea3aab3 100644 --- a/demos/contours.tcl +++ b/demos/contours.tcl @@ -82,16 +82,17 @@ $w.zinc translate $curve3 -130 0 # cloning curve0 as curve4 and moving it slightly set curve4 [$w.zinc clone $curve0 -visible 1 -fillcolor grey50 -tags grouped -fillrule positive] - # the tag "grouped" is used for both curve4 and - # a handle (see just below) - # It is used for translating both easily +# the tag "grouped" is used for both curve4 and +# a handle (see just below) +# It is used for translating both easily set index 2; ## index of the vertex associated to the handle set coord [$w.zinc coords $curve4 0 $index] set x [lindex $coord 0] set y [lindex $coord 1] -set handle [$w.zinc add rectangle 1 "[expr $x-5] [expr $y-5] [expr $x+5] [expr $y+5]" -fillcolor black -filled 1 -tags {grouped}] +set handle [$w.zinc add rectangle 1 "[expr $x-5] [expr $y-5] [expr $x+5] [expr $y+5]" \ + -fillcolor black -filled 1 -tags {grouped}] # adding a 'difference' contour to the curve4 @@ -121,71 +122,68 @@ $w.zinc raise $curve1 # adding drag and drop callback to each visible curve! foreach item "$curve1 $curve2 $curve3 $curve4" { # Some bindings for dragging the items - $w.zinc bind $item <1> "itemStartDrag $item %x %y" - $w.zinc bind $item <B1-Motion> "itemDrag $item %x %y" - # <ButtonRelease-1> release + $w.zinc bind $item <ButtonPress-1> "press $item motion %x %y" + $w.zinc bind $item <ButtonRelease-1> release } # adding drag and drop on curve4 which also moves handle -$w.zinc bind $curve4 <ButtonPress-1> {press $curve4 motionWithHandle} +$w.zinc bind $curve4 <ButtonPress-1> "press $curve4 motionWithHandle %x %y" $w.zinc bind $curve4, <ButtonRelease-1> release # adding drag and drop on handle which also modify curve4 -$w.zinc bind handle <ButtonPress-1> {press $handle moveHandle} -$w.zinc bind handle <ButtonRelease-1> release +$w.zinc bind $handle <ButtonPress-1> "press $handle moveHandle %x %y" +$w.zinc bind $handle <ButtonRelease-1> release # callback for starting a drag -set x_orig "" -set y_orig "" +set xOrig 0 +set yOrig 0 -proc itemStartDrag {item x y} { - global x_orig y_orig - set x_orig $x - set y_orig $y +proc press {item action x y} { + global w xOrig yOrig + + puts "item $item" + set xOrig $x + set yOrig $y + bind $w.zinc <Motion> "$action $item %x %y" } # Callback for moving an item -proc itemDrag {item x y} { - global x_orig y_orig - global w - $w.zinc translate $item [expr $x-$x_orig] [expr $y-$y_orig]; - set x_orig $x; - set y_orig $y; +proc motion {item x y} { + global w xOrig yOrig + + $w.zinc translate $item [expr $x - $xOrig] [expr $y - $yOrig] + set xOrig $x + set yOrig $y } # Callback for moving an item and its handle -proc motionWithHandle {item} { - global x_orig - global y_orig - set ev [$w.zinc XEvent] - set x_orig $ev->x; - set y_orig $ev->y; - - set tag [$w.zinc itemcget $item -tags] - $w.zinc translate $tag [epxr $x-$x_orig] [expr $y-$y_orig] - set x_orig $x; - set y_orig $y; +proc motionWithHandle {item x y} { + global w xOrig yOrig + + set tag [lindex [$w.zinc itemcget $item -tags] 0] + $w.zinc translate $tag [expr $x-$xOrig] [expr $y-$yOrig] + set xOrig $x; + set yOrig $y; } # Callback for moving the handle and modifying curve4 # this code is far from being generic. Only for demonstrating how we can # modify a contour with a unique handle! -proc moveHandle {handle} { - global x_orig - global y_orig - set ev [$w.zinc XEvent] - set x_orig $ev->x; - set y_orig $ev->y; - - $w.zinc translate $handle [expr $x-$x_orig] [expr $y-$y_orig]; - - set ($vertxX,$vertxY) [$w.zinc coords $curve4 0 $index] - $w.zinc coords $curve4 0 $index "[expr $vertxX+($x-$x_orig)] [expr $vertxY+($y-$y_orig)]" - set x_orig $x - set y_orig $y +proc moveHandle {handle x y} { + global w xOrig yOrig curve4 index + + puts "$handle $x $y" + $w.zinc translate $handle [expr $x - $xOrig] [expr $y - $yOrig]; + + foreach {vertxX vertxY} [$w.zinc coords $curve4 0 $index] break + $w.zinc coords $curve4 0 $index "[expr $vertxX+($x-$xOrig)] [expr $vertxY+($y-$yOrig)]" + set xOrig $x + set yOrig $y } proc release {} { - $w.zinc Tk::bind('<Motion>', ''); + global w + + bind $w.zinc <Motion> {} } |