public void Reset()
 {
   _tweener = null;
   _type = AnimationType.None;
   _effect = EffectType.None;
   _currentState = AnimationState.None;
   _currentProcess = _queuedProcess = AnimationProcess.None;
   _amount = 0;
   _delay = _start = _length = 0;
   _startX = _startY = _endX = _endY = 0;
   _centerX = _centerY = 0;
   _startAlpha = 0;
   _endAlpha = 100;
   //_acceleration = 0;
   _condition = 0;
   _isReversible = true;
   _lastCondition = false;
   _repeatAnim = AnimationRepeat.None;
   _clockHandle = ClockHandleType.None;
   _savedMinute = -1;
   _savedHour = -1;
 }
    public bool Create(XmlNode node)
    {
      string animType = node.InnerText.ToLower();
      if (String.Compare(animType, "visible", true) == 0)
      {
        _type = AnimationType.Visible;
      }

      else if (String.Compare(animType, "visiblechange", true) == 0)
      {
        _type = AnimationType.VisibleChange;
      }
      else if (String.Compare(animType, "hidden", true) == 0)
      {
        _type = AnimationType.Hidden;
      }
      else if (String.Compare(animType, "focus", true) == 0)
      {
        _type = AnimationType.Focus;
      }
      else if (String.Compare(animType, "unfocus", true) == 0)
      {
        _type = AnimationType.Unfocus;
      }
      else if (String.Compare(animType, "windowopen", true) == 0)
      {
        _type = AnimationType.WindowOpen;
      }
      else if (String.Compare(animType, "windowclose", true) == 0)
      {
        _type = AnimationType.WindowClose;
      }
      else if (String.Compare(animType, "conditional", true) == 0)
      {
        _type = AnimationType.Conditional;
        SetInitialCondition();
      }
      if (_type == AnimationType.None)
      {
        Log.Error(String.Format("Control has invalid animation type [{0} on {1}]", animType, node.Name));
        return false;
      }
      XmlNode nodeAttribute = node.Attributes.GetNamedItem("condition");
      if (nodeAttribute != null)
      {
        string conditionString = nodeAttribute.Value;
        _condition = GUIInfoManager.TranslateString(conditionString);
      }
      nodeAttribute = node.Attributes.GetNamedItem("effect");
      if (nodeAttribute == null)
      {
        return false;
      }
      string effectType = nodeAttribute.Value;
      // effect type
      if (String.Compare(effectType, "fade", true) == 0)
      {
        _effect = EffectType.Fade;
      }
      else if (String.Compare(effectType, "slide", true) == 0)
      {
        _effect = EffectType.Slide;
      }
      else if (String.Compare(effectType, "rotate", true) == 0)
      {
        _effect = EffectType.RotateZ;
      }
      else if (String.Compare(effectType, "rotatey", true) == 0)
      {
        _effect = EffectType.RotateY;
      }
      else if (String.Compare(effectType, "rotatex", true) == 0)
      {
        _effect = EffectType.RotateX;
      }
      else if (String.Compare(effectType, "zoom", true) == 0)
      {
        _effect = EffectType.Zoom;
      }
      if (_effect == EffectType.None)
      {
        Log.Error(String.Format("Control has invalid effect type [{0} on {1}]", effectType, node.Name));
        return false;
      }
      // time and delay
      nodeAttribute = node.Attributes.GetNamedItem("time");
      UInt32.TryParse(nodeAttribute.Value.ToString(), out _length);

      nodeAttribute = node.Attributes.GetNamedItem("delay");
      if (nodeAttribute != null)
      {
        UInt32.TryParse(nodeAttribute.Value.ToString(), out _delay);
      }

      //_length = (uint)(_length * g_SkinInfo.GetEffectsSlowdown());
      //_delay = (uint)(_delay * g_SkinInfo.GetEffectsSlowdown());

      _tweener = null;
      nodeAttribute = node.Attributes.GetNamedItem("tween");
      if (nodeAttribute != null)
      {
        string tweenMode = nodeAttribute.Value;
        if (tweenMode == "linear")
        {
          _tweener = new LinearTweener();
        }
        else if (tweenMode == "quadratic")
        {
          _tweener = new QuadTweener();
        }
        else if (tweenMode == "cubic")
        {
          _tweener = new CubicTweener();
        }
        else if (tweenMode == "sine")
        {
          _tweener = new SineTweener();
        }
        else if (tweenMode == "back")
        {
          _tweener = new BackTweener();
        }
        else if (tweenMode == "circle")
        {
          _tweener = new CircleTweener();
        }
        else if (tweenMode == "bounce")
        {
          _tweener = new BounceTweener();
        }
        else if (tweenMode == "elastic")
        {
          _tweener = new ElasticTweener();
        }
        nodeAttribute = node.Attributes.GetNamedItem("easing");
        if (nodeAttribute != null && _tweener != null)
        {
          string easing = nodeAttribute.Value;
          if (easing == "in")
          {
            _tweener.Easing = TweenerType.EASE_IN;
          }
          else if (easing == "out")
          {
            _tweener.Easing = TweenerType.EASE_OUT;
          }
          else if (easing == "inout")
          {
            _tweener.Easing = TweenerType.EASE_INOUT;
          }
        }
      }

      // acceleration of effect
      //float accel;
      nodeAttribute = node.Attributes.GetNamedItem("acceleration");
      if (nodeAttribute != null)
      {
        float acceleration = GetFloat(nodeAttribute.Value.ToString());
        if (_tweener == null)
        {
          if (acceleration != 0.0f)
          {
            _tweener = new QuadTweener(acceleration);
            _tweener.Easing = TweenerType.EASE_IN;
          }
          else
          {
            _tweener = new LinearTweener();
          }
        }
      }


      // reversible (defaults to true)
      nodeAttribute = node.Attributes.GetNamedItem("reversible");
      if (nodeAttribute != null)
      {
        string reverse = nodeAttribute.Value;
        if (String.Compare(reverse, "false") == 0)
        {
          _isReversible = false;
        }
      }

      // conditional parameters
      if (_type == AnimationType.Conditional)
      {
        nodeAttribute = node.Attributes.GetNamedItem("pulse");
        if (nodeAttribute != null)
        {
          string reverse = nodeAttribute.Value;
          if (String.Compare(reverse, "true") == 0)
          {
            _repeatAnim = AnimationRepeat.Pulse;
          }
        }
        nodeAttribute = node.Attributes.GetNamedItem("loop");
        if (nodeAttribute != null)
        {
          string reverse = nodeAttribute.Value;
          if (String.Compare(reverse, "true") == 0)
          {
            _repeatAnim = AnimationRepeat.Loop;
          }
        }

        // Analog Clock animation
        nodeAttribute = node.Attributes.GetNamedItem("clockhandle");
        if (nodeAttribute != null)
        {
          string clockType = nodeAttribute.Value;
          if (String.Compare(clockType, "second") == 0)
          {
            _clockHandle = ClockHandleType.Second;
          }
          else if (String.Compare(clockType, "minute") == 0)
          {
            _clockHandle = ClockHandleType.Minute;
          }
          else if (String.Compare(clockType, "hour") == 0)
          {
            _clockHandle = ClockHandleType.Hour;
          }
          else
          {
            _clockHandle = ClockHandleType.None;
          }
        }
      }

      // slide parameters
      if (_effect == EffectType.Slide)
      {
        nodeAttribute = node.Attributes.GetNamedItem("start");
        if (nodeAttribute != null)
        {
          string startPos = nodeAttribute.Value;
          GetPosition(startPos, ref _startX, ref _startY);
        }
        nodeAttribute = node.Attributes.GetNamedItem("end");
        if (nodeAttribute != null)
        {
          string endPos = nodeAttribute.Value;
          GetPosition(endPos, ref _endX, ref _endY);
        }
        // scale our parameters
        GUIGraphicsContext.ScaleHorizontal(ref _startX);
        GUIGraphicsContext.ScaleVertical(ref _startY);
        GUIGraphicsContext.ScaleHorizontal(ref _endX);
        GUIGraphicsContext.ScaleVertical(ref _endY);
      }
      else if (_effect == EffectType.Fade)
      {
        // alpha parameters
        if (_type < 0)
        {
          // out effect defaults
          _startAlpha = 100;
          _endAlpha = 0;
        }
        else
        {
          // in effect defaults
          _startAlpha = 0;
          _endAlpha = 100;
        }
        nodeAttribute = node.Attributes.GetNamedItem("start");
        if (nodeAttribute != null)
        {
          _startAlpha = Int32.Parse(nodeAttribute.Value.ToString());
        }
        nodeAttribute = node.Attributes.GetNamedItem("end");
        if (nodeAttribute != null)
        {
          _endAlpha = Int32.Parse(nodeAttribute.Value.ToString());
        }

        if (_startAlpha > 100)
        {
          _startAlpha = 100;
        }
        if (_endAlpha > 100)
        {
          _endAlpha = 100;
        }
        if (_startAlpha < 0)
        {
          _startAlpha = 0;
        }
        if (_endAlpha < 0)
        {
          _endAlpha = 0;
        }
      }
      else if (_effect == EffectType.RotateZ || _effect == EffectType.RotateX || _effect == EffectType.RotateY)
      {
        nodeAttribute = node.Attributes.GetNamedItem("start");
        if (nodeAttribute != null)
        {
          _startX = float.Parse(nodeAttribute.Value);
        }
        nodeAttribute = node.Attributes.GetNamedItem("end");
        if (nodeAttribute != null)
        {
          _endX = float.Parse(nodeAttribute.Value);
        }

        // convert to a negative to account for our reversed vertical axis
        _startX *= -1;
        _endX *= -1;


        nodeAttribute = node.Attributes.GetNamedItem("center");
        if (nodeAttribute != null)
        {
          string centerPos = nodeAttribute.Value;
          GetPosition(centerPos, ref _centerX, ref _centerY);
          GUIGraphicsContext.ScaleHorizontal(ref _centerX);
          GUIGraphicsContext.ScaleVertical(ref _centerY);
        }
      }
      else // if (effect == EffectType.Zoom)
      {
        // effect defaults
        _startX = _startY = 100;
        _endX = _endY = 100;

        nodeAttribute = node.Attributes.GetNamedItem("start");
        if (nodeAttribute != null)
        {
          string start = nodeAttribute.Value;
          GetPosition(start, ref _startX, ref _startY);
          if (_startX == 0)
          {
            _startX = 100;
          }
          if (_startY == 0)
          {
            _startY = 100;
          }
        }
        nodeAttribute = node.Attributes.GetNamedItem("end");
        if (nodeAttribute != null)
        {
          string endLine = nodeAttribute.Value;
          GetPosition(endLine, ref _endX, ref _endY);
          if (_endX == 0)
          {
            _endX = 100;
          }
          if (_endY == 0)
          {
            _endY = 100;
          }
        }
        nodeAttribute = node.Attributes.GetNamedItem("center");
        if (nodeAttribute != null)
        {
          string center = nodeAttribute.Value;
          GetPosition(center, ref _centerX, ref _centerY);
          GUIGraphicsContext.ScaleHorizontal(ref _centerX);
          GUIGraphicsContext.ScaleVertical(ref _centerY);
        }
        else
        {
          /*
          // no center specified
          // calculate the center position...
          if (_startX != 0)
          {
            float scale = _endX / _startX;
            if (scale != 1)
              _centerX = (_endPosX - scale * _startPosX) / (1 - scale);
          }
          if (_startY != 0)
          {
            float scale = _endY / _startY;
            if (scale != 1)
              _centerY = (_endPosY - scale * _startPosY) / (1 - scale);
          }*/
        }
      }
      return true;
    }
Example #3
0
        public bool Create(XmlNode node)
        {
            string animType = node.InnerText.ToLowerInvariant();

            if (String.Compare(animType, "visible", true) == 0)
            {
                _type = AnimationType.Visible;
            }

            else if (String.Compare(animType, "visiblechange", true) == 0)
            {
                _type = AnimationType.VisibleChange;
            }
            else if (String.Compare(animType, "hidden", true) == 0)
            {
                _type = AnimationType.Hidden;
            }
            else if (String.Compare(animType, "focus", true) == 0)
            {
                _type = AnimationType.Focus;
            }
            else if (String.Compare(animType, "unfocus", true) == 0)
            {
                _type = AnimationType.Unfocus;
            }
            else if (String.Compare(animType, "windowopen", true) == 0)
            {
                _type = AnimationType.WindowOpen;
            }
            else if (String.Compare(animType, "windowclose", true) == 0)
            {
                _type = AnimationType.WindowClose;
            }
            else if (String.Compare(animType, "conditional", true) == 0)
            {
                _type = AnimationType.Conditional;
                SetInitialCondition();
            }
            if (_type == AnimationType.None)
            {
                Log.Error(String.Format("Control has invalid animation type [{0} on {1}]", animType, node.Name));
                return(false);
            }
            XmlNode nodeAttribute = node.Attributes.GetNamedItem("condition");

            if (nodeAttribute != null)
            {
                string conditionString = nodeAttribute.Value;
                _condition = GUIInfoManager.TranslateString(conditionString);
            }
            nodeAttribute = node.Attributes.GetNamedItem("effect");
            if (nodeAttribute == null)
            {
                return(false);
            }
            string effectType = nodeAttribute.Value;

            // effect type
            if (String.Compare(effectType, "fade", true) == 0)
            {
                _effect = EffectType.Fade;
            }
            else if (String.Compare(effectType, "slide", true) == 0)
            {
                _effect = EffectType.Slide;
            }
            else if (String.Compare(effectType, "rotate", true) == 0)
            {
                _effect = EffectType.RotateZ;
            }
            else if (String.Compare(effectType, "rotatey", true) == 0)
            {
                _effect = EffectType.RotateY;
            }
            else if (String.Compare(effectType, "rotatex", true) == 0)
            {
                _effect = EffectType.RotateX;
            }
            else if (String.Compare(effectType, "zoom", true) == 0)
            {
                _effect = EffectType.Zoom;
            }
            if (_effect == EffectType.None)
            {
                Log.Error(String.Format("Control has invalid effect type [{0} on {1}]", effectType, node.Name));
                return(false);
            }
            // time and delay
            nodeAttribute = node.Attributes.GetNamedItem("time");
            UInt32.TryParse(nodeAttribute.Value.ToString(), out _length);

            nodeAttribute = node.Attributes.GetNamedItem("delay");
            if (nodeAttribute != null)
            {
                UInt32.TryParse(nodeAttribute.Value.ToString(), out _delay);
            }

            //_length = (uint)(_length * g_SkinInfo.GetEffectsSlowdown());
            //_delay = (uint)(_delay * g_SkinInfo.GetEffectsSlowdown());

            _tweener      = null;
            nodeAttribute = node.Attributes.GetNamedItem("tween");
            if (nodeAttribute != null)
            {
                string tweenMode = nodeAttribute.Value;
                if (tweenMode == "linear")
                {
                    _tweener = new LinearTweener();
                }
                else if (tweenMode == "quadratic")
                {
                    _tweener = new QuadTweener();
                }
                else if (tweenMode == "cubic")
                {
                    _tweener = new CubicTweener();
                }
                else if (tweenMode == "sine")
                {
                    _tweener = new SineTweener();
                }
                else if (tweenMode == "back")
                {
                    _tweener = new BackTweener();
                }
                else if (tweenMode == "circle")
                {
                    _tweener = new CircleTweener();
                }
                else if (tweenMode == "bounce")
                {
                    _tweener = new BounceTweener();
                }
                else if (tweenMode == "elastic")
                {
                    _tweener = new ElasticTweener();
                }
                nodeAttribute = node.Attributes.GetNamedItem("easing");
                if (nodeAttribute != null && _tweener != null)
                {
                    string easing = nodeAttribute.Value;
                    if (easing == "in")
                    {
                        _tweener.Easing = TweenerType.EASE_IN;
                    }
                    else if (easing == "out")
                    {
                        _tweener.Easing = TweenerType.EASE_OUT;
                    }
                    else if (easing == "inout")
                    {
                        _tweener.Easing = TweenerType.EASE_INOUT;
                    }
                }
            }

            // acceleration of effect
            //float accel;
            nodeAttribute = node.Attributes.GetNamedItem("acceleration");
            if (nodeAttribute != null)
            {
                float acceleration = GetFloat(nodeAttribute.Value.ToString());
                if (_tweener == null)
                {
                    if (acceleration != 0.0f)
                    {
                        _tweener        = new QuadTweener(acceleration);
                        _tweener.Easing = TweenerType.EASE_IN;
                    }
                    else
                    {
                        _tweener = new LinearTweener();
                    }
                }
            }


            // reversible (defaults to true)
            nodeAttribute = node.Attributes.GetNamedItem("reversible");
            if (nodeAttribute != null)
            {
                string reverse = nodeAttribute.Value;
                if (String.Compare(reverse, "false") == 0)
                {
                    _isReversible = false;
                }
            }

            // conditional parameters
            if (_type == AnimationType.Conditional)
            {
                nodeAttribute = node.Attributes.GetNamedItem("pulse");
                if (nodeAttribute != null)
                {
                    string reverse = nodeAttribute.Value;
                    if (String.Compare(reverse, "true") == 0)
                    {
                        _repeatAnim = AnimationRepeat.Pulse;
                    }
                }
                nodeAttribute = node.Attributes.GetNamedItem("loop");
                if (nodeAttribute != null)
                {
                    string reverse = nodeAttribute.Value;
                    if (String.Compare(reverse, "true") == 0)
                    {
                        _repeatAnim = AnimationRepeat.Loop;
                    }
                }

                // Analog Clock animation
                nodeAttribute = node.Attributes.GetNamedItem("clockhandle");
                if (nodeAttribute != null)
                {
                    string clockType = nodeAttribute.Value;
                    if (String.Compare(clockType, "second") == 0)
                    {
                        _clockHandle = ClockHandleType.Second;
                    }
                    else if (String.Compare(clockType, "minute") == 0)
                    {
                        _clockHandle = ClockHandleType.Minute;
                    }
                    else if (String.Compare(clockType, "hour") == 0)
                    {
                        _clockHandle = ClockHandleType.Hour;
                    }
                    else
                    {
                        _clockHandle = ClockHandleType.None;
                    }
                }
            }

            // slide parameters
            if (_effect == EffectType.Slide)
            {
                nodeAttribute = node.Attributes.GetNamedItem("start");
                if (nodeAttribute != null)
                {
                    string startPos = nodeAttribute.Value;
                    GetPosition(startPos, ref _startX, ref _startY);
                }
                nodeAttribute = node.Attributes.GetNamedItem("end");
                if (nodeAttribute != null)
                {
                    string endPos = nodeAttribute.Value;
                    GetPosition(endPos, ref _endX, ref _endY);
                }
                // scale our parameters
                GUIGraphicsContext.ScaleHorizontal(ref _startX);
                GUIGraphicsContext.ScaleVertical(ref _startY);
                GUIGraphicsContext.ScaleHorizontal(ref _endX);
                GUIGraphicsContext.ScaleVertical(ref _endY);
            }
            else if (_effect == EffectType.Fade)
            {
                // alpha parameters
                if (_type < 0)
                {
                    // out effect defaults
                    _startAlpha = 100;
                    _endAlpha   = 0;
                }
                else
                {
                    // in effect defaults
                    _startAlpha = 0;
                    _endAlpha   = 100;
                }
                nodeAttribute = node.Attributes.GetNamedItem("start");
                if (nodeAttribute != null)
                {
                    _startAlpha = Int32.Parse(nodeAttribute.Value.ToString());
                }
                nodeAttribute = node.Attributes.GetNamedItem("end");
                if (nodeAttribute != null)
                {
                    _endAlpha = Int32.Parse(nodeAttribute.Value.ToString());
                }

                if (_startAlpha > 100)
                {
                    _startAlpha = 100;
                }
                if (_endAlpha > 100)
                {
                    _endAlpha = 100;
                }
                if (_startAlpha < 0)
                {
                    _startAlpha = 0;
                }
                if (_endAlpha < 0)
                {
                    _endAlpha = 0;
                }
            }
            else if (_effect == EffectType.RotateZ || _effect == EffectType.RotateX || _effect == EffectType.RotateY)
            {
                nodeAttribute = node.Attributes.GetNamedItem("start");
                if (nodeAttribute != null)
                {
                    _startX = float.Parse(nodeAttribute.Value);
                }
                nodeAttribute = node.Attributes.GetNamedItem("end");
                if (nodeAttribute != null)
                {
                    _endX = float.Parse(nodeAttribute.Value);
                }

                // convert to a negative to account for our reversed vertical axis
                _startX *= -1;
                _endX   *= -1;


                nodeAttribute = node.Attributes.GetNamedItem("center");
                if (nodeAttribute != null)
                {
                    string centerPos = nodeAttribute.Value;
                    GetPosition(centerPos, ref _centerX, ref _centerY);
                    GUIGraphicsContext.ScaleHorizontal(ref _centerX);
                    GUIGraphicsContext.ScaleVertical(ref _centerY);
                }
            }
            else // if (effect == EffectType.Zoom)
            {
                // effect defaults
                _startX = _startY = 100;
                _endX   = _endY = 100;

                nodeAttribute = node.Attributes.GetNamedItem("start");
                if (nodeAttribute != null)
                {
                    string start = nodeAttribute.Value;
                    GetPosition(start, ref _startX, ref _startY);
                    if (_startX == 0)
                    {
                        _startX = 100;
                    }
                    if (_startY == 0)
                    {
                        _startY = 100;
                    }
                }
                nodeAttribute = node.Attributes.GetNamedItem("end");
                if (nodeAttribute != null)
                {
                    string endLine = nodeAttribute.Value;
                    GetPosition(endLine, ref _endX, ref _endY);
                    if (_endX == 0)
                    {
                        _endX = 100;
                    }
                    if (_endY == 0)
                    {
                        _endY = 100;
                    }
                }
                nodeAttribute = node.Attributes.GetNamedItem("center");
                if (nodeAttribute != null)
                {
                    string center = nodeAttribute.Value;
                    GetPosition(center, ref _centerX, ref _centerY);
                    GUIGraphicsContext.ScaleHorizontal(ref _centerX);
                    GUIGraphicsContext.ScaleVertical(ref _centerY);
                }
                else
                {
                    /*
                     * // no center specified
                     * // calculate the center position...
                     * if (_startX != 0)
                     * {
                     * float scale = _endX / _startX;
                     * if (scale != 1)
                     *  _centerX = (_endPosX - scale * _startPosX) / (1 - scale);
                     * }
                     * if (_startY != 0)
                     * {
                     * float scale = _endY / _startY;
                     * if (scale != 1)
                     *  _centerY = (_endPosY - scale * _startPosY) / (1 - scale);
                     * }*/
                }
            }
            return(true);
        }