public static Transform NormalizePathGeometry(PathGeometry geometry, Rect extent, Rect elementRect) { Vector offset = new Vector(extent.Left, extent.Top); double horizontalScale = extent.Width == 0.0 ? 1.0 : elementRect.Width / extent.Width; double verticalScale = extent.Height == 0.0 ? 1.0 : elementRect.Height / extent.Height; return(ScenePathEditorTarget.UpdateAllPoints(geometry, offset, horizontalScale, verticalScale)); }
public static Transform UpdateAllPoints(PathGeometry geometry, Vector offset, double horizontalScale, double verticalScale) { TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add((Transform) new TranslateTransform(-offset.X, -offset.Y)); transformGroup.Children.Add((Transform) new ScaleTransform(horizontalScale, verticalScale)); ScenePathEditorTarget.UpdateAllPoints(geometry, (Transform)transformGroup); return((Transform)transformGroup); }
protected override void EndEditingInternal(bool pathJustCreated) { Matrix identity = Matrix.Identity; if (!pathJustCreated) { Transform geometryTransform = this.pathElement.GeometryTransform; if (geometryTransform != null) { identity = geometryTransform.Value; } } Rect extent1 = PathGeometryUtilities.TightExtent(this.PathGeometry, identity); Rect extent2 = extent1; bool flag1 = false; if (this.ViewModel.AnimationEditor.IsKeyFraming) { if ((Stretch)this.pathElement.GetLocalOrDefaultValueAsWpf(ShapeElement.StretchProperty) != Stretch.None) { flag1 = true; if (!pathJustCreated) { extent1 = PathGeometryUtilities.TightExtent(this.pathElement.PathGeometry, Matrix.Identity); } using (this.ViewModel.ForceBaseValue()) { using (this.ViewModel.AnimationEditor.DeferKeyFraming()) { this.pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.None); this.ViewModel.Document.OnUpdatedEditTransaction(); } } } if (this.pathElement.EnsureSingleSegmentsInPathGeometry()) { this.ViewModel.Document.OnUpdatedEditTransaction(); } } Rect extent3 = PathCommandHelper.InflateRectByStrokeWidth(extent1, this.pathElement, pathJustCreated); Rect rect1 = PathCommandHelper.InflateRectByStrokeWidth(extent2, this.pathElement, pathJustCreated); Rect computedBounds = this.pathElement.GetComputedBounds((Base2DElement)this.pathElement); PathGeometry pathGeometry1 = this.PathGeometry; if (flag1 && !pathJustCreated) { ScenePathEditorTarget.NormalizePathGeometry(pathGeometry1, extent3, computedBounds); } if (flag1) { this.OnMatrixChanged(); } Vector vector1 = new Vector(extent3.Left, extent3.Top); Transform transform = (Transform)null; Point centerPoint = new Point(); bool flag2 = (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated; if (flag2 && !computedBounds.Contains(rect1)) { ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, true); Rect childRect = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement); double x = Math.Min(0.0, rect1.Left); double y = Math.Min(0.0, rect1.Top); Vector vector2 = new Vector(x, y); centerPoint = this.pathElement.RenderTransformOrigin; transform = this.pathElement.RenderTransform; if (transform != null && !transform.Value.IsIdentity) { using (this.ViewModel.ForceBaseValue()) { using (this.ViewModel.AnimationEditor.DeferKeyFraming()) this.UpdateCenterPoint(new Point(0.0, 0.0)); } vector2 *= transform.Value; } double num1 = Math.Max(0.0, rect1.Right - computedBounds.Right); double num2 = Math.Max(0.0, rect1.Bottom - computedBounds.Bottom); childRect.X += vector2.X; childRect.Y += vector2.Y; childRect.Width += -x + num1; childRect.Height += -y + num2; using (this.ViewModel.ForceBaseValue()) { using (this.ViewModel.AnimationEditor.DeferKeyFraming()) designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, childRect); } if (x != 0.0 || y != 0.0) { this.AdjustKeyframes(new Vector(x, y)); ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, new Vector(x, y), 1.0, 1.0); PathGeometry pathGeometry2 = this.pathElement.PathGeometry; ScenePathEditorTarget.UpdateAllPoints(pathGeometry2, new Vector(x, y), 1.0, 1.0); this.pathElement.PathGeometry = pathGeometry2; } this.ViewModel.Document.OnUpdatedEditTransaction(); if (transform != null && !transform.Value.IsIdentity) { using (this.ViewModel.ForceBaseValue()) { using (this.ViewModel.AnimationEditor.DeferKeyFraming()) this.UpdateCenterPoint(centerPoint); } } } if (!flag2 && (Stretch)this.pathElement.GetComputedValueAsWpf(ShapeElement.StretchProperty) == Stretch.None) { ScenePathEditorTarget.UpdateAllPoints(pathGeometry1, vector1, 1.0, 1.0); } if (!flag2) { using (this.ViewModel.ForceBaseValue()) { using (this.ViewModel.AnimationEditor.DeferKeyFraming()) { centerPoint = this.pathElement.RenderTransformOrigin; transform = this.pathElement.RenderTransform; if (!extent3.IsEmpty) { if (transform != null && !transform.Value.IsIdentity) { this.UpdateCenterPoint(new Point(0.0, 0.0)); vector1 *= transform.Value; } ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild((SceneElement)this.pathElement, false); Rect rect2 = designerForChild.GetChildRect((BaseFrameworkElement)this.pathElement); if (pathJustCreated) { rect2 = new Rect(0.0, 0.0, 0.0, 0.0); } double width = extent3.Width; double height = extent3.Height; rect2.Offset(vector1); rect2.Width = width; rect2.Height = height; designerForChild.SetChildRect((BaseFrameworkElement)this.pathElement, rect2); } } } } if (this.pathElement.IsAttached && (this.ViewModel.AnimationEditor.IsKeyFraming || this.pathElement.HasVertexAnimations) && !pathJustCreated) { new PathDiff((Base2DElement)this.pathElement, PathElement.DataProperty, this.PathDiffChangeList).SetPathUsingMinimalDiff(pathGeometry1); } else { this.pathElement.PathGeometry = pathGeometry1; } if (flag2) { return; } using (this.ViewModel.ForceBaseValue()) { using (this.ViewModel.AnimationEditor.DeferKeyFraming()) { if (extent3.IsEmpty) { return; } this.ViewModel.Document.OnUpdatedEditTransaction(); if (transform == null || transform.Value.IsIdentity) { return; } this.UpdateCenterPoint(centerPoint); } } }