public static Matrix GetBrushMatrix(Base2DElement element, object brush, IPropertyId matrixProperty) { Transform transform = BrushAdorner.GetBrushPropertyAsWpf(element, brush, matrixProperty) as Transform; if (transform != null) { return(transform.Value); } return(Matrix.Identity); }
public static Matrix GetStrokeTransform(SceneElement element) { Matrix matrix = new Matrix(); ShapeElement shapeElement = element as ShapeElement; if (shapeElement != null) { Rect computedTightBounds = shapeElement.GetComputedTightBounds(); double strokeWidth = BrushAdorner.GetStrokeWidth(element); double scaleX = computedTightBounds.Width == 0.0 ? 1.0 : 1.0 - strokeWidth / computedTightBounds.Width; double scaleY = computedTightBounds.Height == 0.0 ? 1.0 : 1.0 - strokeWidth / computedTightBounds.Height; matrix.Translate(-0.5, -0.5); matrix.Scale(scaleX, scaleY); matrix.Translate(0.5, 0.5); } return(matrix); }
public static Matrix GetCompleteBrushTransformMatrix(Base2DElement element, object brush, bool includeTransformFromElementToBrushCoordinates) { Matrix matrix1 = Matrix.Identity; if (brush != null && element != null) { Rect computedTightBounds = element.GetComputedTightBounds(); Matrix matrix2 = BrushAdorner.GetBrushMatrix(element, brush, BrushNode.RelativeTransformProperty); if (PlatformTypes.IsInstance(brush, PlatformTypes.GradientBrush, (ITypeResolver)element.ProjectContext)) { if ((BrushMappingMode)BrushAdorner.GetBrushPropertyAsWpf(element, brush, GradientBrushNode.MappingModeProperty) == BrushMappingMode.Absolute) { if (includeTransformFromElementToBrushCoordinates) { Matrix identity = Matrix.Identity; identity.Translate(-computedTightBounds.X, -computedTightBounds.Y); double scaleX = computedTightBounds.Width == 0.0 ? 1.0 : 1.0 / computedTightBounds.Width; double scaleY = computedTightBounds.Height == 0.0 ? 1.0 : 1.0 / computedTightBounds.Height; identity.Scale(scaleX, scaleY); matrix2 = identity * matrix2; } } else if (BrushAdorner.IsAdorningFillProperty((SceneElement)element)) { matrix2 *= BrushAdorner.GetStrokeTransform((SceneElement)element); } } if (PlatformTypes.IsInstance(brush, PlatformTypes.TileBrush, (ITypeResolver)element.ProjectContext) && BrushAdorner.IsAdorningFillProperty((SceneElement)element)) { matrix2 *= BrushAdorner.GetStrokeTransform((SceneElement)element); } Matrix matrix3 = new Matrix(computedTightBounds.Width, 0.0, 0.0, computedTightBounds.Height, computedTightBounds.X, computedTightBounds.Y); matrix1 = matrix2 * matrix3 * BrushAdorner.GetBrushMatrix(element, brush, BrushNode.TransformProperty); } return(matrix1); }
private void UpdateTranslation(bool scrollNow) { SceneView activeView = this.ActiveView; SceneViewModel viewModel = activeView.ViewModel; Vector delta = this.dragCurrentPosition - this.dragStartPosition; if (this.isConstraining) { delta = this.ConstrainDeltaToAxis(delta); } if (delta == this.lastMove || this.IsAltDown) { return; } this.EnsureEditTransaction(); Vector vector1 = delta - this.lastMove; SceneElement primarySelection = viewModel.ElementSelectionSet.PrimarySelection; if (primarySelection == null) { return; } PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection); if (propertyReference == null) { return; } object computedValue = primarySelection.GetComputedValue(propertyReference); if (computedValue != null && !PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)primarySelection.ProjectContext)) { Vector vector2 = vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, true); if (PlatformTypes.IsInstance(computedValue, PlatformTypes.LinearGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool) { ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.StartPointProperty); ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.EndPointProperty); Point point1 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2); Point point2 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2); this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point1); this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point2); } else if (PlatformTypes.IsInstance(computedValue, PlatformTypes.RadialGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool) { ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.CenterProperty); ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.GradientOriginProperty); Point point1 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2); Point point2 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2); this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point1); this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point2); } else { this.TranslateBrushPosition(vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, false), primarySelection); } } activeView.EnsureVisible(this.dragStartPosition + delta, scrollNow); this.lastMove = delta; this.UpdateEditTransaction(); }
protected Point GetRadialGradientEndPoint() { Point point = new Point(); if (PlatformTypes.IsInstance(this.PlatformBrush, PlatformTypes.RadialGradientBrush, (ITypeResolver)this.Element.ProjectContext)) { Vector direction = (Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.CenterProperty) - (Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.GradientOriginProperty); if (direction.X == 0.0 && direction.Y == 0.0) { direction = new Vector(1.0, -1.0); } point = (Point)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.CenterProperty) + BrushAdorner.IntersectRayAndEllipse(direction, (double)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.RadiusXProperty), (double)this.GetBrushPropertyAsWpf(RadialGradientBrushNode.RadiusYProperty)); } return(point); }
public Matrix GetCompleteBrushTransformMatrix(bool includeTransformFromElementToBrushCoordinates) { return(BrushAdorner.GetCompleteBrushTransformMatrix(this.BaseElement, this.PlatformBrush, includeTransformFromElementToBrushCoordinates)); }
public static Matrix GetCompleteInverseBrushTransformMatrix(Base2DElement element, object brush, bool includeTransformFromElementToBrushCoordinates) { return(ElementUtilities.GetInverseMatrix(BrushAdorner.GetCompleteBrushTransformMatrix(element, brush, includeTransformFromElementToBrushCoordinates))); }
public object GetBrushPropertyAsWpf(IPropertyId key) { return(BrushAdorner.GetBrushPropertyAsWpf(this.BaseElement, this.PlatformBrush, key)); }
private void UpdateTranslation(bool scrollNow) { SceneView activeView = this.ActiveView; SceneViewModel viewModel = activeView.ViewModel; if (!this.HasMouseMovedAfterDown) { this.hasInitializedBrush = false; } SceneElement primarySelection = this.ActiveView.ElementSelectionSet.PrimarySelection; if (primarySelection == null) { return; } PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection); if (propertyReference == null || Adorner.NonAffineTransformInParentStack(primarySelection)) { return; } this.EnsureEditTransaction(); if (!this.hasInitializedBrush) { if (!PlatformTypes.IsInstance(this.ActiveView.ElementSelectionSet.PrimarySelection.GetComputedValue(propertyReference), PlatformTypes.GradientBrush, (ITypeResolver)primarySelection.ProjectContext)) { object lastUsed = BrushCategory.GetLastUsed(this.ActiveView.DesignerContext, this.ActiveView.Document.DocumentContext, BrushCategory.Gradient); this.ActiveView.ElementSelectionSet.PrimarySelection.SetValueAsWpf(propertyReference, lastUsed); this.UpdateEditTransaction(); } this.CopyPrimaryBrushToSelection(); this.hasInitializedBrush = true; } object computedValue = primarySelection.GetComputedValue(propertyReference); Matrix matrix = activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, true); Point point1 = this.dragStartPosition * matrix; Point point2 = this.dragCurrentPosition * matrix; Point point3 = RoundingHelper.RoundPosition(point1); Point point4 = RoundingHelper.RoundPosition(point2); if (PlatformTypes.IsInstance(computedValue, PlatformTypes.LinearGradientBrush, (ITypeResolver)primarySelection.ProjectContext)) { this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point3); this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point4); } else if (PlatformTypes.IsInstance(computedValue, PlatformTypes.RadialGradientBrush, (ITypeResolver)primarySelection.ProjectContext)) { this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point3); this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point3); if (this.IsShiftDown) { Vector vector = point4 - point3; this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)vector.Length); this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)vector.Length); } else { Point point5 = RoundingHelper.RoundPosition(new Point(Math.Abs(point3.X - point4.X), Math.Abs(point3.Y - point4.Y))); this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)point5.X); this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)point5.Y); } } activeView.EnsureVisible(this.dragStartPosition + this.dragCurrentPosition - this.dragStartPosition, scrollNow); this.UpdateEditTransaction(); }