/// <summary> /// Sets or replaces default transition. /// </summary> /// <param name="from">May be null to specify all</param> /// <param name="to">May be null to specify all.</param> /// <param name="defaultTime">The default time.</param> /// <param name="stepper">Stepper used.</param> public void SetDefaultTransition(StyleState from, StyleState to, float transitionTime, IUniformStepper stepper) { if (from == null) { from = CommonStyleStates.All; } if (to == null) { to = CommonStyleStates.All; } lock (defaultAnimations) { // We first retrieve it. bool wasFound = true; List <StyleAnimationBucket> bucketList; if (!defaultAnimations.TryGetValue(from, out bucketList)) { wasFound = false; bucketList = new List <StyleAnimationBucket>(); } // We may need to overwrite. StyleAnimationBucket anim = bucketList.Find(delegate(StyleAnimationBucket b) { if (b.TransistTo == to) { return(true); } return(false); }); if (anim == null) { anim = new StyleAnimationBucket(); anim.Stepper = stepper; anim.TransistFrom = from; anim.TransistTo = to; anim.TransitionTime = transitionTime; bucketList.Add(anim); } else { anim = new StyleAnimationBucket(); anim.Stepper = stepper; anim.TransistFrom = from; anim.TransistTo = to; anim.TransitionTime = transitionTime; } // We finally add it. if (!wasFound) { defaultAnimations.Add(from, bucketList); } } }
/// <summary> /// Obtains the default animation time and stepper for some transition. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="defaultTime"></param> /// <param name="stepper"></param> public void GetDefaultTransition(StyleState from, StyleState to, out float defaultTime, out IUniformStepper stepper) { if (from == null) { from = CommonStyleStates.Null; } if (to == null) { to = CommonStyleStates.Null; } lock (defaultAnimations) { List <StyleAnimationBucket> bucketList; if (!defaultAnimations.TryGetValue(from, out bucketList)) { // We need a all-* mapper. if (!defaultAnimations.TryGetValue(CommonStyleStates.All, out bucketList)) { defaultTime = globalDefaultTime; stepper = smoothStepper; return; } } // We now search for direct match first. for (int i = 0; i < bucketList.Count; i++) { if (bucketList[i].TransistTo == to) { defaultTime = bucketList[i].TransitionTime; stepper = bucketList[i].Stepper; return; } } // We try for -all match. for (int i = 0; i < bucketList.Count; i++) { if (bucketList[i].TransistTo == CommonStyleStates.All) { defaultTime = bucketList[i].TransitionTime; stepper = bucketList[i].Stepper; return; } } // Otherwise, use default. defaultTime = globalDefaultTime; stepper = smoothStepper; } }
/// <summary> /// Transists to next state, with time to transist and stepper specified. /// </summary> public void TransistTo(StyleState next, [MinFloat(0.0f)] float timeToTransist, IUniformStepper stepper) { // We default. if (stepper == null) { stepper = smoothStepper; } // Immediate transition. if (MathHelper.NearEqual(timeToTransist, 0.0f)) { currentState = nextState; nextState = null; return; } // We set current. this.timeToTransist = timeToTransist; this.stepper = stepper; if (nextState == null) { // Simple transition time = 0.0f; nextState = next; } else { // Already transisting. if (next == nextState) { return; } // We try to do cool mechanism if back-transition is done. if (next == CurrentState) { currentState = nextState; nextState = next; time = 1.0f - time; } else { // We "skip" the animation to next, currentState = nextState; nextState = next; time = 0.0f; } } }