createLine

$canvaseditor createLine direction
interactively creates a line (free, horizontal, vertical)

obj method canvaseditor createLine {{direction both}} {
  set canvas [my canvas]
  lassign [pointerXY] x y
  #
  set x [$self canvasx $x]
  set y [$self canvasy $y]
  #
  set line [new line $x $y $x $y]
  $self select $line
  #
  $self initUndoRedo "
      $self select
      $line draw no
      " "
      $self select
      $line draw yes
      "
  #
  lassign [$line dots] a b
  $self basicBindings off
  $self statusLine Draw line $direction
  $self pointerToDot $b
  switch -exact -- $direction {
    horizontal {
      bind $canvas <Motion> [subst -nocommand {
          $b configure -x [$self canvasx %x] -y $y
        }]
    }
    vertical {
      bind $canvas <Motion> [subst -nocommand {
          $b configure -x $x -y [$self canvasy %y]
        }]
    }
    default {
      bind $canvas <Motion> [subst -nocommand {
          $b configure\
            -x [$self canvasx %x]\
            -y [$self canvasy %y]
        }]
    }
  }
  bind $canvas <Motion> "+$line draw"
  bind $canvas <<Click>> "
    $self basicBindings
    $self select $line
    $self snapMode off
    $self select $line
    "
  $self canvas configure -cursor pencil
  $line draw
  $self snapMode on
}

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