mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Data bindings - Added binding apply logic to the layer properties
Data bindings - Expanded to support inner layer properties
This commit is contained in:
1 parent
5f34c8afac
commit
ea98c6114a
12 files changed
+191
-29
No files matched your search
@@ -10,6 +10,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public abstract class BaseLayerProperty
|
||||
{
|
||||
private readonly List<DataBinding> _dataBindings = new List<DataBinding>();
|
||||
private bool _isHidden;
|
||||
private bool _keyframesEnabled;
|
||||
|
||||
@@ -30,7 +31,17 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets whether keyframes are supported on this type of property
|
||||
/// </summary>
|
||||
public bool KeyframesSupported { get; protected internal set; } = true;
|
||||
public bool KeyframesSupported { get; protected internal set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether data bindings are supported on this type of property
|
||||
/// </summary>
|
||||
public bool DataBindingsSupported { get; protected internal set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection of the currently applied data bindings
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<DataBinding> DataBindings => _dataBindings.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether keyframes are enabled on this property, has no effect if <see cref="KeyframesSupported" /> is
|
||||
@@ -99,6 +110,12 @@ namespace Artemis.Core
|
||||
/// <returns></returns>
|
||||
public abstract List<PropertyInfo> GetDataBindingProperties();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the provided data binding must be applied to a property
|
||||
/// </summary>
|
||||
/// <param name="dataBinding"></param>
|
||||
protected abstract void ApplyDataBinding(DataBinding dataBinding);
|
||||
|
||||
/// <summary>
|
||||
/// Applies the provided property entity to the layer property by deserializing the JSON base value and keyframe values
|
||||
/// </summary>
|
||||
@@ -113,6 +130,19 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
internal abstract void ApplyToEntity();
|
||||
|
||||
#region Data bindings
|
||||
|
||||
/// <summary>
|
||||
/// Applies the current <see cref="DataBindings" /> to the layer property
|
||||
/// </summary>
|
||||
public void ApplyDataBindings()
|
||||
{
|
||||
foreach (var dataBinding in DataBindings)
|
||||
ApplyDataBinding(dataBinding);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -178,12 +178,6 @@ namespace Artemis.Core
|
||||
return typeof(T);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override List<PropertyInfo> GetDataBindingProperties()
|
||||
{
|
||||
return new List<PropertyInfo> {GetType().GetProperty(nameof(CurrentValue))};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every update (if keyframes are both supported and enabled) to determine the new <see cref="CurrentValue" />
|
||||
/// based on the provided progress
|
||||
@@ -234,6 +228,7 @@ namespace Artemis.Core
|
||||
_keyframes = _keyframes.OrderBy(k => k.Position).ToList();
|
||||
}
|
||||
|
||||
|
||||
internal override void ApplyToLayerProperty(PropertyEntity entity, LayerPropertyGroup layerPropertyGroup, bool fromStorage)
|
||||
{
|
||||
// Doubt this will happen but let's make sure
|
||||
@@ -289,5 +284,23 @@ namespace Artemis.Core
|
||||
EasingFunction = (int) k.EasingFunction
|
||||
}));
|
||||
}
|
||||
|
||||
#region Data bindings
|
||||
|
||||
/// <inheritdoc />
|
||||
public override List<PropertyInfo> GetDataBindingProperties()
|
||||
{
|
||||
return new List<PropertyInfo> {GetType().GetProperty(nameof(CurrentValue))};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void ApplyDataBinding(DataBinding dataBinding)
|
||||
{
|
||||
// The default implementation only supports simple types
|
||||
if (dataBinding.TargetProperty.DeclaringType == GetType())
|
||||
CurrentValue = (T) dataBinding.GetValue(CurrentValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace Artemis.Core
|
||||
internal ColorGradientLayerProperty()
|
||||
{
|
||||
KeyframesSupported = false;
|
||||
DataBindingsSupported = false;
|
||||
}
|
||||
|
||||
public static implicit operator ColorGradient(ColorGradientLayerProperty p)
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Artemis.Core
|
||||
public EnumLayerProperty()
|
||||
{
|
||||
KeyframesSupported = false;
|
||||
DataBindingsSupported = false;
|
||||
}
|
||||
|
||||
public static implicit operator T(EnumLayerProperty<T> p)
|
||||
|
||||
+1
@@ -8,6 +8,7 @@
|
||||
internal LayerBrushReferenceLayerProperty()
|
||||
{
|
||||
KeyframesSupported = false;
|
||||
DataBindingsSupported = false;
|
||||
}
|
||||
|
||||
public static implicit operator LayerBrushReference(LayerBrushReferenceLayerProperty p)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
@@ -10,19 +13,44 @@ namespace Artemis.Core
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts an <see cref="SKColorLayerProperty" /> to an <see cref="SKColor" />
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
/// <returns></returns>
|
||||
public static implicit operator SKColor(SKColorLayerProperty p)
|
||||
{
|
||||
return p.CurrentValue;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||
{
|
||||
CurrentValue = CurrentKeyframe.Value.Interpolate(NextKeyframe.Value, keyframeProgressEased);
|
||||
}
|
||||
|
||||
private static byte ClampToByte(float value)
|
||||
/// <inheritdoc />
|
||||
public override List<PropertyInfo> GetDataBindingProperties()
|
||||
{
|
||||
return (byte) Math.Max(0, Math.Min(255, value));
|
||||
return typeof(SKColor).GetProperties().ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void ApplyDataBinding(DataBinding dataBinding)
|
||||
{
|
||||
if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Alpha))
|
||||
CurrentValue = CurrentValue.WithAlpha((byte) dataBinding.GetValue(BaseValue.Alpha));
|
||||
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Red))
|
||||
CurrentValue = CurrentValue.WithRed((byte) dataBinding.GetValue(BaseValue.Red));
|
||||
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Green))
|
||||
CurrentValue = CurrentValue.WithGreen((byte) dataBinding.GetValue(BaseValue.Green));
|
||||
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Blue))
|
||||
CurrentValue = CurrentValue.WithBlue((byte) dataBinding.GetValue(BaseValue.Blue));
|
||||
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Hue))
|
||||
{
|
||||
CurrentValue.ToHsv(out var h, out var s, out var v);
|
||||
CurrentValue = SKColor.FromHsv((float) dataBinding.GetValue(h), s, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using SkiaSharp;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -8,17 +11,36 @@ namespace Artemis.Core
|
||||
internal SKPointLayerProperty()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts an <see cref="SKPointLayerProperty" /> to an <see cref="SKPoint" />
|
||||
/// </summary>
|
||||
public static implicit operator SKPoint(SKPointLayerProperty p)
|
||||
{
|
||||
return p.CurrentValue;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||
{
|
||||
var xDiff = NextKeyframe.Value.X - CurrentKeyframe.Value.X;
|
||||
var yDiff = NextKeyframe.Value.Y - CurrentKeyframe.Value.Y;
|
||||
CurrentValue = new SKPoint(CurrentKeyframe.Value.X + xDiff * keyframeProgressEased, CurrentKeyframe.Value.Y + yDiff * keyframeProgressEased);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override List<PropertyInfo> GetDataBindingProperties()
|
||||
{
|
||||
return typeof(SKPoint).GetProperties().Where(p => p.CanWrite).ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void ApplyDataBinding(DataBinding dataBinding)
|
||||
{
|
||||
if (dataBinding.TargetProperty.Name == nameof(CurrentValue.X))
|
||||
CurrentValue = new SKPoint((float) dataBinding.GetValue(BaseValue), CurrentValue.Y);
|
||||
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Y))
|
||||
CurrentValue = new SKPoint(CurrentValue.X, (float) dataBinding.GetValue(BaseValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,21 +12,35 @@ namespace Artemis.Core
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts an <see cref="SKSizeLayerProperty" /> to an <see cref="SKSize" />
|
||||
/// </summary>
|
||||
public static implicit operator SKSize(SKSizeLayerProperty p)
|
||||
{
|
||||
return p.CurrentValue;
|
||||
}
|
||||
|
||||
public override List<PropertyInfo> GetDataBindingProperties()
|
||||
{
|
||||
return typeof(SKSize).GetProperties().Where(p => p.CanWrite).ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||
{
|
||||
var widthDiff = NextKeyframe.Value.Width - CurrentKeyframe.Value.Width;
|
||||
var heightDiff = NextKeyframe.Value.Height - CurrentKeyframe.Value.Height;
|
||||
CurrentValue = new SKSize(CurrentKeyframe.Value.Width + widthDiff * keyframeProgressEased, CurrentKeyframe.Value.Height + heightDiff * keyframeProgressEased);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override List<PropertyInfo> GetDataBindingProperties()
|
||||
{
|
||||
return typeof(SKSize).GetProperties().Where(p => p.CanWrite).ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void ApplyDataBinding(DataBinding dataBinding)
|
||||
{
|
||||
if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Height))
|
||||
CurrentValue = new SKSize(CurrentValue.Width, (float) dataBinding.GetValue(BaseValue));
|
||||
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Width))
|
||||
CurrentValue = new SKSize((float) dataBinding.GetValue(BaseValue), CurrentValue.Width);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user