align

$canvaseditor align direction
arranges objects at common left, right, center, top, bottom, or middle.

obj method canvaseditor align how {
  set minX Inf
  set minY Inf
  set maxX -Inf
  set maxY -Inf
  foreach bb [$self selected bbox] {
    foreach {x0 y0 x1 y1} $bb {
      set minX [min $minX $x0]
      set minY [min $minY $y0]
      set maxX [max $maxX $x1]
      set maxY [max $maxY $y1]
    }
  }
  #
  set centerX [/ [+ $minX $maxX] 2.0]
  set centerY [/ [+ $minY $maxY] 2.0]
  #
  foreach obj [$self selected] {
    lassign [$obj bbox] x0 y0 x1 y1
    set cx [/ [+ $x1 $x0] 2.0]
    set cy [/ [+ $y1 $y0] 2.0]
    #
    set dx 0
    set dy 0
    switch -exact -- $how {
      left {
        set dx [- $minX $x0]
      }
      center {
        set dx [- $centerX $cx]
      }
      right {
        set dx [- $maxX $x1]
      }
      top {
        set dy [- $minY $y0]
      }
      middle {
        set dy [- $centerY $cy]
      }
      bottom {
        set dy [- $maxY $y1]
      }
    }
    $obj dots storeXY
    $obj dots transform\
      moveHorizontal [/ $dx [my zoom]]\
      moveVertical [/ $dy [my zoom]]
    $obj draw coords
  }
}

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