Пример #1
0
        static DefaultDrawingPrimitives()
        {
            RedToWhiteGradient = new LinearGradientBrush(Colors.Red, Colors.White, new Point(0, 0), new Point(1, 1));
            RedToWhiteGradient.GradientStops.Add(new GradientStop(Colors.Red, 0.0));
            RedToWhiteGradient.GradientStops.Add(new GradientStop(Colors.White, 1.0));
            RedToWhiteGradient.Freeze();

            WhiteToRedGradient = new LinearGradientBrush(Colors.LightGray, Colors.DarkRed, new Point(0, 0), new Point(1, 1));
            WhiteToRedGradient.GradientStops.Add(new GradientStop(Colors.White, 0.0));
            WhiteToRedGradient.GradientStops.Add(new GradientStop(Colors.Red, 1.0));
            WhiteToRedGradient.Freeze();
            BlackPen.Freeze();
        }
        /// <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);
        }