1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profile editor - Started implementing property add/remove handling

This commit is contained in:
SpoinkyNL 2020-02-11 23:24:17 +01:00
parent c3b296726e
commit 4f66d09755
11 changed files with 98 additions and 24 deletions

View File

@ -139,6 +139,7 @@
<Compile Include="Events\DeviceEventArgs.cs" /> <Compile Include="Events\DeviceEventArgs.cs" />
<Compile Include="Events\FrameRenderedEventArgs.cs" /> <Compile Include="Events\FrameRenderedEventArgs.cs" />
<Compile Include="Events\FrameRenderingEventArgs.cs" /> <Compile Include="Events\FrameRenderingEventArgs.cs" />
<Compile Include="Events\LayerPropertyEventArgs.cs" />
<Compile Include="Exceptions\ArtemisCoreException.cs" /> <Compile Include="Exceptions\ArtemisCoreException.cs" />
<Compile Include="Extensions\DirectoryInfoExtensions.cs" /> <Compile Include="Extensions\DirectoryInfoExtensions.cs" />
<Compile Include="Extensions\DoubleExtensions.cs" /> <Compile Include="Extensions\DoubleExtensions.cs" />

View File

@ -0,0 +1,15 @@
using System;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.Core.Events
{
public class LayerPropertyEventArgs : EventArgs
{
public LayerPropertyEventArgs(BaseLayerProperty layerProperty)
{
LayerProperty = layerProperty;
}
public BaseLayerProperty LayerProperty { get; }
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Extensions; using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.LayerProperties; using Artemis.Core.Models.Profile.LayerProperties;
@ -449,7 +450,7 @@ namespace Artemis.Core.Models.Profile
layerProperty.ApplyToProperty(propertyEntity); layerProperty.ApplyToProperty(propertyEntity);
_properties.Add((layerProperty.PluginInfo.Guid, layerProperty.Id), layerProperty); _properties.Add((layerProperty.PluginInfo.Guid, layerProperty.Id), layerProperty);
OnLayerPropertyRegistered(); OnLayerPropertyRegistered(new LayerPropertyEventArgs(layerProperty));
return propertyEntity != null; return propertyEntity != null;
} }
@ -471,12 +472,12 @@ namespace Artemis.Core.Models.Profile
{ {
if (!_properties.ContainsKey((layerProperty.PluginInfo.Guid, layerProperty.Id))) if (!_properties.ContainsKey((layerProperty.PluginInfo.Guid, layerProperty.Id)))
throw new ArtemisCoreException($"Could not find a property with ID {layerProperty.Id}."); throw new ArtemisCoreException($"Could not find a property with ID {layerProperty.Id}.");
var property = _properties[(layerProperty.PluginInfo.Guid, layerProperty.Id)]; var property = _properties[(layerProperty.PluginInfo.Guid, layerProperty.Id)];
property.Parent?.Children.Remove(property); property.Parent?.Children.Remove(property);
_properties.Remove((layerProperty.PluginInfo.Guid, layerProperty.Id)); _properties.Remove((layerProperty.PluginInfo.Guid, layerProperty.Id));
OnLayerPropertyRemoved(); OnLayerPropertyRemoved(new LayerPropertyEventArgs(property));
} }
/// <summary> /// <summary>
@ -541,8 +542,8 @@ namespace Artemis.Core.Models.Profile
public event EventHandler RenderPropertiesUpdated; public event EventHandler RenderPropertiesUpdated;
public event EventHandler ShapePropertiesUpdated; public event EventHandler ShapePropertiesUpdated;
public event EventHandler LayerPropertyRegistered; public event EventHandler<LayerPropertyEventArgs> LayerPropertyRegistered;
public event EventHandler LayerPropertyRemoved; public event EventHandler<LayerPropertyEventArgs> LayerPropertyRemoved;
private void OnRenderPropertiesUpdated() private void OnRenderPropertiesUpdated()
{ {
@ -561,14 +562,14 @@ namespace Artemis.Core.Models.Profile
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}"; return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
} }
private void OnLayerPropertyRegistered() private void OnLayerPropertyRegistered(LayerPropertyEventArgs e)
{ {
LayerPropertyRegistered?.Invoke(this, EventArgs.Empty); LayerPropertyRegistered?.Invoke(this, e);
} }
private void OnLayerPropertyRemoved() private void OnLayerPropertyRemoved(LayerPropertyEventArgs e)
{ {
LayerPropertyRemoved?.Invoke(this, EventArgs.Empty); LayerPropertyRemoved?.Invoke(this, e);
} }
} }

View File

@ -9,7 +9,6 @@ namespace Artemis.Plugins.LayerBrushes.Noise
{ {
public class NoiseBrush : LayerBrush public class NoiseBrush : LayerBrush
{ {
private const int Scale = 6;
private static readonly Random Rand = new Random(); private static readonly Random Rand = new Random();
private readonly OpenSimplexNoise _noise; private readonly OpenSimplexNoise _noise;
private float _z; private float _z;
@ -42,12 +41,13 @@ namespace Artemis.Plugins.LayerBrushes.Noise
public override void Render(SKCanvas canvas, SKPath path, SKPaint paint) public override void Render(SKCanvas canvas, SKPath path, SKPaint paint)
{ {
return;
var mainColor = MainColorProperty.CurrentValue; var mainColor = MainColorProperty.CurrentValue;
var scale = ScaleProperty.CurrentValue; var scale = ScaleProperty.CurrentValue;
// Scale down the render path to avoid computing a value for every pixel // Scale down the render path to avoid computing a value for every pixel
var width = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / Scale); var width = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / scale.Width);
var height = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / Scale); var height = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / scale.Height);
var opacity = (float) Math.Round(mainColor.Alpha / 255.0, 2, MidpointRounding.AwayFromZero); var opacity = (float) Math.Round(mainColor.Alpha / 255.0, 2, MidpointRounding.AwayFromZero);
using (var bitmap = new SKBitmap(new SKImageInfo(width, height))) using (var bitmap = new SKBitmap(new SKImageInfo(width, height)))
{ {
@ -55,10 +55,10 @@ namespace Artemis.Plugins.LayerBrushes.Noise
// Only compute pixels inside LEDs, due to scaling there may be some rounding issues but it's neglect-able // Only compute pixels inside LEDs, due to scaling there may be some rounding issues but it's neglect-able
foreach (var artemisLed in Layer.Leds) foreach (var artemisLed in Layer.Leds)
{ {
var xStart = artemisLed.AbsoluteRenderRectangle.Left / Scale; var xStart = artemisLed.AbsoluteRenderRectangle.Left / scale.Width;
var xEnd = artemisLed.AbsoluteRenderRectangle.Right / Scale; var xEnd = artemisLed.AbsoluteRenderRectangle.Right / scale.Width;
var yStart = artemisLed.AbsoluteRenderRectangle.Top / Scale; var yStart = artemisLed.AbsoluteRenderRectangle.Top / scale.Height;
var yEnd = artemisLed.AbsoluteRenderRectangle.Bottom / Scale; var yEnd = artemisLed.AbsoluteRenderRectangle.Bottom / scale.Height;
for (var x = xStart; x < xEnd; x++) for (var x = xStart; x < xEnd; x++)
{ {
@ -76,7 +76,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
} }
} }
using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, SKMatrix.MakeScale(Scale, Scale))) using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, SKMatrix.MakeScale(scale.Width, scale.Height)))
{ {
paint.Shader = sh; paint.Shader = sh;
canvas.DrawPath(Layer.LayerShape.Path, paint); canvas.DrawPath(Layer.LayerShape.Path, paint);

View File

@ -35,7 +35,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
public BaseLayerProperty LayerProperty { get; } public BaseLayerProperty LayerProperty { get; }
public LayerPropertyViewModel Parent { get; } public LayerPropertyViewModel Parent { get; }
public List<LayerPropertyViewModel> Children { get; set; } public List<LayerPropertyViewModel> Children { get; }
public bool IsExpanded { get; set; } public bool IsExpanded { get; set; }
@ -78,5 +78,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
match.Initialize(this); match.Initialize(this);
return match; return match;
} }
public IEnumerable<LayerPropertyViewModel> GetAllChildren()
{
var children = new List<LayerPropertyViewModel>();
children.AddRange(Children);
foreach (var layerPropertyViewModel in children)
children.AddRange(layerPropertyViewModel.GetAllChildren());
return children;
}
} }
} }

View File

@ -4,13 +4,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
{ {
public class PropertyTreeChildViewModel : PropertyTreeItemViewModel public class PropertyTreeChildViewModel : PropertyTreeItemViewModel
{ {
public PropertyTreeChildViewModel(LayerPropertyViewModel layerPropertyViewModel) public PropertyTreeChildViewModel(LayerPropertyViewModel layerPropertyViewModel) : base(layerPropertyViewModel)
{ {
LayerPropertyViewModel = layerPropertyViewModel;
PropertyInputViewModel = layerPropertyViewModel.GetPropertyInputViewModel(); PropertyInputViewModel = layerPropertyViewModel.GetPropertyInputViewModel();
} }
public LayerPropertyViewModel LayerPropertyViewModel { get; }
public PropertyInputViewModel PropertyInputViewModel { get; set; } public PropertyInputViewModel PropertyInputViewModel { get; set; }
public override void Update(bool forceUpdate) public override void Update(bool forceUpdate)

View File

@ -4,6 +4,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
{ {
public abstract class PropertyTreeItemViewModel : PropertyChangedBase public abstract class PropertyTreeItemViewModel : PropertyChangedBase
{ {
public LayerPropertyViewModel LayerPropertyViewModel { get; }
protected PropertyTreeItemViewModel(LayerPropertyViewModel layerPropertyViewModel)
{
LayerPropertyViewModel = layerPropertyViewModel;
}
/// <summary> /// <summary>
/// Updates the tree item's input if it is visible and has keyframes enabled /// Updates the tree item's input if it is visible and has keyframes enabled
/// </summary> /// </summary>

View File

@ -1,13 +1,13 @@
using System.Linq; using System.Linq;
using Artemis.Core.Events;
using Stylet; using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
{ {
public class PropertyTreeParentViewModel : PropertyTreeItemViewModel public class PropertyTreeParentViewModel : PropertyTreeItemViewModel
{ {
public PropertyTreeParentViewModel(LayerPropertyViewModel layerPropertyViewModel) public PropertyTreeParentViewModel(LayerPropertyViewModel layerPropertyViewModel) : base(layerPropertyViewModel)
{ {
LayerPropertyViewModel = layerPropertyViewModel;
Children = new BindableCollection<PropertyTreeItemViewModel>(); Children = new BindableCollection<PropertyTreeItemViewModel>();
foreach (var childProperty in layerPropertyViewModel.Children) foreach (var childProperty in layerPropertyViewModel.Children)
@ -17,9 +17,37 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
else else
Children.Add(new PropertyTreeChildViewModel(childProperty)); Children.Add(new PropertyTreeChildViewModel(childProperty));
} }
LayerPropertyViewModel.LayerProperty.Layer.LayerPropertyRegistered += LayerOnLayerPropertyRegistered;
LayerPropertyViewModel.LayerProperty.Layer.LayerPropertyRemoved += LayerOnLayerPropertyRemoved;
}
private void LayerOnLayerPropertyRegistered(object sender, LayerPropertyEventArgs e)
{
if (e.LayerProperty.Parent == LayerPropertyViewModel.LayerProperty)
{
// Problem is we don't have a LayerPropertyViewModel here..
}
}
private void LayerOnLayerPropertyRemoved(object sender, LayerPropertyEventArgs e)
{
// Remove self
if (e.LayerProperty == LayerPropertyViewModel.LayerProperty)
{
LayerPropertyViewModel.LayerProperty.Layer.LayerPropertyRemoved -= LayerOnLayerPropertyRegistered;
LayerPropertyViewModel.LayerProperty.Layer.LayerPropertyRemoved -= LayerOnLayerPropertyRemoved;
}
// Remove child
if (e.LayerProperty.Parent == LayerPropertyViewModel.LayerProperty)
{
var child = Children.FirstOrDefault(c => c.LayerPropertyViewModel.LayerProperty == e.LayerProperty);
if (child != null)
Children.Remove(child);
}
} }
public LayerPropertyViewModel LayerPropertyViewModel { get; }
public BindableCollection<PropertyTreeItemViewModel> Children { get; set; } public BindableCollection<PropertyTreeItemViewModel> Children { get; set; }
public override void Update(bool forceUpdate) public override void Update(bool forceUpdate)

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;
using Stylet; using Stylet;
@ -43,6 +44,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
PropertyTreeItemViewModels.Clear(); PropertyTreeItemViewModels.Clear();
} }
public void AddLayerProperty(BaseLayerProperty layerProperty)
{
}
/// <summary> /// <summary>
/// Updates the tree item's input if it is visible and has keyframes enabled /// Updates the tree item's input if it is visible and has keyframes enabled
/// </summary> /// </summary>

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;
using Stylet; using Stylet;
@ -60,6 +61,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
CreateViewModels(child); CreateViewModels(child);
} }
public void AddLayerProperty(BaseLayerProperty layerProperty)
{
throw new NotImplementedException();
}
public void ClearProperties() public void ClearProperties()
{ {
PropertyTrackViewModels.Clear(); PropertyTrackViewModels.Clear();

View File

@ -1,4 +1,5 @@
using System.Linq; using System.Linq;
using Artemis.Core.Events;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Stylet; using Stylet;
@ -21,6 +22,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
UpdateKeyframes(PropertyTimelineViewModel.LayerPropertiesViewModel.PixelsPerSecond); UpdateKeyframes(PropertyTimelineViewModel.LayerPropertiesViewModel.PixelsPerSecond);
} }
public PropertyTimelineViewModel PropertyTimelineViewModel { get; } public PropertyTimelineViewModel PropertyTimelineViewModel { get; }
public LayerPropertyViewModel LayerPropertyViewModel { get; } public LayerPropertyViewModel LayerPropertyViewModel { get; }
public BindableCollection<PropertyTrackKeyframeViewModel> KeyframeViewModels { get; set; } public BindableCollection<PropertyTrackKeyframeViewModel> KeyframeViewModels { get; set; }