Ejemplo n.º 1
0
        private static object ConvertValueFromString(Type valueType, string value)
        {
            if (value == null)
            {
                return(null);
            }

            //convert value using calculator
            AnimationValueCalculator calc = AnimationValueCalculatorFactory.GetCalculator(valueType);

            return(calc.ConvertToAnimationStepFromString(value));
        }
Ejemplo n.º 2
0
        public static string ConvertValueToString(object value)
        {
            if (value == null)
            {
                return(null);
            }

            Type valueType = value.GetType();

            //convert value using calculator
            AnimationValueCalculator calc = AnimationValueCalculatorFactory.GetCalculator(valueType);

            return(calc.ConvertAnimationStepToString(value));
        }
Ejemplo n.º 3
0
        public void ReInitialize(RadElement element, object initialValue)
        {
            this.cachedStartValue  = initialValue;
            this.cachedEndValue    = this.setting.EndValue;
            this.value             = this.cachedStartValue;
            this.originalNumFrames = this.setting.NumFrames;
            this.numFrames         = this.setting.NumFrames;
            this.interval          = setting.Interval;
            this.step              = this.setting.Step;
            this.reverseStep       = this.setting.ReverseStep;
            this.animationLoopType = this.setting.AnimationLoopType;

            if (this.setting.AnimationType == RadAnimationType.ByStartEndValues)
            {
                if (this.step == null ||
                    this.setting.AnimationType == RadAnimationType.ByStartEndValues &&
                    (this.setting.StartValue == null ||
                     this.setting.StartValueIsCurrentValue)
                    )
                {
                    if (this.setting.EndValue == null)
                    {
                        throw new InvalidOperationException("Error calculating animation step: EndValue is not specified for property '" + this.setting.Property.FullName + "' ");
                    }

                    object startValue = this.CachedStartValue;

                    AnimationValueCalculator calculator = AnimationValueCalculatorFactory.GetCalculator(this.setting.Property.PropertyType);
                    if (calculator != null)
                    {
                        this.step        = calculator.CalculateAnimationStep(startValue, this.setting.EndValue, this.setting.NumFrames);
                        this.reverseStep = calculator.CalculateInversedStep(step);
                    }
                    else
                    {
                        throw new Exception("Error calculating animation step because there is not any calculator for type '" + this.setting.Property.PropertyType + "' registered.");
                    }
                }
            }

            if (this.reverseStep == null)
            {
                AnimationValueCalculator calculator = AnimationValueCalculatorFactory.GetCalculator(this.setting.Property.PropertyType);
                if (calculator != null)
                {
                    this.reverseStep = calculator.CalculateInversedStep(step);
                }
            }
        }
Ejemplo n.º 4
0
 static AnimationValueCalculatorFactory()
 {
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(bool), typeof(AnimationValueBoolCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(int), typeof(AnimationValueIntCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(Rectangle), typeof(AnimationValueRectangleCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(Color), typeof(AnimationValueColorCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(Font), typeof(AnimationValueFontCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(float), typeof(AnimationValueFloatCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(double), typeof(AnimationValueDoubleCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(Padding), typeof(AnimationValuePaddingCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(Size), typeof(AnimationValueSizeCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(SizeF), typeof(AnimationValueSizeFCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(Point), typeof(AnimationValuePointCalculator));
     AnimationValueCalculatorFactory.RegisterAnimationValueCalculatorType(typeof(PointF), typeof(AnimationValuePointFCalculator));
 }
Ejemplo n.º 5
0
        private object GetEndValue(RadObject element)
        {
            if (this.endValue != null)
            {
                return(this.endValue);
            }
            AnimationValueCalculator calculator = AnimationValueCalculatorFactory.GetCalculator(this.Property.PropertyType);
            EasingCalculator         calc       = (EasingCalculator) new StandardEasingCalculator(RadEasingType.InQuad);
            object currValue = this.StartValue;

            for (int currFrameNum = 1; currFrameNum <= this.NumFrames; ++currFrameNum)
            {
                currValue = calculator.CalculateAnimatedValue(this.StartValue, this.EndValue, currValue, this.step, currFrameNum, this.NumFrames, calc);
            }
            return(currValue);
        }
Ejemplo n.º 6
0
        private void ApplyValueInternal(RadElement element)
        {
            RemovePreviousAnimation(element, this.GetAnimatedSetting(element));

            ElementValuesAnimator animator = this.GetAnimator(element);

            animator.ReInitialize(element, this.GetInitialValue(element));

            //notify attached element for animation start event
            if (this.applyDelay <= 0)
            {
                this.OnAnimationStarted(new AnimationStatusEventArgs(element, false));
            }

            if (this.IsAnimationEnabled(element) && (this.AnimatorStyle & AnimatorStyles.AnimateWhenApply) == AnimatorStyles.AnimateWhenApply &&
                element.Visibility == ElementVisibility.Visible && element.ElementTree != null && element.ElementTree.Control.Visible)
            {
                animator.Start(AnimationState.Applying);
                return;
            }

            //we should animate the value, simply calculate the EndValue and apply it to the element.
            AnimationValueCalculator calculator = AnimationValueCalculatorFactory.GetCalculator(this.Property.PropertyType);
            object animatedValue;

            if (this.EndValue == null)
            {
                animatedValue = this.StartValue;
                if (animatedValue == null)
                {
                    animatedValue = animator.CachedStartValue;
                }
                for (int i = 1; i <= this.NumFrames; i++)
                {
                    animatedValue = calculator.CalculateAnimatedValue(this.StartValue, this.EndValue, animatedValue, this.Step, i, this.NumFrames, new StandardEasingCalculator(RadEasingType.InQuad));
                }
            }
            else
            {
                animatedValue = this.EndValue;
            }

            animator.SetCurrentValue(animatedValue);
            //notify for the value change
            this.OnValueApplied(element);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Converts a string to an animation value.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public virtual object ConvertToAnimationStepFromString(string value)
        {
            if (value == null)
            {
                return(null);
            }

            Type valueType = AnimationValueCalculatorFactory.GetRegisteredStepForType(this.AssociatedType);

            if (valueType == null)
            {
                valueType = this.AssociatedType;
            }

            object res = null;

            TypeConverter converter = TypeDescriptor.GetConverter(valueType);

            if (converter != null)
            {
                if (converter.CanConvertFrom(typeof(string)))
                {
                    try
                    {
                        res = converter.ConvertFrom(value);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error setting animation value: " + ex.Message);
                    }
                }
                else
                {
                    //throw new InvalidOperationException(string.Format(
                    //    "The TypeConverter - {0} cannot convert from string, animation step of type {1}",
                    //    converter.ToString(), valueType.FullName));
                    MessageBox.Show(string.Format("The TypeConverter - {0} cannot convert from string, animation step of type {1}", converter.ToString(), valueType.FullName));
                }
            }
            else
            {
                MessageBox.Show("Can't find any TypeConverter for animation step of type " + valueType.FullName);
            }

            return(res);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Retrieves the animation step as a string value.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public virtual string ConvertAnimationStepToString(object value)
        {
            if (value == null)
            {
                return(null);
            }

            string res = value.ToString();

            Type valueType = AnimationValueCalculatorFactory.GetRegisteredStepForType(this.AssociatedType);

            if (valueType == null)
            {
                valueType = this.AssociatedType;
            }

            TypeConverter converter = TypeDescriptor.GetConverter(valueType);

            if (converter != null)
            {
                if (converter.CanConvertTo(typeof(string)))
                {
                    try
                    {
                        res = (string)converter.ConvertTo(value, typeof(string));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error converting animation value: " + ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Can't find TypeConverter to string for animation step " + value.ToString());
                }
            }
            else
            {
                MessageBox.Show("Can't find any TypeConverter for animation property " + value.ToString());
            }

            return(res);
        }
Ejemplo n.º 9
0
 public void Initialize(RadObject element, object initialValue)
 {
     this.startValue = initialValue;
     this.value      = initialValue;
     if (this.setting.EndValue == null && this.setting.Step == null)
     {
         throw new InvalidOperationException("Error calculating animation properties: EndValue and Step are not specified for property '" + this.setting.Property.FullName + "' ");
     }
     this.calculator = AnimationValueCalculatorFactory.GetCalculator(this.setting.Property.PropertyType);
     if (this.calculator == null)
     {
         throw new Exception("Error calculating animation step because there is not any calculator for type '" + (object)this.setting.Property.PropertyType + "' registered.");
     }
     if (this.setting.EndValue == null)
     {
         this.setting.EndValue = this.calculator.CalculateAnimationEndValue(this.startValue, this.setting.Step, this.setting.NumFrames);
     }
     this.step = this.setting.Step != null ? this.setting.Step : this.calculator.CalculateAnimationStep(this.startValue, this.setting.EndValue, this.setting.NumFrames);
     this.easingCalculator.EasingType = this.setting.ApplyEasingType;
 }
Ejemplo n.º 10
0
        public AnimatedPropertySetting(RadProperty property, object animationStartValue, object animationEndValue, int numFrames, int interval)
        {
            base.Property                = property;
            this.interval                = interval;
            this.NumFrames               = numFrames;
            this.StartValue              = animationStartValue;
            this.EndValue                = animationEndValue;
            this.animationType           = RadAnimationType.ByStartEndValues;
            this.skipToEndValueOnReplace = true;

            this.calculator = AnimationValueCalculatorFactory.GetCalculator(base.Property.PropertyType);

            if (calculator != null)
            {
                this.step        = calculator.CalculateAnimationStep(this.StartValue, this.EndValue, numFrames);
                this.reverseStep = calculator.CalculateInversedStep(step);
            }
            else
            {
                throw new Exception("Error calculating animation step because there is not any calculator for type '" + base.Property.PropertyType + "' registered.");
            }
        }