Exemplo n.º 1
0
        protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow)
        {
            dragCurrentPosition += this.adornerOffset;
            dragStartPosition   += this.adornerOffset;
            if (this.UseSnappingEngine && !this.ToolBehaviorContext.SnappingEngine.IsStarted)
            {
                List <BaseFrameworkElement> list = new List <BaseFrameworkElement>();
                foreach (SceneElement sceneElement in this.EditingElementSet.Elements)
                {
                    if (this.EditingElement != sceneElement)
                    {
                        list.Add((BaseFrameworkElement)sceneElement);
                    }
                }
                this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, this.BaseEditingElement, (IList <BaseFrameworkElement>)list);
            }
            Vector       offset    = dragCurrentPosition - dragStartPosition;
            SceneElement container = this.EditingElement.VisualElementAncestor ?? this.EditingElement;

            if (this.UseSnappingEngine)
            {
                Vector vector = this.ToolBehaviorContext.SnappingEngine.SnapRect(this.startBoundsInParent, container, offset, this.ActiveAdorner.EdgeFlags);
                dragCurrentPosition += vector;
            }
            this.currentPointerPosition = this.startPointerPosition + ElementUtilities.GetCorrespondingVector(dragCurrentPosition - dragStartPosition, this.elementToDocumentTransform);
            if (!this.ActiveSceneViewModel.AnimationEditor.IsRecording && !(this is DesignTimeSizeBehavior))
            {
                this.ReplaceSubTransaction();
            }
            this.UpdateScale();
            this.UpdateEditTransaction();
            this.ActiveView.UpdateLayout();
            this.ActiveView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow);
            return(true);
        }
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)
 {
     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.º 4
0
        private void MovePathParts(PathPartSelectionSet pathPartSelectionSet, BaseFrameworkElement sceneElement, PathEditMode pathEditMode, Vector deltaOffset)
        {
            ICollection <PathPart> selectionByElement = pathPartSelectionSet.GetSelectionByElement((SceneElement)sceneElement, pathEditMode);
            Tool activeTool = this.ActiveSceneViewModel.DesignerContext.ToolManager.ActiveTool;

            if (selectionByElement.Count <= 0 || activeTool == null)
            {
                return;
            }
            PathEditorTarget pathEditorTarget = activeTool.GetPathEditorTarget((Base2DElement)sceneElement, pathEditMode);

            if (pathEditorTarget == null)
            {
                return;
            }
            this.EnsureEditTransaction();
            pathEditorTarget.BeginEditing();
            if (!this.pathEditorTargets.ContainsKey(pathEditorTarget))
            {
                this.pathEditorTargets.Add(pathEditorTarget, true);
            }
            Matrix transformToAncestor = pathEditorTarget.GetTransformToAncestor((IViewObject)this.ActiveView.HitTestRoot);
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(deltaOffset, transformToAncestor);

            PathEditBehavior.TranslateSelection(pathEditorTarget, selectionByElement, correspondingVector);
            this.ActiveView.AdornerLayer.InvalidateAdornerVisuals((SceneElement)pathEditorTarget.EditingElement);
        }
Exemplo n.º 5
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);
        }
        protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow)
        {
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(dragCurrentPosition - dragStartPosition, this.elementToDocumentTransform);
            Rect   rect = this.startGeometry.Rect;

            rect.Offset(correspondingVector);
            RectangleGeometry rectangleGeometry = this.startGeometry.Clone();

            rectangleGeometry.Rect = RoundingHelper.RoundRect(rect);
            this.EditingElement.SetLocalValueAsWpf(Base2DElement.ClipProperty, (object)rectangleGeometry);
            this.UpdateEditTransaction();
            this.ActiveView.EnsureVisible(this.ActiveAdorner, scrollNow);
            return(true);
        }
Exemplo n.º 7
0
        protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow)
        {
            this.EnsureEditTransaction();
            if (!this.ToolBehaviorContext.SnappingEngine.IsStarted)
            {
                this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, (BaseFrameworkElement)null, (IList <BaseFrameworkElement>)null);
            }
            dragCurrentPosition = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dragCurrentPosition);
            Matrix transformMatrix = this.EditingElementSet.GetTransformMatrix((IViewObject)this.ActiveView.HitTestRoot);
            Point  point           = this.originalCenter * transformMatrix;

            this.UpdateCenterPoint(this.originalCenter + ElementUtilities.GetCorrespondingVector(dragCurrentPosition - point, transformMatrix));
            this.UpdateEditTransaction();
            this.ActiveView.EnsureVisible(this.ActiveAdorner, scrollNow);
            return(true);
        }
Exemplo n.º 8
0
        protected override void OnDrag(MouseDevice mouseDevice, double zoom)
        {
            Point viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, true);

            this.PathEditorTarget.BeginEditing();
            Vector           correspondingVector = ElementUtilities.GetCorrespondingVector(viewRootCoordinates - this.startRootPoint * this.geometryToDocument, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);
            PathFigureEditor pathFigureEditor    = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.PathEditorTarget.PathGeometry));

            if (!this.adjustLastTangent)
            {
                pathFigureEditor.SetPoint(this.PathEditContext.PartIndex, this.startRootPoint + correspondingVector);
            }
            else
            {
                this.LastTangent = correspondingVector;
            }
            this.View.AdornerLayer.InvalidateAdornerVisuals(this.EditingElement);
            base.OnDrag(mouseDevice, zoom);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        private void MoveSelection()
        {
            Matrix             matrixToAdornerLayer = this.pathPartAdorner.PathAdornerSet.GetTransformMatrixToAdornerLayer();
            Point              pointInAdornerLayer  = this.GetSnappedPointInAdornerLayer();
            PathTangentAdorner pathTangentAdorner   = this.pathPartAdorner as PathTangentAdorner;
            PathEditContext    pathEditContext      = new PathEditContext(this.pathPartAdorner.FigureIndex, this.pathPartAdorner.PartIndex);

            if (pathTangentAdorner != null)
            {
                this.EnsureEditTransaction();
                this.pathEditorTarget.BeginEditing();
                if (!this.HasMouseMovedAfterDown)
                {
                    this.startRootPoint     = PathFigureUtilities.GetPoint(this.pathEditorTarget.PathGeometry.Figures[pathEditContext.FigureIndex], pathEditContext.PartIndex, false);
                    this.correspondingPoint = PathFigureUtilities.GetPoint(this.pathEditorTarget.PathGeometry.Figures[pathEditContext.FigureIndex], pathEditContext.PartIndex, true);
                }
                Point  point = this.IsShiftDown ? this.correspondingPoint : this.startRootPoint;
                Vector correspondingVector = ElementUtilities.GetCorrespondingVector(pointInAdornerLayer - point * matrixToAdornerLayer, matrixToAdornerLayer, this.IsShiftDown ? this.axisConstraint : (AxisConstraint)null);
                new PathFigureEditor(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry)).MoveTangent(pathEditContext.PartIndex, point + correspondingVector, this.isEnforcingSmoothness);
                this.ActiveView.AdornerLayer.InvalidateAdornerVisuals(this.EditingElement);
            }
            else
            {
                this.EnsureEditTransaction();
                PathPointAdorner   pathPointAdorner   = this.pathPartAdorner as PathPointAdorner;
                PathSegmentAdorner pathSegmentAdorner = this.pathPartAdorner as PathSegmentAdorner;
                this.pathPartAdorner.PathAdornerSet.PathEditorTarget.BeginEditing();
                if (!this.HasMouseMovedAfterDown)
                {
                    Point point;
                    if (pathPointAdorner != null)
                    {
                        point = PathFigureUtilities.GetPoint(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry), pathEditContext.PartIndex);
                    }
                    else
                    {
                        PathFigureEditor pathFigureEditor = new PathFigureEditor(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry));
                        int segmentIndex;
                        int segmentPointIndex;
                        PathFigureUtilities.GetSegmentFromPointIndex(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry), pathEditContext.PartIndex, out segmentIndex, out segmentPointIndex);
                        point = pathFigureEditor.Evaluate(segmentIndex, segmentPointIndex, this.pathSegmentParameter) * pathSegmentAdorner.PathGeometryTransformMatrix;
                    }
                    this.startRootPoint    = point;
                    this.previousRootPoint = this.startRootPoint;
                }
                Vector correspondingVector = ElementUtilities.GetCorrespondingVector(pointInAdornerLayer - this.startRootPoint * matrixToAdornerLayer, matrixToAdornerLayer, this.IsShiftDown ? this.axisConstraint : (AxisConstraint)null);
                double zoom = this.ActiveView.Artboard.Zoom;
                Vector rootToArtboardScale = this.ActiveView.Artboard.ViewRootToArtboardScale;
                correspondingVector.X /= zoom * rootToArtboardScale.X;
                correspondingVector.Y /= zoom * rootToArtboardScale.Y;
                Vector vector = this.startRootPoint - this.previousRootPoint + correspondingVector;
                this.previousRootPoint = this.startRootPoint + correspondingVector;
                Vector deltaOffset = matrixToAdornerLayer.Transform(vector);
                PathPartSelectionSet partSelectionSet = this.ActiveSceneViewModel.PathPartSelectionSet;
                if (partSelectionSet == null)
                {
                    return;
                }
                foreach (BaseFrameworkElement sceneElement in (IEnumerable <SceneElement>)partSelectionSet.SelectedPaths)
                {
                    this.MovePathParts(partSelectionSet, sceneElement, PathEditMode.ScenePath, deltaOffset);
                    this.MovePathParts(partSelectionSet, sceneElement, PathEditMode.MotionPath, deltaOffset);
                    this.MovePathParts(partSelectionSet, sceneElement, PathEditMode.ClippingPath, deltaOffset);
                }
            }
        }