|
@@ -2,6 +2,7 @@
|
|
using SkiaSharp;
|
|
using SkiaSharp;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
@@ -39,7 +40,14 @@ namespace PixiEditor.Views.UserControls.Palettes
|
|
public static readonly DependencyProperty HintColorProperty =
|
|
public static readonly DependencyProperty HintColorProperty =
|
|
DependencyProperty.Register("HintColor", typeof(Color), typeof(PaletteColorAdder), new PropertyMetadata(System.Windows.Media.Colors.Transparent));
|
|
DependencyProperty.Register("HintColor", typeof(Color), typeof(PaletteColorAdder), new PropertyMetadata(System.Windows.Media.Colors.Transparent));
|
|
|
|
|
|
|
|
+ public static readonly DependencyProperty SwatchesProperty = DependencyProperty.Register(
|
|
|
|
+ "Swatches", typeof(WpfObservableRangeCollection<SKColor>), typeof(PaletteColorAdder), new PropertyMetadata(default(WpfObservableRangeCollection<SKColor>), OnSwatchesChanged));
|
|
|
|
|
|
|
|
+ public WpfObservableRangeCollection<SKColor> Swatches
|
|
|
|
+ {
|
|
|
|
+ get { return (WpfObservableRangeCollection<SKColor>) GetValue(SwatchesProperty); }
|
|
|
|
+ set { SetValue(SwatchesProperty, value); }
|
|
|
|
+ }
|
|
|
|
|
|
public Color SelectedColor
|
|
public Color SelectedColor
|
|
{
|
|
{
|
|
@@ -63,6 +71,7 @@ namespace PixiEditor.Views.UserControls.Palettes
|
|
if (adder == null || adder.Colors == null) return;
|
|
if (adder == null || adder.Colors == null) return;
|
|
if (e.NewValue != null)
|
|
if (e.NewValue != null)
|
|
{
|
|
{
|
|
|
|
+ adder.UpdateAddButton();
|
|
adder.Colors.CollectionChanged += adder.Colors_CollectionChanged;
|
|
adder.Colors.CollectionChanged += adder.Colors_CollectionChanged;
|
|
}
|
|
}
|
|
else if(e.OldValue != null)
|
|
else if(e.OldValue != null)
|
|
@@ -72,10 +81,41 @@ namespace PixiEditor.Views.UserControls.Palettes
|
|
}
|
|
}
|
|
|
|
|
|
private void Colors_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
|
private void Colors_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ UpdateAddSwatchesButton();
|
|
|
|
+ UpdateAddButton();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void UpdateAddButton()
|
|
{
|
|
{
|
|
AddButton.IsEnabled = !Colors.Contains(ToSKColor(SelectedColor));
|
|
AddButton.IsEnabled = !Colors.Contains(ToSKColor(SelectedColor));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static void OnSwatchesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ PaletteColorAdder adder = (PaletteColorAdder)d;
|
|
|
|
+ if (adder == null || adder.Swatches == null) return;
|
|
|
|
+ if (e.NewValue != null)
|
|
|
|
+ {
|
|
|
|
+ adder.UpdateAddSwatchesButton();
|
|
|
|
+ adder.Swatches.CollectionChanged += adder.Swatches_CollectionChanged;
|
|
|
|
+ }
|
|
|
|
+ else if (e.OldValue != null)
|
|
|
|
+ {
|
|
|
|
+ adder.Swatches.CollectionChanged -= adder.Swatches_CollectionChanged;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void Swatches_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ UpdateAddSwatchesButton();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void UpdateAddSwatchesButton()
|
|
|
|
+ {
|
|
|
|
+ AddFromSwatches.IsEnabled = Swatches != null && Swatches.Any(x => !Colors.Contains(x));
|
|
|
|
+ }
|
|
|
|
+
|
|
public PaletteColorAdder()
|
|
public PaletteColorAdder()
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
@@ -95,5 +135,20 @@ namespace PixiEditor.Views.UserControls.Palettes
|
|
AddButton.IsEnabled = !Colors.Contains(ToSKColor(SelectedColor));
|
|
AddButton.IsEnabled = !Colors.Contains(ToSKColor(SelectedColor));
|
|
|
|
|
|
private static SKColor ToSKColor(Color color) => new SKColor(color.R, color.G, color.B, color.A);
|
|
private static SKColor ToSKColor(Color color) => new SKColor(color.R, color.G, color.B, color.A);
|
|
|
|
+
|
|
|
|
+ private void AddFromSwatches_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (Swatches == null) return;
|
|
|
|
+
|
|
|
|
+ foreach (var color in Swatches)
|
|
|
|
+ {
|
|
|
|
+ if (!Colors.Contains(color))
|
|
|
|
+ {
|
|
|
|
+ Colors.Add(color);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ AddFromSwatches.IsEnabled = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|