From ef07ddc87875cc9b88715099434e2dcff4726322 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Mon, 23 Feb 2004 09:16:48 +0000 Subject: Started reworking Tcl demos --- demos/curveBezier.tcl | 127 ++++++++------- demos/fillRule.tcl | 28 ++-- demos/iconTransform.tcl | 5 +- demos/magicLens.tcl | 2 +- demos/transforms.tcl | 413 ++++++++++++++++++++++-------------------------- demos/zinc-widget | 16 +- 6 files changed, 285 insertions(+), 306 deletions(-) (limited to 'demos') diff --git a/demos/curveBezier.tcl b/demos/curveBezier.tcl index f90f2da..a26f5b8 100644 --- a/demos/curveBezier.tcl +++ b/demos/curveBezier.tcl @@ -13,6 +13,12 @@ wm title $w "Zinc Curve Bezier Demonstration" wm iconname $w Curve set defaultfont [font create -family Helvetica -size 10 -weight bold] +set imagePath [file join $zinc_library demos images] +set texture [image create photo -file [file join $imagePath paper-grey1.gif]] +set splineColor \#AA0000 +set handleColor grey70 +set barColor grey30 +set textColor grey20 frame $w.buttons pack $w.buttons -side bottom -fill x -pady 2m @@ -30,130 +36,129 @@ $w.text insert 0.0 { You can move the handles to modify the bezier curves } -zinc $w.zinc -width 700 -height 650 -font 9x15 -borderwidth 0 -backcolor white +zinc $w.zinc -width 700 -height 650 -font 9x15 -borderwidth 0 -tile $texture pack $w.zinc set group [$w.zinc add group 1] -$w.zinc add text $group -position {50 20} -anchor w \ - -text {Examples of curve items using cubic bezier control points} \ - -color grey20 +$w.zinc add text $group -position {50 20} -anchor w -color $textColor \ + -text {Examples of curve items using cubic bezier control points} -## Please note: much of the following items below could be computed -$w.zinc add text $group -position {25 270} -anchor w -tags bezier1 \ - -color grey20 -width 270 +## Please note: much of the items below could be computed +set t [$w.zinc add text $group -anchor w -tags bezier1 -color $textColor -width 270] +$w.zinc translate $t 25 270 $w.zinc add curve $group {100 200 100 100} -tags {line1 l1-2} \ - -linecolor \#888888 -filled 0 -linewidth 2 + -linecolor $barColor -filled 0 -linewidth 2 $w.zinc add curve $group {400 100 400 200} -tags {line1 l3-4} \ - -linecolor \#888888 -filled 0 -linewidth 2 + -linecolor $barColor -filled 0 -linewidth 2 $w.zinc add curve $group {{100 200} {100 100 c} {400 100 c} {400 200}} \ - -tags bezier1 -closed 0 -linecolor red -linewidth 5 + -tags bezier1 -closed 0 -linecolor $splineColor -linewidth 5 $w.zinc add arc $group {90 190 110 210} -tags {handle1 p1} -filled 1 \ -fillcolor \#BBBBBB $w.zinc add arc $group {90 90 110 110} -tags {handle1 p2} -filled 1 \ - -linewidth 0 -fillcolor grey80 -filled 1 + -linewidth 0 -fillcolor $handleColor -filled 1 $w.zinc add arc $group {390 90 410 110} -tags {handle1 p3} -filled 1 \ - -linewidth 0 -fillcolor grey80 -filled 1 + -linewidth 0 -fillcolor $handleColor -filled 1 $w.zinc add arc $group {390 190 410 210} -tags {handle1 p4} -filled 1 \ -fillcolor \#BBBBBB -$w.zinc add text $group -position {570 270} -anchor w -tags bezier2 \ - -color grey20 -width 270 +set t [$w.zinc add text $group -anchor w -tags bezier2 -color $textColor -width 270] +$w.zinc translate $t 570 270 $w.zinc add curve $group {600 200 675 100} -tags {line2 l1-2} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {975 100 900 200} -tags {line2 l3-4} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {{600 200} {675 100 c} {975 100 c} {900 200}} \ - -tags bezier2 -closed 0 -linecolor red -linewidth 5 + -tags bezier2 -closed 0 -linecolor $splineColor -linewidth 5 $w.zinc add arc $group {590 190 610 210} -tags {handle2 p1} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor $w.zinc add arc $group {665 90 685 110} -tags {handle2 p2} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {965 90 985 110} -tags {handle2 p3} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {890 190 910 210} -tags {handle2 p4} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor -$w.zinc add text $group -position {25 570} -anchor w -tags bezier3 \ - -color grey20 -width 270 +set t [$w.zinc add text $group -anchor w -tags bezier3 -color $textColor -width 270] +$w.zinc translate $t 25 570 $w.zinc add curve $group {100 500 25 400} -tags {line3 l1-2} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {475 400 400 500} -tags {line3 l3-4} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {{100 500} {25 400 c} {475 400 c} {400 500}} \ - -tags {bezier3} -closed 0 -linecolor red -linewidth 5 + -tags {bezier3} -closed 0 -linecolor $splineColor -linewidth 5 $w.zinc add arc $group {90 490 110 510} -tags {handle3 p1} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor $w.zinc add arc $group {15 390 35 410} -tags {handle3 p2} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {465 390 485 410} -tags {handle3 p3} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {390 490 410 510} -tags {handle3 p4} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor -$w.zinc add text $group -position {570 570} -anchor w -tags bezier4 \ - -color grey20 -width 270 +set t [$w.zinc add text $group -anchor w -tags bezier4 -color $textColor -width 270] +$w.zinc translate $t 570 570 $w.zinc add curve $group {600 500 600 350} -tags {line4 l1-2} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {900 650 900 500} -tags {line4 l3-4} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {{600 500} {600 350 c} {900 650 c} {900 500}} \ - -tags {bezier4} -closed 0 -linecolor red -linewidth 5 + -tags {bezier4} -closed 0 -linecolor $splineColor -linewidth 5 $w.zinc add arc $group {590 490 610 510} -tags {handle4 p1} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor $w.zinc add arc $group {590 340 610 360} -tags {handle4 p2} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {890 640 910 660} -tags {handle4 p3} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {890 490 910 510} -tags {handle4 p4} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor -$w.zinc add text $group -position {25 870} -anchor w -tags bezier5 \ - -color grey20 -width 270 +set t [$w.zinc add text $group -anchor w -tags bezier5 -color $textColor -width 270] +$w.zinc translate $t 25 870 $w.zinc add curve $group {100 800 175 700} -tags {line5 l1-2} \ - -linecolor \#888888 -filled 0 -linewidth 2 + -linecolor $barColor -filled 0 -linewidth 2 $w.zinc add curve $group {325 700 400 800} -tags {line5 l3-4} \ - -linecolor \#888888 -filled 0 -linewidth 2 + -linecolor $barColor -filled 0 -linewidth 2 $w.zinc add curve $group {{100 800} {175 700 c} {325 700 c} {400 800}} \ - -tags {bezier5} -closed 0 -linecolor red -linewidth 5 + -tags {bezier5} -closed 0 -linecolor $splineColor -linewidth 5 $w.zinc add arc $group {90 790 110 810} -tags {handle5 p1} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor $w.zinc add arc $group {165 690 185 710} -tags {handle5 p2} -filled 1 \ - -linewidth 0 -fillcolor grey80 -filled 1 + -linewidth 0 -fillcolor $handleColor -filled 1 $w.zinc add arc $group {315 690 335 710} -tags {handle5 p3} -filled 1 \ - -linewidth 0 -fillcolor grey80 -filled 1 + -linewidth 0 -fillcolor $handleColor -filled 1 $w.zinc add arc $group {390 790 410 810} -tags {handle5 p4} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor -$w.zinc add text $group -position {570 970} -anchor w -tags bezier6 \ - -color grey20 -width 280 +set t [$w.zinc add text $group -anchor w -tags bezier6 -color $textColor -width 280] +$w.zinc translate $t 570 970 $w.zinc add curve $group {600 800 625 700} -tags {line6 l1-2} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {725 700 750 800} -tags {line6 l3-4} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {750 800 775 900} -tags {line6 l4-5} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group {875 900 900 800} -tags {line6 l6-7} \ - -linecolor \#888888 -linewidth 2 + -linecolor $barColor -linewidth 2 $w.zinc add curve $group { {600 800} {625 700 c} {725 700 c} {750 800} {775 900 c} {875 900 c} {900 800} -} -tags {bezier6} -filled 0 -closed 0 -linecolor red -linewidth 5 +} -tags {bezier6} -filled 0 -closed 0 -linecolor $splineColor -linewidth 5 $w.zinc add arc $group {590 790 610 810} -tags {handle6 p1} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor $w.zinc add arc $group {615 690 635 710} -tags {handle6 p2} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {715 690 735 710} -tags {handle6 p3} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {740 790 760 810} -tags {handle6 p4} -filled 1 \ -linecolor blue -fillcolor blue -linewidth 2 $w.zinc add arc $group {766 891 784 909} -tags {handle6 p5} -filled 1 \ - -linecolor grey80 -linewidth 4 + -fillcolor $handleColor $w.zinc add arc $group {865 890 885 910} -tags {handle6 p6} -filled 1 \ - -linewidth 0 -fillcolor grey80 + -linewidth 0 -fillcolor $handleColor $w.zinc add arc $group {890 790 910 810} -tags {handle6 p7} -filled 1 \ - -linecolor grey80 -linewidth 2 + -fillcolor $handleColor $w.zinc scale $group 0.6 0.6 diff --git a/demos/fillRule.tcl b/demos/fillRule.tcl index d04b211..640fd1e 100644 --- a/demos/fillRule.tcl +++ b/demos/fillRule.tcl @@ -28,12 +28,15 @@ pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 ####### -fillrule attribute of curves ####### contour coords and clone method -zinc $w.zinc -width 550 -height 630 -font 10x20 -borderwidth 0 -backcolor white +set imagePath [file join $zinc_library demos images] +set texture [image create photo -file [file join $imagePath paper-grey1.gif]] + +zinc $w.zinc -width 550 -height 680 -font 10x20 -borderwidth 0 -tile $texture pack $w.zinc -$w.zinc add text 1 -position {20 8} -text {This still static example reproduces figure 11-3 - of "The OpenGL Programming Guide 3rd Edition" V 1.2} +$w.zinc add text 1 -position {20 8} -alignment center -text {This static example reproduces figure 11-3 +of "The OpenGL Programming Guide 3rd Edition" V 1.2} set group [$w.zinc add group 1] @@ -42,7 +45,7 @@ set curve1 [$w.zinc add curve $g1 {}] $w.zinc contour $curve1 add +1 { 0 0 0 120 120 120 120 0 0 0} $w.zinc contour $curve1 add +1 { 20 20 20 100 100 100 100 20 20 20} $w.zinc contour $curve1 add +1 { 40 40 40 80 80 80 80 40 40 40} -$w.zinc translate $g1 40 40 +$w.zinc translate $g1 100 100 set g2 [$w.zinc add group $group] @@ -50,7 +53,7 @@ set curve2 [$w.zinc add curve $g2 {}] $w.zinc contour $curve2 add +1 { 0 0 0 120 120 120 120 0 0 0} $w.zinc contour $curve2 add -1 { 20 20 20 100 100 100 100 20 20 20} $w.zinc contour $curve2 add -1 { 40 40 40 80 80 80 80 40 40 40} -$w.zinc translate $g2 200 40 +$w.zinc translate $g2 260 100 set g3 [$w.zinc add group $group] @@ -58,22 +61,25 @@ set curve3 [$w.zinc add curve $g3 {}] $w.zinc contour $curve3 add +1 { 20 0 20 120 100 120 100 0 20 0} $w.zinc contour $curve3 add +1 { 40 20 60 120 80 20 40 20} $w.zinc contour $curve3 add +1 { 0 60 0 80 120 80 120 60 0 60} -$w.zinc translate $g3 360 40 +$w.zinc translate $g3 420 100 set g4 [$w.zinc add group $group] set curve4 [$w.zinc add curve $g4 {}] $w.zinc contour $curve4 add +1 { 0 0 0 140 140 140 140 60 60 60 60 80 80 80 80 40 40 40 40 100 100 100 100 20 20 20 20 120 120 120 120 0 0 0} -$w.zinc translate $g4 520 40 +$w.zinc translate $g4 580 100 $w.zinc scale $group 0.6 0.6 -$w.zinc translate $group 80 20 +$w.zinc translate $group 80 40 -$w.zinc add text $group -position {-110 40} -text "contours\nand\nwinding\nnumbers" -$w.zinc add text $group -position {-110 170} -text "winding\nrules" +set t [$w.zinc add text $group -underlined yes -text "Contours"] +$w.zinc translate $t 280 30 +set t [$w.zinc add text $group -underlined yes -text "-fillrule"] +$w.zinc translate $t -110 30 set dy 0 foreach fillrule {odd nonzero positive negative abs_geq_2} { set dy [expr $dy + 160] - $w.zinc add text $group -position "-110 [expr 100+$dy]" -text $fillrule + set t [$w.zinc add text $group -text $fillrule] + $w.zinc translate $t -110 [expr 100+$dy] foreach item "$curve1 $curve2 $curve3 $curve4" { set clone [$w.zinc clone $item -fillrule $fillrule -filled 1] $w.zinc translate $clone 0 $dy diff --git a/demos/iconTransform.tcl b/demos/iconTransform.tcl index 2dd4d45..442d7a5 100644 --- a/demos/iconTransform.tcl +++ b/demos/iconTransform.tcl @@ -31,12 +31,11 @@ pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 text $w.text -relief sunken -borderwidth 2 -height 6 pack $w.text -expand yes -fill both -$w.text insert end {This demo needs openGL for rescaling/rotating the icon - You can transform this gif image with your mouse: +$w.text insert end {You can transform this image with your mouse: Drag-Button 1 for moving, Drag-Button 2 for zooming, Drag-Button 3 for rotating, - Shift-Drag-Button 1 for modifying the transparency.} + Shift-Drag-Button 1 for modifying the transparency (OpenGL only).} ########################################### diff --git a/demos/magicLens.tcl b/demos/magicLens.tcl index a095248..b44254b 100644 --- a/demos/magicLens.tcl +++ b/demos/magicLens.tcl @@ -169,7 +169,7 @@ proc LensTranslate {way} { } -set w .testGraphics +set w .magicLens catch {destroy $w} toplevel $w wm title $w "Color Magic Lens Demonstration" diff --git a/demos/transforms.tcl b/demos/transforms.tcl index 3c6f5b6..c5222dd 100644 --- a/demos/transforms.tcl +++ b/demos/transforms.tcl @@ -80,20 +80,20 @@ tk_optionMenu $w.f.types itemType Rectangle Arc Curve Icon Tabular \ Text Track Triangles WayPoint grid $w.f.types -row 0 -column 1 -sticky w -button $w.f.add -text {Add item} -command addItem +button $w.f.add -text {Add item} -command "addItem $w.zinc" grid $w.f.add -row 0 -column 2 -padx 10 -sticky ew -button $w.f.addg -text {Add group} -command addGroup +button $w.f.addg -text {Add group} -command "addGroup $w.zinc" grid $w.f.addg -row 0 -column 3 -padx 10 -sticky ew -button $w.f.remove -text Remove -command removeItem +button $w.f.remove -text Remove -command "removeItem $w.zinc" grid $w.f.remove -row 0 -column 4 -padx 10 -sticky ew -checkbutton $w.f.cscale -text -composescale -command toggleComposeScale \ +checkbutton $w.f.cscale -text -composescale -command "toggleComposeScale $w.zinc" \ -variable composeScale grid $w.f.cscale -row 0 -column 6 -sticky w -checkbutton $w.f.crot -text -composesrotation -command toggleComposeRot \ +checkbutton $w.f.crot -text -composesrotation -command "toggleComposeRot $w.zinc" \ -variable composeRot grid $w.f.crot -row 1 -column 6 -sticky w @@ -101,57 +101,57 @@ grid $w.f.crot -row 1 -column 6 -sticky w set world [$w.zinc add group $top] set currentGroup $world $w.zinc add curve $top {0 0 80 0} -linewidth 3 \ - -linecolor $worldAxisColor -lastend {6 8 3} -tags "axis:$world" + -linecolor $worldAxisColor -lastend {6 8 3} -tags axis:$world $w.zinc add curve $top {0 0 0 80} -linewidth 3 \ - -linecolor $worldAxisColor -lastend {6 8 3} -tags "axis:$world" + -linecolor $worldAxisColor -lastend {6 8 3} -tags axis:$world $w.zinc add rectangle $top {-2 -2 2 2} -filled 1 \ -fillcolor $worldAxisColor -linecolor $worldAxisColor \ - -linewidth 3 -tags "axis:$world" + -linewidth 3 -tags axis:$world $w.zinc add text $top -text "This is the origin\nof the world" \ -anchor s -color $worldAxisColor -alignment center \ -tags [list "axis:$world" text] - - -bind $w.zinc <1> "mouseAdd Item %x %y" -bind $w.zinc <2> "mouseAdd Group %x %y" -bind $w.zinc moveUp -bind $w.zinc moveLeft -bind $w.zinc moveRight -bind $w.zinc moveDown -bind $w.zinc scaleDown -bind $w.zinc scaleDown -bind $w.zinc scaleUp -bind $w.zinc scaleUp -bind $w.zinc reset -bind $w.zinc resetChildren -bind $w.zinc rotateLeft -bind $w.zinc rotateRight -bind $w.zinc {swapAxis y} -bind $w.zinc {swapAxis y} -bind $w.zinc {swapAxis x} -bind $w.zinc {swapAxis x} -bind $w.zinc deleteItem - -bind $w.zinc "resize %w %h" +$w.zinc lower axis:$world + +bind $w.zinc <1> {mouseAdd %W Item %x %y} +bind $w.zinc <2> {mouseAdd %W Group %x %y} +bind $w.zinc {moveUp %W} +bind $w.zinc {moveLeft %W} +bind $w.zinc {moveRight %W} +bind $w.zinc {moveDown %W} +bind $w.zinc {scaleDown %W} +bind $w.zinc {scaleDown %W} +bind $w.zinc {scaleUp %W} +bind $w.zinc {scaleUp %W} +bind $w.zinc {reset %W} +bind $w.zinc {resetChildren %W} +bind $w.zinc {rotateLeft %W} +bind $w.zinc {rotateRight %W} +bind $w.zinc {swapAxis %W y} +bind $w.zinc {swapAxis %W y} +bind $w.zinc {swapAxis %W x} +bind $w.zinc {swapAxis %W x} +bind $w.zinc {removeItem %W} + +bind $w.zinc {resize %W %w %h} focus $w.zinc tk_focusFollowsMouse -proc resize {width height} { - global w world +proc resize {z width height} { + global world set x [expr $width/2] set y [expr $height/2] - $w.zinc treset $world - $w.zinc treset "axis:$world" - $w.zinc translate $world $x $y - $w.zinc translate "axis:$world" $x $y + $z treset $world + $z treset axis:$world + $z translate $world $x $y + $z translate axis:$world $x $y } -proc swapAxis {axis} { - global w currentItem +proc swapAxis {z axis} { + global currentItem set sx 1 set sy 1 @@ -161,361 +161,334 @@ proc swapAxis {axis} { set sy -1 } if {$currentItem != 0} { - $w.zinc scale $currentItem $sx $sy - $w.zinc scale "axisgrp:$currentItem" $sx $sy + $z scale $currentItem $sx $sy + $z scale axisgrp:$currentItem $sx $sy } } -proc toggleComposeRot {} { - global w currentItem composeRot +proc toggleComposeRot {z} { + global currentItem composeRot if {$currentItem != 0} { - $w.zinc itemconfigure $currentItem -composerotation $composeRot - $w.zinc itemconfigure "axisgrp:$currentItem" -composerotation $composeRot + $z itemconfigure $currentItem -composerotation $composeRot + $z itemconfigure axisgrp:$currentItem -composerotation $composeRot } } -proc toggleComposeScale {} { - global w currentItem composeScale +proc toggleComposeScale {z} { + global currentItem composeScale if {$currentItem != 0} { - $w.zinc itemconfigure $currentItem -composescale $composeScale - $w.zinc itemconfigure "axisgrp:$currentItem" -composescale $composeScale + $z itemconfigure $currentItem -composescale $composeScale + $z itemconfigure axisgrp:$currentItem -composescale $composeScale } } -proc deleteItem {} { - global w currentItem currentGroup world - +proc removeItem {z} { + global currentGroup currentItem world + if {$currentItem != 0} { - $w.zinc remove $currentItem - $w.zinc remove axisgrp:$currentItem - if { $currentGroup == $currentItem } { + $z remove $currentItem axisgrp:$currentItem + if {$currentItem == $currentGroup} { set currentGroup $world } set currentItem 0 + set composeScale 1 + set composeRot 1 } } -proc dragItem {x y} { - global w drag currentItem +proc dragItem {z x y} { + global drag currentItem set drag 1 if {$currentItem == 0} { return } - set group [$w.zinc group $currentItem] - foreach {x y} [$w.zinc transform $group "$x $y"] break + set group [$z group $currentItem] + foreach {x y} [$z transform $group [list $x $y]] break - $w.zinc treset $currentItem - $w.zinc treset "axisgrp:$currentItem" - $w.zinc translate $currentItem $x $y - $w.zinc translate "axisgrp:$currentItem" $x $y + $z treset $currentItem + $z treset axisgrp:$currentItem + $z translate $currentItem $x $y + $z translate axisgrp:$currentItem $x $y } -proc select {} { - global w - - foreach t [$w.zinc gettags current] { +proc select {z} { + foreach t [$z gettags current] { if {[regexp {^axis:(\d+)} $t m item]} { - changeItem $item + changeItem $z $item } } } -proc changeItem {item} { - global w currentItem currentGroup +proc changeItem {z item} { + global currentItem currentGroup global composeRot composeScale global drag activeAxisColor inactiveAxisColor if {($currentItem != 0) && !$drag} { - $w.zinc itemconfigure "axis:$currentItem && !text" \ + $z itemconfigure axis:$currentItem&&!text \ -linecolor $inactiveAxisColor -fillcolor $inactiveAxisColor - if {$currentItem != $currentGroup} { - $w.zinc itemconfigure "axis:$currentItem && !text" -linewidth 1 - } } if {($currentItem == 0) || ($item != $currentItem)} { - $w.zinc itemconfigure "axis:$item && !text" \ + $z itemconfigure axis:$item&&!text \ -linecolor $activeAxisColor -fillcolor $activeAxisColor -linewidth 3 set currentItem $item - set composeRot [$w.zinc itemcget $currentItem -composerotation] - $w.zinc itemconfigure "axisgrp:$currentItem" -composerotation $composeRot - set composeScale [$w.zinc itemcget $currentItem -composescale] - $w.zinc itemconfigure "axisgrp:$currentItem" -composescale $composeScale + set composeRot [$z itemcget $currentItem -composerotation] + $z itemconfigure axisgrp:$currentItem -composerotation $composeRot + set composeScale [$z itemcget $currentItem -composescale] + $z itemconfigure axisgrp:$currentItem -composescale $composeScale } elseif {!$drag} { set currentItem 0 set composeRot 1 set composeScale 1 } - set drag 0 } -proc selectGroup {} { - global w - - foreach t [$w.zinc gettags current] { +proc selectGroup {z} { + foreach t [$z gettags current] { if {[regexp {^axis:(\d+)} $t m item]} { - changeGroup $item + changeGroup $z $item + return } } } -proc changeGroup {grp} { - global w currentItem currentGroup world +proc changeGroup {z grp} { + global currentItem currentGroup world - changeItem $grp - $w.zinc itemconfigure "axis:$currentGroup && !text" -linewidth 1 + changeItem $z $grp if {$currentItem != 0} { set currentGroup $currentItem } else { set currentGroup $world } - - $w.zinc itemconfigure "axis:$currentGroup && !text" -linewidth 3 } -proc reset {} { - global w currentItem +proc reset {z } { + global currentItem if {$currentItem != 0} { - $w.zinc treset $currentItem - $w.zinc treset "axisgrp:$currentItem" + $z treset $currentItem + $z treset axisgrp:$currentItem } } -proc resetChildren {} { - global w currentItem +proc resetChildren {z} { + global currentItem - if {($currentItem != 0) && ([$w.zinc type $currentItem] == "group")} { - $w.zinc addtag rt withtag .$currentItem. - $w.zinc treset rt - $w.zinc dtag rt rt + if {($currentItem != 0) && ([$z type $currentItem] == "group")} { + $z addtag rt withtag .$currentItem. + $z treset rt + $z dtag rt rt } } -proc moveUp {} { - move 0 20 +proc moveUp {z} { + move $z 0 20 } -proc moveDown {} { - move 0 -20 +proc moveDown {z} { + move $z 0 -20 } -proc moveRight {} { - move 20 0 +proc moveRight {z} { + move $z 20 0 } -proc moveLeft {} { - move -20 0 +proc moveLeft {z} { + move $z -20 0 } -proc move {dx dy} { - global w currentItem +proc move {z dx dy} { + global currentItem if {$currentItem != 0} { - $w.zinc translate $currentItem $dx $dy - $w.zinc translate "axisgrp:$currentItem" $dx $dy + $z translate $currentItem $dx $dy + $z translate axisgrp:$currentItem $dx $dy } } -proc scaleUp {} { - scale 1.1 1.1 +proc scaleUp {z} { + scale $z 1.1 1.1 } -proc scaleDown {} { - scale 0.9 0.9 +proc scaleDown {z} { + scale $z 0.9 0.9 } -proc scale {dx dy} { - global w currentItem +proc scale {z dx dy} { + global currentItem if {$currentItem != 0} { - $w.zinc scale $currentItem $dx $dy - $w.zinc scale "axisgrp:$currentItem" $dx $dy + $z scale $currentItem $dx $dy + $z scale axisgrp:$currentItem $dx $dy } } -proc rotateLeft {} { - rotate [expr -3.14159/18] +proc rotateLeft {z} { + rotate $z [expr -3.14159/18] } -proc rotateRight {} { - rotate [expr 3.14159/18] +proc rotateRight {z} { + rotate $z [expr 3.14159/18] } -proc rotate {angle} { - global w currentItem +proc rotate {z angle} { + global currentItem if {$currentItem != 0} { - $w.zinc rotate $currentItem $angle - $w.zinc rotate "axisgrp:$currentItem" $angle + $z rotate $currentItem $angle + $z rotate axisgrp:$currentItem $angle } } -proc newRectangle {} { - global w currentGroup +proc newRectangle {z} { + global currentGroup - return [$w.zinc add rectangle $currentGroup {-15 -15 15 15} \ + return [$z add rectangle $currentGroup {-15 -15 15 15} \ -filled 1 -linewidth 0 -fillcolor tan] } -proc newArc {} { - global w currentGroup +proc newArc {z} { + global currentGroup - return [$w.zinc add arc $currentGroup {-25 -15 25 15} \ + return [$z add arc $currentGroup {-25 -15 25 15} \ -filled 1 -linewidth 0 -fillcolor tan] } -proc newCurve {} { - global w currentGroup +proc newCurve {z} { + global currentGroup - return [$w.zinc add curve $currentGroup {-15 -15 -15 15 15 15 15 -15} \ + return [$z add curve $currentGroup {-15 -15 -15 15 15 15 15 -15} \ -filled 1 -linewidth 0 -fillcolor tan] } -proc newText {} { - global w currentGroup +proc newText {z} { + global currentGroup - set item [$w.zinc add text $currentGroup -anchor s] - $w.zinc itemconfigure $item -text "Item id: $item" + set item [$z add text $currentGroup -anchor s] + $z itemconfigure $item -text "Item id: $item" return $item; } -proc newIcon {} { - global w currentGroup +proc newIcon {z} { + global currentGroup - return [$w.zinc add icon $currentGroup -image logo -anchor center] + return [$z add icon $currentGroup -image logo -anchor center] } -proc newTriangles {} { - global w currentGroup +proc newTriangles {z} { + global currentGroup - return [$w.zinc add triangles $currentGroup \ + return [$z add triangles $currentGroup \ {-25 15 -10 -15 5 15 20 -15 35 15 50 -30} \ -colors {tan wheat tan wheat}] } -proc newTrack {} { - global w currentGroup +proc newTrack {z} { + global currentGroup set labelformat {x80x50+0+0 a0a0^0^0 a0a0^0>1 a0a0>2>1 x30a0>3>1 a0a0^0>2} - set item [$w.zinc add track $currentGroup 6 -labelformat $labelformat \ + set item [$z add track $currentGroup 6 -labelformat $labelformat \ -speedvector {30 -15} -markersize 20] - $w.zinc itemconfigure $item 0 -filled 0 -bordercolor DarkGreen -border contour - $w.zinc itemconfigure $item 1 -filled 1 -backcolor gray60 -text AFR6128 - $w.zinc itemconfigure $item 2 -filled 0 -backcolor gray65 -text 390 - $w.zinc itemconfigure $item 3 -filled 0 -backcolor gray65 -text / - $w.zinc itemconfigure $item 4 -filled 0 -backcolor gray65 -text 350 - $w.zinc itemconfigure $item 5 -filled 0 -backcolor gray65 -text TUR + $z itemconfigure $item 0 -filled 0 -bordercolor DarkGreen -border contour + $z itemconfigure $item 1 -filled 1 -backcolor gray60 -text AFR6128 + $z itemconfigure $item 2 -filled 0 -backcolor gray65 -text 390 + $z itemconfigure $item 3 -filled 0 -backcolor gray65 -text / + $z itemconfigure $item 4 -filled 0 -backcolor gray65 -text 350 + $z itemconfigure $item 5 -filled 0 -backcolor gray65 -text TUR return $item; } -proc newWayPoint {} { - global w currentGroup +proc newWayPoint {z} { + global currentGroup set labelformat {a0a0+0+0 a0a0>0^1} - set item [$w.zinc add waypoint $currentGroup 2 -labelformat $labelformat] - $w.zinc itemconfigure $item 0 -filled 1 -backcolor DarkGreen -text TUR - $w.zinc itemconfigure $item 1 -text >>> + set item [$z add waypoint $currentGroup 2 -labelformat $labelformat] + $z itemconfigure $item 0 -filled 1 -backcolor DarkGreen -text TUR + $z itemconfigure $item 1 -text >>> return $item; } -proc newTabular {} { - global w currentGroup +proc newTabular {z} { + global currentGroup set labelformat {f700f600+0+0 f700a0^0^0 f700a0^0>1 \ f700a0^0>2 f700a0^0>3 f700a0^0>4 f700a0^0>5} - set item [$w.zinc add tabular $currentGroup 7 -labelformat $labelformat] - $w.zinc itemconfigure $item 0 -filled 1 -border contour \ + set item [$z add tabular $currentGroup 7 -labelformat $labelformat] + $z itemconfigure $item 0 -filled 1 -border contour \ -bordercolor black -backcolor gray60 - $w.zinc itemconfigure $item 1 -alignment center -text AFR6128 - $w.zinc itemconfigure $item 2 -alignment center -text 390 - $w.zinc itemconfigure $item 3 -alignment center -text 370 - $w.zinc itemconfigure $item 4 -alignment center -text 350 - $w.zinc itemconfigure $item 5 -alignment center -text 330 - $w.zinc itemconfigure $item 6 -alignment center -text TUR + $z itemconfigure $item 1 -alignment center -text AFR6128 + $z itemconfigure $item 2 -alignment center -text 390 + $z itemconfigure $item 3 -alignment center -text 370 + $z itemconfigure $item 4 -alignment center -text 350 + $z itemconfigure $item 5 -alignment center -text 330 + $z itemconfigure $item 6 -alignment center -text TUR return $item; } -proc addAxes {item length command inFront} { - global w currentGroup +proc addAxes {z item length command inFront} { + global currentGroup - set axesGroup [$w.zinc add group $currentGroup -tags "axisgrp:$item"] - $w.zinc add curve $axesGroup "0 0 $length 0" -linewidth 2 \ - -lastend {6 8 3} -tags "axis:$item" - $w.zinc add curve $axesGroup "0 0 0 $length" -linewidth 2 \ - -lastend {6 8 3} -tags "axis:$item" - $w.zinc add rectangle $axesGroup {-2 -2 2 2} -filled 1 \ - -linewidth 0 -composescale 0 -tags "axis:$item" + set axesGroup [$z add group $currentGroup -tags axisgrp:$item] + $z add curve $axesGroup [list 0 0 $length 0] -linewidth 3 \ + -lastend {6 8 3} -tags axis:$item + $z add curve $axesGroup [list 0 0 0 $length] -linewidth 3 \ + -lastend {6 8 3} -tags axis:$item + $z add rectangle $axesGroup {-3 -3 3 3} -filled 1 \ + -linewidth 0 -composescale 0 -tags axis:$item if {$inFront} { - $w.zinc raise $item $axesGroup + $z raise $item $axesGroup } - $w.zinc bind "axis:$item" "dragItem %x %y" - $w.zinc bind "axis:$item" $command + $z bind axis:$item {dragItem %W %x %y} + $z bind axis:$item "$command %W; set drag 0" } -proc addItem {} { +proc addItem {z} { global itemType set length 25 set itemOnTop 0 - set item [eval "new$itemType"] + set item [eval "new$itemType $z"] if {($itemType == "Track") || ($itemType == "WayPoint")} { set itemOnTop 1 } - addAxes $item 25 select $itemOnTop - changeItem $item + addAxes $z $item 25 select $itemOnTop + changeItem $z $item } -proc addGroup {} { - global w currentGroup +proc addGroup {z} { + global currentGroup - set item [$w.zinc add group $currentGroup] + set item [$z add group $currentGroup] - addAxes $item 80 selectGroup 1 - changeGroup $item + addAxes $z $item 80 selectGroup 1 + changeGroup $z $item } -proc mouseAdd {itemOrGroup x y} { - global w currentGroup currentItem - - foreach {x y} [$w.zinc transform $currentGroup "$x $y"] break - set item [$w.zinc find withtag current] +proc mouseAdd {z itemOrGroup x y} { + global currentGroup currentItem - if {[llength $item] != 0} { - foreach t [$w.zinc gettags [lindex $item 0]] { - if {[regexp {^axis} $t]} { - return; - } - } + if {[llength [$z find withtag current]] != 0} { + return } - eval "add$itemOrGroup" + foreach {x y} [$z transform $currentGroup [list $x $y]] break - $w.zinc translate $currentItem $x $y - $w.zinc translate "axisgrp:$currentItem" $x $y -} + eval "add$itemOrGroup $z" -proc removeItem {} { - global w currentGroup currentItem world - - if {$currentItem != 0} { - $w.zinc remove $currentItem "axisgrp:$currentItem" - if {$currentItem == $currentGroup} { - set currentGroup $world - } - set currentItem 0 - set composeScale 1 - set composeRot 1 - } + $z translate $currentItem $x $y + $z translate axisgrp:$currentItem $x $y } + diff --git a/demos/zinc-widget b/demos/zinc-widget index bde9898..1ff1f05 100644 --- a/demos/zinc-widget +++ b/demos/zinc-widget @@ -125,8 +125,6 @@ set lastLine "" .t insert end "2. All items options (and their types).\n" {demo demo-allOptions} .t insert end "3. Examples of line style and line termination.\n" {demo demo-lines} .t insert end "4. Curves with multiple contours.\n" {demo demo-contours} -.t insert end "5. Examples of labelformat.\n" {demo demo-labelformat} -.t insert end "6. Use of mapinfos.\n" {demo demo-mapinfo} .t insert end "7. Curves with cubic bezier control points.\n" {demo demo-curveBezier} .t insert end "8. Curves with multiple contours and various fillrule.\n" {demo demo-fillRule} @@ -137,15 +135,8 @@ set lastLine "" .t insert end "4. \"Windows\" with four glasses using curve with multiple contours.\n" {demo demo-windowContours} .t insert end "5. Pathtags demonstration.\n" {demo demo-pathTags} -.t insert end "\n" {} "Interactions\n" title -.t insert end "1. Simple interaction on a track.\n" {demo demo-simpleInteractionTrack} -.t insert end "2. Text input in a text item and a track item.\n" {demo demo-textInput} - .t insert end "\n" {} "Transformation\n" title -.t insert end "1. Translating.\n" {demo demo-translation} -.t insert end "2. Rotating.\n" {demo demo-rotation} -.t insert end "3. Zooming.\n" {demo demo-zoom} -.t insert end "4. Transformation testbed.\n" {demo demo-transforms} +.t insert end "1. Transformation testbed.\n" {demo demo-transforms} .t insert end "\n" {} "Use of open GL\n" title .t insert end "1. The TkZinc Logo.\n" {demo demo-tkZincLogo} @@ -157,6 +148,11 @@ set lastLine "" .t insert end "7. The triangles item.\n" {demo demo-triangles} .t insert end "8. Relief testbed.\n" {demo demo-reliefs} +.t insert end "\n" {} "ATC oriented features and items\n" title +.t insert end "1. Examples of labelformat.\n" {demo demo-labelformat} +.t insert end "2. Simple interaction on a track.\n" {demo demo-simpleInteractionTrack} +.t insert end "3. Text input in a text item and a track item.\n" {demo demo-textInput} + .t configure -state disabled focus .s -- cgit v1.1