public override object CalculateAnimatedValue(object startValue, object endValue, object currValue, object step, int currFrameNum, int totalFrameNum, EasingCalculator calc)
        {
            Color currColor = (Color)currValue;
            ColorAnimationStep colorStep = (ColorAnimationStep)step;

            int newA;
            int newR;
            int newG;
            int newB;

            if (endValue == null)
            {
                newA = Math.Max(0, Math.Min(255, currColor.A + colorStep.A));
                newR = Math.Max(0, Math.Min(255, currColor.R + colorStep.R));
                newG = Math.Max(0, Math.Min(255, currColor.G + colorStep.G));
                newB = Math.Max(0, Math.Min(255, currColor.B + colorStep.B));

                return(Color.FromArgb(newA, newR, newG, newB));
            }

            Color startColor = (Color)startValue;
            Color endColor   = (Color)endValue;

            newA = Math.Max(0, Math.Min(255, calc.CalculateCurrentValue(startColor.A, endColor.A, currFrameNum, totalFrameNum)));
            newR = Math.Max(0, Math.Min(255, calc.CalculateCurrentValue(startColor.R, endColor.R, currFrameNum, totalFrameNum)));
            newG = Math.Max(0, Math.Min(255, calc.CalculateCurrentValue(startColor.G, endColor.G, currFrameNum, totalFrameNum)));
            newB = Math.Max(0, Math.Min(255, calc.CalculateCurrentValue(startColor.B, endColor.B, currFrameNum, totalFrameNum)));

            return(Color.FromArgb(newA, newR, newG, newB));
        }
        public override object ConvertFrom(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value)
        {
            string str = (string)value;

            if (string.IsNullOrEmpty(str))
            {
                ColorAnimationStep colorAnimationStep = new ColorAnimationStep(0, 0, 0, 0);
            }
            CultureInfo serializationCulture = AnimationValueCalculatorFactory.SerializationCulture;

            string[] strArray = str.Split(serializationCulture.TextInfo.ListSeparator[0]);
            if (strArray.Length < 2)
            {
                strArray = str.Split(',');
            }
            if (strArray.Length == 3)
            {
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(int));
                return((object)new ColorAnimationStep(0, (int)converter.ConvertFrom(context, serializationCulture, (object)strArray[0]), (int)converter.ConvertFrom(context, serializationCulture, (object)strArray[1]), (int)converter.ConvertFrom(context, serializationCulture, (object)strArray[2])));
            }
            if (strArray.Length != 4)
            {
                throw this.GetConvertFromException(value);
            }
            TypeConverter converter1 = TypeDescriptor.GetConverter(typeof(int));

            return((object)new ColorAnimationStep((int)converter1.ConvertFrom(context, serializationCulture, (object)strArray[0]), (int)converter1.ConvertFrom(context, serializationCulture, (object)strArray[1]), (int)converter1.ConvertFrom(context, serializationCulture, (object)strArray[2]), (int)converter1.ConvertFrom(context, serializationCulture, (object)strArray[3])));
        }
Example #3
0
        public override object CalculateAnimationEndValue(
            object animationStartValue,
            object animationStep,
            int numFrames)
        {
            Color color = (Color)animationStartValue;
            ColorAnimationStep colorAnimationStep = (ColorAnimationStep)animationStep;

            return((object)Color.FromArgb(this.CalculateIntEndValue((int)color.A, colorAnimationStep.A, numFrames, 0, (int)byte.MaxValue), this.CalculateIntEndValue((int)color.R, colorAnimationStep.R, numFrames, 0, (int)byte.MaxValue), this.CalculateIntEndValue((int)color.G, colorAnimationStep.G, numFrames, 0, (int)byte.MaxValue), this.CalculateIntEndValue((int)color.B, colorAnimationStep.B, numFrames, 0, (int)byte.MaxValue)));
        }
Example #4
0
        private void ColorAnimationForm_Load(object sender, EventArgs e)
        {
            if (AnimatedSetting.Step != null)
            {
                //TODO: What if the step is different type?
                ColorAnimationStep step = (ColorAnimationStep)XmlAnimatedPropertySetting.DeserializeStep(AnimatedSetting.Step);

                this.upDownStepA.Value = step.A;
                this.upDownStepR.Value = step.R;
                this.upDownStepG.Value = step.G;
                this.upDownStepB.Value = step.B;
            }
            else
            {
                this.checkBoxUseCurrentValue.Checked = true;
            }

            if (AnimatedSetting.ReverseStep != null)
            {
                //TODO: What if the step is different type?
                ColorAnimationStep step = (ColorAnimationStep)XmlAnimatedPropertySetting.DeserializeStep(AnimatedSetting.ReverseStep);

                this.upDownReverseStepA.Value = step.A;
                this.upDownReverseStepR.Value = step.R;
                this.upDownReverseStepG.Value = step.G;
                this.upDownReverseStepB.Value = step.B;
            }

            if (AnimatedSetting.Value != null)
            {
                this.colorComboStart.SelectedColor   = (Color)AnimatedSetting.Value;//(Color)XmlPropertySetting.DeserializeValue(Property, AnimatedSetting.Value);
                this.checkBoxUseCurrentValue.Checked = false;
            }
            else
            {
                this.checkBoxUseCurrentValue.Checked = true;
            }


            if (AnimatedSetting.EndValue != null)
            {
                this.colorComboEnd.SelectedColor = (Color)AnimatedSetting.EndValue;//(Color)XmlPropertySetting.DeserializeValue(Property, AnimatedSetting.EndValue);
            }
            if (AnimatedSetting.ReverseStep == null)
            {
                this.checkBoxAutomaticReverse.Checked = true;
            }
        }
Example #5
0
        public override object CalculateAnimatedValue(
            object startValue,
            object endValue,
            object currValue,
            object step,
            int currFrameNum,
            int totalFrameNum,
            EasingCalculator calc)
        {
            Color color1 = (Color)currValue;
            ColorAnimationStep colorAnimationStep = (ColorAnimationStep)step;

            if (endValue == null)
            {
                return((object)Color.FromArgb(Math.Max(0, Math.Min((int)byte.MaxValue, (int)color1.A + colorAnimationStep.A)), Math.Max(0, Math.Min((int)byte.MaxValue, (int)color1.R + colorAnimationStep.R)), Math.Max(0, Math.Min((int)byte.MaxValue, (int)color1.G + colorAnimationStep.G)), Math.Max(0, Math.Min((int)byte.MaxValue, (int)color1.B + colorAnimationStep.B))));
            }
            Color color2 = (Color)startValue;
            Color color3 = (Color)endValue;

            return((object)Color.FromArgb(Math.Max(0, Math.Min((int)byte.MaxValue, calc.CalculateCurrentValue((int)color2.A, (int)color3.A, currFrameNum, totalFrameNum))), Math.Max(0, Math.Min((int)byte.MaxValue, calc.CalculateCurrentValue((int)color2.R, (int)color3.R, currFrameNum, totalFrameNum))), Math.Max(0, Math.Min((int)byte.MaxValue, calc.CalculateCurrentValue((int)color2.G, (int)color3.G, currFrameNum, totalFrameNum))), Math.Max(0, Math.Min((int)byte.MaxValue, calc.CalculateCurrentValue((int)color2.B, (int)color3.B, currFrameNum, totalFrameNum)))));
        }
Example #6
0
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            ColorAnimationStep step = (ColorAnimationStep)value;

            CultureInfo currCulture = AnimationValueCalculatorFactory.SerializationCulture;

            if (step == null)
            {
                return((string)null);
            }

            TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));

            string[] resArray = new string[]
            {
                (string)intConverter.ConvertTo(context, currCulture, step.A, destinationType),
                " " + (string)intConverter.ConvertTo(context, currCulture, step.R, destinationType),
                " " + (string)intConverter.ConvertTo(context, currCulture, step.G, destinationType),
                " " + (string)intConverter.ConvertTo(context, currCulture, step.B, destinationType)
            };

            return(string.Join(currCulture.TextInfo.ListSeparator, resArray));
        }
        public override object ConvertTo(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value,
            Type destinationType)
        {
            ColorAnimationStep colorAnimationStep   = (ColorAnimationStep)value;
            CultureInfo        serializationCulture = AnimationValueCalculatorFactory.SerializationCulture;

            if (colorAnimationStep == null)
            {
                return((object)null);
            }
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(int));

            string[] strArray = new string[4]
            {
                (string)converter.ConvertTo(context, serializationCulture, (object)colorAnimationStep.A, destinationType),
                " " + (string)converter.ConvertTo(context, serializationCulture, (object)colorAnimationStep.R, destinationType),
                " " + (string)converter.ConvertTo(context, serializationCulture, (object)colorAnimationStep.G, destinationType),
                " " + (string)converter.ConvertTo(context, serializationCulture, (object)colorAnimationStep.B, destinationType)
            };
            return((object)string.Join(serializationCulture.TextInfo.ListSeparator, strArray));
        }
        public override object CalculateInversedStep(object step)
        {
            ColorAnimationStep colorBase = (ColorAnimationStep)step;

            return(new ColorAnimationStep(-colorBase.A, -colorBase.R, -colorBase.G, -colorBase.B));
        }
Example #9
0
        public override object CalculateInversedStep(object step)
        {
            ColorAnimationStep colorAnimationStep = (ColorAnimationStep)step;

            return((object)new ColorAnimationStep(-colorAnimationStep.A, -colorAnimationStep.R, -colorAnimationStep.G, -colorAnimationStep.B));
        }