# tkCanvasItemOutline.tcl console show canvas .c -width 480 -height 480 -bg black pack .c bind . q {destroy .} bind .c{showDot .c %x %y} bind .c {moveDot .c %x %y} bind .c {hideDot .c} set ::prevcx "" set ::prevcy "" proc showDot {c x y} { set cx [$c canvasx $x] set cy [$c canvasy $y] $c create line $cx [expr $cy-5] $cx [expr $cy+6] -fill green -width 1 -tags cur -state disabled $c create line [expr $cx-5] $cy [expr $cx+6] $cy -fill green -width 1 -tags cur -state disabled set ::prevcx $cx set ::prevcy $cy } proc moveDot {c x y} { set cx [$c canvasx $x] set cy [$c canvasy $y] set dx [expr $cx - $::prevcx] set dy [expr $cy - $::prevcy] $c move cur $dx $dy set ::prevcx $cx set ::prevcy $cy } proc hideDot {c} { $c delete cur } #canvas item test: for { set wi 0 } { $wi < 10 } {incr wi} { set testitem [.c create rectangle [expr 120+$wi*20] 100 [expr 139+$wi*20] 110 -width $wi -outline red -fill blue] .c bind $testitem {putCanvXY .c %x %y enter} .c bind $testitem {putCanvXY .c %x %y motion} .c bind $testitem {putCanvXY .c %x %y leave} puts "horiz: wi=$wi: coords: [.c coords $testitem]; bbox: [.c bbox $testitem]" } for { set wi 0 } { $wi < 10 } {incr wi} { set testitem [.c create rectangle 70 [expr 150+$wi*20] 80 [expr 169+$wi*20] -width $wi -outline red -fill blue] .c bind $testitem {putCanvXY .c %x %y enter} .c bind $testitem {putCanvXY .c %x %y motion} .c bind $testitem {putCanvXY .c %x %y leave} puts "vert: wi=$wi: coords: [.c coords $testitem]; bbox: [.c bbox $testitem]" } proc putCanvXY {c x y str} { puts "cx: [$c canvasx $x] cy: [$c canvasy $y] ($str)" }
width option | d1 | d2 | coords x0 y0 x1 y1 | bbox x0 y0 x1 y1 | actual outline coverage | cx for Enter event |
---|---|---|---|---|---|---|
0 | 0 | 0 | 70 150 80 169 | 69 149 81 170 | (no outline. body:70-80) | 69-81 |
1 | 1 | 1 | 70 170 80 189 | 69 169 81 190 | 70-70, 81-81 | 69-81 |
2 | 1 | 1 | 70 190 80 209 | 69 189 81 210 | 69-70, 80-81 | 68-82 |
3 | 2 | 3 | 70 210 80 229 | 68 208 82 231 | 69-71, 80-82 | 68-82 |
4 | 2 | 3 | 70 230 80 249 | 68 228 82 251 | 68-71, 79-82 | 67-83 |
5 | 3 | 5 | 70 250 80 269 | 67 247 83 272 | 68-72, 79-83 | 67-83 |
6 | 3 | 5 | 70 270 80 289 | 67 267 83 292 | 67-72, 78-83 | 66-84 |
7 | 4 | 7 | 70 290 80 309 | 66 286 84 313 | 67-73, 78-84 | 66-84 |
8 | 4 | 7 | 70 310 80 329 | 66 306 84 333 | 66-73, 77-84 | 65-85 |
9 | 5 | 9 | 70 330 80 349 | 65 325 85 354 | 66-74, 77-85 | 65-85 |