private void ApplyRelativeTransformToElements(IEnumerable targetElements, PropertyReference reference, IApplyRelativeTransform transformModel) { foreach (SceneNode sceneNode in targetElements) { SceneElement sceneElement = sceneNode as SceneElement; if (sceneElement != null) { if (sceneElement is BaseFrameworkElement && sceneElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset) { sceneElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5)); } object computedValueAsWpf = sceneElement.GetComputedValueAsWpf(reference); object obj = transformModel.ApplyRelativeTransform(computedValueAsWpf); CanonicalTransform canonicalTransform = obj as CanonicalTransform; if (canonicalTransform != (CanonicalTransform)null) { sceneElement.SetValue(reference, canonicalTransform.GetPlatformTransform(sceneElement.Platform.GeometryHelper)); } else { CanonicalTransform3D canonicalTransform3D = obj as CanonicalTransform3D; if (canonicalTransform3D != (CanonicalTransform3D)null) { sceneElement.SetValue(reference, (object)canonicalTransform3D.ToTransform()); } } } } }
public object ApplyRelativeTransform(object transform) { if (transform != null) { Transform transform1 = transform as Transform; if (transform1 != null) { CanonicalTransform canonicalTransform = new CanonicalTransform(transform1); Point center = canonicalTransform.Center; canonicalTransform.ApplyScale(new Vector(1.0, 1.0) - this.ComponentVector * 2.0, canonicalTransform.Center, center); canonicalTransform.RotationAngle = -canonicalTransform.RotationAngle; Vector skew = canonicalTransform.Skew; canonicalTransform.Skew = new Vector(-skew.X, -skew.Y); return((object)canonicalTransform); } Transform3D transform2 = transform as Transform3D; if (transform2 != null) { CanonicalTransform3D canonicalTransform3D = new CanonicalTransform3D(transform2); Point3D center = canonicalTransform3D.Center; Vector3D scale = new Vector3D(1.0, 1.0, 1.0) - this.ComponentVector3D * 2.0; canonicalTransform3D.ApplyScale(scale, center); canonicalTransform3D.RotationAngles = -canonicalTransform3D.RotationAngles; return((object)canonicalTransform3D); } } return((object)Transform.Identity); }
protected virtual void UpdateCenterPoint(Point centerPoint) { CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.EditingElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty)); Point elementCoordinates = this.BaseEditingElement.RenderTransformOriginInElementCoordinates; Vector translation = canonicalTransform.Translation; Rect computedTightBounds = ((Base2DElement)this.EditingElement).GetComputedTightBounds(); Point renderTransformOrigin = this.BaseEditingElement.RenderTransformOrigin; Point point2 = new Point((centerPoint.X - computedTightBounds.Left) / (computedTightBounds.Width == 0.0 ? 1.0 : computedTightBounds.Width), (centerPoint.Y - computedTightBounds.Top) / (computedTightBounds.Height == 0.0 ? 1.0 : computedTightBounds.Height)); point2 = RoundingHelper.RoundPosition(point2); Point newOrigin = new Point(computedTightBounds.Left + point2.X * computedTightBounds.Width, computedTightBounds.Top + point2.Y * computedTightBounds.Height); canonicalTransform.UpdateForNewOrigin(elementCoordinates, newOrigin); canonicalTransform.TranslationX = RoundingHelper.RoundLength(canonicalTransform.TranslationX); canonicalTransform.TranslationY = RoundingHelper.RoundLength(canonicalTransform.TranslationY); if (!Point.Equals(renderTransformOrigin, point2)) { this.BaseEditingElement.RenderTransformOrigin = point2; } if (!object.Equals((object)translation.X, (object)canonicalTransform.TranslationX)) { this.EditingElement.SetValue(this.EditingElement.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)canonicalTransform.TranslationX); } if (object.Equals((object)translation.Y, (object)canonicalTransform.TranslationY)) { return; } this.EditingElement.SetValue(this.EditingElement.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)canonicalTransform.TranslationY); }
private Canvas AddCanvasLevel(ConvertibleDrawing.DrawingStackEntry entry) { Canvas canvas = new Canvas(); DrawingGroup drawingGroup = entry.Drawing as DrawingGroup; if (entry.Transform != Transform.Identity) { CanonicalTransform canonicalTransform = new CanonicalTransform(entry.Transform); if (drawingGroup.Transform != null) { canonicalTransform = new CanonicalTransform(entry.Transform.Value * drawingGroup.Transform.Value); } ConvertibleDrawing.SetValueIfNotDefault(UIElement.RenderTransformProperty, (DependencyObject)canvas, (object)canonicalTransform.TransformGroup); } ConvertibleDrawing.SetPositionInCanvas((UIElement)canvas, entry.Offset); ConvertibleDrawing.SetValueIfNotDefault(UIElement.BitmapEffectProperty, (DependencyObject)canvas, (object)drawingGroup.BitmapEffect); ConvertibleDrawing.SetValueIfNotDefault(UIElement.BitmapEffectInputProperty, (DependencyObject)canvas, (object)drawingGroup.BitmapEffectInput); ConvertibleDrawing.SetValueIfNotDefault(UIElement.OpacityProperty, (DependencyObject)canvas, (object)drawingGroup.Opacity); ConvertibleDrawing.SetValueIfNotDefault(UIElement.OpacityMaskProperty, (DependencyObject)canvas, (object)drawingGroup.OpacityMask); ConvertibleDrawing.SetValueIfNotDefault(UIElement.ClipProperty, (DependencyObject)canvas, (object)drawingGroup.ClipGeometry); if (!double.IsInfinity(drawingGroup.Bounds.Height)) { ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.HeightProperty, (DependencyObject)canvas, (object)drawingGroup.Bounds.Height); } if (!double.IsInfinity(drawingGroup.Bounds.Width)) { ConvertibleDrawing.SetValueIfNotDefault(FrameworkElement.WidthProperty, (DependencyObject)canvas, (object)drawingGroup.Bounds.Width); } entry.Canvas.Children.Add((UIElement)canvas); return(canvas); }
private void UpdateSkew() { Vector vector1 = this.transformedDisplacementVector * Vector.Multiply(this.currentPointerPosition - this.lastPointerPosition, this.transformedDisplacementVector); this.lastPointerPosition = this.currentPointerPosition; double num1 = Vector.Multiply(this.ActiveAdorner.InverseTransformVector(vector1 * this.documentToObjectTransform, false), this.displacementVector); Point relativeBrushCenter = this.ActiveAdorner.RelativeBrushCenter; Point fixedPoint = !this.skewAroundCenter ? this.oppositeAdornerPosition : relativeBrushCenter; Vector vector2 = fixedPoint - this.adornerPosition; if (vector2.LengthSquared < FloatingPointArithmetic.DistanceTolerance) { return; } vector2 /= vector2.Length; double num2 = vector2.X * this.displacementVector.X + vector2.Y * this.displacementVector.Y; if ((this.displacementVector - vector2 * num2).LengthSquared < FloatingPointArithmetic.DistanceTolerance) { return; } CanonicalTransform transform = new CanonicalTransform(this.ActiveAdorner.BrushTransform); transform.UpdateCenter(relativeBrushCenter); transform.ApplySkewScale(this.displacementVector, this.adornerPosition - fixedPoint, transform.Center, fixedPoint, this.displacementVector, this.adornerPosition - fixedPoint + this.displacementVector * num1); if ((Math.Abs(transform.SkewX) - 90.0) * (Math.Abs(transform.SkewX) - 90.0) < FloatingPointArithmetic.DistanceTolerance || (Math.Abs(transform.SkewY) - 90.0) * (Math.Abs(transform.SkewY) - 90.0) < FloatingPointArithmetic.DistanceTolerance) { return; } this.SetBrushTransform(transform); }
protected override bool OnButtonDown(Point pointerPosition) { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.RotateElement); this.inverseCoordinateSpace = 1.0; SceneView activeView = this.ActiveView; CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.EditingElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty)); this.rootCenter = this.EditingElementSet.RenderTransformOriginInElementCoordinates * this.EditingElementSet.GetTransformMatrix((IViewObject)this.ActiveView.HitTestRoot); Matrix matrix = Matrix.Identity; if (this.EditingElement != this.RootNode) { SceneNode parent = this.EditingElement.Parent; BaseFrameworkElement frameworkElement = (BaseFrameworkElement)null; while (parent != null && (frameworkElement = parent as BaseFrameworkElement) == null) { parent = parent.Parent; } if (frameworkElement != null && frameworkElement.Visual != null) { matrix = activeView.GetComputedTransformToRoot((SceneElement)frameworkElement); } } this.inverseCoordinateSpace = (double)Math.Sign(matrix.Determinant); this.lastPointerAngle = this.GetAngle(pointerPosition); this.unsnappedAngle = canonicalTransform.RotationAngle; this.EnsureEditTransaction(); this.snapping = false; this.snapping = this.IsShiftDown; this.Initialize(); return(true); }
public void TranslateBrushPosition(Vector elementDelta, SceneElement element) { PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)element); if (propertyReference == null) { return; } object computedValue = element.GetComputedValue(propertyReference); if (computedValue == null || PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)element.ProjectContext)) { return; } ReferenceStep referenceStep = (ReferenceStep)element.Platform.Metadata.ResolveProperty(BrushNode.RelativeTransformProperty); object obj = element.ViewModel.DefaultView.ConvertToWpfValue(referenceStep.GetCurrentValue(computedValue)); CanonicalTransform canonicalTransform = !(obj is Transform) ? new CanonicalTransform(Matrix.Identity) : new CanonicalTransform((Transform)obj); elementDelta *= canonicalTransform.TransformGroup.Value; double valueToSet1 = RoundingHelper.RoundLength(canonicalTransform.TranslationX + elementDelta.X); double valueToSet2 = RoundingHelper.RoundLength(canonicalTransform.TranslationY + elementDelta.Y); this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationXReference, valueToSet1); this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationYReference, valueToSet2); }
private void UpdateScale() { Vector scale = new Vector(1.0, 1.0); if (this.constrainAspectRatio) scale.X = scale.Y = 0.0; if (this.ActiveAdorner.TestFlags(EdgeFlags.LeftOrRight)) { double num = this.initialPointerPosition.X - this.currentCenter.X; scale.X = Math.Abs(num) >= 1E-06 ? (this.currentPointerPosition.X - this.currentCenter.X) / num : 1.0; } if (this.ActiveAdorner.TestFlags(EdgeFlags.TopOrBottom)) { double num = this.initialPointerPosition.Y - this.currentCenter.Y; scale.Y = Math.Abs(num) >= 1E-06 ? (this.currentPointerPosition.Y - this.currentCenter.Y) / num : 1.0; } if (this.constrainAspectRatio) { double num = Math.Max(Math.Abs(scale.X), Math.Abs(scale.Y)); scale.X = scale.X < 0.0 ? -num : num; scale.Y = scale.Y < 0.0 ? -num : num; } CanonicalTransform transform = new CanonicalTransform(this.initialBrushTransform); transform.UpdateCenter(this.ActiveAdorner.RelativeBrushCenter); transform.ApplyScale(scale, transform.Center, this.currentCenter); this.SetBrushTransform(transform); }
public override void Draw(DrawingContext context, Matrix matrix) { if (this.Icon == null) { return; } if (!this.IsActive) { context.PushOpacity(0.5); } CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix)); ScaleTransform scaleTransform = new ScaleTransform(canonicalTransform.ScaleX, canonicalTransform.ScaleY); canonicalTransform.Scale = new Vector(1.0, 1.0); Transform transform = DockAdorner.RemoveScaleFromCanonicalTransform(canonicalTransform); context.PushTransform(transform); Point adornerPosition = this.GetAdornerPosition(scaleTransform); context.PushTransform((Transform) new TranslateTransform(adornerPosition.X, adornerPosition.Y)); context.DrawDrawing(this.Icon); context.Pop(); context.Pop(); if (this.IsActive) { return; } context.Pop(); }
public DrawingStackEntry(Canvas canvas, Drawing drawing, Matrix matrix) { this.canvas = canvas; this.drawing = drawing; this.matrix = matrix; this.offset = new Point(this.matrix.OffsetX, this.matrix.OffsetY); this.transform = new CanonicalTransform(this.matrix); this.transform.Translation = new Vector(0.0, 0.0); }
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 TryGetTranslateAnimationProperties() { if (!this.Element.IsViewObjectValid || !CanonicalTransform.IsCanonical((Transform)this.Element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty))) { return; } this.positionXAnimationProperty = this.AdornerSet.ViewModel.AnimationEditor.GetAnimationProperty((SceneNode)this.Element, this.Element.ViewModel.DefaultView.ConvertFromWpfPropertyReference(this.Element.Platform.Metadata.CommonProperties.RenderTransformTranslationX)); this.positionYAnimationProperty = this.AdornerSet.ViewModel.AnimationEditor.GetAnimationProperty((SceneNode)this.Element, this.Element.ViewModel.DefaultView.ConvertFromWpfPropertyReference(this.Element.Platform.Metadata.CommonProperties.RenderTransformTranslationY)); this.hasValidTranslateAnimationProperty = true; }
public override Point GetClickablePoint(Matrix matrix) { CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix)); ScaleTransform scaleTransform = new ScaleTransform(canonicalTransform.ScaleX, canonicalTransform.ScaleY); canonicalTransform.Scale = new Vector(1.0, 1.0); Point adornerPosition = this.GetAdornerPosition(scaleTransform); return(new Point(adornerPosition.X + this.Icon.Bounds.Width / 2.0, adornerPosition.Y + this.Icon.Bounds.Height / 2.0) * canonicalTransform.TransformGroup.Value); }
protected Matrix TruncateMatrix(Matrix matrix) { CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix)); return(new CanonicalTransform() { Skew = canonicalTransform.Skew, RotationAngle = canonicalTransform.RotationAngle }.TransformGroup.Value); }
protected void MoveDraggedElementsInContainer() { Point point1 = this.DragCurrentPosition; if (this.IsConstraining) { point1 = this.ConstrainPointToAxis(this.DragStartPosition, this.DragCurrentPosition); } Point point2 = this.ActiveView.TransformPoint((IViewObject)this.ActiveView.HitTestRoot, this.LayoutContainer.Visual, point1); Point point3 = this.ActiveView.TransformPoint((IViewObject)this.ActiveView.HitTestRoot, this.LayoutContainer.Visual, this.DragStartPosition); for (int index = 0; index < this.DraggedElements.Count; ++index) { BaseFrameworkElement child = this.DraggedElements[index]; if (child.IsViewObjectValid) { LayoutOverrides overridesToIgnore = LayoutOverrides.None; if (point1.X != this.DragStartPosition.X) { overridesToIgnore |= LayoutOverrides.CenterHorizontalAlignment; } if (point1.Y != this.DragStartPosition.Y) { overridesToIgnore |= LayoutOverrides.CenterVerticalAlignment; } if (this.Context.IsRecordingKeyframes) { Vector vector = point2 - point3; CanonicalTransform canonicalTransform = this.Context.BaseRenderTransforms[index]; double num1 = RoundingHelper.RoundLength(vector.X + canonicalTransform.TranslationX); double num2 = RoundingHelper.RoundLength(vector.Y + canonicalTransform.TranslationY); if (!object.Equals((object)canonicalTransform.TranslationX, (object)num1)) { child.SetValue(child.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num1); } if (!object.Equals((object)canonicalTransform.TranslationY, (object)num2)) { child.SetValue(child.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num2); } } else { Point location = point2; ILayoutDesigner designerForChild = this.ActiveView.ViewModel.GetLayoutDesignerForChild((SceneElement)child, false); Rect childRect = designerForChild.GetChildRect(child); Point point4 = this.ActiveView.TransformPoint(child.Visual, this.LayoutContainer.Visual, this.Context.Offsets[index]); point4.Offset(-childRect.X, -childRect.Y); location.Offset(-point4.X, -point4.Y); Rect rect = new Rect(location, this.Context.LayoutCacheRecords[index].Rect.Size); designerForChild.SetChildRect(child, rect, this.Context.LayoutCacheRecords[index].Overrides, overridesToIgnore, LayoutOverrides.None); } } } this.Context.Transaction.UpdateEditTransaction(); }
protected override bool OnButtonDown(Point pointerPosition) { this.initialBrushTransform = new CanonicalTransform(this.ActiveAdorner.BrushTransform); this.initialRootToBrushMatrix = this.ActiveView.GetComputedTransformFromRoot(this.EditingElement) * this.ActiveAdorner.GetCompleteInverseBrushTransformMatrix(false); this.initialPointerPosition = pointerPosition * this.initialRootToBrushMatrix; this.constrainAspectRatio = this.IsShiftDown; this.scaleAroundCenter = this.IsAltDown; this.currentPointerPosition = this.initialPointerPosition; this.UpdateCenter(); return true; }
protected virtual void ApplyScale(Vector scale, Point center) { CanonicalTransform newTransform = new CanonicalTransform(this.startTransform); newTransform.ApplyScale(scale, this.BaseEditingElement.RenderTransformOriginInElementCoordinates, center); newTransform.ScaleX = RoundingHelper.RoundScale(newTransform.ScaleX); newTransform.ScaleY = RoundingHelper.RoundScale(newTransform.ScaleY); newTransform.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX); newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY); AdornedToolBehavior.UpdateElementTransform(this.EditingElement, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Translation); }
public override Rect GetChildRect(BaseFrameworkElement child) { CanonicalTransform canonicalTransform = new CanonicalTransform(child.GetEffectiveRenderTransform(false)); canonicalTransform.SkewX = 0.0; canonicalTransform.SkewY = 0.0; canonicalTransform.RotationAngle = 0.0; Rect computedTightBounds = child.GetComputedTightBounds(); computedTightBounds.Transform(canonicalTransform.TransformGroup.Value); return(computedTightBounds); }
private void UpdateCenterPoint(Point centerPoint) { CanonicalTransform canonicalTransform = new CanonicalTransform(this.pathElement.RenderTransform); Point elementCoordinates = this.pathElement.RenderTransformOriginInElementCoordinates; Rect computedBounds = this.pathElement.GetComputedBounds((Base2DElement)this.pathElement); Point newOrigin = new Point(computedBounds.Left + centerPoint.X * computedBounds.Width, computedBounds.Top + centerPoint.Y * computedBounds.Height); canonicalTransform.UpdateForNewOrigin(elementCoordinates, newOrigin); this.pathElement.RenderTransformOriginInElementCoordinates = newOrigin; this.pathElement.SetValue(this.pathElement.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)canonicalTransform.TranslationX); this.pathElement.SetValue(this.pathElement.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)canonicalTransform.TranslationY); }
protected void SetBrushTransform(CanonicalTransform transform) { this.EnsureEditTransaction(); transform.CenterX = RoundingHelper.RoundLength(transform.CenterX); transform.CenterY = RoundingHelper.RoundLength(transform.CenterY); transform.ScaleX = RoundingHelper.RoundScale(transform.ScaleX); transform.ScaleY = RoundingHelper.RoundScale(transform.ScaleY); transform.SkewX = RoundingHelper.RoundAngle(transform.SkewX); transform.SkewY = RoundingHelper.RoundAngle(transform.SkewY); transform.RotationAngle = RoundingHelper.RoundAngle(transform.RotationAngle); transform.TranslationX = RoundingHelper.RoundLength(transform.TranslationX); transform.TranslationY = RoundingHelper.RoundLength(transform.TranslationY); IProjectContext projectContext = this.ActiveDocument.ProjectContext; CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.GetBrushValue(BrushNode.RelativeTransformProperty)); if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterX, transform.CenterX) != 0 || JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterY, transform.CenterY) != 0) { this.SetBrushValue(BrushNode.RelativeTransformProperty, transform.GetPlatformTransform(this.RootNode.Platform.GeometryHelper)); } else { if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleX, transform.ScaleX) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleXReference, transform.ScaleX); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleY, transform.ScaleY) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleYReference, transform.ScaleY); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewX, transform.SkewX) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewXReference, transform.SkewX); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewY, transform.SkewY) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewYReference, transform.SkewY); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.RotationAngle, transform.RotationAngle) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushRotationAngleReference, transform.RotationAngle); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationX, transform.TranslationX) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationXReference, transform.TranslationX); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationY, transform.TranslationY) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationYReference, transform.TranslationY); } } this.UpdateEditTransaction(); }
protected override bool OnButtonDown(Point pointerPosition) { this.pixelToBrushTransform = this.ActiveView.GetComputedTransformFromRoot(this.EditingElement) * this.ActiveAdorner.GetCompleteInverseBrushTransformMatrix(false); this.brushCenter = this.ActiveAdorner.RelativeBrushCenter; this.inverseCoordinateSpace = (double)Math.Sign(this.ActiveAdorner.BrushTransform.Value.Determinant); this.startVector = pointerPosition * this.pixelToBrushTransform - this.brushCenter; this.startVector.Normalize(); this.lastPointerAngle = this.GetAngle(this.startVector); this.initialBrushTransform = new CanonicalTransform(this.ActiveAdorner.BrushTransform); this.unsnappedAngle = this.initialBrushTransform.RotationAngle; this.EnsureEditTransaction(); this.snapping = this.IsShiftDown; return(true); }
protected void FlipElements(BasisComponent basisComponent, string description) { SceneElementSelectionSet elementSelectionSet = this.SceneViewModel.ElementSelectionSet; PropertyReference propertyReference = (PropertyReference)null; foreach (SceneElement sceneElement in elementSelectionSet.Selection) { if (sceneElement is BaseFrameworkElement || sceneElement is StyleNode) { propertyReference = new PropertyReference((ReferenceStep)sceneElement.ProjectContext.ResolveProperty(Base2DElement.RenderTransformProperty)); break; } if (sceneElement is Base3DElement) { propertyReference = new PropertyReference((ReferenceStep)sceneElement.ProjectContext.ResolveProperty((sceneElement as Base3DElement).TransformPropertyId)); break; } } if (propertyReference == null) { return; } using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(description)) { foreach (SceneElement sceneElement in elementSelectionSet.Selection) { object computedValueAsWpf = sceneElement.GetComputedValueAsWpf(propertyReference); object obj = new ReflectTransform(basisComponent).ApplyRelativeTransform(computedValueAsWpf); CanonicalTransform canonicalTransform = obj as CanonicalTransform; if (canonicalTransform != (CanonicalTransform)null) { sceneElement.SetValue(propertyReference, canonicalTransform.GetPlatformTransform(sceneElement.Platform.GeometryHelper)); if (sceneElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset) { sceneElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5)); } } else { CanonicalTransform3D canonicalTransform3D = obj as CanonicalTransform3D; if (canonicalTransform3D != (CanonicalTransform3D)null) { sceneElement.SetValue(propertyReference, (object)canonicalTransform3D.ToTransform()); } } } editTransaction.Commit(); } }
private void UpdateRotation() { double num = this.unsnappedAngle; if (this.snapping) { num = this.SnapToAngle(this.unsnappedAngle, BrushRotateBehavior.shiftSnapAngle); } Point relativeBrushCenter = this.ActiveAdorner.RelativeBrushCenter; CanonicalTransform transform = new CanonicalTransform(this.initialBrushTransform); transform.UpdateCenter(relativeBrushCenter); transform.ApplyRotation(num - this.initialBrushTransform.RotationAngle, relativeBrushCenter); this.SetBrushTransform(transform); }
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); }
public override void SetChildRect(BaseFrameworkElement child, Rect rect, LayoutOverrides layoutOverrides, LayoutOverrides overridesToIgnore, LayoutOverrides nonExplicitOverrides, SetRectMode setRectMode) { if (child == null) { throw new ArgumentNullException("child"); } CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)child.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty)); Vector translation = canonicalTransform.Translation; canonicalTransform.TranslationX = 0.0; canonicalTransform.TranslationY = 0.0; canonicalTransform.SkewX = 0.0; canonicalTransform.SkewY = 0.0; canonicalTransform.RotationAngle = 0.0; Rect computedTightBounds = child.GetComputedTightBounds(); double num1 = computedTightBounds.Width == 0.0 ? 0.0 : rect.Width / computedTightBounds.Width; double num2 = computedTightBounds.Height == 0.0 ? 0.0 : rect.Height / computedTightBounds.Height; double num3 = RoundingHelper.RoundScale(num1); double num4 = RoundingHelper.RoundScale(num2); if ((overridesToIgnore & LayoutOverrides.Width) != LayoutOverrides.None && !object.Equals((object)canonicalTransform.ScaleX, (object)num3)) { child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformScaleX, (object)num3); } if ((overridesToIgnore & LayoutOverrides.Height) != LayoutOverrides.None && !object.Equals((object)canonicalTransform.ScaleY, (object)num4)) { child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformScaleY, (object)num4); } canonicalTransform.ScaleX = num3; canonicalTransform.ScaleY = num4; canonicalTransform.Center = child.RenderTransformOriginInElementCoordinates; computedTightBounds.Transform(canonicalTransform.TransformGroup.Value); double num5 = rect.Left - computedTightBounds.Left + translation.X; double num6 = rect.Top - computedTightBounds.Top + translation.Y; double num7 = RoundingHelper.RoundLength(num5); double num8 = RoundingHelper.RoundLength(num6); if (!object.Equals((object)translation.X, (object)num7)) { child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num7); } if (object.Equals((object)translation.Y, (object)num8)) { return; } child.SetValueAsWpf(child.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num8); }
private void Initialize(Point pointerPosition) { this.canonicalTransform = new CanonicalTransform((Transform)this.EditingElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty)); this.adornerPosition = this.ActiveAdorner.GetOffsetAnchorPoint(Matrix.Identity, 2.0); this.skewAroundCenter = this.IsAltDown; switch (this.ActiveAdorner.EdgeFlags) { case EdgeFlags.Left: this.displacementVector = new Vector(0.0, 1.0); this.oppositeAdornerPosition = this.GetAnchorPointAdornerPosition(EdgeFlags.Right, Matrix.Identity); break; case EdgeFlags.Top: this.displacementVector = new Vector(1.0, 0.0); this.oppositeAdornerPosition = this.GetAnchorPointAdornerPosition(EdgeFlags.Bottom, Matrix.Identity); break; case EdgeFlags.Right: this.displacementVector = new Vector(0.0, -1.0); this.oppositeAdornerPosition = this.GetAnchorPointAdornerPosition(EdgeFlags.Left, Matrix.Identity); break; case EdgeFlags.Bottom: this.displacementVector = new Vector(-1.0, 0.0); this.oppositeAdornerPosition = this.GetAnchorPointAdornerPosition(EdgeFlags.Top, Matrix.Identity); break; default: throw new InvalidOperationException(ExceptionStringTable.SkewBehaviorInvalidAnchor); } this.startPointerPosition = pointerPosition; Matrix computedTransformToRoot = this.ActiveView.GetComputedTransformToRoot(this.EditingElement); if (computedTransformToRoot.HasInverse) { Matrix matrix = computedTransformToRoot; matrix.Invert(); this.documentToObjectTransform = matrix; this.behaviorEnabled = true; } else { this.behaviorEnabled = false; } this.transformedDisplacementVector = this.displacementVector * computedTransformToRoot; this.transformedDisplacementVector /= this.transformedDisplacementVector.Length; }
protected static Transform RemoveScaleFromCanonicalTransform(CanonicalTransform canonicalTransform) { TransformCollection children = canonicalTransform.TransformGroup.Children; TransformCollection transformCollection = new TransformCollection(); foreach (Transform transform in children) { if (!typeof(ScaleTransform).IsAssignableFrom(transform.GetType())) { transformCollection.Add(transform); } } return((Transform) new TransformGroup() { Children = transformCollection }); }
protected override void ApplyScale(Vector scale, Point center) { Vector scale1 = new Vector(Math.Abs(scale.X), Math.Abs(scale.Y)); Vector scale2 = new Vector(scale.X < 0.0 ? -1.0 : 1.0, scale.Y < 0.0 ? -1.0 : 1.0); Vector vector1 = new Vector(this.StartCenter.X, this.StartCenter.Y); Size newSize = this.ComputeNewSize(scale1); Point topLeft = this.StartBounds.TopLeft; CanonicalTransform canonicalTransform = new CanonicalTransform(this.StartTransform); canonicalTransform.ApplyScale(scale, this.StartCenter, center); Point point1 = (topLeft - vector1) * canonicalTransform.TransformGroup.Value + vector1; Point renderTransformOrigin = this.BaseEditingElement.RenderTransformOrigin; renderTransformOrigin.X *= newSize.Width; renderTransformOrigin.Y *= newSize.Height; CanonicalTransform newTransform = new CanonicalTransform(this.StartTransform); newTransform.ApplyScale(scale2, renderTransformOrigin, center); Vector vector2 = (Vector)renderTransformOrigin; Point point2 = (topLeft - vector2) * newTransform.TransformGroup.Value + vector2; newTransform.Translation += point1 - point2; AdornedToolBehavior.UpdateElementTransform(this.EditingElement, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale); ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild(this.EditingElement, true); Rect rect = this.initialRect; rect.Offset(newTransform.TranslationX - this.StartTransform.TranslationX, newTransform.TranslationY - this.StartTransform.TranslationY); rect.Width = newSize.Width; rect.Height = newSize.Height; LayoutOverrides overridesToIgnore = (LayoutOverrides)(0 | (!object.Equals((object)rect.Width, (object)this.StartSize.Width) ? 16 : 0) | (!object.Equals((object)rect.Height, (object)this.StartSize.Height) ? 32 : 0)); designerForChild.SetChildRect(this.BaseEditingElement, rect, this.initialOverrides, overridesToIgnore, LayoutOverrides.None); if (!object.Equals((object)rect.Width, (object)this.StartSize.Width) || !object.Equals((object)rect.Height, (object)this.StartSize.Height)) { PathElement.EnsureStretchIsFill((SceneNode)this.EditingElement); } if (this.transformHelper == null) { return; } this.transformHelper.Update(scale1.X, scale1.Y); }
private void UpdateSkew() { if (!this.behaviorEnabled) { return; } Vector vector1 = this.MouseDevice.GetPosition((IInputElement)this.ActiveView.ViewRootContainer) - this.startPointerPosition; double num1 = vector1.X * this.transformedDisplacementVector.X + vector1.Y * this.transformedDisplacementVector.Y; vector1.X = this.transformedDisplacementVector.X * num1; vector1.Y = this.transformedDisplacementVector.Y * num1; Vector vector2 = vector1 * this.documentToObjectTransform; double num2 = vector2.X * this.displacementVector.X + vector2.Y * this.displacementVector.Y; CanonicalTransform newTransform = new CanonicalTransform(this.canonicalTransform); Point fixedPoint = !this.skewAroundCenter ? this.oppositeAdornerPosition : this.BaseEditingElement.RenderTransformOriginInElementCoordinates; Vector vector3 = fixedPoint - this.adornerPosition; if (vector3.LengthSquared < FloatingPointArithmetic.DistanceTolerance) { return; } Vector vector4 = vector3 / vector3.Length; double num3 = vector4.X * this.displacementVector.X + vector4.Y * this.displacementVector.Y; if ((this.displacementVector - vector4 * num3).LengthSquared < FloatingPointArithmetic.DistanceTolerance) { return; } newTransform.ApplySkewScale(this.displacementVector, this.adornerPosition - fixedPoint, this.BaseEditingElement.RenderTransformOriginInElementCoordinates, fixedPoint, this.displacementVector, this.adornerPosition - fixedPoint + this.displacementVector * num2); 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.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX); newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY); if ((Math.Abs(newTransform.Skew.X) - 90.0) * (Math.Abs(newTransform.Skew.X) - 90.0) < FloatingPointArithmetic.DistanceTolerance || (Math.Abs(newTransform.Skew.Y) - 90.0) * (Math.Abs(newTransform.Skew.Y) - 90.0) < FloatingPointArithmetic.DistanceTolerance) { return; } AdornedToolBehavior.UpdateElementTransform(this.EditingElement, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Skew | AdornedToolBehavior.TransformPropertyFlags.Translation); }
private void SetupTransform(UIElement adorner) { BaseAdornerLayout.LayoutCache cache = BaseAdornerLayout.GetCache((DependencyObject)adorner); CanonicalTransform canonicalTransform1 = new CanonicalTransform(cache.ElementToDesignerViewTransformMatrix); CanonicalTransform canonicalTransform2 = new CanonicalTransform(cache.DesignerViewToViewportMatrix); Vector vector = VectorUtilities.Scale(canonicalTransform1.Scale, canonicalTransform2.Scale); adorner.SetValue(TransformAwareAdornerLayout.DesignerElementScalingFactorWithZoom, (object)vector); CanonicalTransform canonicalTransform3 = new CanonicalTransform(canonicalTransform1); canonicalTransform3.Scale = VectorUtilities.Unscale(new Vector((double)Math.Sign(vector.X), (double)Math.Sign(vector.Y)), canonicalTransform2.Scale); AdornerPanel adornerPanel = adorner as AdornerPanel; if (adornerPanel != null) { if (!adornerPanel.UseMirrorTransform) { canonicalTransform3.Scale = VectorUtilities.Unscale(new Vector(1.0, 1.0), canonicalTransform2.Scale); } else { adornerPanel.IsMirroredTransform = vector.X < 0.0; } } Transform renderTransform = AdornerProperties.GetRenderTransform((DependencyObject)adorner); Transform transform = (Transform)canonicalTransform3.ToTransform(); if (renderTransform != null) { transform = (Transform) new TransformGroup() { Children = { transform, renderTransform } } } ; adorner.RenderTransform = transform; }