From 92a3e0d61b4d8793b6fbbcc2f9e7abe7444a15d6 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Fri, 17 Apr 2020 23:01:42 +0200 Subject: [PATCH] Color brush - Fixed gradient picker not appearing Gradient picker - Use dialog instead of a popup window --- src/Artemis.Core/Artemis.Core.csproj | 6 +- src/Artemis.Core/FodyWeavers.xsd | 10 ++ .../Models/Profile/ColorGradient.cs | 5 +- src/Artemis.Storage/Artemis.Storage.csproj | 2 +- .../Artemis.UI.Shared.csproj | 2 +- .../Controls/DeviceVisualizer.cs | 20 +++- .../Controls/GradientPicker.xaml.cs | 14 ++- .../Screens/GradientEditor/ColorStopView.xaml | 4 +- .../GradientEditor/GradientEditorView.xaml | 101 ++++++++++-------- .../GradientEditor/GradientEditorViewModel.cs | 30 +++++- .../Services/GradientPickerService.cs | 16 ++- .../Interfaces/IGradientPickerService.cs | 2 +- src/Artemis.UI/Artemis.UI.csproj | 6 +- src/Artemis.UI/FodyWeavers.xsd | 10 ++ src/Artemis.UI/Screens/Home/HomeView.xaml | 6 +- .../LayerProperties/LayerPropertiesView.xaml | 56 ++++++---- .../ColorGradientPropertyInputView.xaml | 3 +- .../Artemis.Plugins.Devices.DMX.csproj | 2 +- .../Artemis.Plugins.Devices.WS281X.csproj | 2 +- .../ColorBrush.cs | 4 +- .../NoiseBrush.cs | 6 +- 21 files changed, 206 insertions(+), 101 deletions(-) diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index 0562dc31d..0ae5dbd13 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -22,13 +22,13 @@ - - + + - + diff --git a/src/Artemis.Core/FodyWeavers.xsd b/src/Artemis.Core/FodyWeavers.xsd index 2f1b8aae7..221aeb8a5 100644 --- a/src/Artemis.Core/FodyWeavers.xsd +++ b/src/Artemis.Core/FodyWeavers.xsd @@ -31,6 +31,16 @@ Used to control if equality checks should use the static Equals method resolved from the base class. + + + Used to turn off build warnings from this weaver. + + + + + Used to turn off build warnings about mismatched On_PropertyName_Changed methods. + + diff --git a/src/Artemis.Core/Models/Profile/ColorGradient.cs b/src/Artemis.Core/Models/Profile/ColorGradient.cs index 36b48c397..6f5e0ec41 100644 --- a/src/Artemis.Core/Models/Profile/ColorGradient.cs +++ b/src/Artemis.Core/Models/Profile/ColorGradient.cs @@ -47,7 +47,10 @@ namespace Artemis.Core.Models.Profile public SKColor GetColor(float position) { - var point = Stops.SingleOrDefault(f => f.Position == position); + if (!Stops.Any()) + return SKColor.Empty; + + var point = Stops.FirstOrDefault(f => f.Position == position); if (point != null) return point.Color; var before = Stops.First(w => w.Position == Stops.Min(m => m.Position)); diff --git a/src/Artemis.Storage/Artemis.Storage.csproj b/src/Artemis.Storage/Artemis.Storage.csproj index 0247c7075..5efccadd8 100644 --- a/src/Artemis.Storage/Artemis.Storage.csproj +++ b/src/Artemis.Storage/Artemis.Storage.csproj @@ -5,6 +5,6 @@ 7 - + \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index a958d4de9..d09cfde49 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs index c106546d1..1d1123483 100644 --- a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs +++ b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs @@ -21,14 +21,28 @@ namespace Artemis.UI.Shared.Controls private readonly DrawingGroup _backingStore; private readonly List _deviceVisualizerLeds; private BitmapImage _deviceImage; + private bool _subscribed; public DeviceVisualizer() { _backingStore = new DrawingGroup(); _deviceVisualizerLeds = new List(); - RGBSurface.Instance.Updated += RgbSurfaceOnUpdated; - Unloaded += (sender, args) => Dispose(); + Loaded += (sender, args) => SubscribeToUpdate(true); + Unloaded += (sender, args) => SubscribeToUpdate(false); + } + + private void SubscribeToUpdate(bool subscribe) + { + if (_subscribed == subscribe) + return; + + if (subscribe) + RGBSurface.Instance.Updated += RgbSurfaceOnUpdated; + else + RGBSurface.Instance.Updated -= RgbSurfaceOnUpdated; + + _subscribed = subscribe; } public ArtemisDevice Device @@ -131,7 +145,7 @@ namespace Artemis.UI.Shared.Controls bitmapBrush.Freeze(); _backingStore.OpacityMask = bitmapBrush; } - + private void RgbSurfaceOnUpdated(UpdatedEventArgs e) { Dispatcher.Invoke(() => diff --git a/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs b/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs index 8e740ebac..3a3a59c97 100644 --- a/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs +++ b/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs @@ -46,6 +46,15 @@ namespace Artemis.UI.Shared.Controls set => SetValue(ColorGradientProperty, value); } + /// + /// Gets or sets the currently selected color gradient + /// + public string DialogHost + { + get => (string) GetValue(DialogHostProperty); + set => SetValue(DialogHostProperty, value); + } + public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] @@ -67,7 +76,7 @@ namespace Artemis.UI.Shared.Controls private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e) { - GradientPickerService.ShowGradientPicker(ColorGradient); + GradientPickerService.ShowGradientPicker(ColorGradient, DialogHost); } #region Static WPF fields @@ -75,6 +84,9 @@ namespace Artemis.UI.Shared.Controls public static readonly DependencyProperty ColorGradientProperty = DependencyProperty.Register(nameof(ColorGradient), typeof(ColorGradient), typeof(GradientPicker), new FrameworkPropertyMetadata(default(ColorGradient), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ColorGradientPropertyChangedCallback)); + public static readonly DependencyProperty DialogHostProperty = DependencyProperty.Register(nameof(DialogHost), typeof(string), typeof(GradientPicker), + new FrameworkPropertyMetadata(default(string))); + public static readonly RoutedEvent ColorGradientChangedEvent = EventManager.RegisterRoutedEvent(nameof(ColorGradient), RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler), typeof(GradientPicker)); diff --git a/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopView.xaml b/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopView.xaml index be290ccf5..8a7972d8f 100644 --- a/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopView.xaml +++ b/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopView.xaml @@ -42,7 +42,7 @@ - + @@ -53,7 +53,7 @@ - + + - - + + - - + + + - + - + Gradient saving not implemented yet - + Soon you'll be able to store different gradients for usage throughout your profiles and quickly select them @@ -50,14 +49,16 @@ - + - + - + @@ -85,31 +86,39 @@ - + IsEnabled="{Binding HasSelectedColorStopViewModel}" /> - + - - + + + + @@ -134,7 +134,7 @@ - Open Source @@ -178,7 +178,7 @@ --> - - - - - - - + - - - - - + + + + + + + @@ -131,7 +142,8 @@ - + - + - + diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyInput/ColorGradientPropertyInputView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyInput/ColorGradientPropertyInputView.xaml index d50535da3..c871a6cbe 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyInput/ColorGradientPropertyInputView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/PropertyTree/PropertyInput/ColorGradientPropertyInputView.xaml @@ -15,7 +15,8 @@ + ColorGradient="{Binding ColorGradientInputValue}" + DialogHost="PropertyTreeDialogHost"/> \ No newline at end of file diff --git a/src/Plugins/Artemis.Plugins.Devices.DMX/Artemis.Plugins.Devices.DMX.csproj b/src/Plugins/Artemis.Plugins.Devices.DMX/Artemis.Plugins.Devices.DMX.csproj index 1fa3b1b68..a8943908b 100644 --- a/src/Plugins/Artemis.Plugins.Devices.DMX/Artemis.Plugins.Devices.DMX.csproj +++ b/src/Plugins/Artemis.Plugins.Devices.DMX/Artemis.Plugins.Devices.DMX.csproj @@ -24,7 +24,7 @@ - + diff --git a/src/Plugins/Artemis.Plugins.Devices.WS281X/Artemis.Plugins.Devices.WS281X.csproj b/src/Plugins/Artemis.Plugins.Devices.WS281X/Artemis.Plugins.Devices.WS281X.csproj index 41b49f390..c8d3b4d15 100644 --- a/src/Plugins/Artemis.Plugins.Devices.WS281X/Artemis.Plugins.Devices.WS281X.csproj +++ b/src/Plugins/Artemis.Plugins.Devices.WS281X/Artemis.Plugins.Devices.WS281X.csproj @@ -24,7 +24,7 @@ - + diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs index 405b5acf6..5b7b2d46c 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Color/ColorBrush.cs @@ -28,9 +28,9 @@ namespace Artemis.Plugins.LayerBrushes.Color private void UpdateColorProperties() { - Layer.Properties.RemoveLayerProperty(ColorProperty); + UnRegisterLayerProperty(ColorProperty); ColorProperty = null; - Layer.Properties.RemoveLayerProperty(GradientProperty); + UnRegisterLayerProperty(GradientProperty); GradientProperty = null; if (GradientTypeProperty.Value == GradientType.Solid) diff --git a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs index 5f6e66c14..dccd0c453 100644 --- a/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs +++ b/src/Plugins/Artemis.Plugins.LayerBrushes.Noise/NoiseBrush.cs @@ -180,9 +180,11 @@ namespace Artemis.Plugins.LayerBrushes.Noise private void CreateColorMap(object sender, EventArgs e) { - _colorMap = new SKColor[101]; + var colorMap = new SKColor[101]; for (var i = 0; i < 101; i++) - _colorMap[i] = GradientColorProperty.Value.GetColor(i / 100f); + colorMap[i] = GradientColorProperty.Value.GetColor(i / 100f); + + _colorMap = colorMap; } }