Posted to tcl by kbk at Fri Feb 25 20:13:39 GMT 2011view raw

  1. proc startSelection {x y} {
  2. variable xstart
  3. variable ystart
  4. set xstart [.c canvasx $x]
  5. set ystart [.c canvasy $y]
  6. .c create rectangle $xstart $ystart $xstart $ystart -tags selector \
  7. -outline green -dash - -fill {}
  8. }
  9.  
  10. proc adjustSelection {x y} {
  11. variable xstart
  12. variable ystart
  13. set x [.c canvasx $x]
  14. set y [.c canvasy $y]
  15. .c coords selector $xstart $ystart $x $y
  16. return [list $xstart $ystart $x $y]
  17. }
  18.  
  19. proc endSelection {x y b} {
  20. lassign [adjustSelection $x $y] x0 y0 x1 y1
  21. .c delete selector
  22. # At this point you probably want to do [.c find overlapping $x0 $y0 $x1 $y1] and
  23. # do something with the result.
  24. }
  25.  
  26. bind .c <ButtonPress-1> [list startSelection %x %y]
  27. bind .c <B1-Motion> [list adjustSelection %x %y]
  28. bind .c <ButtonRelease-1> [list endSelection %x %y %b]