| Description: |
If, in a canvas <Motion> handler, you draw within 2 pels of the cursor hot spot, then <Enter> bindings on canvas items don't work. Happens with 8.5, 8.6b1, and possibly earlier. The example below uses the 'none' cursor, but the bug will also occur with any of the stock cursors.
-cut here ----------------------------------------
#NB: THIS WORKS, AS IS, EXHIBITING THE DESIRED BEHAVIOUR (rectangle changes colour
# on enter/leave).
#TO EXHIBIT THE BUG, CHANGE 0 TO 1 THREE LINES BELOW THIS.
package require Tk
set cursor_style 0
# space at hot point. Works.
# set cursor_style to 1 for no space, -> doesn't work
proc main {} {
pack [canvas .c -bg white]
set r [.c create rectangle 40 40 240 140 -fill cyan]
.c bind $r <Enter> [list .c itemconfigure $r -fill pink]
.c bind $r <Leave> [list .c itemconfigure $r -fill cyan]
.c configure -cursor "none"
set ::cursor_items ""
bind .c <Enter> {draw_cursor %x %y}
bind .c <Motion> {draw_cursor %x %y}
bind .c <Leave> erase_cursor
}
proc erase_cursor {} {
foreach x $::cursor_items {.c delete $x}
}
proc draw_cursor {x y} {
erase_cursor
set ::cursor_items ""
if {$::cursor_style == 0} {set d 2} else {set d 0}
set s 24
# s sets cursor size, d is central gap size
set x1 [expr {$x - $s}]
set x2 [expr {$x + $s}]
set y1 [expr {$y - $s}]
set y2 [expr {$y + $s}]
lappend ::cursor_items [.c create line $x1 $y [expr {$x - $d}] $y ]
lappend ::cursor_items [.c create line [expr {$x + $d}] $y $x2 $y ]
lappend ::cursor_items [.c create line $x $y1 $x [expr {$y - $d}]]
lappend ::cursor_items [.c create line $x [expr {$y + $d}] $x $y2]
}
main
|