示例#1
0
 private void CalcTabStops()
 {
     _gradStops.Clear();
     if (Value > 0)
     {
         double dLineValue = (1 - Value / MaxValue) / 2;
         if (dLineValue > 0.49)
         {
             dLineValue = 0.49;
         }
         _gradStops.Add(new GradientStop(Colors.Transparent, 0.500));
         _gradStops.Add(new GradientStop(Colors.Transparent, 1.0));
         _gradStops.Add(new GradientStop(FillColor, 0.499));
         _gradStops.Add(new GradientStop(Colors.Transparent, dLineValue));
         _gradStops.Add(new GradientStop(FillColor, dLineValue + 0.001));
     }
     else
     {
         double dLineValue = 0.5 + (Value / MinValue / 2);
         if (dLineValue >= 1)
         {
             dLineValue = 0.998;
         }
         if (dLineValue == 0.5)
         {
             dLineValue = 0.5001;
         }
         _gradStops.Add(new GradientStop(Colors.Transparent, dLineValue + 0.01));
         _gradStops.Add(new GradientStop(Colors.Transparent, 1.0));
         _gradStops.Add(new GradientStop(FillColor, dLineValue));
         _gradStops.Add(new GradientStop(Colors.Transparent, 0.5));
         _gradStops.Add(new GradientStop(FillColor, 0.501));
     }
     this.InvalidateVisual();
 }
示例#2
0
        public GradientStopCollection ToMediaGradient()
        {
            MediaGradient.Clear();
            int k = 0;

            if (IsInverted)
            {
                k = 1;
            }
            for (int i = 0; i < ColorSet.Count; i++)
            {
                MediaGradient.Add(new GradientStop(ColorSet[i].ToMediaColor(), Math.Abs(k - ParameterSet[i])));
            }

            return(MediaGradient);
        }
        ////////////////////////////////////////
        #region Public Methods

        /// <summary>
        /// Creates a new color ramp from the inputted values.
        /// </summary>
        /// <param name="gradient">The GradientStopCollection this is attached to.</param>
        /// <param name="isDynamic">Indicates whether or not offsets for each stop change with the primary offset.</param>
        /// <param name="offset">The primary offset for tracking gradients on the color ramp this collection represents.</param>
        /// <param name="rampHues">The colors used to construct the ramp.</param>
        /// <param name="maxR">The maximum byte value for the red channel.</param>
        /// <param name="maxB">The maximum byte value for the blue channel.</param>
        /// <param name="maxG">The maximum byte value for the green channel.</param>
        /// <returns>The attached GradientStopCollection with new colors and offsets.</returns>
        public static GradientStopCollection CreateColorRamp(this GradientStopCollection gradient, bool isDynamic, double offset, Color[] rampHues, byte maxR, byte maxB, byte maxG)
        {
            double adjOffset  = offset / 10.0;
            int    totalStops = rampHues.Length;

            double stopOffset;

            if (gradient != null)
            {
                gradient.Clear();
            }
            else
            {
                gradient = new GradientStopCollection();
            }

            for (int i = 0; i < totalStops; i++)
            {
                Color color = Color.FromRgb(
                    (rampHues[i].R < maxR) ? rampHues[i].R : maxR,
                    (rampHues[i].G < maxR) ? rampHues[i].G : maxG,
                    (rampHues[i].B < maxR) ? rampHues[i].B : maxB
                    );

                if (isDynamic)
                {
                    stopOffset = (double)i * (1.0 / totalStops) * adjOffset * (totalStops / 2.0);
                }
                else
                {
                    stopOffset = (double)i * (1.0 / totalStops);
                }

                gradient.Add(new GradientStop(color, stopOffset));
            }

            return(gradient);
        }
示例#4
0
        private void UpdateShadowBrush(LinearGradientBrush brush)
        {
            if (_shadowGradients == null)
            {
                return;
            }

            Color firstStopColor = Colors.Transparent;

            for (int i = 0; i < _shadowGradients.Count; i++)
            {
                GradientStopCollection targetGradients = _shadowGradients[i].GradientStops;
                GradientStopCollection sourceGradients = brush.GradientStops;

                targetGradients.Clear();
                for (int j = 0; j < sourceGradients.Count; j++)
                {
                    if ((i == 0) && (j == 0))
                    {
                        firstStopColor = sourceGradients[j].Color;
                    }

                    GradientStop stop = new GradientStop()
                    {
                        Color  = sourceGradients[j].Color,
                        Offset = sourceGradients[j].Offset
                    };
                    targetGradients.Add(stop);
                }
            }

            if (_shadowFill != null)
            {
                _shadowFill.Color = firstStopColor;
            }
        }
示例#5
0
 private void BtnRemoveAll_Clicked(object sender, RoutedEventArgs e)
 {
     colorListString.Clear();
     colors.Clear();
     ListBox_ColorList.Items.Clear();
 }