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

Refactored shape brushes to use the properties system

This commit is contained in:
Robert 2020-02-11 19:10:31 +01:00
parent 022e14e98d
commit 9b1d28840c
40 changed files with 650 additions and 686 deletions

View File

@ -152,8 +152,10 @@
<Compile Include="Models\Profile\KeyframeEngines\FloatKeyframeEngine.cs" /> <Compile Include="Models\Profile\KeyframeEngines\FloatKeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\IntKeyframeEngine.cs" /> <Compile Include="Models\Profile\KeyframeEngines\IntKeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\KeyframeEngine.cs" /> <Compile Include="Models\Profile\KeyframeEngines\KeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\SKColorKeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\SKPointKeyframeEngine.cs" /> <Compile Include="Models\Profile\KeyframeEngines\SKPointKeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\SKSizeKeyframeEngine.cs" /> <Compile Include="Models\Profile\KeyframeEngines\SKSizeKeyframeEngine.cs" />
<Compile Include="Models\Profile\LayerBrushReference.cs" />
<Compile Include="Models\Profile\LayerProperties\BaseKeyframe.cs" /> <Compile Include="Models\Profile\LayerProperties\BaseKeyframe.cs" />
<Compile Include="Models\Profile\LayerProperties\Keyframe.cs" /> <Compile Include="Models\Profile\LayerProperties\Keyframe.cs" />
<Compile Include="Models\Profile\LayerProperties\BaseLayerProperty.cs" /> <Compile Include="Models\Profile\LayerProperties\BaseLayerProperty.cs" />
@ -178,8 +180,6 @@
<Compile Include="Plugins\LayerBrush\LayerBrush.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrush.cs" />
<Compile Include="Plugins\LayerBrush\LayerBrushDescriptor.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrushDescriptor.cs" />
<Compile Include="Plugins\LayerBrush\LayerBrushProvider.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrushProvider.cs" />
<Compile Include="Plugins\LayerBrush\LayerBrushSettings.cs" />
<Compile Include="Plugins\LayerBrush\LayerBrushViewModel.cs" />
<Compile Include="Plugins\Models\PluginInfo.cs" /> <Compile Include="Plugins\Models\PluginInfo.cs" />
<Compile Include="Plugins\Models\PluginSetting.cs" /> <Compile Include="Plugins\Models\PluginSetting.cs" />
<Compile Include="Plugins\Models\PluginSettings.cs" /> <Compile Include="Plugins\Models\PluginSettings.cs" />

View File

@ -1,4 +1,5 @@
using System; using System;
using Artemis.Core.Plugins.Models;
namespace Artemis.Core namespace Artemis.Core
{ {
@ -6,5 +7,6 @@ namespace Artemis.Core
{ {
public static readonly string DataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Artemis\\"; public static readonly string DataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Artemis\\";
public static readonly string ConnectionString = $"FileName={DataFolder}\\database.db;Mode=Exclusive"; public static readonly string ConnectionString = $"FileName={DataFolder}\\database.db;Mode=Exclusive";
public static readonly PluginInfo CorePluginInfo = new PluginInfo {Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core"};
} }
} }

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class SKColorKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKColor)};
protected override object GetInterpolatedValue()
{
var currentKeyframe = (Keyframe<SKColor>) CurrentKeyframe;
var nextKeyframe = (Keyframe<SKColor>) NextKeyframe;
var redDiff = nextKeyframe.Value.Red - currentKeyframe.Value.Red;
var greenDiff = nextKeyframe.Value.Green - currentKeyframe.Value.Green;
var blueDiff = nextKeyframe.Value.Blue - currentKeyframe.Value.Blue;
var alphaDiff = nextKeyframe.Value.Alpha - currentKeyframe.Value.Alpha;
return new SKColor(
(byte) (currentKeyframe.Value.Red + redDiff * KeyframeProgressEased),
(byte) (currentKeyframe.Value.Green + greenDiff * KeyframeProgressEased),
(byte) (currentKeyframe.Value.Blue + blueDiff * KeyframeProgressEased),
(byte)(currentKeyframe.Value.Alpha + alphaDiff * KeyframeProgressEased)
);
}
}
}

View File

@ -8,15 +8,18 @@ using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerShapes; using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.Models;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ninject;
using Ninject.Parameters;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Models.Profile namespace Artemis.Core.Models.Profile
{ {
public sealed class Layer : ProfileElement public sealed class Layer : ProfileElement
{ {
private readonly Dictionary<string, BaseLayerProperty> _properties; private readonly Dictionary<(Guid, string), BaseLayerProperty> _properties;
private LayerShape _layerShape; private LayerShape _layerShape;
private List<ArtemisLed> _leds; private List<ArtemisLed> _leds;
private SKPath _path; private SKPath _path;
@ -31,12 +34,12 @@ namespace Artemis.Core.Models.Profile
Name = name; Name = name;
_leds = new List<ArtemisLed>(); _leds = new List<ArtemisLed>();
_properties = new Dictionary<string, BaseLayerProperty>(); _properties = new Dictionary<(Guid, string), BaseLayerProperty>();
CreateDefaultProperties(); CreateDefaultProperties();
CreateShapeType(); ApplyShapeType();
ShapeTypeProperty.ValueChanged += (sender, args) => CreateShapeType(); ShapeTypeProperty.ValueChanged += (sender, args) => ApplyShapeType();
} }
internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity) internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity)
@ -50,27 +53,12 @@ namespace Artemis.Core.Models.Profile
Order = layerEntity.Order; Order = layerEntity.Order;
_leds = new List<ArtemisLed>(); _leds = new List<ArtemisLed>();
_properties = new Dictionary<string, BaseLayerProperty>(); _properties = new Dictionary<(Guid, string), BaseLayerProperty>();
CreateDefaultProperties(); CreateDefaultProperties();
CreateShapeType(); ApplyShapeType();
ShapeTypeProperty.ValueChanged += (sender, args) => CreateShapeType(); ShapeTypeProperty.ValueChanged += (sender, args) => ApplyShapeType();
}
private void CreateShapeType()
{
switch (ShapeTypeProperty.CurrentValue)
{
case LayerShapeType.Ellipse:
LayerShape = new Ellipse(this);
break;
case LayerShapeType.Rectangle:
LayerShape = new Rectangle(this);
break;
default:
throw new ArgumentOutOfRangeException();
}
} }
internal LayerEntity LayerEntity { get; set; } internal LayerEntity LayerEntity { get; set; }
@ -126,6 +114,8 @@ namespace Artemis.Core.Models.Profile
public LayerProperty<SKBlendMode> BlendModeProperty { get; set; } public LayerProperty<SKBlendMode> BlendModeProperty { get; set; }
public LayerProperty<LayerBrushReference> BrushReferenceProperty { get; set; }
/// <summary> /// <summary>
/// The anchor point property of this layer, also found in <see cref="Properties" /> /// The anchor point property of this layer, also found in <see cref="Properties" />
/// </summary> /// </summary>
@ -156,6 +146,39 @@ namespace Artemis.Core.Models.Profile
/// </summary> /// </summary>
public LayerBrush LayerBrush { get; internal set; } public LayerBrush LayerBrush { get; internal set; }
#region Storage
internal override void ApplyToEntity()
{
// Properties
LayerEntity.Id = EntityId;
LayerEntity.ParentId = Parent?.EntityId ?? new Guid();
LayerEntity.Order = Order;
LayerEntity.Name = Name;
LayerEntity.ProfileId = Profile.EntityId;
foreach (var layerProperty in Properties)
layerProperty.ApplyToEntity();
// LEDs
LayerEntity.Leds.Clear();
foreach (var artemisLed in Leds)
{
var ledEntity = new LedEntity
{
DeviceHash = artemisLed.Device.RgbDevice.GetDeviceHashCode(),
LedName = artemisLed.RgbLed.Id.ToString()
};
LayerEntity.Leds.Add(ledEntity);
}
// Conditions TODO
LayerEntity.Condition.Clear();
}
#endregion
#region Rendering
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
foreach (var property in Properties) foreach (var property in Properties)
@ -276,6 +299,29 @@ namespace Artemis.Core.Models.Profile
LayerBrush?.Render(canvas, LayerShape.Path, paint); LayerBrush?.Render(canvas, LayerShape.Path, paint);
} }
internal void CalculateRenderProperties()
{
if (!Leds.Any())
{
Path = new SKPath();
LayerShape?.CalculateRenderProperties();
OnRenderPropertiesUpdated();
return;
}
var path = new SKPath {FillType = SKPathFillType.Winding};
foreach (var artemisLed in Leds)
path.AddRect(artemisLed.AbsoluteRenderRectangle);
Path = path;
// This is called here so that the shape's render properties are up to date when other code
// responds to OnRenderPropertiesUpdated
LayerShape?.CalculateRenderProperties();
OnRenderPropertiesUpdated();
}
private SKPoint GetLayerAnchorPosition() private SKPoint GetLayerAnchorPosition()
{ {
var positionProperty = PositionProperty.CurrentValue; var positionProperty = PositionProperty.CurrentValue;
@ -290,43 +336,9 @@ namespace Artemis.Core.Models.Profile
return position; return position;
} }
internal override void ApplyToEntity() #endregion
{
// Properties
LayerEntity.Id = EntityId;
LayerEntity.ParentId = Parent?.EntityId ?? new Guid();
LayerEntity.Order = Order;
LayerEntity.Name = Name;
LayerEntity.ProfileId = Profile.EntityId;
foreach (var layerProperty in Properties)
layerProperty.ApplyToEntity();
// LEDs #region LED management
LayerEntity.Leds.Clear();
foreach (var artemisLed in Leds)
{
var ledEntity = new LedEntity
{
DeviceHash = artemisLed.Device.RgbDevice.GetDeviceHashCode(),
LedName = artemisLed.RgbLed.Id.ToString()
};
LayerEntity.Leds.Add(ledEntity);
}
// Conditions TODO
LayerEntity.Condition.Clear();
// Brush
if (LayerBrush != null)
{
LayerEntity.BrushEntity = new BrushEntity
{
BrushPluginGuid = LayerBrush.Descriptor.LayerBrushProvider.PluginInfo.Guid,
BrushType = LayerBrush.GetType().Name,
Configuration = JsonConvert.SerializeObject(LayerBrush.Settings)
};
}
}
/// <summary> /// <summary>
/// Adds a new <see cref="ArtemisLed" /> to the layer and updates the render properties. /// Adds a new <see cref="ArtemisLed" /> to the layer and updates the render properties.
@ -385,47 +397,39 @@ namespace Artemis.Core.Models.Profile
CalculateRenderProperties(); CalculateRenderProperties();
} }
internal void CalculateRenderProperties() #endregion
#region Shape management
private void ApplyShapeType()
{ {
if (!Leds.Any()) switch (ShapeTypeProperty.CurrentValue)
{ {
Path = new SKPath(); case LayerShapeType.Ellipse:
LayerShape = new Ellipse(this);
LayerShape?.CalculateRenderProperties(); break;
OnRenderPropertiesUpdated(); case LayerShapeType.Rectangle:
return; LayerShape = new Rectangle(this);
break;
default:
throw new ArgumentOutOfRangeException();
} }
var path = new SKPath {FillType = SKPathFillType.Winding};
foreach (var artemisLed in Leds)
path.AddRect(artemisLed.AbsoluteRenderRectangle);
Path = path;
// This is called here so that the shape's render properties are up to date when other code
// responds to OnRenderPropertiesUpdated
LayerShape?.CalculateRenderProperties();
OnRenderPropertiesUpdated();
} }
#endregion
public override string ToString()
{
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}
#region Properties #region Properties
/// <summary> /// <summary>
/// Adds the provided layer property to the layer. /// Adds the provided layer property and its children to the layer.
/// If found, the last stored base value and keyframes will be applied to the provided property. /// If found, the last stored base value and keyframes will be applied to the provided property.
/// </summary> /// </summary>
/// <typeparam name="T">The type of value of the layer property</typeparam> /// <typeparam name="T">The type of value of the layer property</typeparam>
/// <param name="layerProperty">The property to apply to the layer</param> /// <param name="layerProperty">The property to apply to the layer</param>
/// <returns>True if an existing value was found and applied, otherwise false.</returns> /// <returns>True if an existing value was found and applied, otherwise false.</returns>
public bool AddLayerProperty<T>(LayerProperty<T> layerProperty) public bool RegisterLayerProperty<T>(LayerProperty<T> layerProperty)
{ {
return AddLayerProperty((BaseLayerProperty) layerProperty); return RegisterLayerProperty((BaseLayerProperty) layerProperty);
} }
/// <summary> /// <summary>
@ -434,9 +438,9 @@ namespace Artemis.Core.Models.Profile
/// </summary> /// </summary>
/// <param name="layerProperty">The property to apply to the layer</param> /// <param name="layerProperty">The property to apply to the layer</param>
/// <returns>True if an existing value was found and applied, otherwise false.</returns> /// <returns>True if an existing value was found and applied, otherwise false.</returns>
public bool AddLayerProperty(BaseLayerProperty layerProperty) public bool RegisterLayerProperty(BaseLayerProperty layerProperty)
{ {
if (_properties.ContainsKey(layerProperty.Id)) if (_properties.ContainsKey((layerProperty.PluginInfo.Guid, layerProperty.Id)))
throw new ArtemisCoreException($"Duplicate property ID detected. Layer already contains a property with ID {layerProperty.Id}."); throw new ArtemisCoreException($"Duplicate property ID detected. Layer already contains a property with ID {layerProperty.Id}.");
var propertyEntity = LayerEntity.PropertyEntities.FirstOrDefault(p => p.Id == layerProperty.Id && p.ValueType == layerProperty.Type.Name); var propertyEntity = LayerEntity.PropertyEntities.FirstOrDefault(p => p.Id == layerProperty.Id && p.ValueType == layerProperty.Type.Name);
@ -444,66 +448,91 @@ namespace Artemis.Core.Models.Profile
if (propertyEntity != null) if (propertyEntity != null)
layerProperty.ApplyToProperty(propertyEntity); layerProperty.ApplyToProperty(propertyEntity);
_properties.Add(layerProperty.Id, layerProperty); _properties.Add((layerProperty.PluginInfo.Guid, layerProperty.Id), layerProperty);
OnLayerPropertyRegistered();
return propertyEntity != null; return propertyEntity != null;
} }
/// <summary>
/// Removes the provided layer property from the layer.
/// </summary>
/// <typeparam name="T">The type of value of the layer property</typeparam>
/// <param name="layerProperty">The property to remove from the layer</param>
public void RemoveLayerProperty<T>(LayerProperty<T> layerProperty)
{
RemoveLayerProperty((BaseLayerProperty) layerProperty);
}
/// <summary>
/// Removes the provided layer property from the layer.
/// </summary>
/// <param name="layerProperty">The property to remove from the layer</param>
public void RemoveLayerProperty(BaseLayerProperty layerProperty)
{
if (!_properties.ContainsKey((layerProperty.PluginInfo.Guid, layerProperty.Id)))
throw new ArtemisCoreException($"Could not find a property with ID {layerProperty.Id}.");
var property = _properties[(layerProperty.PluginInfo.Guid, layerProperty.Id)];
property.Parent?.Children.Remove(property);
_properties.Remove((layerProperty.PluginInfo.Guid, layerProperty.Id));
OnLayerPropertyRemoved();
}
/// <summary> /// <summary>
/// If found, returns the <see cref="LayerProperty{T}" /> matching the provided ID /// If found, returns the <see cref="LayerProperty{T}" /> matching the provided ID
/// </summary> /// </summary>
/// <typeparam name="T">The type of the layer property</typeparam> /// <typeparam name="T">The type of the layer property</typeparam>
/// <param name="pluginInfo">The plugin this property belongs to</param>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
public LayerProperty<T> GetLayerPropertyById<T>(string id) public LayerProperty<T> GetLayerPropertyById<T>(PluginInfo pluginInfo, string id)
{ {
if (!_properties.ContainsKey(id)) if (!_properties.ContainsKey((pluginInfo.Guid, id)))
return null; return null;
var property = _properties[id]; var property = _properties[(pluginInfo.Guid, id)];
if (property.Type != typeof(T)) if (property.Type != typeof(T))
throw new ArtemisCoreException($"Property type mismatch. Expected property {property} to have type {typeof(T)} but it has {property.Type} instead."); throw new ArtemisCoreException($"Property type mismatch. Expected property {property} to have type {typeof(T)} but it has {property.Type} instead.");
return (LayerProperty<T>) _properties[id]; return (LayerProperty<T>) _properties[(pluginInfo.Guid, id)];
} }
private void CreateDefaultProperties() private void CreateDefaultProperties()
{ {
var shape = new LayerProperty<object>(this, null, "Core.Shape", "Shape", "A collection of basic shape properties."); // Shape
var shape = new LayerProperty<object>(this, "Core.Shape", "Shape", "A collection of basic shape properties.");
ShapeTypeProperty = new LayerProperty<LayerShapeType>(this, shape, "Core.ShapeType", "Shape type", "The type of shape to draw in this layer.") {CanUseKeyframes = false}; ShapeTypeProperty = new LayerProperty<LayerShapeType>(this, shape, "Core.ShapeType", "Shape type", "The type of shape to draw in this layer.") {CanUseKeyframes = false};
FillTypeProperty = new LayerProperty<LayerFillType>(this, shape, "Core.FillType", "Fill type", "How to make the shape adjust to scale changes.") {CanUseKeyframes = false}; FillTypeProperty = new LayerProperty<LayerFillType>(this, shape, "Core.FillType", "Fill type", "How to make the shape adjust to scale changes.") {CanUseKeyframes = false};
BlendModeProperty = new LayerProperty<SKBlendMode>(this, shape, "Core.BlendMode", "Blend mode", "How to blend this layer into the resulting image.") {CanUseKeyframes = false}; BlendModeProperty = new LayerProperty<SKBlendMode>(this, shape, "Core.BlendMode", "Blend mode", "How to blend this layer into the resulting image.") {CanUseKeyframes = false};
shape.Children.Add(ShapeTypeProperty); ShapeTypeProperty.Value = LayerShapeType.Rectangle;
shape.Children.Add(FillTypeProperty); FillTypeProperty.Value = LayerFillType.Stretch;
shape.Children.Add(BlendModeProperty); BlendModeProperty.Value = SKBlendMode.SrcOver;
var transform = new LayerProperty<object>(this, null, "Core.Transform", "Transform", "A collection of transformation properties.") {ExpandByDefault = true}; RegisterLayerProperty(shape);
foreach (var shapeProperty in shape.Children)
RegisterLayerProperty(shapeProperty);
// Brush
var brush = new LayerProperty<object>(this, "Core.Brush", "Brush", "A collection of properties that configure the selected brush.");
BrushReferenceProperty = new LayerProperty<LayerBrushReference>(this, brush, "Core.BrushReference", "Brush type", "The type of brush to use for this layer.") {CanUseKeyframes = false};
RegisterLayerProperty(brush);
foreach (var brushProperty in brush.Children)
RegisterLayerProperty(brushProperty);
// Transform
var transform = new LayerProperty<object>(this, "Core.Transform", "Transform", "A collection of transformation properties.") {ExpandByDefault = true};
AnchorPointProperty = new LayerProperty<SKPoint>(this, transform, "Core.AnchorPoint", "Anchor Point", "The point at which the shape is attached to its position."); AnchorPointProperty = new LayerProperty<SKPoint>(this, transform, "Core.AnchorPoint", "Anchor Point", "The point at which the shape is attached to its position.");
PositionProperty = new LayerProperty<SKPoint>(this, transform, "Core.Position", "Position", "The position of the shape."); PositionProperty = new LayerProperty<SKPoint>(this, transform, "Core.Position", "Position", "The position of the shape.");
ScaleProperty = new LayerProperty<SKSize>(this, transform, "Core.Scale", "Scale", "The scale of the shape.") {InputAffix = "%"}; ScaleProperty = new LayerProperty<SKSize>(this, transform, "Core.Scale", "Scale", "The scale of the shape.") {InputAffix = "%"};
RotationProperty = new LayerProperty<float>(this, transform, "Core.Rotation", "Rotation", "The rotation of the shape in degrees.") {InputAffix = "°"}; RotationProperty = new LayerProperty<float>(this, transform, "Core.Rotation", "Rotation", "The rotation of the shape in degrees.") {InputAffix = "°"};
OpacityProperty = new LayerProperty<float>(this, transform, "Core.Opacity", "Opacity", "The opacity of the shape.") {InputAffix = "%"}; OpacityProperty = new LayerProperty<float>(this, transform, "Core.Opacity", "Opacity", "The opacity of the shape.") {InputAffix = "%"};
transform.Children.Add(AnchorPointProperty);
transform.Children.Add(PositionProperty);
transform.Children.Add(ScaleProperty);
transform.Children.Add(RotationProperty);
// Set default values
ShapeTypeProperty.Value = LayerShapeType.Rectangle;
FillTypeProperty.Value = LayerFillType.Stretch;
BlendModeProperty.Value = SKBlendMode.SrcOver;
ScaleProperty.Value = new SKSize(100, 100); ScaleProperty.Value = new SKSize(100, 100);
OpacityProperty.Value = 100; OpacityProperty.Value = 100;
RegisterLayerProperty(transform);
transform.Children.Add(OpacityProperty);
AddLayerProperty(shape);
foreach (var shapeProperty in shape.Children)
AddLayerProperty(shapeProperty);
AddLayerProperty(transform);
foreach (var transformProperty in transform.Children) foreach (var transformProperty in transform.Children)
AddLayerProperty(transformProperty); RegisterLayerProperty(transformProperty);
} }
#endregion #endregion
@ -512,6 +541,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 LayerPropertyRemoved;
private void OnRenderPropertiesUpdated() private void OnRenderPropertiesUpdated()
{ {
@ -524,6 +555,21 @@ namespace Artemis.Core.Models.Profile
} }
#endregion #endregion
public override string ToString()
{
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}
private void OnLayerPropertyRegistered()
{
LayerPropertyRegistered?.Invoke(this, EventArgs.Empty);
}
private void OnLayerPropertyRemoved()
{
LayerPropertyRemoved?.Invoke(this, EventArgs.Empty);
}
} }
public enum LayerShapeType public enum LayerShapeType

View File

@ -0,0 +1,21 @@
using System;
using Artemis.Core.Plugins.LayerBrush;
namespace Artemis.Core.Models.Profile
{
/// <summary>
/// A reference to a <see cref="LayerBrushDescriptor" />
/// </summary>
public class LayerBrushReference
{
/// <summary>
/// The GUID of the plugin the brush descriptor resides in
/// </summary>
public Guid BrushPluginGuid { get; set; }
/// <summary>
/// The full type name of the brush descriptor
/// </summary>
public string BrushType { get; set; }
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.KeyframeEngines; using Artemis.Core.Models.Profile.KeyframeEngines;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Utilities; using Artemis.Core.Utilities;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -13,9 +14,10 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{ {
private object _baseValue; private object _baseValue;
protected BaseLayerProperty(Layer layer, BaseLayerProperty parent, string id, string name, string description, Type type) protected BaseLayerProperty(Layer layer, PluginInfo pluginInfo, BaseLayerProperty parent, string id, string name, string description, Type type)
{ {
Layer = layer; Layer = layer;
PluginInfo = pluginInfo;
Parent = parent; Parent = parent;
Id = id; Id = id;
Name = name; Name = name;
@ -23,8 +25,14 @@ namespace Artemis.Core.Models.Profile.LayerProperties
Type = type; Type = type;
CanUseKeyframes = true; CanUseKeyframes = true;
// This can only be null if accessed internally
if (PluginInfo == null)
PluginInfo = Constants.CorePluginInfo;
Children = new List<BaseLayerProperty>(); Children = new List<BaseLayerProperty>();
BaseKeyframes = new List<BaseKeyframe>(); BaseKeyframes = new List<BaseKeyframe>();
parent?.Children.Add(this);
} }
/// <summary> /// <summary>
@ -32,6 +40,11 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// </summary> /// </summary>
public Layer Layer { get; } public Layer Layer { get; }
/// <summary>
/// Info of the plugin associated with this property
/// </summary>
public PluginInfo PluginInfo { get; }
/// <summary> /// <summary>
/// Gets the parent property of this property. /// Gets the parent property of this property.
/// </summary> /// </summary>

View File

@ -1,14 +1,73 @@
using System.Collections.ObjectModel; using System;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Artemis.Core.Plugins.Models;
namespace Artemis.Core.Models.Profile.LayerProperties namespace Artemis.Core.Models.Profile.LayerProperties
{ {
/// <summary>
/// Represents a property on the layer. This property is visible in the profile editor and can be key-framed (unless
/// opted out)
/// </summary>
/// <typeparam name="T"></typeparam>
public class LayerProperty<T> : BaseLayerProperty public class LayerProperty<T> : BaseLayerProperty
{ {
public LayerProperty(Layer layer, BaseLayerProperty parent, string id, string name, string description) : base(layer, parent, id, name, description, typeof(T)) internal LayerProperty(Layer layer, BaseLayerProperty parent, string id, string name, string description) : base(layer, null, parent, id, name, description, typeof(T))
{ {
} }
internal LayerProperty(Layer layer, string id, string name, string description) : base(layer, null, null, id, name, description, typeof(T))
{
}
/// <summary>
/// Represents a property on the layer. This property is visible in the profile editor and can be key-framed (unless
/// opted out)
/// <para>
/// Note: The value and keyframes of the property are stored using the ID, after adding the property to the layer
/// these are restored.
/// </para>
/// </summary>
/// <param name="layer">The layer the property is applied to</param>
/// <param name="pluginInfo">The plugin to create this property for</param>
/// <param name="parent">The parent of this property, use this to create a tree-hierarchy in the editor</param>
/// <param name="id">A and ID identifying your property, must be unique within your plugin</param>
/// <param name="name">A name for your property, this is visible in the editor</param>
/// <param name="description">A description for your property, this is visible in the editor</param>
public LayerProperty(Layer layer, PluginInfo pluginInfo, BaseLayerProperty parent, string id, string name, string description) : base(layer, pluginInfo, parent, id, name, description,
typeof(T))
{
if (layer == null)
throw new ArgumentNullException(nameof(layer));
if (pluginInfo == null)
throw new ArgumentNullException(nameof(pluginInfo));
if (id == null)
throw new ArgumentNullException(nameof(id));
}
/// <summary>
/// Represents a property on the layer. This property is visible in the profile editor and can be key-framed (unless
/// opted out)
/// <para>
/// Note: The value and keyframes of the property are stored using the ID, after adding the property to the layer
/// these are restored.
/// </para>
/// </summary>
/// <param name="layer">The layer the property is applied to</param>
/// <param name="pluginInfo">The plugin to create this property for</param>
/// <param name="id">A and ID identifying your property, must be unique within your plugin</param>
/// <param name="name">A name for your property, this is visible in the editor</param>
/// <param name="description">A description for your property, this is visible in the editor</param>
public LayerProperty(Layer layer, PluginInfo pluginInfo, string id, string name, string description) : base(layer, pluginInfo, null, id, name, description, typeof(T))
{
if (layer == null)
throw new ArgumentNullException(nameof(layer));
if (pluginInfo == null)
throw new ArgumentNullException(nameof(pluginInfo));
if (id == null)
throw new ArgumentNullException(nameof(id));
}
/// <summary> /// <summary>
/// Gets or sets the value of the property without any keyframes applied /// Gets or sets the value of the property without any keyframes applied
/// </summary> /// </summary>

View File

@ -1,32 +1,25 @@
using System; using System;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush namespace Artemis.Core.Plugins.LayerBrush
{ {
public abstract class LayerBrush : IDisposable public abstract class LayerBrush : IDisposable
{ {
protected LayerBrush(Layer layer, LayerBrushSettings settings, LayerBrushDescriptor descriptor) protected LayerBrush(Layer layer, LayerBrushDescriptor descriptor)
{ {
Layer = layer; Layer = layer;
Settings = settings;
Descriptor = descriptor; Descriptor = descriptor;
} }
public Layer Layer { get; } public Layer Layer { get; }
public LayerBrushSettings Settings { get; }
public LayerBrushDescriptor Descriptor { get; } public LayerBrushDescriptor Descriptor { get; }
public virtual void Dispose() public virtual void Dispose()
{ {
} }
/// <summary>
/// Called by the profile editor to populate the brush properties panel
/// </summary>
/// <returns></returns>
public abstract LayerBrushViewModel GetViewModel();
/// <summary> /// <summary>
/// Called before rendering every frame, write your update logic here /// Called before rendering every frame, write your update logic here
/// </summary> /// </summary>
@ -46,5 +39,38 @@ namespace Artemis.Core.Plugins.LayerBrush
public virtual void Render(SKCanvas canvas, SKPath path, SKPaint paint) public virtual void Render(SKCanvas canvas, SKPath path, SKPaint paint)
{ {
} }
/// <summary>
/// Provides an easy way to add your own properties to the layer, for more info see <see cref="LayerProperty{T}" />.
/// <para>Note: If found, the last value and keyframes are loaded and set when calling this method.</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="parent">The parent of this property, use this to create a tree-hierarchy in the editor</param>
/// <param name="id">A and ID identifying your property, must be unique within your plugin</param>
/// <param name="name">A name for your property, this is visible in the editor</param>
/// <param name="description">A description for your property, this is visible in the editor</param>
/// <returns>The layer property</returns>
protected LayerProperty<T> RegisterLayerProperty<T>(BaseLayerProperty parent, string id, string name, string description)
{
var property = new LayerProperty<T>(Layer, Descriptor.LayerBrushProvider.PluginInfo, parent, id, name, description);
Layer.RegisterLayerProperty(property);
return property;
}
/// <summary>
/// Provides an easy way to add your own properties to the layer, for more info see <see cref="LayerProperty{T}" />.
/// <para>Note: If found, the last value and keyframes are loaded and set when calling this method.</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id">A and ID identifying your property, must be unique within your plugin</param>
/// <param name="name">A name for your property, this is visible in the editor</param>
/// <param name="description">A description for your property, this is visible in the editor</param>
/// <returns>The layer property</returns>
protected LayerProperty<T> RegisterLayerProperty<T>(string id, string name, string description)
{
var property = new LayerProperty<T>(Layer, Descriptor.LayerBrushProvider.PluginInfo, Layer.BrushReferenceProperty.Parent, id, name, description);
Layer.RegisterLayerProperty(property);
return property;
}
} }
} }

View File

@ -1,18 +0,0 @@
using System;
using System.Xml.Serialization;
using Newtonsoft.Json;
using Stylet;
namespace Artemis.Core.Plugins.LayerBrush
{
public abstract class LayerBrushSettings : PropertyChangedBase
{
/// <summary>
/// Gets or sets the dispatcher to use to dispatch PropertyChanged events. Defaults to
/// Execute.DefaultPropertyChangedDispatcher
/// </summary>
[XmlIgnore]
[JsonIgnore]
public override Action<Action> PropertyChangedDispatcher { get; set; } = Execute.DefaultPropertyChangedDispatcher;
}
}

View File

@ -1,14 +0,0 @@
using Stylet;
namespace Artemis.Core.Plugins.LayerBrush
{
public abstract class LayerBrushViewModel : PropertyChangedBase
{
protected LayerBrushViewModel(LayerBrush brush)
{
Brush = brush;
}
public LayerBrush Brush { get; }
}
}

View File

@ -75,14 +75,9 @@ namespace Artemis.Core.RGB.NET
{ {
foreach (var renderTarget in renderTargets) foreach (var renderTarget in renderTargets)
{ {
if (renderTarget.Led.Id == LedId.Keyboard_W)
Console.WriteLine();
var scaledLocation = renderTarget.Point * Scale; var scaledLocation = renderTarget.Point * Scale;
if (scaledLocation.X < Bitmap.Width && scaledLocation.Y < Bitmap.Height) if (scaledLocation.X < Bitmap.Width && scaledLocation.Y < Bitmap.Height)
{
var test = Bitmap.GetPixel(scaledLocation.X.RoundToInt(), scaledLocation.Y.RoundToInt());
RenderedTargets[renderTarget] = Bitmap.GetPixel(scaledLocation.X.RoundToInt(), scaledLocation.Y.RoundToInt()).ToRgbColor(); RenderedTargets[renderTarget] = Bitmap.GetPixel(scaledLocation.X.RoundToInt(), scaledLocation.Y.RoundToInt()).ToRgbColor();
}
} }
} }

View File

@ -12,10 +12,8 @@ namespace Artemis.Core.Services.Interfaces
/// <see cref="LayerBrushDescriptor" /> to the provided <see cref="Layer" />. /// <see cref="LayerBrushDescriptor" /> to the provided <see cref="Layer" />.
/// </summary> /// </summary>
/// <param name="layer">The layer to add the new layer element to</param> /// <param name="layer">The layer to add the new layer element to</param>
/// <param name="brushDescriptor">The descriptor of the new layer brush</param>
/// <param name="settings">JSON settings to be deserialized and injected into the layer brush</param>
/// <returns></returns> /// <returns></returns>
LayerBrush InstantiateLayerBrush(Layer layer, LayerBrushDescriptor brushDescriptor, string settings = null); LayerBrush InstantiateLayerBrush(Layer layer);
/// <summary> /// <summary>
/// Instantiates and adds a compatible <see cref="KeyframeEngine" /> to the provided <see cref="LayerProperty{T}" /> /// Instantiates and adds a compatible <see cref="KeyframeEngine" /> to the provided <see cref="LayerProperty{T}" />

View File

@ -1,13 +1,10 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.KeyframeEngines; using Artemis.Core.Models.Profile.KeyframeEngines;
using Artemis.Core.Models.Profile.LayerProperties; using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Newtonsoft.Json;
using Ninject; using Ninject;
using Ninject.Parameters; using Ninject.Parameters;
using Serilog; using Serilog;
@ -18,57 +15,38 @@ namespace Artemis.Core.Services
{ {
private readonly IKernel _kernel; private readonly IKernel _kernel;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IPluginService _pluginService;
public LayerService(IKernel kernel, ILogger logger) public LayerService(IKernel kernel, ILogger logger, IPluginService pluginService)
{ {
_kernel = kernel; _kernel = kernel;
_logger = logger; _logger = logger;
_pluginService = pluginService;
} }
public LayerBrush InstantiateLayerBrush(Layer layer, LayerBrushDescriptor brushDescriptor, string settings) public LayerBrush InstantiateLayerBrush(Layer layer)
{ {
// Determine the settings type declared by the layer element RemoveLayerBrush(layer);
object settingsInstance = null;
var properties = brushDescriptor.LayerBrushType.GetProperties();
var settingsType = properties.FirstOrDefault(p => p.Name == "Settings" &&
p.DeclaringType == brushDescriptor.LayerBrushType)?.PropertyType;
// Deserialize the settings if provided, check for null in JSON as well var descriptorReference = layer.BrushReferenceProperty.CurrentValue;
if (settings != null && settings != "null") if (descriptorReference == null)
{ return null;
// Setting where provided but no settings type was found, something is wrong
if (settingsType == null)
{
throw new ArtemisPluginException(
brushDescriptor.LayerBrushProvider.PluginInfo,
$"Settings where provided but layer element of type {brushDescriptor.LayerBrushType.Name} has no Settings property."
);
}
try // Get a matching descriptor
{ var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>();
settingsInstance = JsonConvert.DeserializeObject(settings, settingsType); var descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList();
} var descriptor = descriptors.FirstOrDefault(d => d.LayerBrushProvider.PluginInfo.Guid == descriptorReference.BrushPluginGuid &&
catch (JsonSerializationException e) d.LayerBrushType.Name == descriptorReference.BrushType);
{
_logger.Warning(e, "Failed to deserialize settings for layer type {type}, resetting element settings - Plugin info: {pluginInfo}",
brushDescriptor.LayerBrushType.Name,
brushDescriptor.LayerBrushProvider.PluginInfo);
settingsInstance = Activator.CreateInstance(settingsType); if (descriptor == null)
} return null;
}
// If no settings found, provide a fresh instance of the settings type
else if (settingsType != null)
settingsInstance = Activator.CreateInstance(settingsType);
var arguments = new IParameter[] var arguments = new IParameter[]
{ {
new ConstructorArgument("layer", layer), new ConstructorArgument("layer", layer),
new ConstructorArgument("settings", settingsInstance), new ConstructorArgument("descriptor", descriptor)
new ConstructorArgument("descriptor", brushDescriptor)
}; };
var layerElement = (LayerBrush) _kernel.Get(brushDescriptor.LayerBrushType, arguments); var layerElement = (LayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
layer.LayerBrush = layerElement; layer.LayerBrush = layerElement;
return layerElement; return layerElement;
@ -92,10 +70,17 @@ namespace Artemis.Core.Services
return keyframeEngine; return keyframeEngine;
} }
public void RemoveLayerBrush(Layer layer, LayerBrush layerElement) public void RemoveLayerBrush(Layer layer)
{ {
if (layer.LayerBrush == null)
return;
var brush = layer.LayerBrush; var brush = layer.LayerBrush;
layer.LayerBrush = null; layer.LayerBrush = null;
var propertiesToRemove = layer.Properties.Where(l => l.PluginInfo == brush.Descriptor.LayerBrushProvider.PluginInfo).ToList();
foreach (var layerProperty in propertiesToRemove)
layer.RemoveLayerProperty(layerProperty);
brush.Dispose(); brush.Dispose();
} }
} }

View File

@ -12,8 +12,7 @@ namespace Artemis.Core.Services
internal SettingsService(IPluginSettingRepository pluginSettingRepository) internal SettingsService(IPluginSettingRepository pluginSettingRepository)
{ {
var pluginInfo = new PluginInfo {Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core"}; _pluginSettings = new PluginSettings(Constants.CorePluginInfo, pluginSettingRepository);
_pluginSettings = new PluginSettings(pluginInfo, pluginSettingRepository);
} }
public PluginSetting<T> GetSetting<T>(string name, T defaultValue = default) public PluginSetting<T> GetSetting<T>(string name, T defaultValue = default)

View File

@ -148,20 +148,9 @@ namespace Artemis.Core.Services.Storage
private void InstantiateProfileLayerBrushes(Profile profile) private void InstantiateProfileLayerBrushes(Profile profile)
{ {
var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>();
var descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList();
// Only instantiate brushes for layers without an existing brush instance // Only instantiate brushes for layers without an existing brush instance
foreach (var layer in profile.GetAllLayers().Where(l => l.LayerBrush == null && l.LayerEntity.BrushEntity != null)) foreach (var layer in profile.GetAllLayers().Where(l => l.LayerBrush == null))
{ _layerService.InstantiateLayerBrush(layer);
// Get a matching descriptor
var descriptor = descriptors.FirstOrDefault(d => d.LayerBrushProvider.PluginInfo.Guid == layer.LayerEntity.BrushEntity.BrushPluginGuid &&
d.LayerBrushType.Name == layer.LayerEntity.BrushEntity.BrushType);
// If a descriptor that matches if found, instantiate it with the GUID of the element entity
if (descriptor != null)
_layerService.InstantiateLayerBrush(layer, descriptor, layer.LayerEntity.BrushEntity.Configuration);
}
} }
private void InstantiateProfileKeyframeEngines(Profile profile) private void InstantiateProfileKeyframeEngines(Profile profile)

View File

@ -90,8 +90,6 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ColorBrushSettings.cs" />
<Compile Include="ColorBrushViewModel.cs" />
<Compile Include="ColorBrush.cs" /> <Compile Include="ColorBrush.cs" />
<Compile Include="ColorBrushProvider.cs" /> <Compile Include="ColorBrushProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@ -114,12 +112,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Page Include="ColorBrushView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View File

@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.ComponentModel;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp; using SkiaSharp;
@ -10,12 +11,15 @@ namespace Artemis.Plugins.LayerBrushes.Color
public class ColorBrush : LayerBrush public class ColorBrush : LayerBrush
{ {
private readonly List<SKColor> _testColors; private readonly List<SKColor> _testColors;
private SKColor _color;
private SKPaint _paint; private SKPaint _paint;
private SKShader _shader; private SKShader _shader;
public ColorBrush(Layer layer, ColorBrushSettings settings, LayerBrushDescriptor descriptor) : base(layer, settings, descriptor) public ColorBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
{ {
Settings = settings; ColorProperty = RegisterLayerProperty<SKColor>("Brush.Color", "Main color", "The color of the brush.");
GradientTypeProperty = RegisterLayerProperty<GradientType>("Brush.GradientType", "Gradient type", "The scale of the noise.");
GradientTypeProperty.CanUseKeyframes = false;
_testColors = new List<SKColor>(); _testColors = new List<SKColor>();
for (var i = 0; i < 9; i++) for (var i = 0; i < 9; i++)
@ -28,19 +32,19 @@ namespace Artemis.Plugins.LayerBrushes.Color
CreateShader(); CreateShader();
Layer.RenderPropertiesUpdated += (sender, args) => CreateShader(); Layer.RenderPropertiesUpdated += (sender, args) => CreateShader();
Settings.PropertyChanged += (sender, args) => CreateShader();
} }
public new ColorBrushSettings Settings { get; } public LayerProperty<SKColor> ColorProperty { get; set; }
public LayerProperty<GradientType> GradientTypeProperty { get; set; }
private void CreateShader() private void CreateShader()
{ {
var center = new SKPoint(Layer.Bounds.MidX, Layer.Bounds.MidY); var center = new SKPoint(Layer.Bounds.MidX, Layer.Bounds.MidY);
SKShader shader; SKShader shader;
switch (Settings.GradientType) switch (GradientTypeProperty.CurrentValue)
{ {
case GradientType.Solid: case GradientType.Solid:
shader = SKShader.CreateColor(_testColors.First()); shader = SKShader.CreateColor(_color);
break; break;
case GradientType.LinearGradient: case GradientType.LinearGradient:
shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(Layer.Bounds.Width, 0), _testColors.ToArray(), SKShaderTileMode.Repeat); shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(Layer.Bounds.Width, 0), _testColors.ToArray(), SKShaderTileMode.Repeat);
@ -63,9 +67,16 @@ namespace Artemis.Plugins.LayerBrushes.Color
oldPaint?.Dispose(); oldPaint?.Dispose();
} }
public override LayerBrushViewModel GetViewModel() public override void Update(double deltaTime)
{ {
return new ColorBrushViewModel(this); // Only recreate the shader if the color changed
if (_color != ColorProperty.CurrentValue)
{
_color = ColorProperty.CurrentValue;
CreateShader();
}
base.Update(deltaTime);
} }
public override void Render(SKCanvas canvas, SKPath path, SKPaint paint) public override void Render(SKCanvas canvas, SKPath path, SKPaint paint)
@ -74,4 +85,19 @@ namespace Artemis.Plugins.LayerBrushes.Color
canvas.DrawPath(path, paint); canvas.DrawPath(path, paint);
} }
} }
public enum GradientType
{
[Description("Solid")]
Solid,
[Description("Linear Gradient")]
LinearGradient,
[Description("Radial Gradient")]
RadialGradient,
[Description("Sweep Gradient")]
SweepGradient
}
} }

View File

@ -1,46 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel;
using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp;
namespace Artemis.Plugins.LayerBrushes.Color
{
public class ColorBrushSettings : LayerBrushSettings
{
private List<SKColor> _colors;
private GradientType _gradientType;
public ColorBrushSettings()
{
GradientType = GradientType.Solid;
Colors = new List<SKColor>();
}
public GradientType GradientType
{
get => _gradientType;
set => SetAndNotify(ref _gradientType, value);
}
public List<SKColor> Colors
{
get => _colors;
set => SetAndNotify(ref _colors, value);
}
}
public enum GradientType
{
[Description("Solid")]
Solid,
[Description("Linear Gradient")]
LinearGradient,
[Description("Radial Gradient")]
RadialGradient,
[Description("Sweep Gradient")]
SweepGradient
}
}

View File

@ -1,134 +0,0 @@
<UserControl x:Class="Artemis.Plugins.LayerBrushes.Color.ColorBrushView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:colorBrush="clr-namespace:Artemis.Plugins.LayerBrushes.Color"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type colorBrush:ColorBrushViewModel}}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Teal.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Teal.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Brush type -->
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">Brush type</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ComboBox HorizontalAlignment="Left"
ItemsSource="{Binding Path=BrushTypes}"
SelectedValuePath="Value"
DisplayMemberPath="Description"
SelectedValue="{Binding Path=ColorBrush.Settings.GradientType}" />
</StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid>
<!-- Sample 1 -->
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">Setting title</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}">Setting subtitle</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="Default ToggleButton Style" />
</StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid>
<!-- Sample 1 -->
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">Setting title</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}">Setting subtitle</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="Default ToggleButton Style" />
</StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid>
<!-- Setting 2 -->
<Grid Grid.Row="4">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">Setting title</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}">Setting subtitle</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="Default ToggleButton Style" />
</StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid>
<!-- Setting 2 -->
<Grid Grid.Row="5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">Setting title</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}">Setting subtitle</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" ToolTip="Default ToggleButton Style" />
</StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid>
</Grid>
</UserControl>

View File

@ -1,17 +0,0 @@
using System.Collections.Generic;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.UI.Shared.Utilities;
namespace Artemis.Plugins.LayerBrushes.Color
{
public class ColorBrushViewModel : LayerBrushViewModel
{
public ColorBrushViewModel(ColorBrush element) : base(element)
{
ColorBrush = element;
}
public ColorBrush ColorBrush { get; }
public IEnumerable<ValueDescription> BrushTypes => EnumUtilities.GetAllValuesAndDescriptions(typeof(GradientType));
}
}

View File

@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<ShouldIncludeNativeSkiaSharp>false</ShouldIncludeNativeSkiaSharp> <ShouldIncludeNativeSkiaSharp>false</ShouldIncludeNativeSkiaSharp>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp> <NuGetPackageImportStamp>
</NuGetPackageImportStamp> </NuGetPackageImportStamp>
@ -90,8 +90,6 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="NoiseBrushSettings.cs" />
<Compile Include="NoiseBrushViewModel.cs" />
<Compile Include="NoiseBrush.cs" /> <Compile Include="NoiseBrush.cs" />
<Compile Include="NoiseBrushProvider.cs" /> <Compile Include="NoiseBrushProvider.cs" />
<Compile Include="Utilities\OpenSimplexNoise.cs" /> <Compile Include="Utilities\OpenSimplexNoise.cs" />
@ -115,12 +113,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Page Include="NoiseBrushView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View File

@ -1,5 +1,6 @@
using System; using System;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Plugins.LayerBrushes.Noise.Utilities; using Artemis.Plugins.LayerBrushes.Noise.Utilities;
using SkiaSharp; using SkiaSharp;
@ -13,20 +14,25 @@ namespace Artemis.Plugins.LayerBrushes.Noise
private readonly OpenSimplexNoise _noise; private readonly OpenSimplexNoise _noise;
private float _z; private float _z;
public NoiseBrush(Layer layer, NoiseBrushSettings settings, LayerBrushDescriptor descriptor) : base(layer, settings, descriptor) public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
{ {
Settings = settings; MainColorProperty = RegisterLayerProperty<SKColor>("Brush.MainColor", "Main color", "The main color of the noise.");
ScaleProperty = RegisterLayerProperty<SKSize>("Brush.Scale", "Scale", "The scale of the noise.");
AnimationSpeedProperty = RegisterLayerProperty<float>("Brush.AnimationSpeed", "Animation speed", "The speed at which the noise moves.");
ScaleProperty.InputAffix = "%";
_z = Rand.Next(0, 4096); _z = Rand.Next(0, 4096);
_noise = new OpenSimplexNoise(Rand.Next(0, 4096)); _noise = new OpenSimplexNoise(Rand.Next(0, 4096));
} }
public new NoiseBrushSettings Settings { get; } public LayerProperty<SKColor> MainColorProperty { get; set; }
public LayerProperty<SKSize> ScaleProperty { get; set; }
public LayerProperty<float> AnimationSpeedProperty { get; set; }
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
// TODO: Come up with a better way to use deltaTime // TODO: Come up with a better way to use deltaTime
_z += Settings.AnimationSpeed / 500f / 0.04f * (float) deltaTime; _z += AnimationSpeedProperty.CurrentValue / 500f / 0.04f * (float) deltaTime;
if (_z >= float.MaxValue) if (_z >= float.MaxValue)
_z = 0; _z = 0;
@ -34,17 +40,15 @@ namespace Artemis.Plugins.LayerBrushes.Noise
base.Update(deltaTime); base.Update(deltaTime);
} }
public override LayerBrushViewModel GetViewModel()
{
return new NoiseBrushViewModel(this);
}
public override void Render(SKCanvas canvas, SKPath path, SKPaint paint) public override void Render(SKCanvas canvas, SKPath path, SKPaint paint)
{ {
var mainColor = MainColorProperty.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);
var height = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / Scale); var height = (int) (Math.Max(path.Bounds.Width, path.Bounds.Height) / Scale);
var opacity = (float) Math.Round(Settings.Color.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)))
{ {
bitmap.Erase(new SKColor(0, 0, 0, 0)); bitmap.Erase(new SKColor(0, 0, 0, 0));
@ -60,15 +64,14 @@ namespace Artemis.Plugins.LayerBrushes.Noise
{ {
for (var y = yStart; y < yEnd; y++) for (var y = yStart; y < yEnd; y++)
{ {
var v = _noise.Evaluate(Settings.XScale * x / width, Settings.YScale * y / height, _z); var v = _noise.Evaluate(scale.Width * x / width, scale.Height * y / height, _z);
var alpha = (byte) ((v + 1) * 127 * opacity); var alpha = (byte) ((v + 1) * 127 * opacity);
// There's some fun stuff we can do here, like creating hard lines // There's some fun stuff we can do here, like creating hard lines
// if (alpha > 128) // if (alpha > 128)
// alpha = 255; // alpha = 255;
// else // else
// alpha = 0; // alpha = 0;
var color = new SKColor(Settings.Color.Red, Settings.Color.Green, Settings.Color.Blue, alpha); bitmap.SetPixel((int) x, (int) y, new SKColor(mainColor.Red, mainColor.Green, mainColor.Blue, alpha));
bitmap.SetPixel((int) x, (int) y, color);
} }
} }
} }

View File

@ -1,44 +0,0 @@
using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp;
namespace Artemis.Plugins.LayerBrushes.Noise
{
public class NoiseBrushSettings : LayerBrushSettings
{
private float _animationSpeed;
private SKBlendMode _blendMode;
private SKColor _color;
private float _xScale;
private float _yScale;
public SKColor Color
{
get => _color;
set => SetAndNotify(ref _color, value);
}
public SKBlendMode BlendMode
{
get => _blendMode;
set => SetAndNotify(ref _blendMode, value);
}
public float XScale
{
get => _xScale;
set => SetAndNotify(ref _xScale, value);
}
public float YScale
{
get => _yScale;
set => SetAndNotify(ref _yScale, value);
}
public float AnimationSpeed
{
get => _animationSpeed;
set => SetAndNotify(ref _animationSpeed, value);
}
}
}

View File

@ -1,140 +0,0 @@
<UserControl x:Class="Artemis.Plugins.LayerBrushes.Noise.NoiseBrushView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
xmlns:noiseBrush="clr-namespace:Artemis.Plugins.LayerBrushes.Noise"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type noiseBrush:NoiseBrushViewModel}}">
<!-- <UserControl.Resources> -->
<!-- <ResourceDictionary> -->
<!-- <ResourceDictionary.MergedDictionaries> -->
<!-- <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> -->
<!-- </ResourceDictionary.MergedDictionaries> -->
<!-- <converters:SKColorToColorConverter x:Key="SKColorToColorConverter" /> -->
<!-- </ResourceDictionary> -->
<!-- </UserControl.Resources> -->
<!-- -->
<!-- <Grid Margin="12"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- <RowDefinition Height="Auto" /> -->
<!-- </Grid.RowDefinitions> -->
<!-- -->
<!-- <Grid Grid.Row="0"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Text="Noise color" /> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <artemis:ColorPicker Color="{Binding Brush.Settings.Color, Converter={StaticResource SKColorToColorConverter}}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- <Grid Grid.Row="1"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="Blend mode" /> -->
<!-- </TextBlock> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"> -->
<!-- <Run Text="Affects how the noise is rendered on the rest of the layer" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <ComboBox HorizontalAlignment="Left" -->
<!-- ItemsSource="{Binding BlendModes}" -->
<!-- SelectedValuePath="Value" -->
<!-- DisplayMemberPath="Description" -->
<!-- Width="100" -->
<!-- SelectedValue="{Binding Brush.Settings.BlendMode}" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- <Grid Grid.Row="2"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="X Scale" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding Brush.Settings.XScale}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- ~1~ Sample 1 @1@ -->
<!-- <Grid Grid.Row="3"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="Y Scale" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- <Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding Brush.Settings.YScale}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- -->
<!-- ~1~ Setting 2 @1@ -->
<!-- <Grid Grid.Row="4"> -->
<!-- <Grid.RowDefinitions> -->
<!-- <RowDefinition /> -->
<!-- <RowDefinition /> -->
<!-- </Grid.RowDefinitions> -->
<!-- <Grid.ColumnDefinitions> -->
<!-- <ColumnDefinition Width="*" /> -->
<!-- <ColumnDefinition Width="Auto" /> -->
<!-- </Grid.ColumnDefinitions> -->
<!-- <StackPanel Grid.Column="0" VerticalAlignment="Center"> -->
<!-- <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> -->
<!-- <Run Text="Animation speed" /> -->
<!-- </TextBlock> -->
<!-- </StackPanel> -->
<!-- <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> -->
<!-- -->
<!-- <Slider Orientation="Horizontal" TickFrequency="1" Minimum="1" Maximum="100" Value="{Binding Brush.Settings.AnimationSpeed}" Width="100" /> -->
<!-- </StackPanel> -->
<!-- <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> -->
<!-- </Grid> -->
<!-- </Grid> -->
</UserControl>

View File

@ -1,18 +0,0 @@
using System.Collections.Generic;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.UI.Shared.Utilities;
using SkiaSharp;
namespace Artemis.Plugins.LayerBrushes.Noise
{
public class NoiseBrushViewModel : LayerBrushViewModel
{
public NoiseBrushViewModel(NoiseBrush brush) : base(brush)
{
Brush = brush;
}
public new NoiseBrush Brush { get; }
public IEnumerable<ValueDescription> BlendModes => EnumUtilities.GetAllValuesAndDescriptions(typeof(SKBlendMode));
}
}

View File

@ -23,8 +23,6 @@ namespace Artemis.Storage.Entities.Profile
public List<PropertyEntity> PropertyEntities { get; set; } public List<PropertyEntity> PropertyEntities { get; set; }
public List<ProfileConditionEntity> Condition { get; set; } public List<ProfileConditionEntity> Condition { get; set; }
public BrushEntity BrushEntity { get; set; }
[BsonRef("ProfileEntity")] [BsonRef("ProfileEntity")]
public ProfileEntity Profile { get; set; } public ProfileEntity Profile { get; set; }

View File

@ -89,15 +89,24 @@
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Grid HorizontalAlignment="Stretch"> <Grid HorizontalAlignment="Stretch">
<!-- Style="{StaticResource MaterialDesignFloatingHintTextBox}" -->
<!-- Padding="0 0 10 0" -->
<TextBox x:Name="ColorCodeTextBox" <TextBox x:Name="ColorCodeTextBox"
materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
Text="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource ColorToStringConverter}}" Text="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource ColorToStringConverter}}"
MinWidth="95" MinWidth="95"
Padding="0 0 10 0" MaxLength="9"
Margin="0"
Padding="-1"
HorizontalAlignment="Stretch" /> HorizontalAlignment="Stretch" />
<Border Width="15" Height="15" CornerRadius="15" Margin="0,0,0,5" VerticalAlignment="Bottom" HorizontalAlignment="Right" Background="{StaticResource Checkerboard}"> <Border Width="15"
Height="15"
CornerRadius="15"
Margin="0,0,0,2"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Background="{StaticResource Checkerboard}">
<Ellipse Stroke="{DynamicResource NormalBorderBrush}" Cursor="Hand" MouseUp="UIElement_OnMouseUp"> <Ellipse Stroke="{DynamicResource NormalBorderBrush}" Cursor="Hand" MouseUp="UIElement_OnMouseUp">
<Ellipse.Fill> <Ellipse.Fill>
<SolidColorBrush Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=OneWay}" /> <SolidColorBrush Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=OneWay}" />

View File

@ -169,6 +169,10 @@
</Compile> </Compile>
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\LayerPropertiesViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\LayerPropertiesViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\LayerPropertyViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\LayerPropertyViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\BrushPropertyInputView.xaml.cs">
<DependentUpon>BrushPropertyInputView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\BrushPropertyInputViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\EnumPropertyInputView.xaml.cs"> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\EnumPropertyInputView.xaml.cs">
<DependentUpon>EnumPropertyInputView.xaml</DependentUpon> <DependentUpon>EnumPropertyInputView.xaml</DependentUpon>
</Compile> </Compile>
@ -176,6 +180,10 @@
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\FloatPropertyInputViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\FloatPropertyInputViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\IntPropertyInputViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\IntPropertyInputViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\PropertyInputViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\PropertyInputViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKColorPropertyInputView.xaml.cs">
<DependentUpon>SKColorPropertyInputView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKColorPropertyInputViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKPointPropertyInputViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKPointPropertyInputViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKSizePropertyInputViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKSizePropertyInputViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyTreeChildViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyTreeChildViewModel.cs" />
@ -302,6 +310,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\BrushPropertyInputView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\EnumPropertyInputView.xaml"> <Page Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\EnumPropertyInputView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -314,6 +326,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKColorPropertyInputView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKPointPropertyInputView.xaml"> <Page Include="Screens\Module\ProfileEditor\LayerProperties\PropertyTree\PropertyInput\SKPointPropertyInputView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -15,11 +15,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
// Keeping the scroll viewers in sync is up to the view, not a viewmodel concern // Keeping the scroll viewers in sync is up to the view, not a viewmodel concern
private void TimelineScrollChanged(object sender, ScrollChangedEventArgs e) private void TimelineScrollChanged(object sender, ScrollChangedEventArgs e)
{ {
if (sender == TimelineHeaderScrollViewer) if (e.OriginalSource == TimelineHeaderScrollViewer)
TimelineRailsScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset); TimelineRailsScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset);
else if (sender == PropertyTreeScrollViewer) else if (e.OriginalSource == PropertyTreeScrollViewer)
TimelineRailsScrollViewer.ScrollToVerticalOffset(e.VerticalOffset); TimelineRailsScrollViewer.ScrollToVerticalOffset(e.VerticalOffset);
else if (sender == TimelineRailsScrollViewer) else if (e.OriginalSource == TimelineRailsScrollViewer)
{ {
TimelineHeaderScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset); TimelineHeaderScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset);
PropertyTreeScrollViewer.ScrollToVerticalOffset(e.VerticalOffset); PropertyTreeScrollViewer.ScrollToVerticalOffset(e.VerticalOffset);

View File

@ -41,6 +41,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
PopulateProperties(); PopulateProperties();
_profileEditorService.SelectedProfileElementChanged += (sender, args) => PopulateProperties(); _profileEditorService.SelectedProfileElementChanged += (sender, args) => PopulateProperties();
_profileEditorService.SelectedProfileChanged += (sender, args) => PopulateProperties();
_profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged; _profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged;
} }

View File

@ -0,0 +1,28 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.BrushPropertyInputView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 0" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<ComboBox Width="132"
Margin="0 2"
Padding="0 -1"
Height="15"
materialDesign:ValidationAssist.UsePopup="True"
HorizontalAlignment="Left"
ItemsSource="{Binding Path=EnumValues}"
SelectedValuePath="Value"
DisplayMemberPath="Description"
SelectedValue="{Binding Path=BrushInputValue}"
RequestBringIntoView="{s:Action OnRequestBringIntoView}"
materialDesign:ComboBoxAssist.ClassicMode="True">
</ComboBox>
<TextBlock Margin="5 0 0 0" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
{
/// <summary>
/// Interaction logic for BrushPropertyInputView.xaml
/// </summary>
public partial class BrushPropertyInputView : UserControl
{
public BrushPropertyInputView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Utilities;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
{
public class BrushPropertyInputViewModel : PropertyInputViewModel
{
private readonly ILayerService _layerService;
private readonly IPluginService _pluginService;
public BrushPropertyInputViewModel(IProfileEditorService profileEditorService, ILayerService layerService, IPluginService pluginService) : base(profileEditorService)
{
_layerService = layerService;
_pluginService = pluginService;
EnumValues = new BindableCollection<ValueDescription>();
_pluginService.PluginLoaded += (sender, args) => UpdateEnumValues();
}
public BindableCollection<ValueDescription> EnumValues { get; }
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(LayerBrushReference)};
public LayerBrushReference BrushInputValue
{
get => (LayerBrushReference) InputValue;
set
{
InputValue = value;
_layerService.InstantiateLayerBrush(LayerPropertyViewModel.LayerProperty.Layer);
}
}
protected override void OnInitialized()
{
UpdateEnumValues();
base.OnInitialized();
}
public void UpdateEnumValues()
{
var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>();
var descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList();
EnumValues.Clear();
foreach (var layerBrushDescriptor in descriptors)
{
var brushName = layerBrushDescriptor.LayerBrushType.Name;
var brushGuid = layerBrushDescriptor.LayerBrushProvider.PluginInfo.Guid;
if (BrushInputValue != null && BrushInputValue.BrushType == brushName && BrushInputValue.BrushPluginGuid == brushGuid)
EnumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = BrushInputValue});
else
EnumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = new LayerBrushReference {BrushType = brushName, BrushPluginGuid = brushGuid}});
}
}
public override void Update()
{
NotifyOfPropertyChange(() => BrushInputValue);
}
}
}

View File

@ -23,11 +23,6 @@
SelectedValue="{Binding Path=EnumInputValue}" SelectedValue="{Binding Path=EnumInputValue}"
RequestBringIntoView="{s:Action OnRequestBringIntoView}" RequestBringIntoView="{s:Action OnRequestBringIntoView}"
materialDesign:ComboBoxAssist.ClassicMode="True"> materialDesign:ComboBoxAssist.ClassicMode="True">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem" BasedOn="{StaticResource MaterialDesignComboBoxItemStyle}">
<EventSetter Event="RequestBringIntoView" Handler="OnRequestBringIntoView"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox> </ComboBox>
<TextBlock Margin="5 0 0 0" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" /> <TextBlock Margin="5 0 0 0" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
</StackPanel> </StackPanel>

View File

@ -24,10 +24,5 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
{ {
InitializeComponent(); InitializeComponent();
} }
private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
e.Handled = true;
}
} }
} }

View File

@ -0,0 +1,25 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.SKColorPropertyInputView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:SKColorPropertyInputViewModel}">
<UserControl.Resources>
<converters:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 0" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<artemis:ColorPicker Width="132"
Margin="0 2"
Padding="0 -1"
Color="{Binding SKColorInputValue, Converter={StaticResource SKColorToColorConverter}}" />
<TextBlock Margin="5 0 0 0" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
{
/// <summary>
/// Interaction logic for SKColorPropertyInputView.xaml
/// </summary>
public partial class SKColorPropertyInputView : UserControl
{
public SKColorPropertyInputView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Artemis.UI.Services.Interfaces;
using SkiaSharp;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
{
public class SKColorPropertyInputViewModel : PropertyInputViewModel
{
public SKColorPropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
{
}
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKColor)};
public SKColor SKColorInputValue
{
get => (SKColor?) InputValue ?? new SKColor();
set => InputValue = value;
}
public override void Update()
{
NotifyOfPropertyChange(() => SKColorInputValue);
}
}
}

View File

@ -16,12 +16,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
public override void Update(bool forceUpdate) public override void Update(bool forceUpdate)
{ {
if (forceUpdate) if (forceUpdate)
PropertyInputViewModel.Update(); PropertyInputViewModel?.Update();
else else
{ {
// Only update if visible and if keyframes are enabled // Only update if visible and if keyframes are enabled
if (LayerPropertyViewModel.Parent.IsExpanded && LayerPropertyViewModel.KeyframesEnabled) if (LayerPropertyViewModel.Parent.IsExpanded && LayerPropertyViewModel.KeyframesEnabled)
PropertyInputViewModel.Update(); PropertyInputViewModel?.Update();
} }
} }
} }

View File

@ -91,10 +91,10 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Rectangle Grid.Row="0" Grid.Column="0" Fill="{DynamicResource MaterialDesignPaper}" /> <Rectangle Grid.Row="0" Grid.Column="0" Fill="Black" Opacity="0.15" />
<Rectangle Grid.Row="0" Grid.Column="1" /> <Rectangle Grid.Row="0" Grid.Column="1" />
<Rectangle Grid.Row="1" Grid.Column="0" /> <Rectangle Grid.Row="1" Grid.Column="0" />
<Rectangle Grid.Row="1" Grid.Column="1" Fill="{DynamicResource MaterialDesignPaper}" /> <Rectangle Grid.Row="1" Grid.Column="1" Fill="Black" Opacity="0.15" />
</Grid> </Grid>
</VisualBrush.Visual> </VisualBrush.Visual>
</VisualBrush> </VisualBrush>