コード例 #1
0
ファイル: Palette.cs プロジェクト: DireAussie/MinimalRune
 /// <summary>
 /// Cleans up gradient (removes redundant gradients stops).
 /// </summary>
 /// <param name="gradientStops">The gradient.</param>
 private static void CleanUpGradient(GradientStopCollection gradientStops)
 {
     for (int i = gradientStops.Count - 2; i > 0; i--)
     {
         Color previousColor = gradientStops[i - 1].Color;
         Color currentColor = gradientStops[i].Color;
         Color nextColor = gradientStops[i + 1].Color;
         if (previousColor == currentColor && currentColor == nextColor)
             gradientStops.RemoveAt(i);
     }
 }
コード例 #2
0
        public void setColors(Canvas linearGradient, List <string> colors)
        {
            GradientStopCollection stops = _linearGradient.GradientStops;

            for (int i = 0; i < colors.Count; i++)
            {
                GradientStop stop = i < stops.Count ? stops[i] : new GradientStop();
                stop.Color = ColorHelpers.Parse(Convert.ToUInt32(colors[i]));
                if (i < stops.Count)
                {
                    stops.RemoveAt(i);
                }
                stops.Insert(i, stop);
            }
            _linearGradient.GradientStops = stops;
        }
コード例 #3
0
 public void setLocations(Canvas linearGradient, List <float> locations)
 {
     if (locations != null)
     {
         GradientStopCollection stops = _linearGradient.GradientStops;
         for (int i = 0; i < locations.Count; i++)
         {
             GradientStop stop = i < stops.Count ? stops[i] : new GradientStop();
             stop.Offset = locations[i];
             if (i < stops.Count)
             {
                 stops.RemoveAt(i);
             }
             stops.Insert(i, stop);
         }
         _linearGradient.GradientStops = stops;
     }
 }
コード例 #4
0
        private void buttonRemove_Click(object sender, RoutedEventArgs e)
        {
            FormattedListBoxItem selectedItem =
                listBoxGradientStopCollection.SelectedItem as FormattedListBoxItem;

            if (selectedItem == null)
            {
                return;
            }
            int index = listBoxGradientStopCollection.SelectedIndex;

            // Remove GradientStop
            listBoxGradientStopCollection.Items.Remove(selectedItem);
            listBoxGradientStopCollection.SelectedItem = null;
            gradientStopCollection.RemoveAt(index);

            // Update UI
            SetPreviewSwatch();
            SetEnabledButtons();
            buttonSave.IsEnabled = true;
        }