Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        public override void Update(TickEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            float seconds = args.SecondsElapsed;

            time = Timer.SecondsElapsed;

            switch (state)
            {
            case TextFadeState.BeforeFadeIn:
                if (time >= startTime)
                {
                    state = TextFadeState.FadeIn;
                }
                break;

            case TextFadeState.FadeIn:
                if (seconds <= (float.MaxValue / inSpeed) - alpha)
                {
                    alpha += seconds * inSpeed;
                }
                else
                {
                    alpha = float.MaxValue;
                }

                if (alpha >= 255)
                {
                    alpha = 255;
                    state = TextFadeState.BeforeFadeOut;
                }
                this.Surface.Alpha = (byte)alpha;
                break;

            case TextFadeState.BeforeFadeOut:
                if (time >= this.EndTime)
                {
                    state = TextFadeState.FadeOut;
                }
                break;

            case TextFadeState.FadeOut:
                alpha -= seconds * outSpeed;

                if (alpha <= 0)
                {
                    alpha = 0;
                    state = TextFadeState.Finished;
                }
                this.Surface.Alpha = (byte)alpha;
                break;
            }
        }
Exemple #2
0
        private void updateTransitions()
        {
            // Staying -> FadingOut
            // This can occur by a natural wait OR if the target text has changed.
            if (_currState == TextFadeState.Staying &&
                (_currT >= _stayTime || !_currText.Equals(_targetText)))
            {
                _currState = TextFadeState.FadingOut;
                _currT     = 0f;
            }

            // FadingOut -> Hidden
            if (_currState == TextFadeState.FadingOut && _currT >= fadeTime)
            {
                _currState = TextFadeState.Hidden;
                _currT     = 0f;
            }

            // Hidden -> FadingIn
            // Requires a new target text, this also calculates the "stay time" for the new
            // target text and changes the current text.
            if (_currState == TextFadeState.Hidden && !_currText.Equals(_targetText))
            {
                _currText = _targetText;
                _stayTime = _currText.Length * durationPerCharacter;

                // Only transition to "fading in" if the text to display has content.
                // This prevents a delay where empty text has to fade in and out before new
                // text can come in.
                if (!string.IsNullOrEmpty(_currText))
                {
                    _currState = TextFadeState.FadingIn;
                    _currT     = 0f;
                }
            }

            // FadingIn -> Staying
            if (_currState == TextFadeState.FadingIn && _currT >= fadeTime)
            {
                _currState = TextFadeState.Staying;
                _currT     = 0f;
            }
        }
Exemple #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        public override void Update(TickEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            float seconds = args.SecondsElapsed;
            time = Timer.SecondsElapsed;

            switch (state)
            {
                case TextFadeState.BeforeFadeIn:
                    if (time >= startTime)
                    {
                        state = TextFadeState.FadeIn;
                    }
                    break;

                case TextFadeState.FadeIn:
                    if (seconds <= (float.MaxValue / inSpeed) - alpha)
                    {
                        alpha += seconds * inSpeed;
                    }
                    else
                    {
                        alpha = float.MaxValue;
                    }

                    if (alpha >= 255)
                    {
                        alpha = 255;
                        state = TextFadeState.BeforeFadeOut;
                    }
                    this.Surface.Alpha = (byte)alpha;
                    break;

                case TextFadeState.BeforeFadeOut:
                    if (time >= this.EndTime)
                    {
                        state = TextFadeState.FadeOut;
                    }
                    break;

                case TextFadeState.FadeOut:
                    alpha -= seconds * outSpeed;

                    if (alpha <= 0)
                    {
                        alpha = 0;
                        state = TextFadeState.Finished;
                    }
                    this.Surface.Alpha = (byte)alpha;
                    break;
            }
        }