protected override void OnDrag(MouseDevice mouseDevice, double zoom)
        {
            this.currentTangentPoint = this.GetPointInViewRootCoordinates(mouseDevice, true);
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(this.currentTangentPoint - this.currentNodePoint, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);
            Vector lastTangent         = this.LastTangent;

            this.LastTangent = correspondingVector;
            PathFigure       pathFigure       = this.PathEditContext.GetPathFigure(this.Path);
            PathFigureEditor pathFigureEditor = pathFigure == null ? (PathFigureEditor)null : new PathFigureEditor(pathFigure);

            if (pathFigureEditor != null && !PathFigureUtilities.IsIsolatedPoint(pathFigureEditor.PathFigure))
            {
                PathGeometryEditor pathGeometryEditor = this.BeginEditing();
                bool  flag   = PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure);
                int   index  = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - (flag ? 0 : 1);
                Point point1 = pathFigureEditor.GetPoint(index - 1);
                Point point2 = pathFigureEditor.GetPoint(index);
                if (pathFigureEditor.GetPointKind(index) == PathPointKind.Line)
                {
                    pathGeometryEditor.RemoveLastSegmentOfFigure(this.PathEditContext.FigureIndex);
                    if (flag)
                    {
                        pathGeometryEditor.CloseFigureWithCubicBezier(point1, point2, this.PathEditContext.FigureIndex);
                    }
                    else
                    {
                        pathGeometryEditor.AppendCubicBezier(point1, point2, point2, this.PathEditContext.FigureIndex);
                    }
                    pathFigureEditor = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path));
                }
                if (!this.IsAltDown)
                {
                    if (!this.areTangentsSymmetric)
                    {
                        double length = this.LastTangent.Length;
                        if (length > 0.0)
                        {
                            int    num1 = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure);
                            double num2 = (pathFigureEditor.GetPoint(num1 - 1) - pathFigureEditor.GetPoint(num1 - 2)).Length / length;
                            pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, num1 - 2, point2 - num2 * this.LastTangent);
                        }
                    }
                    else
                    {
                        int pointIndex = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - (PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure) ? 1 : 2);
                        pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, pointIndex, point2 - this.LastTangent);
                    }
                }
                if (PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure) && pathFigureEditor.GetPointKind(3) == PathPointKind.Cubic && this.areTangentsSymmetric)
                {
                    pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, 1, point2 + this.LastTangent);
                }
                this.PathEditorTarget.AddCriticalEdit();
            }
            base.OnDrag(mouseDevice, zoom);
        }
Example #2
0
        protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
        {
            PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.EditPath);
            Vector lastTangent = this.LastTangent;

            base.OnBegin(pathEditContext, mouseDevice);
            PathGeometryEditor pathGeometryEditor     = this.BeginEditing();
            Matrix             elementTransformToRoot = this.EditingElementTransformToRoot;
            Point  lastPoint       = this.GetLastPoint(pathEditContext.FigureIndex);
            Point  point1          = elementTransformToRoot.Transform(lastPoint);
            Vector vector          = this.GetPointInViewRootCoordinates(mouseDevice, true) - point1;
            Size   devicePixelSize = DeviceUtilities.GetDevicePixelSize(this.View.Zoom);

            if (Math.Abs(vector.X) < devicePixelSize.Width / 2.0)
            {
                vector.X = 0.0;
            }
            if (Math.Abs(vector.Y) < devicePixelSize.Height / 2.0)
            {
                vector.Y = 0.0;
            }
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(vector, elementTransformToRoot, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);
            Point  point2 = lastPoint + correspondingVector;

            if (VectorUtilities.IsZero(lastTangent))
            {
                pathGeometryEditor.AppendLineSegment(point2, pathEditContext.FigureIndex);
            }
            else
            {
                Point q = lastPoint + lastTangent;
                pathGeometryEditor.AppendCubicBezier(q, point2, point2, pathEditContext.FigureIndex);
            }
            int        figureIndex = pathEditContext.FigureIndex;
            PathFigure figure      = this.Path.Figures[figureIndex];

            this.PathEditContext = new PathEditContext(figureIndex, PathFigureUtilities.PointCount(figure) - 1);
            this.Initialize(elementTransformToRoot.Transform(point2), true, elementTransformToRoot);
        }