From 839c6cd06b3fccc2e6dc227746e58b3544a70b22 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Sun, 30 Mar 2003 09:09:44 +0000 Subject: Mise � jour interm�diaire --- demos/contours.tcl | 92 ++++++++++++++++++++++----------------------- demos/groupsInAtcStrips.tcl | 2 +- demos/iconTransform.tcl | 18 +++++---- demos/tiger.tcl | 5 ++- demos/tkZincLogo.tcl | 24 ++++++------ demos/zinc-widget | 9 +++-- 6 files changed, 77 insertions(+), 73 deletions(-) (limited to 'demos') 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 "itemDrag $item %x %y" - # release + $w.zinc bind $item "press $item motion %x %y" + $w.zinc bind $item release } # adding drag and drop on curve4 which also moves handle -$w.zinc bind $curve4 {press $curve4 motionWithHandle} +$w.zinc bind $curve4 "press $curve4 motionWithHandle %x %y" $w.zinc bind $curve4, release # adding drag and drop on handle which also modify curve4 -$w.zinc bind handle {press $handle moveHandle} -$w.zinc bind handle release +$w.zinc bind $handle "press $handle moveHandle %x %y" +$w.zinc bind $handle 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 "$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('', ''); + global w + + bind $w.zinc {} } diff --git a/demos/groupsInAtcStrips.tcl b/demos/groupsInAtcStrips.tcl index fb6bdd0..578b688 100644 --- a/demos/groupsInAtcStrips.tcl +++ b/demos/groupsInAtcStrips.tcl @@ -70,7 +70,7 @@ pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 text $w.text -relief sunken -borderwidth 2 -height 5 pack $w.text -expand yes -fill both -$w.text insert end {'These fake air Traffic Control electronic strips illustrates +$w.text insert end {These fake air Traffic Control electronic strips illustrates the use of groups for an advanced graphic design. The following interactions are possible: "drag&drop button1" on the callsign. diff --git a/demos/iconTransform.tcl b/demos/iconTransform.tcl index 7f245dc..4d00bad 100644 --- a/demos/iconTransform.tcl +++ b/demos/iconTransform.tcl @@ -11,7 +11,7 @@ set w .iconTransform catch {destroy $w} toplevel $w wm title $w "Zinc icon scale/rotate Demonstration" -wm iconname $w zincTransform +wm iconname $w iconTransform set defaultfont "-adobe-helvetica-bold-r-normal-*-120-*-*-*-*-*-*" @@ -33,9 +33,9 @@ pack $w.text -expand yes -fill both $w.text insert end {This demo needs openGL for rescaling/rotating the icon You can transform this earth gif image with your mouse: - Drag-Button 1 for zooming the earth, - Drag-Button 2 for rotating the earth, - Drag-Button 3 for moving the earth, + Drag-Button 1 for moving the earth, + Drag-Button 2 for zooming the earth, + Drag-Button 3 for rotating the earth, Shift-Drag-Button 1 for modifying the earth transparency.} @@ -64,6 +64,8 @@ bind $w.zinc "press motion %x %y" bind $w.zinc release bind $w.zinc "press zoom %x %y" bind $w.zinc release +bind $w.zinc "press mouseRotate %x %y" +bind $w.zinc release # # Controls for alpha and gradient @@ -123,7 +125,7 @@ proc mouseRotate {x y} { global w curAngle topGroup set lAngle [expr atan2($y, $x)] - $w.zinc rotate $topGroup [expr -($lAngle - $curAngle)] + $w.zinc rotate $topGroup [expr $lAngle - $curAngle] set curAngle $lAngle } @@ -134,11 +136,11 @@ proc release {} { } proc modifyAlpha {x y} { - global w + global w topGroup set xRate [expr double($x) / [$w.zinc cget -width]] set xRate [expr ($xRate < 0) ? 0 : ($xRate > 1) ? 1 : $xRate] - set alpha [expr $xRate * 100] + set alpha [expr int($xRate * 100)] - $w.zinc itemconfigure $group -alpha $alpha + $w.zinc itemconfigure $topGroup -alpha $alpha } diff --git a/demos/tiger.tcl b/demos/tiger.tcl index b0ac265..c494c7b 100644 --- a/demos/tiger.tcl +++ b/demos/tiger.tcl @@ -534,6 +534,8 @@ bind $w.zinc "press motion %x %y" bind $w.zinc release bind $w.zinc "press zoom %x %y" bind $w.zinc release +bind $w.zinc "press mouseRotate %x %y" +bind $w.zinc release set curX 0 @@ -577,7 +579,6 @@ proc zoom {x y} { } set sx [expr 1.0 + (double($x - $curX) / $maxX)] set sy [expr 1.0 + (double($y - $curY) / $maxY)] - puts "x: $x cur: $curX max: $maxX $sx" $w.zinc scale $topGroup $sx $sx set curX $x set curY $y @@ -587,7 +588,7 @@ proc mouseRotate {x y} { global w curAngle topGroup set lAngle [expr atan2($y, $x)] - $w.zinc rotate $topGroup [expr -($lAngle - $curAngle)] + $w.zinc rotate $topGroup [expr $lAngle - $curAngle] set curAngle $lAngle } diff --git a/demos/tkZincLogo.tcl b/demos/tkZincLogo.tcl index 6db4031..2e72f36 100644 --- a/demos/tkZincLogo.tcl +++ b/demos/tkZincLogo.tcl @@ -34,7 +34,7 @@ pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 ####################### #################### -text $w.text -relief sunken -borderwidth 2 -height 5 +text $w.text -relief sunken -borderwidth 2 -height 7 pack $w.text -expand yes -fill both $w.text insert end {This tkZinc logo should used openGL for a correct rendering! @@ -53,9 +53,9 @@ zinc $w.zinc -width 350 -height 250 -render 1 -font 10x20 \ -borderwidth 3 -relief sunken pack $w.zinc -set group [$w.zinc add group 1] +set topGroup [$w.zinc add group 1] -set logo [zincLogo::create $w.zinc $group 800 40 70 0.6 0.6] +set logo [zincLogo::create $w.zinc $topGroup 800 40 70 0.6 0.6] # # Controls for the window transform. @@ -64,6 +64,8 @@ bind $w.zinc "press motion %x %y" bind $w.zinc release bind $w.zinc "press zoom %x %y" bind $w.zinc release +bind $w.zinc "press mouseRotate %x %y" +bind $w.zinc release # # Controls for alpha and gradient @@ -122,10 +124,10 @@ proc zoom {x y} { } proc mouseRotate {x y} { - global w curAngle topGroup + global w curAngle logo set lAngle [expr atan2($y, $x)] - $w.zinc rotate $topGroup [expr -($lAngle - $curAngle)] + $w.zinc rotate $logo [expr $lAngle - $curAngle] set curAngle $lAngle } @@ -136,21 +138,21 @@ proc release {} { } proc modifyAlpha {x y} { - global w + global w topGroup set xRate [expr double($x) / [$w.zinc cget -width]] set xRate [expr ($xRate < 0) ? 0 : ($xRate > 1) ? 1 : $xRate] - set alpha [expr $xRate * 100] + set alpha [expr int($xRate * 100)] - $w.zinc itemconfigure $group -alpha $alpha + $w.zinc itemconfigure $topGroup -alpha $alpha } proc modifyGradient {x y} { global w - set yRate [expr double($ly) / [$w.zinc cget -height]] + set yRate [expr double($y) / [$w.zinc cget -height]] set yRate [expr ($yRate < 0) ? 0 : ($yRate > 1) ? 1 : $yRate] - set gradientPercent [expr int($yRate * 100)] + set gradPercent [expr int($yRate * 100)] - $w.zinc itemconfigure letters -fillcolor => "=axial 270|#ffffff;100 0 28|#66848c;100 $gradientpercent|#7192aa;100 100" + $w.zinc itemconfigure letters -fillcolor "=axial 270|#ffffff;100 0 28|#66848c;100 $gradPercent|#7192aa;100 100" } diff --git a/demos/zinc-widget b/demos/zinc-widget index d468e3e..f09baa3 100644 --- a/demos/zinc-widget +++ b/demos/zinc-widget @@ -145,10 +145,11 @@ set lastLine "" .t insert end "\n" {} "Use of open GL\n" title .t insert end "1. The TkZinc Logo.\n" {demo demo-tkZincLogo} .t insert end "2. Applying transformations to an icon.\n" {demo demo-iconTransform} -.t insert end "3. Axial color variation on the X axis.\n" {demo demo-colorX} -.t insert end "4. Axial color variation on the Y axis.\n" {demo demo-colorY} -.t insert end "5. Circular color variation.\n" {demo demo-colorCircular} -.t insert end "6. The triangles item.\n" {demo demo-triangles} +.t insert end "3. Using the alpha information from an image (Need Img ext.).\n" {demo demo-photoAlpha} +.t insert end "4. Axial color variation on the X axis.\n" {demo demo-colorX} +.t insert end "5. Axial color variation on the Y axis.\n" {demo demo-colorY} +.t insert end "6. Circular color variation.\n" {demo demo-colorCircular} +.t insert end "7. The triangles item.\n" {demo demo-triangles} .t configure -state disabled focus .s -- cgit v1.1