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); }
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(); }