/// <summary>
        /// Called when current freezed copy of the <see cref="GradientBrush"/> is changed.
        /// </summary>
        /// <param name="oldValue">
        /// The original <see cref="GradientBrush"/> value.
        /// </param>
        protected override void OnAnimationBrushChanged(GradientBrush oldValue)
        {
            brush = null;

            if (AnimationBrush == null ||
                AnimationBrush.GradientStops == null ||
                AnimationBrush.GradientStops.Count == 0)
            {
                return;
            }

            brush = AnimationBrush.Clone();
        }
        /// <summary>
        /// Get the current <see cref="GradientBrush"/> value for the specified progress between 0 to 1 inclusive.
        /// </summary>
        /// <param name="defaultOriginalBrush">
        /// The default <see cref="GradientBrush"/> instance.
        /// </param>
        /// <param name="defaultDestinationBrush">
        /// The default <see cref="GradientBrush"/> instance.
        /// </param>
        /// <param name="progress">
        /// The current progress between 0 to 1 inclusive.
        /// </param>
        /// <returns>
        /// The current <see cref="GradientBrush"/> value for the specified progress between 0 to 1 inclusive.
        /// </returns>
        protected override GradientBrush GetCurrentValue(
            GradientBrush defaultOriginalBrush,
            GradientBrush defaultDestinationBrush,
            double progress)
        {
            if (AnimationBrush == null)
            {
                return(defaultOriginalBrush);
            }

            //
            //  Either no gradient stop defined or the current value is right at
            //  the start.
            //
            if (progress.IsCloseTo(MinimumValue) ||
                distance.IsCloseTo(MinimumValue))
            {
                return(AnimationBrush);
            }

            GradientBrush brush = AnimationBrush.Clone();

            brush.GradientStops.Clear();

            double startOffset = StartOffset;
            double offset      = distance * progress;

            foreach (GradientStop gradientStop in AnimationBrush.GradientStops)
            {
                double stepOffset = gradientStop.Offset + offset - startOffset;
                if (stepOffset.IsLessThan(0))
                {
                    continue;
                }

                // Stop shifting gradient stops further beyond maximum
                if (stepOffset.IsCloseTo(MaximumValue))
                {
                    break;
                }

                GradientStop step = new GradientStop(gradientStop.Color, gradientStop.Offset + offset);
                brush.GradientStops.Add(step);
            }

            brush.Freeze();

            return(brush);
        }
Exemple #3
0
        /// <summary>
        /// Called when current freezed copy of the <see cref="GradientBrush"/> is changed.
        /// </summary>
        /// <param name="oldValue">
        /// The original <see cref="GradientBrush"/> value.
        /// </param>
        protected override void OnAnimationBrushChanged(GradientBrush oldValue)
        {
            stops = null;
            brush = null;
            total = 0;

            if (AnimationBrush == null ||
                AnimationBrush.GradientStops == null ||
                AnimationBrush.GradientStops.Count == 0)
            {
                return;
            }

            List <GradientStop> list = new List <GradientStop>();

            foreach (GradientStop stop in
                     AnimationBrush.GradientStops.OrderBy(value => value.Offset))
            {
                if (!list.Exists(
                        value => value.Offset.IsCloseTo(stop.Offset)))
                {
                    list.Add(stop);
                }
            }

            if (list.Count < 2)
            {
                return;
            }

            for (int i = 1; i < list.Count; i++)
            {
                total += list[i].Offset - list[i - 1].Offset;
            }
            stops = new ReadOnlyCollection <GradientStop>(list);

            brush = AnimationBrush.Clone();
            brush.GradientStops.Clear();

            brush.GradientStops.Add(new GradientStop(stops.First().Color, 0));
            brush.GradientStops.Add(new GradientStop(stops.Last().Color, 1));
        }