private Matrix GetTransformMatrix(IViewObject targetVisual, bool includeParentTransforms) { Matrix matrix = Matrix.Identity; if (!this.AdornsMultipleElements) { IViewObject viewTargetElement = this.PrimaryElement.ViewTargetElement; if (viewTargetElement != null && this.ViewModel.DefaultView.IsInArtboard(this.PrimaryElement)) { matrix = VectorUtilities.GetMatrixFromTransform(this.ViewModel.DefaultView.ComputeTransformToVisual(viewTargetElement, targetVisual)); } } else { if (this.cachedTransform == null) { CanonicalDecomposition transformToRootVisual = this.SharedTransformToRootVisual; this.EnsureBounds(); Matrix identity = Matrix.Identity; identity.Translate(this.cachedBounds.X, this.cachedBounds.Y); this.cachedTransform = (Transform) new MatrixTransform(identity * transformToRootVisual.Value); } Matrix computedTransformToRoot = this.ViewModel.DefaultView.GetComputedTransformToRoot(targetVisual); Transform transform = (Transform)this.ViewModel.DefaultView.Artboard.CalculateTransformFromContentToArtboard().Inverse; computedTransformToRoot.Append(transform.Value); matrix = this.cachedTransform.Value * computedTransformToRoot; } return(matrix); }
protected override void ApplyScale(Vector scale, Point center) { Rect elementBounds = this.EditingElementSet.ElementBounds; Matrix m = this.startSharedTransform; Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(m); Matrix matrix1 = new Matrix(); matrix1.Translate(-center.X, -center.Y); foreach (SceneElement element in this.EditingElementSet.Elements) { Matrix matrix2 = this.elementToElementsTransformDictionary[element] * matrix1; Point point1 = this.startCentersDictionary[element]; Matrix matrix3 = this.startTransformsDictionary[element]; Rect rect = this.startBoundsDictionary[element]; Point point2 = new Point(rect.X + rect.Width * point1.X, rect.Y + rect.Height * point1.Y); Point point3 = matrix2.Transform(point2); Vector vector = new Point(scale.X * point3.X, scale.Y * point3.Y) - point3; Matrix matrix4 = matrix3 * inverseMatrix; matrix4.ScaleAt(scale.X, scale.Y, matrix4.OffsetX, matrix4.OffsetY); matrix4.Translate(vector.X, vector.Y); CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * m); newTransform.ScaleX = RoundingHelper.RoundScale(newTransform.ScaleX); newTransform.ScaleY = RoundingHelper.RoundScale(newTransform.ScaleY); newTransform.SkewX = RoundingHelper.RoundAngle(newTransform.SkewX); newTransform.SkewY = RoundingHelper.RoundAngle(newTransform.SkewY); newTransform.RotationAngle = RoundingHelper.RoundAngle(newTransform.RotationAngle); newTransform.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX); newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY); AdornedToolBehavior.UpdateElementTransform(element, newTransform, AdornedToolBehavior.TransformPropertyFlags.All); } }
public void Update() { this.cachedTransform = (Transform)null; this.boundsCached = false; this.cachedBounds = Rect.Empty; this.sharedTransformToRootVisual = (CanonicalDecomposition)null; this.needsUpdate = false; this.primaryNonAffine = new bool?(); }
private System.Windows.Media.Geometry GetTransformedClippingGeometry(SceneElement clipper, Transform transform) { RectangleElement rectangleElement = clipper as RectangleElement; if (rectangleElement == null || !this.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.PrefersRectangularClippingPath)) { PathGeometry pathGeometry = PathGeometryUtilities.TransformGeometry(this.ApplyCurrentClippingToGeometry((System.Windows.Media.Geometry)PathConversionHelper.ConvertToPathGeometry(clipper), clipper), transform); if (pathGeometry.Bounds == Rect.Empty) { pathGeometry = new PathGeometry(); } return((System.Windows.Media.Geometry)pathGeometry); } RectangleGeometry rectangleGeometry = rectangleElement.ViewModel.DefaultView.GetRenderedGeometryAsWpf((SceneElement)rectangleElement) as RectangleGeometry; if (rectangleGeometry == null) { return((System.Windows.Media.Geometry) new RectangleGeometry()); } CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition(transform.Value); Matrix matrix = new Matrix(); matrix.Scale(canonicalDecomposition.ScaleX, canonicalDecomposition.ScaleY); matrix.Translate(canonicalDecomposition.TranslationX, canonicalDecomposition.TranslationY); Rect rect = rectangleGeometry.Rect; rect.Transform(matrix); rectangleGeometry.Rect = RoundingHelper.RoundRect(rect); CanonicalTransform canonicalTransform = new CanonicalTransform(); bool flag = false; canonicalTransform.CenterX = canonicalDecomposition.TranslationX; canonicalTransform.CenterY = canonicalDecomposition.TranslationY; if (canonicalDecomposition.RotationAngle != 0.0) { canonicalTransform.RotationAngle = canonicalDecomposition.RotationAngle; flag = true; } if (canonicalDecomposition.SkewX != 0.0 || canonicalDecomposition.SkewY != 0.0) { canonicalTransform.SkewX = RoundingHelper.RoundLength(canonicalDecomposition.SkewX); canonicalTransform.SkewY = RoundingHelper.RoundLength(canonicalDecomposition.SkewY); flag = true; } if (flag) { rectangleGeometry.Transform = (Transform)canonicalTransform.TransformGroup; } if ((double)rectangleElement.GetComputedValue(RectangleElement.RadiusXProperty) != 0.0 || (double)rectangleElement.GetComputedValue(RectangleElement.RadiusYProperty) != 0.0) { rectangleGeometry.ClearValue(RectangleGeometry.RadiusXProperty); rectangleGeometry.ClearValue(RectangleGeometry.RadiusYProperty); this.SceneView.ShowBubble(StringTable.ClippingRectanglePropertiesLostWarning, MessageBubbleType.Warning); } return((System.Windows.Media.Geometry)rectangleGeometry); }
private void StartDrag() { Matrix matrixToAdornerLayer = this.ElementSet.GetTransformMatrixToAdornerLayer(); this.initialZoom = this.DesignerContext.ActiveView.Artboard.Zoom; this.initialBounds = this.ElementSet.ElementBounds; this.initialSharedTransform = this.ElementSet.CalculateSharedTransform(); this.initialRenderTransformOrigin = this.ElementSet.RenderTransformOrigin; this.initialOffset = new Vector(matrixToAdornerLayer.OffsetX, matrixToAdornerLayer.OffsetY); this.startArtboardOrigin = this.DesignerContext.ActiveView.Artboard.ArtboardBounds.TopLeft; }
protected override void ApplyScale(Vector scale, Point center) { Dictionary <SceneElement, Size> dictionary = this.CalculateClampedSizes(ref scale); Vector vector1 = new Vector(scale.X < 0.0 ? -1.0 : 1.0, scale.Y < 0.0 ? -1.0 : 1.0); Matrix startSharedTransform = this.StartSharedTransform; Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(startSharedTransform); ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild(this.EditingElementSet.PrimaryElement, true); foreach (SceneElement index in this.EditingElementSet.Elements) { double width = dictionary[index].Width; double height = dictionary[index].Height; Rect rect1 = this.StartBoundsDictionary[index]; Point renderTransformOrigin = ((Base2DElement)index).RenderTransformOrigin; Point point1 = new Point(rect1.X + rect1.Width * renderTransformOrigin.X, rect1.Y + rect1.Height * renderTransformOrigin.Y); Matrix matrix1 = this.ElementToElementsTransformDictionary[index]; Matrix matrix2 = new Matrix(); matrix2.Translate(-center.X, -center.Y); matrix1 *= matrix2; Point point2 = matrix1.Transform(point1); Vector vector2 = new Point(point2.X * scale.X, point2.Y * scale.Y) - point2; Vector vector3 = new Vector((width - rect1.Width) * renderTransformOrigin.X, (height - rect1.Height) * renderTransformOrigin.Y); Vector vector4 = vector2 * startSharedTransform - vector3; Matrix matrix3 = this.StartTransformsDictionary[index]; Matrix m = new Matrix(); m.Scale(scale.X, scale.Y); Matrix matrix4 = ElementUtilities.GetInverseMatrix(m) * matrix3 * inverseMatrix; Vector vector5 = new Vector(matrix3.OffsetX, matrix3.OffsetY) * inverseMatrix; matrix4.ScaleAt(scale.X, scale.Y, vector5.X, vector5.Y); CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * startSharedTransform); newTransform.ScaleX *= vector1.X; newTransform.ScaleY *= vector1.Y; newTransform.Translation += vector4; AdornedToolBehavior.UpdateElementTransform(index, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Skew | AdornedToolBehavior.TransformPropertyFlags.RotatationAngle); Rect rect2 = this.initialRects[index]; rect2.Offset(newTransform.TranslationX - this.initialTransforms[index].TranslationX, newTransform.TranslationY - this.initialTransforms[index].TranslationY); rect2.Width = width; rect2.Height = height; BaseFrameworkElement child = (BaseFrameworkElement)index; LayoutOverrides overridesToIgnore = (LayoutOverrides)(0 | (!object.Equals((object)width, (object)rect1.Width) ? 16 : 0) | (!object.Equals((object)height, (object)rect1.Height) ? 32 : 0)); designerForChild.SetChildRect(child, rect2, this.initialOverrides[index], overridesToIgnore, LayoutOverrides.None); if (!object.Equals((object)width, (object)rect1.Width) || !object.Equals((object)height, (object)rect1.Height)) { PathElement.EnsureStretchIsFill((SceneNode)index); } PathElement.PathTransformHelper pathTransformHelper; if (this.pathTransformHelpers.TryGetValue(index, out pathTransformHelper)) { pathTransformHelper.Update(scale.X * vector1.X, scale.Y * vector1.Y); } } }
protected static void UpdateElementTransform(SceneElement element, CanonicalDecomposition newTransform, AdornedToolBehavior.TransformPropertyFlags properties) { Transform transform = element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty) as Transform; CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition(); if (transform != null) { canonicalDecomposition = new CanonicalTransform(transform).Decomposition; } double num1 = RoundingHelper.RoundScale(newTransform.ScaleX); double num2 = RoundingHelper.RoundScale(newTransform.ScaleY); double num3 = RoundingHelper.RoundLength(newTransform.TranslationX); double num4 = RoundingHelper.RoundLength(newTransform.TranslationY); double num5 = RoundingHelper.RoundLength(newTransform.SkewX); double num6 = RoundingHelper.RoundLength(newTransform.SkewY); double num7 = RoundingHelper.RoundAngle(newTransform.RotationAngle); if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleX, num1)) { element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleX, (object)num1); } if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleY, num2)) { element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleY, (object)num2); } if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationX, num3)) { element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num3); } if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationY, num4)) { element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num4); } if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewX, num5)) { element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewX, (object)num5); } if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewY, num6)) { element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewY, (object)num6); } if ((properties & AdornedToolBehavior.TransformPropertyFlags.RotatationAngle) == AdornedToolBehavior.TransformPropertyFlags.None || Tolerances.AreClose(canonicalDecomposition.RotationAngle, num7)) { return; } element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformRotationAngle, (object)num7); }
protected override void Initialize() { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.MultipleElementRotate); this.FireNotifications(false); CanonicalDecomposition canonicalDecomposition = this.EditingElementSet.CalculateSharedTransform(); this.UnsnappedAngle = canonicalDecomposition.RotationAngle; this.initialBounds = this.EditingElementSet.Bounds; this.intialRenderTransformOrigin = this.EditingElementSet.RenderTransformOrigin; this.initialSharedTransform = canonicalDecomposition; this.initialElementSetCenter = this.EditingElementSet.RenderTransformOriginInElementCoordinates; foreach (SceneElement element in this.EditingElementSet.Elements) { this.initialTransforms[element] = new CanonicalTransform((Transform)element.GetComputedValueAsWpf(element.Platform.Metadata.CommonProperties.RenderTransform)); this.elementsToElement[element] = ElementUtilities.GetInverseMatrix(this.EditingElementSet.GetTransformToElementSpaceFromMemberElement(element)); } this.initialArtboardOrigin = this.EditingElement.DesignerContext.ActiveView.Artboard.ArtboardBounds.TopLeft; }
private Matrix GetTransformMatrixToAdornerLayer(bool includeParentTransforms) { Matrix identity1 = Matrix.Identity; if (!this.AdornsMultipleElements) { identity1.Append(this.CalculatePrimaryElementTransformMatrixToAdornerLayer()); } else { if (this.cachedTransform == null) { CanonicalDecomposition canonicalDecomposition = includeParentTransforms ? this.SharedTransformToRootVisual : this.CalculateSharedTransform(); this.EnsureBounds(); Matrix identity2 = Matrix.Identity; identity2.Translate(this.cachedBounds.X, this.cachedBounds.Y); this.cachedTransform = (Transform) new MatrixTransform(identity2 * canonicalDecomposition.Value); } identity1 = this.cachedTransform.Value; } return(identity1); }
private CanonicalDecomposition CalculateSharedTransform(bool scaleByZoom, bool addParentToRoot) { bool flag = false; CanonicalDecomposition canonicalDecomposition1 = new CanonicalDecomposition(); this.hasHomogenousRotation = true; this.hasHomogenousSkew = true; foreach (SceneElement sceneElement in this.elements) { if (sceneElement is BaseFrameworkElement) { if (!sceneElement.IsAttached) { return(new CanonicalDecomposition()); } Transform identity = Transform.Identity; Transform transform = sceneElement.GetComputedValueAsWpf(sceneElement.Platform.Metadata.CommonProperties.RenderTransform) as Transform ?? Transform.Identity; CanonicalDecomposition canonicalDecomposition2 = new CanonicalDecomposition(); CanonicalDecomposition canonicalDecomposition3 = !CanonicalTransform.IsCanonical(transform) ? new CanonicalDecomposition(transform.Value) : new CanonicalTransform(transform).Decomposition; if (!double.IsNaN(canonicalDecomposition3.ScaleX) && !double.IsNaN(canonicalDecomposition3.ScaleY)) { if (!flag) { canonicalDecomposition1 = canonicalDecomposition3; canonicalDecomposition1.ScaleX = (double)Math.Sign(canonicalDecomposition1.ScaleX); canonicalDecomposition1.ScaleY = (double)Math.Sign(canonicalDecomposition1.ScaleY); flag = true; } else { if (Math.Sign(canonicalDecomposition3.ScaleX) != Math.Sign(canonicalDecomposition1.ScaleX)) { canonicalDecomposition1.ScaleX = 1.0; } if (Math.Sign(canonicalDecomposition3.ScaleY) != Math.Sign(canonicalDecomposition1.ScaleY)) { canonicalDecomposition1.ScaleY = 1.0; } if (!Tolerances.AreClose(canonicalDecomposition3.RotationAngle, canonicalDecomposition1.RotationAngle) || !Tolerances.AreClose(canonicalDecomposition3.SkewX, canonicalDecomposition1.SkewX) || !Tolerances.AreClose(canonicalDecomposition3.SkewY, canonicalDecomposition1.SkewY)) { canonicalDecomposition1.RotationAngle = 0.0; canonicalDecomposition1.SkewX = 0.0; canonicalDecomposition1.SkewY = 0.0; this.hasHomogenousSkew = false; this.hasHomogenousRotation = false; } } } } } double zoom = this.DesignerContext.ActiveView.Artboard.Zoom; if (scaleByZoom) { canonicalDecomposition1.ScaleX = zoom * canonicalDecomposition1.ScaleX; canonicalDecomposition1.ScaleY = zoom * canonicalDecomposition1.ScaleY; } canonicalDecomposition1.Translation = new Vector(0.0, 0.0); if (addParentToRoot && this.PrimaryElement.VisualElementAncestor != null) { Matrix computedTransformToRoot = this.ViewModel.DefaultView.GetComputedTransformToRoot(this.PrimaryElement.VisualElementAncestor.Visual); Transform transform = this.ViewModel.DefaultView.Artboard.CalculateTransformFromContentToArtboard(); computedTransformToRoot.Append(transform.Value); computedTransformToRoot.OffsetX = 0.0; computedTransformToRoot.OffsetY = 0.0; CanonicalDecomposition canonicalDecomposition2 = new CanonicalDecomposition(computedTransformToRoot); canonicalDecomposition1.Scale = new Vector(canonicalDecomposition1.ScaleX * (canonicalDecomposition2.ScaleX / zoom), canonicalDecomposition1.ScaleY * (canonicalDecomposition2.ScaleY / zoom)); canonicalDecomposition1.Skew += canonicalDecomposition2.Skew; canonicalDecomposition1.RotationAngle *= (double)(Math.Sign(canonicalDecomposition2.ScaleX) * Math.Sign(canonicalDecomposition2.ScaleY)); canonicalDecomposition1.RotationAngle += canonicalDecomposition2.RotationAngle; canonicalDecomposition1.Translation += canonicalDecomposition2.Translation; } return(canonicalDecomposition1); }