public static LayoutRoundingStatus GetLayoutRoundingStatus(SceneElement element) { if (!LayoutRoundingHelper.ShouldConsiderLayoutRoundingAdjustment(element)) { return(LayoutRoundingStatus.Off); } IProperty property = LayoutRoundingHelper.ResolveUseLayoutRoundingProperty((SceneNode)element); if (property == null || !LayoutRoundingHelper.GetUseLayoutRounding(element)) { return(LayoutRoundingStatus.Off); } LayoutRoundingStatus layoutRoundingStatus = LayoutRoundingStatus.On; bool flag = element.IsSet((IPropertyId)property) == PropertyState.Set; if (!flag && PlatformTypes.Path.IsAssignableFrom((ITypeId)element.Type)) { layoutRoundingStatus |= LayoutRoundingStatus.ShouldTurnOff; } else if (LayoutRoundingHelper.IsAxisAligned(element)) { layoutRoundingStatus |= LayoutRoundingStatus.ShouldSnapToPixel; } else if (!flag || LayoutRoundingHelper.GetAutoLayoutRounding(element)) { layoutRoundingStatus |= LayoutRoundingStatus.ShouldTurnOff; } return(layoutRoundingStatus); }
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()); } } } } }
private void UpdateAmbientValueFromSceneElement(SceneElement element, PropertyReference propertyReference) { bool strictTypeCheck = true; PropertyReference propertyReference1 = SceneNodeObjectSet.FilterProperty((SceneNode)element, propertyReference, strictTypeCheck); if (!element.IsViewObjectValid || propertyReference1 == null || propertyReference1.PlatformMetadata != element.Platform.Metadata) { return; } AmbientPropertyManager.AmbientPropertyValue ambientPropertyValue = this.GetAmbientPropertyValue(propertyReference1.FirstStep); if (ambientPropertyValue == null) { return; } using (element.ViewModel.ForceBaseValue()) { if (element.IsSet(propertyReference1) == PropertyState.Unset) { ambientPropertyValue.Value = null; } else { DocumentNodePath valueAsDocumentNode = element.GetLocalValueAsDocumentNode(propertyReference1); if (!this.HasValidValue(element.ViewModel, valueAsDocumentNode)) { return; } ambientPropertyValue.Value = valueAsDocumentNode.Node; } } }
private static void UpdateItemsSourceOnItemsChanged(SceneElement itemsControl) { if (PropertyState.Unset == itemsControl.IsSet(ItemsControlElement.ItemsSourceProperty)) { return; } itemsControl.ClearValue(ItemsControlElement.ItemTemplateProperty); itemsControl.ClearValue(ItemsControlElement.ItemsSourceProperty); }
private void ReleaseClippingPath(SceneElement sceneElement, SceneEditTransaction editTransaction) { if (sceneElement.IsSet(Base2DElement.ClipProperty) != PropertyState.Set) { return; } SceneNode sceneNode = (SceneNode)sceneElement; for (SceneNode parent = sceneElement.Parent; parent != null; parent = parent.Parent) { PanelElement panelElement = parent as PanelElement; if (panelElement != null) { MatrixTransform matrixTransform = new MatrixTransform(sceneElement.GetComputedTransformToElement((SceneElement)panelElement)); PathGeometry pathGeometry1 = new PathGeometry(); System.Windows.Media.Geometry geometry = (System.Windows.Media.Geometry)sceneElement.GetLocalOrDefaultValueAsWpf(Base2DElement.ClipProperty); if (geometry != null) { pathGeometry1 = PathGeometryUtilities.TransformGeometry(geometry, (Transform)matrixTransform); } PathElement pathElement = (PathElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Path); using (pathElement.ViewModel.ForceBaseValue()) { this.DesignerContext.AmbientPropertyManager.ApplyAmbientProperties((SceneNode)pathElement); pathElement.SetValueAsWpf(ShapeElement.StrokeProperty, (object)Brushes.Black); pathElement.ClearValue(ShapeElement.FillProperty); pathElement.ClearValue(ShapeElement.StrokeThicknessProperty); panelElement.Children.Insert(panelElement.Children.IndexOf(sceneNode) + 1, (SceneNode)pathElement); ReferenceStep singleStep1 = (ReferenceStep)pathElement.ProjectContext.ResolveProperty(Base2DElement.ClipProperty); ReferenceStep singleStep2 = (ReferenceStep)pathElement.ProjectContext.ResolveProperty(PathElement.DataProperty); PathCommandHelper.MoveVertexAnimations(sceneElement, new PropertyReference(singleStep1), (SceneElement)pathElement, new PropertyReference(singleStep2), (Transform)matrixTransform); Rect bounds = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry1.Bounds, pathElement, false); Rect maxAnimatedExtent = PathCommandHelper.FindMaxAnimatedExtent((SceneElement)pathElement, bounds, new PropertyReference(singleStep2)); editTransaction.Update(); Vector vector = new Vector(-maxAnimatedExtent.Left, -maxAnimatedExtent.Top); panelElement.LayoutDesigner.SetChildRect((BaseFrameworkElement)pathElement, maxAnimatedExtent); Transform transform = (Transform) new TranslateTransform(vector.X, vector.Y); PathGeometry pathGeometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry1, transform); pathElement.PathGeometry = pathGeometry2; PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, new PropertyReference(singleStep2), transform); pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)(Stretch)(pathElement.HasVertexAnimations ? 0 : 1)); break; } } else { sceneNode = parent; } } }
public static DocumentNodePath ProvideStyleOrTemplateNodePath(SceneElement targetElement, PropertyReference targetPropertyReference) { DocumentNodePath documentNodePath = (DocumentNodePath)null; ReferenceStep targetProperty = targetPropertyReference[0]; StyleNode styleNode = targetElement as StyleNode; if (targetPropertyReference.TargetType.IsAssignableFrom(targetElement.TargetType) || styleNode != null && targetPropertyReference.TargetType.IsAssignableFrom(styleNode.StyleTargetType)) { IViewObjectFactory viewObjectFactory = targetElement.Platform.ViewObjectFactory; object computedValue = targetElement.GetComputedValue(targetPropertyReference); DocumentNodePath valuePath = (DocumentNodePath)null; if (computedValue != null) { IViewObject instance = viewObjectFactory.Instantiate(computedValue); valuePath = targetElement.ViewModel.DefaultView.GetCorrespondingNodePath(instance, true); } if (valuePath == null && !BaseFrameworkElement.StyleProperty.Equals((object)targetProperty)) { BaseFrameworkElement frameworkElement = targetElement as BaseFrameworkElement; if (frameworkElement != null) { frameworkElement.FindMissingImplicitStyle(); } if (computedValue != null) { IViewObject instance = viewObjectFactory.Instantiate(computedValue); DocumentNodePath correspondingNodePath = targetElement.ViewModel.DefaultView.GetCorrespondingNodePath(instance, true); if (correspondingNodePath != null) { valuePath = ControlStylingOperations.FindTemplateWithinStyle(correspondingNodePath, targetElement, (IPropertyId)targetProperty, (IPropertyId)targetProperty); } } } if (ControlStylingOperations.ShouldSetEditingContextToNodePath(valuePath, targetElement, targetProperty)) { documentNodePath = valuePath; } } if (documentNodePath == null && styleNode != null && targetElement.IsSet(targetPropertyReference) == PropertyState.Set) { DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference); if (ControlStylingOperations.ShouldSetEditingContextToNodePath(valueAsDocumentNode, targetElement, targetProperty)) { documentNodePath = valueAsDocumentNode; } } return(documentNodePath); }
private static bool IsAxisAligned(SceneElement element) { if (element.IsSet(Base2DElement.RenderTransformProperty) == PropertyState.Set) { Matrix matrixFromTransform = VectorUtilities.GetMatrixFromTransform(element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty) as GeneralTransform); if (!matrixFromTransform.IsIdentity) { Vector vector1 = matrixFromTransform.Transform(new Vector(1.0, 0.0)); Vector vector2 = matrixFromTransform.Transform(new Vector(0.0, 1.0)); double num = 1E-06; if (Math.Abs(vector1.Y) > num || Math.Abs(vector2.X) > num) { return(false); } } } return(true); }
public static bool UpdateLayoutRounding(SceneElement element) { if (!LayoutRoundingHelper.ShouldConsiderLayoutRoundingAdjustment(element)) { return(false); } IPropertyId propertyKey = (IPropertyId)LayoutRoundingHelper.ResolveUseLayoutRoundingProperty((SceneNode)element); if (propertyKey == null) { return(false); } bool flag1 = element.IsSet(propertyKey) == PropertyState.Set; if (PlatformTypes.Path.IsAssignableFrom((ITypeId)element.Type)) { if (!flag1 && (bool)element.GetComputedValue(propertyKey)) { element.SetLocalValue(Base2DElement.UseLayoutRoundingProperty, (object)false); LayoutRoundingHelper.SetAutoLayoutRounding(element, false); return(true); } } else if (!flag1 || LayoutRoundingHelper.GetAutoLayoutRounding(element)) { bool flag2 = (bool)element.GetComputedValue(propertyKey); if (LayoutRoundingHelper.IsAxisAligned(element)) { if (!flag2) { element.ClearValue(propertyKey); LayoutRoundingHelper.SetAutoLayoutRounding(element, false); return(true); } } else if (flag2) { element.SetValue(propertyKey, (object)false); LayoutRoundingHelper.SetAutoLayoutRounding(element, true); return(true); } } return(false); }
protected DocumentNode ProvideCurrentTemplate(SceneElement targetElement, PropertyReference targetPropertyReference, out IList <DocumentCompositeNode> auxillaryResources) { IPlatform platform = this.SceneViewModel.ProjectContext.Platform; FrameworkTemplateElement frameworkTemplateElement1 = (FrameworkTemplateElement)null; auxillaryResources = (IList <DocumentCompositeNode>)null; if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set) { FrameworkTemplateElement frameworkTemplateElement2 = targetElement.GetLocalValueAsSceneNode(targetPropertyReference) as FrameworkTemplateElement; if (frameworkTemplateElement2 != null) { frameworkTemplateElement1 = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as FrameworkTemplateElement; if (frameworkTemplateElement1 != null) { auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(frameworkTemplateElement2.DocumentNode); } } } if (frameworkTemplateElement1 == null) { object computedValue = targetElement.GetComputedValue(targetPropertyReference); DocumentNode root = computedValue == null ? (DocumentNode)null : this.SceneView.GetCorrespondingDocumentNode(platform.ViewObjectFactory.Instantiate(computedValue), true); IPropertyId targetProperty = (IPropertyId)targetElement.Platform.Metadata.ResolveProperty(BaseFrameworkElement.StyleProperty); DocumentCompositeNode documentCompositeNode1 = targetElement.DocumentNode as DocumentCompositeNode; if (!targetElement.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf) && documentCompositeNode1 != null && (root == null && targetPropertyReference.ReferenceSteps.Count == 1)) { ITypeId styleTargetType = (ITypeId)targetElement.Type; DocumentNode currentStyle = (DocumentNode)null; ReferenceStep referenceStep = targetPropertyReference.ReferenceSteps[0]; object defaultStyleKey = this.GetDefaultStyleKey(targetElement, styleTargetType, targetProperty); if (defaultStyleKey != null) { bool isThemeStyle; IList <DocumentCompositeNode> auxillaryResources1; this.ResolveDefaultStyle(targetElement, defaultStyleKey, true, out currentStyle, out isThemeStyle, out auxillaryResources1); } DocumentCompositeNode documentCompositeNode2 = currentStyle as DocumentCompositeNode; if (documentCompositeNode2 != null) { DocumentCompositeNode documentCompositeNode3 = documentCompositeNode2.Properties[StyleNode.SettersProperty] as DocumentCompositeNode; if (documentCompositeNode3 != null) { foreach (DocumentNode documentNode1 in (IEnumerable <DocumentNode>)documentCompositeNode3.Children) { DocumentCompositeNode documentCompositeNode4 = documentNode1 as DocumentCompositeNode; if (documentCompositeNode4 != null) { IMemberId memberId = (IMemberId)DocumentPrimitiveNode.GetValueAsMember(documentCompositeNode4.Properties[SetterSceneNode.PropertyProperty]); DocumentNode documentNode2 = documentCompositeNode4.Properties[SetterSceneNode.ValueProperty]; if (memberId != null && documentNode2 != null && referenceStep.Equals((object)memberId)) { root = documentNode2; break; } } } } } } if (root != null) { frameworkTemplateElement1 = this.SceneViewModel.GetSceneNode(root.Clone(this.SceneViewModel.Document.DocumentContext)) as FrameworkTemplateElement; auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(root); } else { frameworkTemplateElement1 = this.SceneViewModel.CreateSceneNode(computedValue) as FrameworkTemplateElement; } } if (frameworkTemplateElement1 == null) { return((DocumentNode)null); } return(frameworkTemplateElement1.DocumentNode); }
protected DocumentNode ProvideCurrentStyle(SceneElement targetElement, IType targetType, PropertyReference targetPropertyReference, bool allowDefaultStyle, out IList <DocumentCompositeNode> auxillaryResources) { auxillaryResources = (IList <DocumentCompositeNode>)null; DocumentNode currentStyle = (DocumentNode)null; bool isThemeStyle = false; IType targetType1 = targetType; if (!this.TargetProperty.Equals((object)BaseFrameworkElement.StyleProperty)) { IDocumentContext documentContext = this.SceneViewModel.Document.DocumentContext; Type propertyTargetType = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty); targetType1 = propertyTargetType == (Type)null ? (IType)null : this.SceneViewModel.ProjectContext.GetType(propertyTargetType); } if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set) { DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference); if (valueAsDocumentNode != null && valueAsDocumentNode.Node is DocumentCompositeNode && PlatformTypes.Style.IsAssignableFrom((ITypeId)valueAsDocumentNode.Node.Type) && (!StyleNode.IsDefaultValue(valueAsDocumentNode.Node) || allowDefaultStyle)) { StyleNode styleNode = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as StyleNode; if (styleNode != null) { currentStyle = styleNode.DocumentNode; auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(valueAsDocumentNode.Node); } } } if (currentStyle == null) { object obj = this.ResolveCurrentStyle(targetElement, targetPropertyReference, allowDefaultStyle); if (obj != null) { DocumentNode correspondingDocumentNode = this.SceneView.GetCorrespondingDocumentNode(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(obj), true); if (correspondingDocumentNode != null && PlatformTypes.Style.IsAssignableFrom((ITypeId)correspondingDocumentNode.Type)) { currentStyle = correspondingDocumentNode; } else if (obj is Style) { StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(obj); if (targetType1 != null) { styleNode.StyleTargetTypeId = targetType1; } currentStyle = styleNode.DocumentNode; } } if (currentStyle != null && !allowDefaultStyle && StyleNode.IsDefaultValue(currentStyle)) { currentStyle = (DocumentNode)null; } } if (currentStyle == null) { object defaultStyleKey = this.GetDefaultStyleKey(targetElement, (ITypeId)targetType1, (IPropertyId)this.TargetProperty); if (defaultStyleKey != null) { this.ResolveDefaultStyle(targetElement, defaultStyleKey, allowDefaultStyle, out currentStyle, out isThemeStyle, out auxillaryResources); } } if (currentStyle != null && !allowDefaultStyle) { List <DocumentCompositeNode> list = new List <DocumentCompositeNode>(); DocumentCompositeNode node = currentStyle as DocumentCompositeNode; IProperty property = this.SceneViewModel.ProjectContext.ResolveProperty(StyleNode.BasedOnProperty); while (node != null && property != null && (node.Type.Equals((object)PlatformTypes.Style) && node.Properties.Count == 2) && (node.Properties[(IPropertyId)property] != null && node.Properties[StyleNode.TargetTypeProperty] != null)) { node = node.Properties[StyleNode.BasedOnProperty] as DocumentCompositeNode; if (node != null) { if (DocumentNodeUtilities.IsDynamicResource((DocumentNode)node) || DocumentNodeUtilities.IsStaticResource((DocumentNode)node)) { DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node); if (resourceKey != null && auxillaryResources != null) { foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources) { if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode))) { node = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode; break; } } } } if (PlatformTypes.Style.IsAssignableFrom((ITypeId)node.Type)) { currentStyle = (DocumentNode)node; list.Add(node); } } } if (auxillaryResources != null) { foreach (DocumentNode documentNode in list) { DocumentCompositeNode parent = documentNode.Parent; if (parent != null && parent.Type.Equals((object)PlatformTypes.DictionaryEntry)) { auxillaryResources.Remove(parent); } } } if (currentStyle != null && (list.Count > 0 || currentStyle.DocumentRoot != null)) { currentStyle = currentStyle.Clone(targetElement.DocumentContext); } if (auxillaryResources != null) { for (int index = 0; index < auxillaryResources.Count; ++index) { if (auxillaryResources[index].DocumentRoot != null) { auxillaryResources[index] = (DocumentCompositeNode)auxillaryResources[index].Clone(targetElement.DocumentContext); } } } if (isThemeStyle) { ReplaceStyleTemplateCommand.StripFormatting(currentStyle); if (auxillaryResources != null) { for (int index = 0; index < auxillaryResources.Count; ++index) { ReplaceStyleTemplateCommand.StripFormatting((DocumentNode)auxillaryResources[index]); } } } DocumentCompositeNode documentCompositeNode = currentStyle as DocumentCompositeNode; if (documentCompositeNode != null && targetType1 != null) { documentCompositeNode.Properties[StyleNode.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType1)); } if (targetType1 != null) { ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(currentStyle, auxillaryResources, targetType1); } } return(currentStyle); }