Ejemplo n.º 1
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (IsDisposed)
            {
                return;
            }
            if (_newSegCtl != null)
            {
                _newSegCtl.OnMouseMove(sender, e);
                return;
            }
            if (_containerPanel.EditMode) // && object.ReferenceEquals(this, sender))
            {
                Point newMousePosition = MousePosition;
                if (e.Button != MouseButtons.Left)
                {
                    Point ptCtlLoc = PointToClient(newMousePosition);
                    // No Left button.  Not trying to drag.  Just set cursor
                    Rectangle rcEntire = new Rectangle(Point.Empty, Size);
                    if (rcEntire.Contains(ptCtlLoc))
                    {
                        _containerPanel.Cursor = Cursors.SizeAll;
                    }
                    else
                    {
                        _containerPanel.Cursor = Cursors.Default;
                    }
                }
                else
                {
                    // Get Head in panel coordinates
                    int x = newMousePosition.X - _lastMousePosition.X;
                    int y = newMousePosition.Y - _lastMousePosition.Y;
                    if (x == 0 && y == 0)
                    {
                        return;
                    }
                    // Which Drag are we trying to do?
                    bool bMovingVertical = Math.Abs(x) < Math.Abs(y);
                    bool bInLine         = bMovingVertical == Vertical;
                    switch (DragMode)
                    {
                    case eDrag.None:
                        return;

                    case eDrag.BodyClick:
                    case eDrag.HeadClick:
                    case eDrag.TailClick:
                        // Not dragging yet
                        // Have we dragged far enough
                        int totalPixDragDistance = (x * x + y * y);
                        if (totalPixDragDistance < 5 || Math.Abs(x) == Math.Abs(y))
                        {
                            // Not far enough or indeterminatant
                            return;
                        }
                        if (bInLine)
                        {
                            _segMoves = new SMPathSegment[] { _pathSeg };
                            DragMode  = eDrag.Extending;
                        }
                        break;
                    }
                    // Not in line move
                    SMPathSegment segPrevious = _pathSeg.Previous;;
                    SMPathSegment segNext     = _pathSeg.Next;;
                    switch (DragMode)
                    {
                    case  eDrag.BodyClick:
                        if (segPrevious == null)
                        {
                            DragMode = eDrag.None;
                            _flowItem.ChangeExit(FirstPathSeg, x, y);
                            _ctlBase.RebuildSegment(FirstPathSeg);
                            return;
                        }
                        _segMoves = new SMPathSegment[] { segPrevious, segNext };
                        DragMode  = eDrag.Extending;
                        break;

                    case eDrag.HeadClick:
                        if (IsLast)
                        {
                            CreateNewSegment(eDrag.Extending, x, y);
                        }
                        else
                        {
                            // Same as moving the body
                            _segMoves = new SMPathSegment[] { segPrevious, segNext };
                            DragMode  = eDrag.Extending;
                        }
                        break;

                    case eDrag.TailClick:
                        _segMoves = new SMPathSegment[] { segPrevious, segNext };
                        DragMode  = eDrag.Extending;
                        break;
                    }
                    //
                    if (DragMode == eDrag.Extending)
                    {
                        DoExtensions(x, y);
                        _lastMousePosition = newMousePosition;
                    }
                }
            }
        }