/// <summary> /// Creates a time manager object in the stopped state. /// </summary> /// <param name="clock"> /// An interface to an object that provides real-time clock values to the time /// manager. The manager will query this interface whenever it needs to know the /// current time. This parameter may be null. /// </param> /// <remarks> /// If the clock parameter is null, the time manager uses a default system clock /// to drive the timing engine. To start the clock moving, call the /// <see cref="TimeManager.Start"/> method. /// </remarks> public TimeManager(IClock clock) { _eventQueue = new Queue<WeakReference>(); Clock = clock; _timeState = TimeState.Stopped; _lastTimeState = TimeState.Stopped; _globalTime = new TimeSpan(-1); _lastTickTime = new TimeSpan(-1); _nextTickTimeQueried = false; _isInTick = false; ParallelTimeline timeManagerTimeline = new ParallelTimeline(new TimeSpan(0), Duration.Forever); timeManagerTimeline.Freeze(); _timeManagerClock = new ClockGroup(timeManagerTimeline); _timeManagerClock.MakeRoot(this); }
/// <summary/> protected internal override int ApplyClocks(ClockGroup parentClock, int clockIndex) { var count = 0; if (_hasCenterDifference) { ApplyPropertyClock(Sprite.CenterProperty, parentClock, clockIndex + count); count++; } return count; }
/// <summary> /// Return the duration from a specific clock /// </summary> /// <param name="clock"> /// The Clock whose natural duration is desired. /// </param> /// <returns> /// A Duration quantity representing the natural duration. /// </returns> protected override Duration GetNaturalDurationCore(Clock clock) { Duration simpleDuration = TimeSpan.Zero; ClockGroup clockGroup = clock as ClockGroup; if (clockGroup != null) { List <Clock> children = clockGroup.InternalChildren; // The container ends when all of its children have ended at least // one of their active periods. if (children != null) { bool hasChildWithUnresolvedDuration = false; for (int childIndex = 0; childIndex < children.Count; childIndex++) { Duration childEndOfActivePeriod = children[childIndex].EndOfActivePeriod; if (childEndOfActivePeriod == Duration.Forever) { // If we have even one child with a duration of forever // our resolved duration will also be forever. It doesn't // matter if other children have unresolved durations. return(Duration.Forever); } else if (childEndOfActivePeriod == Duration.Automatic) { hasChildWithUnresolvedDuration = true; } else if (childEndOfActivePeriod > simpleDuration) { simpleDuration = childEndOfActivePeriod; } } // We've iterated through all our children. We know that at this // point none of them have a duration of Forever or we would have // returned already. If any of them still have unresolved // durations then our duration is also still unresolved and we // will return automatic. Otherwise, we'll fall out of the 'if' // block and return the simpleDuration as our final resolved // duration. if (hasChildWithUnresolvedDuration) { return(Duration.Automatic); } } } return(simpleDuration); }
/// <summary> /// Creates a time manager object in the stopped state. /// </summary> /// <param name="clock"> /// An interface to an object that provides real-time clock values to the time /// manager. The manager will query this interface whenever it needs to know the /// current time. This parameter may be null. /// </param> /// <remarks> /// If the clock parameter is null, the time manager uses a default system clock /// to drive the timing engine. To start the clock moving, call the /// <see cref="TimeManager.Start"/> method. /// </remarks> public TimeManager(IClock clock) { _eventQueue = new Queue <WeakReference>(); Clock = clock; _timeState = TimeState.Stopped; _lastTimeState = TimeState.Stopped; _globalTime = new TimeSpan(-1); _lastTickTime = new TimeSpan(-1); _nextTickTimeQueried = false; _isInTick = false; ParallelTimeline timeManagerTimeline = new ParallelTimeline(new TimeSpan(0), Duration.Forever); timeManagerTimeline.Freeze(); _timeManagerClock = new ClockGroup(timeManagerTimeline); _timeManagerClock.MakeRoot(this); }
/// <summary> /// Advances the enumerator to the next element of the collection. /// </summary> /// <returns> /// true if the enumerator was successfully advanced to the next /// element; false if the enumerator has passed the end of the /// collection. /// </returns> public bool MoveNext() { // If the collection is no longer empty, it means it was // modified and we should thrown an exception. Otherwise, we // are still valid, but the collection is empty so we should // just return false. // _owner.VerifyAccess(); ClockGroup clockGroup = _owner as ClockGroup; if (clockGroup != null && clockGroup.InternalChildren != null) { throw new InvalidOperationException(SR.Get(SRID.Timing_EnumeratorInvalidated)); } return(false); }
// Recursive postfix walk, culled by NeedsPostfixTraversal flags (hence cannot use PostfixSubtreeEnumerator) private void ComputeTreeStatePostfix() { if (_children != null) { for (int c = 0; c < _children.Count; c++) { if (_children[c].NeedsPostfixTraversal) // Traverse deeper if this is part of the visited tree subset { ClockGroup group = _children[c] as ClockGroup; Debug.Assert(group != null); // We should only have this flag set for ClockGroups group.ComputeTreeStatePostfix(); } } ClipNextTickByChildren(); } }
/// <summary> /// Copies the elements of the collection to an array, starting at a /// particular array index. /// </summary> /// <param name="array"> /// The one-dimensional array that is the destination of the elements /// copied from the collection. The Array must have zero-based indexing. /// </param> /// <param name="index"> /// The zero-based index in array at which copying begins. /// </param> public void CopyTo(Clock[] array, int index) { // _owner.VerifyAccess(); ClockGroup clockGroup = _owner as ClockGroup; if (clockGroup != null) { List <Clock> list = clockGroup.InternalChildren; if (list != null) { // Get free parameter validation from Array.Copy list.CopyTo(array, index); } } // Need to perform parameter validation in the list == null case }
/// <summary> /// constructor /// </summary> /// <param name="machineModel">machine model</param> /// <param name="keyFrames">animation keyframe</param> public AnimationCtrl(ref ClockGroup animationClock) { try { //bool searchfound = false; //_MachineModel = machineModel; if (animationClock == null) return; _ClockGroup = animationClock; //for (int i = 0; i < _AnimationClock.Length; i++) //{ // for (int j = 0; j < _AnimationClock[i].Length; j++) // { // if (_AnimationClock[i][j] != null) // { // searchfound = true; // _TargetBase = (TargetType)i; // _KeyFrameTypeBase = (AnimationKeyFrame)j; // break; // } // } // if (searchfound) // break; //} //if (searchfound) //{ // _AnimationClock[(int)_TargetBase][(int)_KeyFrameTypeBase].Completed -= new EventHandler(AnimationCtrl_Completed); // _AnimationClock[(int)_TargetBase][(int)_KeyFrameTypeBase].Completed += new EventHandler(this.AnimationCtrl_Completed); //} _ClockGroup.Completed -= new EventHandler(AnimationCtrl_Completed); _ClockGroup.Completed += new EventHandler(this.AnimationCtrl_Completed); } catch (Exception ex) { throw ex; } }
/// <summary> /// Returns an enumerator that can iterate through a collection. /// </summary> /// <returns> /// An enumerator that can iterate through a collection. /// </returns> IEnumerator <Clock> IEnumerable <Clock> .GetEnumerator() { // _owner.VerifyAccess(); List <Clock> list = null; ClockGroup clockGroup = _owner as ClockGroup; if (clockGroup != null) { list = clockGroup.InternalChildren; } if (list != null) { return(list.GetEnumerator()); } else { return(new ClockEnumerator(_owner)); } }
/// <summary> /// Gets or sets the element at the specified index. /// </summary> /// <value> /// The element at the specified index. /// </value> public Clock this[int index] { get { // _owner.VerifyAccess(); List <Clock> list = null; ClockGroup clockGroup = _owner as ClockGroup; if (clockGroup != null) { list = clockGroup.InternalChildren; } if (list == null) { throw new ArgumentOutOfRangeException("index"); } return(list[index]); } }
/// <summary/> protected internal override int ApplyClocks(ClockGroup parentClock, int clockIndex) { var count = 0; if (_hasWidthDifference) { ApplyPropertyClock(FrameworkElement.WidthProperty, parentClock, clockIndex + count); count++; } if (_hasHeightDifference) { ApplyPropertyClock(FrameworkElement.HeightProperty, parentClock, clockIndex + count); count++; } return count; }
/// <summary>A helper method for applying the given animation clock to the specified property on the target element.</summary> protected void ApplyPropertyClock(IAnimatable target, DependencyProperty property, ClockGroup parentClock, int clockIndex) { target.ApplyAnimationClock(property, (AnimationClock)parentClock.Children[clockIndex], HandoffBehavior.SnapshotAndReplace); }
/// <summary>Override this method to apply the clocks for the animations that were defined by this effect.</summary> /// <param name="parentClock">The parent clock that contains the animation clocks of this effect.</param> /// <param name="clockIndex">The index of the first animation clock that belongs to this effect under the parent clock.</param> /// <returns>The number of animation clocks applied by this effect.</returns> protected internal virtual int ApplyClocks(ClockGroup parentClock, int clockIndex) { return 0; }
/// <summary/> protected internal override int ApplyClocks(ClockGroup parentClock, int clockIndex) { var count = 0; if (_hasColorDifference) { if (Property.PropertyType == typeof(Color)) { ApplyPropertyClock(Property, parentClock, clockIndex + count); count++; } else if (Property.PropertyType == typeof(Brush)) { var target = Target as DependencyObject; Brush brush = target.GetValue(Property) as Brush; SolidColorBrush solidBrush = null; if (brush == null) { solidBrush = new SolidColorBrush(new Color()); target.SetValue(Property, solidBrush); } else { solidBrush = brush as SolidColorBrush; Assumption.NotNull(solidBrush, "'{0}' effect can only be applied to a 'SolidColorBrush'"); if (solidBrush.IsFrozen) { solidBrush = new SolidColorBrush(solidBrush.Color); target.SetValue(Property, solidBrush); } } ApplyPropertyClock(solidBrush, SolidColorBrush.ColorProperty, parentClock, clockIndex + count); count++; } } return count; }
/// <summary/> protected internal override int ApplyClocks(ClockGroup parentClock, int clockIndex) { var clock = (ClockGroup)parentClock.Children[clockIndex]; var count = 0; for (int i=0; i<Children.Count; i++) { count += Children[i].ApplyClocks(clock, count); } return (count > 0 ? 1 : 0); }
/// <summary/> protected internal override int ApplyClocks(ClockGroup parentClock, int clockIndex) { return 1; }
/// <summary> /// Advances the enumerator to the next element of the collection. /// </summary> /// <returns> /// true if the enumerator was successfully advanced to the next element, /// false if the enumerator has passed the end of the collection. /// </returns> public bool MoveNext() { // Get the iteration started in the right place, if we are just starting if ((_flags & SubtreeFlag.Reset) != 0) { // We are just getting started. The first clock is either the root // or its first child if ((_flags & SubtreeFlag.ProcessRoot) != 0) { // Start with the root _currentClock = _rootClock; } else { // Start with the root's first child if (_rootClock != null) { ClockGroup rootClockGroup = _rootClock as ClockGroup; if (rootClockGroup != null) { _currentClock = rootClockGroup.FirstChild; } else { _currentClock = null; } } } // Next time we won't be getting started anymore _flags &= ~SubtreeFlag.Reset; } else if (_currentClock != null) { // The next clock is possibly the first child of the current clock ClockGroup currentClockGroup = _currentClock as ClockGroup; Clock nextClock = (currentClockGroup == null) ? null : currentClockGroup.FirstChild; // Skip the children if explicitly asked to do so, or if there aren't any if (((_flags & SubtreeFlag.SkipSubtree) != 0) || (nextClock == null)) { // Pop back to the first ancestor that has siblings (current clock included). Don't // go back further than the root of the subtree. At the end of this loop, nextClock // will point to the proper next clock. while ((_currentClock != _rootClock) && ((nextClock = _currentClock.NextSibling) == null)) { _currentClock = _currentClock.InternalParent; } // Don't process siblings of the root if (_currentClock == _rootClock) { nextClock = null; } _flags &= ~SubtreeFlag.SkipSubtree; } _currentClock = nextClock; } return(_currentClock != null); }
/// <summary>A helper method for applying the given animation clock to the specified target property.</summary> protected void ApplyPropertyClock(DependencyProperty property, ClockGroup parentClock, int clockIndex) { ApplyPropertyClock(Target, property, parentClock, clockIndex); }