diff --git a/src/Artemis.Core/RGB.NET/BitmapBrush.cs b/src/Artemis.Core/RGB.NET/BitmapBrush.cs index 166bbe509..fc1e82f96 100644 --- a/src/Artemis.Core/RGB.NET/BitmapBrush.cs +++ b/src/Artemis.Core/RGB.NET/BitmapBrush.cs @@ -117,7 +117,7 @@ namespace Artemis.Core.RGB.NET { var x = left + horizontalSteps * horizontalStep; var y = top + verticalSteps * verticalStep; - if (x < 0 || x > bitmapWidth || y < 0 || y > bitmapHeight) + if (x < 0 || x >= bitmapWidth || y < 0 || y >= bitmapHeight) continue; var color = pixmap.GetPixelColor(x, y); diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsView.xaml index 03ceb7435..cb720b948 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsView.xaml @@ -12,7 +12,6 @@ d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:EffectsViewModel}"> - @@ -24,14 +23,16 @@ Think of things like blur, black & white but also audio visualization etc. - - + + + - + diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs index 74fd252fa..14903f320 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.LayerEffect; using Artemis.Core.Services.Interfaces; @@ -17,6 +19,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects _layerService = layerService; LayerPropertiesViewModel = layerPropertiesViewModel; LayerEffectDescriptors = new BindableCollection(); + PropertyChanged += HandleSelectedLayerEffectChanged; } public LayerPropertiesViewModel LayerPropertiesViewModel { get; } @@ -24,27 +27,30 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects public BindableCollection LayerEffectDescriptors { get; set; } public bool HasLayerEffectDescriptors => LayerEffectDescriptors.Any(); - public LayerEffectDescriptor SelectedLayerEffectDescriptor - { - get => null; - set => AddLayerEffect(value); - } + public LayerEffectDescriptor SelectedLayerEffectDescriptor { get; set; } public void PopulateDescriptors() { var layerBrushProviders = _pluginService.GetPluginsOfType(); + var descriptors = layerBrushProviders.SelectMany(l => l.LayerEffectDescriptors).ToList(); + LayerEffectDescriptors.AddRange(descriptors.Except(LayerEffectDescriptors)); + LayerEffectDescriptors.RemoveRange(LayerEffectDescriptors.Except(descriptors)); - if (LayerEffectDescriptors.Any()) - LayerEffectDescriptors.Clear(); - LayerEffectDescriptors.AddRange(layerBrushProviders.SelectMany(l => l.LayerEffectDescriptors)); - + SelectedLayerEffectDescriptor = null; NotifyOfPropertyChange(nameof(HasLayerEffectDescriptors)); } - private void AddLayerEffect(LayerEffectDescriptor value) + private void HandleSelectedLayerEffectChanged(object sender, PropertyChangedEventArgs e) { - if (LayerPropertiesViewModel.SelectedLayer != null && value != null) - _layerService.AddLayerEffect(LayerPropertiesViewModel.SelectedLayer, value); + if (e.PropertyName == nameof(SelectedLayerEffectDescriptor) && SelectedLayerEffectDescriptor != null) + { + // Jump off the UI thread and let the fancy animation run + Task.Run(async () => + { + await Task.Delay(500); + return _layerService.AddLayerEffect(LayerPropertiesViewModel.SelectedLayer, SelectedLayerEffectDescriptor); + }); + } } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml index 9d0cf4415..fdb982d2f 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml @@ -125,22 +125,33 @@ - - + - + + + + - - + + + + + diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs index 73fcdfbd2..4a6b5e7c7 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; +using System.ComponentModel; using System.Linq; using System.Windows; using System.Windows.Input; @@ -15,8 +15,6 @@ using Artemis.UI.Ninject.Factories; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree; -using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree; -using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem; using Artemis.UI.Shared.Events; using Artemis.UI.Shared.Services.Interfaces; using GongSolutions.Wpf.DragDrop; @@ -29,7 +27,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties { private readonly ILayerPropertyVmFactory _layerPropertyVmFactory; private LayerPropertyGroupViewModel _brushPropertyGroup; - private DateTime _lastToggle; public LayerPropertiesViewModel(IProfileEditorService profileEditorService, ICoreService coreService, ISettingsService settingsService, ILayerPropertyVmFactory layerPropertyVmFactory) @@ -41,6 +38,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties SettingsService = settingsService; LayerPropertyGroups = new BindableCollection(); + PropertyChanged += HandlePropertyTreeIndexChanged; } public IProfileEditorService ProfileEditorService { get; } @@ -58,6 +56,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties } public int PropertyTreeIndex { get; set; } + public bool PropertyTreeVisible => PropertyTreeIndex == 0; public Layer SelectedLayer { get; set; } public Folder SelectedFolder { get; set; } @@ -65,22 +64,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties public TreeViewModel TreeViewModel { get; set; } public EffectsViewModel EffectsViewModel { get; set; } public TimelineViewModel TimelineViewModel { get; set; } - - #region Effects - - public void ToggleAddEffect() - { - if (DateTime.Now - _lastToggle < TimeSpan.FromMilliseconds(500)) - return; - - _lastToggle = DateTime.Now; - PropertyTreeIndex = PropertyTreeIndex == 0 ? 1 : 0; - if (PropertyTreeIndex == 1) - EffectsViewModel.PopulateDescriptors(); - } - - #endregion - + protected override void OnInitialActivate() { PopulateProperties(ProfileEditorService.SelectedProfileElement); @@ -107,6 +91,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties base.OnDeactivate(); } + private void HandlePropertyTreeIndexChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(PropertyTreeIndex) && PropertyTreeIndex == 1) + EffectsViewModel.PopulateDescriptors(); + } + private void ProfileEditorServiceOnProfileElementSelected(object sender, ProfileElementEventArgs e) { PopulateProperties(e.ProfileElement); @@ -292,7 +282,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties if (source == target || target?.GroupType != LayerEffectRoot || source?.GroupType != LayerEffectRoot) return; - + dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; dropInfo.Effects = DragDropEffects.Move; } @@ -338,7 +328,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties var order = 1; foreach (var groupViewModel in LayerPropertyGroups.Where(p => p.GroupType == LayerEffectRoot)) { - groupViewModel.UpdateOrder(order); order++; }