private bool CanOptimizeAnimation(KeyFrameAnimationSceneNode nodeToTest) { TimelineSceneNode.PropertyNodePair elementAndProperty = nodeToTest.TargetElementAndProperty; if (elementAndProperty.PropertyReference == null || FromToAnimationSceneNode.GetFromToAnimationForType((ITypeId)elementAndProperty.PropertyReference.ValueTypeId, nodeToTest.ProjectContext) == null || (nodeToTest.KeyFrameCount != 1 || DesignTimeProperties.ExplicitAnimationProperty.Equals((object)elementAndProperty.PropertyReference[0]))) { return(false); } KeyFrameSceneNode keyFrameAtIndex = nodeToTest.GetKeyFrameAtIndex(0); Duration? nullable = nodeToTest.GetLocalOrDefaultValueAsWpf(TimelineSceneNode.DurationProperty) as Duration?; bool flag = !nullable.HasValue || nullable.Value == Duration.Automatic || nullable.Value.HasTimeSpan && nullable.Value.TimeSpan.TotalSeconds == keyFrameAtIndex.Time; if (keyFrameAtIndex.InterpolationType != KeyFrameInterpolationType.Easing || !flag) { return(false); } foreach (IMemberId memberId in (IEnumerable <IProperty>)((DocumentCompositeNode)nodeToTest.DocumentNode).Properties.Keys) { switch (memberId.Name) { case "Duration": case "TargetName": case "TargetProperty": case "BeginTime": case "IsAnimationProxy": case "KeyFrames": case "ShouldSerialize": continue; default: return(false); } } return(true); }
private void Rebuild() { this.X1Property = this.CreateProperty("KeySpline.ControlPoint1/X"); this.Y1Property = this.CreateProperty("KeySpline.ControlPoint1/Y"); this.X2Property = this.CreateProperty("KeySpline.ControlPoint2/X"); this.Y2Property = this.CreateProperty("KeySpline.ControlPoint2/Y"); if (this.keySplineProperty == null || this.keySplineProperty.IsEmpty) { return; } KeyFrameSceneNode keyFrameSceneNode = this.keySplineProperty.SceneNodeObjectSet.RepresentativeSceneNode as KeyFrameSceneNode; if (keyFrameSceneNode == null) { return; } ReferenceStep singleStep = (IProperty)keyFrameSceneNode.Type.GetMember(MemberType.LocalProperty, "KeyTime", MemberAccessTypes.Public) as ReferenceStep; if (singleStep != null) { this.keyTimeProperty = new PropertyReference(singleStep); this.keySplineProperty.SceneNodeObjectSet.RegisterPropertyChangedHandler(this.keyTimeProperty, new Microsoft.Expression.DesignSurface.Documents.PropertyReferenceChangedEventHandler(this.KeyTimePropertyChanged)); } this.UpdateTime0KeyFrameStatus(); }
public string GetUndoString(object obj) { KeyFrameSceneNode keyFrameSceneNode = obj as KeyFrameSceneNode; if (keyFrameSceneNode == null) { return(""); } return(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "{0}", new object[1] { (object)keyFrameSceneNode.Time })); }
private void MovePropertiesFromOptimizedToProxy(AnimationProxyManager.AnimationProxyData data) { if (data.OptimizedAnimation == null || data.ProxyAnimation == null) { return; } KeyFrameSceneNode keyFrameAtIndex = data.ProxyAnimation.GetKeyFrameAtIndex(0); if (keyFrameAtIndex == null) { return; } SceneNode.CopyPropertyValue((SceneNode)data.OptimizedAnimation, data.OptimizedAnimation.ToProperty, (SceneNode)keyFrameAtIndex, keyFrameAtIndex.ValueProperty); SceneNode.CopyPropertyValue((SceneNode)data.OptimizedAnimation, data.OptimizedAnimation.EasingFunctionProperty, (SceneNode)keyFrameAtIndex, keyFrameAtIndex.EasingFunctionProperty); keyFrameAtIndex.Time = data.OptimizedAnimation.Duration; }
public static double GetKeyframeValue(KeyFrameSceneNode node) { if (node.Value is double) { return((double)node.Value); } if (node.IsValueExpression(node.ValueProperty)) { object computedValue = node.GetComputedValue(node.ValueProperty); if (computedValue is double) { return((double)computedValue); } } return(0.0); }
private FromToAnimationSceneNode ConvertToOptimizedAnimation(KeyFrameAnimationSceneNode proxyAnimation) { StoryboardTimelineSceneNode controllingStoryboard = proxyAnimation.ControllingStoryboard; FromToAnimationSceneNode animationSceneNode = FromToAnimationSceneNode.Factory.InstantiateWithTarget(this.viewModel, proxyAnimation.TargetElement, proxyAnimation.TargetProperty, proxyAnimation.StoryboardContainer, FromToAnimationSceneNode.GetFromToAnimationForType(proxyAnimation.AnimatedType, proxyAnimation.ProjectContext)); KeyFrameSceneNode keyFrameAtIndex = proxyAnimation.GetKeyFrameAtIndex(0); animationSceneNode.Duration = keyFrameAtIndex.Time; SceneNode.CopyPropertyValue((SceneNode)keyFrameAtIndex, keyFrameAtIndex.ValueProperty, (SceneNode)animationSceneNode, animationSceneNode.ToProperty); SceneNode.CopyPropertyValue((SceneNode)keyFrameAtIndex, keyFrameAtIndex.EasingFunctionProperty, (SceneNode)animationSceneNode, animationSceneNode.EasingFunctionProperty); animationSceneNode.IsOptimized = true; proxyAnimation.IsAnimationProxy = true; proxyAnimation.ShouldSerialize = false; keyFrameAtIndex.ShouldSerialize = false; int index = proxyAnimation.ControllingStoryboard.Children.IndexOf((TimelineSceneNode)proxyAnimation); proxyAnimation.ControllingStoryboard.Children.Insert(index, (TimelineSceneNode)animationSceneNode); return(animationSceneNode); }
public void ConvertSelection(KeyFrameInterpolationType keyframeInterpolationType) { SceneNode sceneNode = this.selectedObjects[0]; if (sceneNode.ViewModel == null) { return; } SceneViewModel viewModel = sceneNode.ViewModel; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.ConvertKeyFramesUndoUnit, false)) { bool flag = false; foreach (object obj in this.selectedObjects) { KeyFrameSceneNode keyFrame = obj as KeyFrameSceneNode; if (keyFrame == null || keyFrame.KeyFrameAnimation == null) { flag = false; break; } if (keyFrame.InterpolationType != keyframeInterpolationType) { KeyFrameSceneNode selectionToExtend = keyFrame.KeyFrameAnimation.ReplaceKeyFrame(keyFrame, keyframeInterpolationType, (KeySpline)null); if (selectionToExtend == null) { flag = false; break; } viewModel.KeyFrameSelectionSet.ExtendSelection(selectionToExtend); flag = true; } } if (flag) { editTransaction.Commit(); viewModel.RefreshSelection(); } else { editTransaction.Cancel(); } } }
private void DeselectTime0KeyFrames() { if (this.keySplineProperty == null || this.keySplineProperty.IsEmpty) { return; } List <KeyFrameSceneNode> list = new List <KeyFrameSceneNode>(); KeyFrameSelectionSet frameSelectionSet = this.keySplineProperty.SceneNodeObjectSet.ViewModel.KeyFrameSelectionSet; KeyFrameSceneNode primarySelection = frameSelectionSet.PrimarySelection; foreach (KeyFrameSceneNode keyFrameSceneNode in frameSelectionSet.Selection) { if (keyFrameSceneNode.Time != 0.0) { list.Add(keyFrameSceneNode); } } frameSelectionSet.SetSelection((ICollection <KeyFrameSceneNode>)list, primarySelection); }
protected override List <TimelineSceneNode> GetAnimationsToCopy() { List <TimelineSceneNode> list = new List <TimelineSceneNode>(); if (this.ViewModel.ElementSelectionSet.Count == 0 && this.ViewModel.KeyFrameSelectionSet.Count > 0) { Dictionary <TimelineSceneNode.PropertyNodePair, KeyFrameAnimationSceneNode> dictionary = new Dictionary <TimelineSceneNode.PropertyNodePair, KeyFrameAnimationSceneNode>(); foreach (KeyFrameSceneNode keyFrameSceneNode1 in this.ViewModel.KeyFrameSelectionSet.Selection) { if (!AnimationProxyManager.IsAnimationProxy((TimelineSceneNode)keyFrameSceneNode1.KeyFrameAnimation)) { KeyFrameSceneNode keyFrameSceneNode2 = this.ViewModel.GetSceneNode(keyFrameSceneNode1.DocumentNode.Clone(keyFrameSceneNode1.DocumentNode.DocumentRoot.DocumentContext)) as KeyFrameSceneNode; if (keyFrameSceneNode2 != null) { TimelineSceneNode.PropertyNodePair key1 = new TimelineSceneNode.PropertyNodePair(keyFrameSceneNode1.TargetElement, keyFrameSceneNode1.TargetProperty); KeyFrameAnimationSceneNode animationSceneNode; if (!dictionary.ContainsKey(key1)) { animationSceneNode = (KeyFrameAnimationSceneNode)KeyFrameAnimationSceneNode.Factory.Instantiate(this.ViewModel, (ITypeId)keyFrameSceneNode1.KeyFrameAnimation.Type); DocumentCompositeNode documentCompositeNode = (DocumentCompositeNode)animationSceneNode.DocumentNode; foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)((DocumentCompositeNode)keyFrameSceneNode1.KeyFrameAnimation.DocumentNode).Properties) { IProperty key2 = keyValuePair.Key; if (!keyFrameSceneNode1.KeyFrameAnimation.KeyFramesProperty.Equals((object)key2) && !DesignTimeProperties.ShouldSerializeProperty.Equals((object)key2) && !DesignTimeProperties.IsAnimationProxyProperty.Equals((object)key2)) { documentCompositeNode.Properties[(IPropertyId)key2] = keyValuePair.Value.Clone(documentCompositeNode.Context); } } dictionary.Add(key1, animationSceneNode); list.Add((TimelineSceneNode)animationSceneNode); } else { animationSceneNode = dictionary[key1]; } animationSceneNode.AddKeyFrame(keyFrameSceneNode2); } } else { FromToAnimationSceneNode animationSceneNode1 = this.ViewModel.AnimationProxyManager != null?this.ViewModel.AnimationProxyManager.GetAnimationForProxy(keyFrameSceneNode1.KeyFrameAnimation) : (FromToAnimationSceneNode)null; if (animationSceneNode1 != null) { FromToAnimationSceneNode animationSceneNode2 = this.ViewModel.GetSceneNode(animationSceneNode1.DocumentNode.Clone(animationSceneNode1.DocumentContext)) as FromToAnimationSceneNode; list.Add((TimelineSceneNode)animationSceneNode2); dictionary.Add(animationSceneNode1.TargetElementAndProperty, (KeyFrameAnimationSceneNode)null); } } } } else if (this.ViewModel.ElementSelectionSet.Count > 0 && this.ViewModel.KeyFrameSelectionSet.Count == 0) { foreach (TimelineSceneNode timelineSceneNode in (IEnumerable <TimelineSceneNode>) this.SourceState.Storyboard.Children) { if (timelineSceneNode.ShouldSerialize) { SceneElement sceneElement = timelineSceneNode.TargetElement as SceneElement; if (sceneElement != null && this.ViewModel.ElementSelectionSet.IsSelected(sceneElement)) { list.Add(timelineSceneNode); } } } } return(list); }
public override DocumentNode GetLocalValueAsDocumentNode(SceneNodeProperty property, GetLocalValueFlags flags, out bool isMixed) { DocumentNode documentNode = (DocumentNode)null; bool flag = false; foreach (SceneNode sceneNode1 in this.Objects) { PropertyReference propertyReference1 = SceneNodeObjectSet.FilterProperty(sceneNode1, property.Reference); if (propertyReference1 != null) { DocumentNode other = (DocumentNode)null; if ((flags & GetLocalValueFlags.CheckKeyframes) != GetLocalValueFlags.None && sceneNode1.ViewModel.AnimationEditor.ActiveStoryboardTimeline != null && this.ShouldAllowAnimation) { SceneNode ancestor = (SceneNode)null; PropertyReference propertyReference2 = propertyReference1; SceneNode sceneNode2 = sceneNode1; if (this.FindAncestor(sceneNode1, out ancestor, ref propertyReference2, new Predicate <SceneNode>(SceneNodeObjectSetBase.IsAnimationParent))) { sceneNode2 = ancestor; } foreach (TimelineSceneNode timelineSceneNode in (IEnumerable <TimelineSceneNode>)sceneNode1.ViewModel.AnimationEditor.ActiveStoryboardTimeline.Children) { TimelineSceneNode.PropertyNodePair elementAndProperty = timelineSceneNode.TargetElementAndProperty; if (elementAndProperty.SceneNode == sceneNode2 && elementAndProperty.PropertyReference != null) { PropertyReference propertyReference3 = SceneNodeObjectSet.FilterProperty(elementAndProperty.SceneNode, elementAndProperty.PropertyReference); if (propertyReference2.Equals((object)propertyReference3)) { KeyFrameAnimationSceneNode animationSceneNode1 = timelineSceneNode as KeyFrameAnimationSceneNode; FromToAnimationSceneNode animationSceneNode2 = timelineSceneNode as FromToAnimationSceneNode; if (animationSceneNode1 != null) { KeyFrameSceneNode keyFrameAtTime = animationSceneNode1.GetKeyFrameAtTime(sceneNode1.ViewModel.AnimationEditor.AnimationTime); if (keyFrameAtTime != null) { using ((flags & GetLocalValueFlags.Resolve) == GetLocalValueFlags.None ? this.ViewModel.ForceBaseValue() : (IDisposable)null) { other = keyFrameAtTime.ValueNode; break; } } else { break; } } else if (animationSceneNode2 != null) { double animationTime = sceneNode1.ViewModel.AnimationEditor.AnimationTime; using ((flags & GetLocalValueFlags.Resolve) == GetLocalValueFlags.None ? this.ViewModel.ForceBaseValue() : (IDisposable)null) { DocumentNodePath documentNodePath = (DocumentNodePath)null; if (animationTime == animationSceneNode2.Begin + animationSceneNode2.Duration) { documentNodePath = animationSceneNode2.GetLocalValueAsDocumentNode(animationSceneNode2.ToProperty); } else if (animationTime == animationSceneNode2.Begin) { documentNodePath = animationSceneNode2.GetLocalValueAsDocumentNode(animationSceneNode2.FromProperty); } other = documentNodePath != null ? documentNodePath.Node : (DocumentNode)null; break; } } else { break; } } } } } if (other == null) { if ((flags & GetLocalValueFlags.Resolve) != GetLocalValueFlags.None) { DocumentNodePath valueAsDocumentNode = sceneNode1.GetLocalValueAsDocumentNode(propertyReference1); if (valueAsDocumentNode != null) { other = valueAsDocumentNode.Node; } } else { other = (DocumentNode)sceneNode1.GetLocalValue(propertyReference1, PropertyContext.AsDocumentNodes); } } if (!flag) { if (other == null && (flags & GetLocalValueFlags.SkipCheckIfMixed) != GetLocalValueFlags.None) { isMixed = false; return((DocumentNode)null); } flag = true; documentNode = other; } else if (documentNode == null && other != null || documentNode != null && !documentNode.Equals(other)) { isMixed = true; return((DocumentNode)null); } } } isMixed = false; return(documentNode); }
private void UpdateProxyTable(Dictionary <AnimationProxyManager.TargetNamePropertyPair, AnimationProxyManager.AnimationProxyData> proxyTable, StoryboardTimelineSceneNode storyboard, AnimationProxyManager.AllowedChange allowedChange) { if (allowedChange != AnimationProxyManager.AllowedChange.Any) { proxyTable.Clear(); } List <KeyFrameAnimationSceneNode> list1 = new List <KeyFrameAnimationSceneNode>(); foreach (TimelineSceneNode timeline in (IEnumerable <TimelineSceneNode>)storyboard.Children) { FromToAnimationSceneNode animationSceneNode = timeline as FromToAnimationSceneNode; KeyFrameAnimationSceneNode nodeToTest = timeline as KeyFrameAnimationSceneNode; if (animationSceneNode != null && animationSceneNode.IsOptimized || nodeToTest != null && nodeToTest.IsAnimationProxy) { AnimationProxyManager.TargetNamePropertyPair key = new AnimationProxyManager.TargetNamePropertyPair(timeline); if (key.TargetName != null) { AnimationProxyManager.AnimationProxyData animationProxyData; if (!proxyTable.TryGetValue(key, out animationProxyData)) { animationProxyData = new AnimationProxyManager.AnimationProxyData((FromToAnimationSceneNode)null, (KeyFrameAnimationSceneNode)null); proxyTable[key] = animationProxyData; } if (animationSceneNode != null) { animationProxyData.OptimizedAnimation = animationSceneNode; } else { animationProxyData.ProxyAnimation = nodeToTest; } } } else if (nodeToTest != null && this.CanOptimizeAnimation(nodeToTest)) { list1.Add(nodeToTest); } } if (allowedChange != AnimationProxyManager.AllowedChange.OnlyNonSerializing && allowedChange != AnimationProxyManager.AllowedChange.Any) { return; } if (allowedChange == AnimationProxyManager.AllowedChange.Any) { foreach (KeyFrameAnimationSceneNode proxyAnimation in list1) { FromToAnimationSceneNode optimizedAnimation = this.ConvertToOptimizedAnimation(proxyAnimation); AnimationProxyManager.TargetNamePropertyPair key = new AnimationProxyManager.TargetNamePropertyPair((TimelineSceneNode)proxyAnimation); AnimationProxyManager.AnimationProxyData animationProxyData; if (proxyTable.TryGetValue(key, out animationProxyData)) { if (animationProxyData.OptimizedAnimation != null && animationProxyData.OptimizedAnimation.IsInDocument) { animationProxyData.OptimizedAnimation.ControllingStoryboard.Children.Remove((TimelineSceneNode)animationProxyData.OptimizedAnimation); } if (animationProxyData.ProxyAnimation != null && animationProxyData.ProxyAnimation.IsInDocument) { animationProxyData.ProxyAnimation.ControllingStoryboard.Children.Remove((TimelineSceneNode)animationProxyData.ProxyAnimation); } proxyTable.Remove(key); } proxyTable.Add(key, new AnimationProxyManager.AnimationProxyData(optimizedAnimation, proxyAnimation)); } } List <AnimationProxyManager.TargetNamePropertyPair> list2 = new List <AnimationProxyManager.TargetNamePropertyPair>(); foreach (KeyValuePair <AnimationProxyManager.TargetNamePropertyPair, AnimationProxyManager.AnimationProxyData> keyValuePair in proxyTable) { AnimationProxyManager.AnimationProxyData animationProxyData = keyValuePair.Value; int count = list2.Count; if (animationProxyData.ProxyAnimation != null && !keyValuePair.Key.Equals((object)new AnimationProxyManager.TargetNamePropertyPair((TimelineSceneNode)animationProxyData.ProxyAnimation))) { animationProxyData.ProxyAnimation = (KeyFrameAnimationSceneNode)null; } if (animationProxyData.OptimizedAnimation != null && !keyValuePair.Key.Equals((object)new AnimationProxyManager.TargetNamePropertyPair((TimelineSceneNode)animationProxyData.OptimizedAnimation))) { animationProxyData.OptimizedAnimation = (FromToAnimationSceneNode)null; } if (animationProxyData.OptimizedAnimation == null && animationProxyData.ProxyAnimation == null) { list2.Add(keyValuePair.Key); } else if (animationProxyData.OptimizedAnimation == null || !animationProxyData.OptimizedAnimation.IsInDocument) { if (allowedChange == AnimationProxyManager.AllowedChange.Any) { if (animationProxyData.ProxyAnimation != null && animationProxyData.ProxyAnimation.IsInDocument) { this.viewModel.AnimationEditor.RemoveAnimation(storyboard, (TimelineSceneNode)animationProxyData.ProxyAnimation); if (animationProxyData.OptimizedAnimation != null && animationProxyData.OptimizedAnimation.IsInDocument) { animationProxyData.OptimizedAnimation.IsOptimized = false; } } list2.Add(keyValuePair.Key); } } else if (animationProxyData.ProxyWasUserDeleted && !animationProxyData.OptimizedAnimationAdded) { if (allowedChange == AnimationProxyManager.AllowedChange.Any) { this.viewModel.AnimationEditor.RemoveAnimation(storyboard, (TimelineSceneNode)animationProxyData.OptimizedAnimation); list2.Add(keyValuePair.Key); } } else if (animationProxyData.ProxyAnimation == null || !animationProxyData.ProxyAnimation.IsInDocument) { if (allowedChange == AnimationProxyManager.AllowedChange.OnlyNonSerializing || allowedChange == AnimationProxyManager.AllowedChange.Any) { animationProxyData.OptimizedAnimation.Invalidate(); if (animationProxyData.OptimizedAnimation.TargetElement != null) { KeyFrameAnimationSceneNode animationSceneNode = KeyFrameAnimationSceneNode.Factory.InstantiateWithTarget(this.viewModel, animationProxyData.OptimizedAnimation.TargetElement, animationProxyData.OptimizedAnimation.TargetProperty, animationProxyData.OptimizedAnimation.StoryboardContainer, KeyFrameAnimationSceneNode.GetKeyFrameAnimationForType(animationProxyData.OptimizedAnimation.AnimatedType, animationProxyData.OptimizedAnimation.ProjectContext)); animationSceneNode.AddKeyFrame(animationProxyData.OptimizedAnimation.Duration, animationProxyData.OptimizedAnimation.To); KeyFrameSceneNode keyFrameAtIndex = animationSceneNode.GetKeyFrameAtIndex(0); SceneNode.CopyPropertyValue((SceneNode)animationProxyData.OptimizedAnimation, animationProxyData.OptimizedAnimation.EasingFunctionProperty, (SceneNode)keyFrameAtIndex, keyFrameAtIndex.EasingFunctionProperty); keyFrameAtIndex.ShouldSerialize = false; animationSceneNode.ShouldSerialize = false; animationSceneNode.IsAnimationProxy = true; storyboard.Children.Insert(storyboard.Children.IndexOf((TimelineSceneNode)animationProxyData.OptimizedAnimation) + 1, (TimelineSceneNode)animationSceneNode); animationProxyData.ProxyAnimation = animationSceneNode; } } } else if (!this.CanOptimizeAnimation(animationProxyData.ProxyAnimation)) { if (allowedChange == AnimationProxyManager.AllowedChange.Any) { this.RemoveOptimizedAndPromoteProxy(animationProxyData); list2.Add(keyValuePair.Key); } } else if ((!animationProxyData.OptimizedAnimation.IsOptimized || !AnimationProxyManager.CanFromToAnimationBeOptimized(animationProxyData.OptimizedAnimation)) && allowedChange == AnimationProxyManager.AllowedChange.Any) { this.viewModel.AnimationEditor.RemoveAnimation(storyboard, (TimelineSceneNode)animationProxyData.ProxyAnimation); animationProxyData.OptimizedAnimation.IsOptimized = false; list2.Add(keyValuePair.Key); } if (count == list2.Count && allowedChange == AnimationProxyManager.AllowedChange.Any) { if (!animationProxyData.OptimizedAnimationPropertyChanged && !animationProxyData.OptimizedAnimationAdded) { this.MovePropertiesFromProxyToOptimized(animationProxyData); } else { this.MovePropertiesFromOptimizedToProxy(animationProxyData); } } animationProxyData.ResetUpdateState(); } foreach (AnimationProxyManager.TargetNamePropertyPair key in list2) { proxyTable.Remove(key); } }