selectByRect

$canvaseditor selectByRect enclosed
selects objects overlapping or enclosed by previously made rectangle

obj method canvaseditor selectByRect {{how enclosed}} {
  lassign [$self canvas coords selection] selx0 sely0 selx1 sely1
  $self canvas delete selection
  set items [$self canvas find $how $selx0 $sely0 $selx1 $sely1]
  set objects ""
  foreach item $items {
    if {[$self canvas itemcget $item -state] eq "disabled"} continue
    foreach tag [$self canvas gettags $item] {
      if {[regexp {(line|fill)(::.*)} $tag - class object]} then {
        lappend objects [$object topgroup]
      }
    }
  }
  set objects [lunique $objects]
  if {$how eq "enclosed"} then {
    set result {}
    foreach object $objects {
      lassign [$object bbox] objx0 objy0 objx1 objy1
      if {$selx0 > $objx0} continue
      if {$sely0 > $objy0} continue
      if {$selx1 < $objx1} continue
      if {$sely1 < $objy1} continue
      lappend result $object
    }
  } else {
    set result $objects
  }
  $self basicBindings on
  if {$result ne {}} then {
    $self select {*}$result 
  }
}

© Wolf-Dieter Busch | Home | Sitemap | Urheber | A-Z