canvasZ

$fill canvasZ
returns current index in canvas stack
$fill canvasZ indexZ
positions to desired indexZ in canvas stack. Manages additionally that stack order of lines remains untouched.

obj method fill canvasZ {{Z {}}} {
  set tag fill$self
  set item [$self canvas find withtag $tag]
  set myZindex [lsearch [$self canvas find all] $item]
  if {[string is integer -strict $Z]} then {
    $self canvas dtag edit$self
    foreach line [$self lines] {
      $self canvas addtag edit$self withtag line$line
    }
    if {$myZindex != $Z} then {
      if {$Z == 0} then {
        $self canvas lower $tag
      } else {
        if {$myZindex < $Z} then {
          set targetZ [+ $Z 2 [llength [my lines]]]
        } else {
          set targetZ $Z
        }
        set itemBelow [lindex [$self canvas find all] $targetZ-1]
        $self canvas raise $tag {*}$itemBelow
      }
    }
    $self canvas raise edit$self $tag
    $self canvas dtag edit$self
  } else {
    if {$Z ne ""} then {
      lindex [$self canvas find all] $myZindex-1
    } else {
      set myZindex
    }
  }
}

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