/// <summary> /// Causes this object to blink visibible and invisible at the stated interval /// for the stated duration. If duration is -1, the object will blink forever. /// </summary> public void animatedAlphaFadeIn(int duration) { animationTime = 0; animationDuration = duration; animationType = ViewAnimationType.AlphaFadeIn; }
/// <summary> /// Move this object incrementally towards its goal. /// </summary> private void UpdateAnimation() { switch (animationType) { case ViewAnimationType.Slide: //stop sliding if time is greater than duration if (animationTime > animationDuration) { SetDrawFrame(animationRect); animationRect = Rectangle.Empty; animationType = ViewAnimationType.None; break; } double newWeight; if (!accelPolarity) newWeight = Math.Sqrt(animationTime / animationDuration); else newWeight = Math.Pow(animationTime / animationDuration, 4); double oldWeight = 1.0 - newWeight; int newX = (int)((oldWeight * oldRect.X) + (newWeight * animationRect.X)); int newY = (int)((oldWeight * oldRect.Y) + (newWeight * animationRect.Y)); SetDrawFrame(new Rectangle(newX, newY, drawRect.Width, drawRect.Height)); animationTime++; break; case ViewAnimationType.Blink: //stop blinking if time is greater than duration, unless duration is -1 if (animationTime > animationDuration && animationDuration != -1) { hidden = false; animationType = ViewAnimationType.None; } //otherwise check if blinking this update and toggle hidden if true else { if (animationTime % blinkFrameInterval == 0) hidden = !hidden; animationTime++; } break; case ViewAnimationType.AlphaFadeIn: if (animationTime > animationDuration) { animationTime = animationDuration; animationType = ViewAnimationType.None; } else animationTime++; break; case ViewAnimationType.Expand: if (animationTime > animationDuration) { animationTime = animationDuration; animationType = ViewAnimationType.None; } else { //case where we're using the negative horizontal parabola thingy or whatever that is, //the same kind of acceleration behavior though if (accelPolarity) { } else { SetDrawFrame(new Rectangle( oldRect.X + (int)(horizontalDifference * (animationTime / animationDuration)), oldRect.Y + (int)(verticalDifference * (animationTime / animationDuration)), oldRect.Width + (int)(widthDifference * (animationTime / animationDuration)), oldRect.Height + (int)(heightDifference * (animationTime / animationDuration)))); } animationTime++; } break; } }
public void stopAnimation() { animationType = ViewAnimationType.None; }
/// <summary> /// Animate a frame change over the next XXX tics using a negative horizontal parabola. /// </summary> /// <param name="newFrame">New Rectangle to occupy.</param> /// <param name="durationInTics">Time to take.</param> /// <param name="polarity">Whether this animation is accelerating (true) or deccelerating (false).</param> public void animatedFrameSlide(Point offset, int duration, bool polarity) { //if (hidden) // Don't calculate animations if we aren't being shown //{ // MoveFrame(offset.X, offset.Y); //} //else //{ animationType = ViewAnimationType.Slide; if (animationRect.Equals(Rectangle.Empty)) animationRect = drawRect; animationTime = 0; animationDuration = duration; animationRect.Offset(offset); oldRect = drawRect; accelPolarity = polarity; //} }
/// <summary> /// Causes this object to blink visibible and invisible at the stated interval /// for the stated duration. If duration is -1, the object will blink forever. /// </summary> /// <param name="endRect">Ending rectangle size</param> /// <param name="duration">Time to take</param> /// <param name="useNHP">If true, this view will expand using animatedFrameSlide's negative horizontal parabola</param> public void animatedExpand(Rectangle endRect, int duration, bool useNHP) { animationRect = endRect; animationTime = 0; animationDuration = duration; animationType = ViewAnimationType.Expand; oldRect = drawRect; accelPolarity = useNHP; horizontalDifference = endRect.X - oldRect.X; verticalDifference = endRect.Y - oldRect.Y; widthDifference = endRect.Width - oldRect.Width; heightDifference = endRect.Height - oldRect.Height; }
/// <summary> /// Causes this object to blink visibible and invisible at the stated interval /// for the stated duration. If duration is -1, the object will blink forever. /// </summary> public void animatedBlink(int interval, int duration) { animationTime = 0; animationDuration = duration; blinkFrameInterval = interval; animationType = ViewAnimationType.Blink; }