Exemplo n.º 1
0
 protected override void OnDrag(MouseDevice mouseDevice, double zoom)
 {
     if (this.IsActive)
     {
         PathGeometryEditor pathGeometryEditor = this.BeginEditing();
         PathFigureEditor   pathFigureEditor   = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path));
         int figureIndex       = this.PathEditContext.FigureIndex;
         int partIndex         = this.PathEditContext.PartIndex;
         int ofUpstreamSegment = pathFigureEditor.GetFirstIndexOfUpstreamSegment(partIndex);
         if (!this.hasDragged)
         {
             Point point1 = pathFigureEditor.GetPoint(ofUpstreamSegment);
             Point point2 = pathFigureEditor.GetPoint(partIndex);
             if (VectorUtilities.ArePathPointsVeryClose(point2, pathFigureEditor.GetPoint(ofUpstreamSegment + 2)) && VectorUtilities.ArePathPointsVeryClose(point1, pathFigureEditor.GetPoint(ofUpstreamSegment + 1)))
             {
                 pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 1, VectorUtilities.WeightedAverage(point1, point2, 1.0 / 3.0));
                 pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 2, VectorUtilities.WeightedAverage(point1, point2, 2.0 / 3.0));
                 this.initialFirstCubicHandle  = pathFigureEditor.GetPoint(ofUpstreamSegment + 1);
                 this.initialSecondCubicHandle = pathFigureEditor.GetPoint(ofUpstreamSegment + 2);
             }
             this.hasDragged = true;
         }
         Vector correspondingVector = ElementUtilities.GetCorrespondingVector((this.GetPointInViewRootCoordinates(mouseDevice, false) - this.initialPointerPosition) * this.damping, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);
         Vector vector1             = correspondingVector * this.firstHandleCoef;
         Vector vector2             = correspondingVector * this.secondHandleCoef;
         pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 1, this.initialFirstCubicHandle + vector1);
         pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 2, this.initialSecondCubicHandle + vector2);
     }
     base.OnDrag(mouseDevice, zoom);
 }
Exemplo n.º 2
0
        protected override void OnDrag(MouseDevice mouseDevice, double zoom)
        {
            Point  point  = PathFigureUtilities.GetPoint(this.PathEditContext.GetPathFigure(this.Path), this.PathEditContext.PartIndex);
            Point  point1 = this.geometryToDocument.Transform(point);
            Point  viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, true);
            Vector vector = viewRootCoordinates - point1;
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(vector, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);

            if (this.hasMoved || Tolerances.HaveMoved(point1, viewRootCoordinates, zoom))
            {
                this.hasMoved = true;
                PathGeometry       path               = this.Path;
                int                figureIndex        = this.PathEditContext.FigureIndex;
                int                partIndex          = this.PathEditContext.PartIndex;
                PathGeometryEditor pathGeometryEditor = this.BeginEditing();
                PathFigureEditor   pathFigureEditor   = new PathFigureEditor(path.Figures[figureIndex]);
                if (partIndex > 0 || PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure))
                {
                    pathGeometryEditor.SetPoint(figureIndex, partIndex - 1, point - correspondingVector);
                }
                if (pathFigureEditor.GetLastIndexOfDownstreamSegment(partIndex) != partIndex)
                {
                    pathGeometryEditor.SetPoint(figureIndex, partIndex + 1, point + correspondingVector);
                }
                if (partIndex == PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - 1 && PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure))
                {
                    this.LastTangent = vector;
                }
                this.PathEditorTarget.AddCriticalEdit();
            }
            base.OnDrag(mouseDevice, zoom);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 protected override void OnEnd()
 {
     if (!this.hasDragged)
     {
         PathFigureEditor pathFigureEditor = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path));
         int partIndex         = this.PathEditContext.PartIndex;
         int ofUpstreamSegment = pathFigureEditor.GetFirstIndexOfUpstreamSegment(partIndex);
         if (!VectorUtilities.ArePathPointsVeryClose(pathFigureEditor.GetPoint(ofUpstreamSegment), pathFigureEditor.GetPoint(ofUpstreamSegment + 1)) || !VectorUtilities.ArePathPointsVeryClose(pathFigureEditor.GetPoint(partIndex), pathFigureEditor.GetPoint(ofUpstreamSegment + 2)))
         {
             PathGeometryEditor pathGeometryEditor = this.BeginEditing();
             pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, ofUpstreamSegment + 2, pathFigureEditor.GetPoint(partIndex));
             pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, ofUpstreamSegment + 1, pathFigureEditor.GetPoint(ofUpstreamSegment));
         }
     }
     base.OnEnd();
 }