/// <summary> /// Finds any properties in the old-transition that are also in the new one, /// and removes them from the old one. /// </summary> /// <param name="newTransition">The new transition.</param> /// <param name="oldTransition">The old transition.</param> private void removeDuplicates(ZeroitTransitorEdit newTransition, ZeroitTransitorEdit oldTransition) { // Note: This checking might be a bit more efficient if it did the checking // with a set rather than looking through lists. That said, it is only done // when transitions are added (which isn't very often) rather than on the // timer, so I don't think this matters too much. // We get the list of properties for the old and new transitions... IList <ZeroitTransitorEdit.TransitionedPropertyInfo> newProperties = newTransition.TransitionedProperties; IList <ZeroitTransitorEdit.TransitionedPropertyInfo> oldProperties = oldTransition.TransitionedProperties; // We loop through the old properties backwards (as we may be removing // items from the list if we find a match)... for (int i = oldProperties.Count - 1; i >= 0; i--) { // We get one of the properties from the old transition... ZeroitTransitorEdit.TransitionedPropertyInfo oldProperty = oldProperties[i]; // Is this property part of the new transition? foreach (ZeroitTransitorEdit.TransitionedPropertyInfo newProperty in newProperties) { if (oldProperty.target == newProperty.target && oldProperty.propertyInfo == newProperty.propertyInfo) { // The old transition contains the same property as the new one, // so we remove it from the old transition... oldTransition.removeProperty(oldProperty); } } } }
/// <summary> /// Creates and immediately runs a transition on the property passed in. /// </summary> /// <param name="target">The target.</param> /// <param name="strPropertyName">Name of the string property.</param> /// <param name="destinationValue">The destination value.</param> /// <param name="transitionMethod">The transition method.</param> public static void run(object target, string strPropertyName, object destinationValue, ITransitionType transitionMethod) { ZeroitTransitorEdit t = new ZeroitTransitorEdit(transitionMethod); t.add(target, strPropertyName, destinationValue); t.run(); }
/// <summary> /// Checks if any existing transitions are acting on the same properties as the /// transition passed in. If so, we remove the duplicated properties from the /// older transitions. /// </summary> /// <param name="transition">The transition.</param> private void removeDuplicates(ZeroitTransitorEdit transition) { // We look through the set of transitions we're currently managing... foreach (KeyValuePair <ZeroitTransitorEdit, bool> pair in m_Transitions) { removeDuplicates(transition, pair.Key); } }
/// <summary> /// Called when the transition we have just run has completed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void onTransitionCompleted(object sender, ZeroitTransitorEdit.Args e) { // We unregister from the completed event... ZeroitTransitorEdit transition = (ZeroitTransitorEdit)sender; transition.TransitionCompletedEvent -= onTransitionCompleted; // We remove the completed transition from our collection, and // run the next one... m_listTransitions.RemoveFirst(); runNextTransition(); }
/// <summary> /// Called when a transition has completed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void onTransitionCompleted(object sender, ZeroitTransitorEdit.Args e) { // We stop observing the transition... ZeroitTransitorEdit transition = (ZeroitTransitorEdit)sender; transition.TransitionCompletedEvent -= onTransitionCompleted; // We remove the transition from the collection we're managing... lock (m_Lock) { m_Transitions.Remove(transition); } }
/// <summary> /// You register a transition with the manager here. This will start to run /// the transition as the manager's timer ticks. /// </summary> /// <param name="transition">The transition.</param> public void register(ZeroitTransitorEdit transition) { lock (m_Lock) { // We check to see if the properties of this transition // are already being animated by any existing transitions... removeDuplicates(transition); // We add the transition to the collection we manage, and // observe it so that we know when it has completed... m_Transitions[transition] = true; transition.TransitionCompletedEvent += onTransitionCompleted; } }
/// <summary> /// Runs the next transition in the list. /// </summary> private void runNextTransition() { if (m_listTransitions.Count == 0) { return; } // We find the next transition and run it. We also register // for its completed event, so that we can start the next transition // when this one completes... ZeroitTransitorEdit nextTransition = m_listTransitions.First.Value; nextTransition.TransitionCompletedEvent += onTransitionCompleted; nextTransition.run(); }
/// <summary> /// Starts the animation. /// </summary> public void Activate() { int x = Duration; int flashes = No_Of_Flashes; switch (Transitions) { case TransitionType.Accelaration: ZeroitTransitorEdit accelerate = new ZeroitTransitorEdit(new TransitionType_Acceleration(x)); accelerate.add(Target, Position.ToString(), Destination); accelerate.run(); break; case TransitionType.Bounce: ZeroitTransitorEdit bounce = new ZeroitTransitorEdit(new TransitionType_Bounce(x)); bounce.add(Target, Position.ToString(), Destination); bounce.run(); break; case TransitionType.CriticalDamping: ZeroitTransitorEdit criticalDumping = new ZeroitTransitorEdit(new TransitionType_CriticalDamping(x)); criticalDumping.add(Target, Position.ToString(), Destination); criticalDumping.run(); break; case TransitionType.Deceleration: ZeroitTransitorEdit deceleration = new ZeroitTransitorEdit(new TransitionType_Deceleration(x)); deceleration.add(Target, Position.ToString(), Destination); deceleration.run(); break; case TransitionType.EaseInEaseOut: ZeroitTransitorEdit easeInEaseOut = new ZeroitTransitorEdit(new TransitionType_EaseInEaseOut(x)); easeInEaseOut.add(Target, Position.ToString(), Destination); easeInEaseOut.run(); break; case TransitionType.Flash: ZeroitTransitorEdit flash = new ZeroitTransitorEdit(new TransitionType_Flash(flashes, x)); flash.add(Target, Position.ToString(), Destination); flash.run(); break; case TransitionType.Linear: ZeroitTransitorEdit linear = new ZeroitTransitorEdit(new TransitionType_Linear(x)); linear.add(Target, Position.ToString(), Destination); linear.run(); break; case TransitionType.ThrowAndCatch: ZeroitTransitorEdit throwAndCatch = new ZeroitTransitorEdit(new TransitionType_ThrowAndCatch(x)); throwAndCatch.add(Target, Position.ToString(), Destination); throwAndCatch.run(); break; case TransitionType.Zeroit: ZeroitTransitorEdit zeroit = new ZeroitTransitorEdit(new TransitionType_Zeroit(x)); zeroit.add(Target, Position.ToString(), Destination); zeroit.run(); break; default: break; } }