Data bindings - Highlight current property

Data bindings - Disable data-bound property inputs
Data bindings - Use toggle to indicate data bindings being enabled
This commit is contained in:
SpoinkyNL committed 2020-09-15 23:18:21 +02:00
1 parent 2ac81e7f74
commit 9373d15715
29 files changed
+295 -58

No files matched your search

@@ -27,6 +27,16 @@ namespace Artemis.Core
);
}
public static SKColor Sum(this SKColor a, SKColor b)
{
return new SKColor(
ClampToByte(a.Red + b.Red),
ClampToByte(a.Green + b.Green),
ClampToByte(a.Blue + b.Blue),
ClampToByte(a.Alpha + b.Alpha)
);
}
private static byte ClampToByte(float value)
{
return (byte) Math.Clamp(value, 0, 255);
@@ -0,0 +1,20 @@
using SkiaSharp;
namespace Artemis.Core
{
/// <inheritdoc />
public class SKColorDataBindingConverter : DataBindingConverter<SKColor, SKColor>
{
/// <inheritdoc />
public override SKColor Sum(SKColor a, SKColor b)
{
return a.Sum(b);
}
/// <inheritdoc />
public override SKColor Interpolate(SKColor a, SKColor b, double progress)
{
return a.Interpolate(b, (float)progress);
}
}
}
@@ -40,12 +40,18 @@ namespace Artemis.Core
/// <para><c>null</c> if the <see cref="PropertyExpression" /> is not a member expression</para>
/// </summary>
public MemberInfo Member { get; }
/// <summary>
/// Gets the data binding created using this registration
/// </summary>
public DataBinding<TLayerProperty, TProperty> DataBinding { get; internal set; }
/// <inheritdoc />
public IDataBinding GetDataBinding()
{
return DataBinding;
}
/// <inheritdoc />
public IDataBinding CreateDataBinding()
{
@@ -1,12 +1,17 @@
namespace Artemis.Core
{
/// <summary>
/// Represents a data binding registration
/// Represents a data binding registration
/// </summary>
public interface IDataBindingRegistration
{
/// <summary>
/// If found, creates a data binding from storage
/// Returns the data binding applied using this registration
/// </summary>
public IDataBinding GetDataBinding();
/// <summary>
/// If found, creates a data binding from storage
/// </summary>
/// <returns></returns>
IDataBinding CreateDataBinding();
@@ -13,6 +13,11 @@ namespace Artemis.Core
/// </summary>
public interface ILayerProperty : IStorageModel, IUpdateModel, IDisposable
{
/// <summary>
/// Gets the description attribute applied to this property
/// </summary>
public PropertyDescriptionAttribute PropertyDescription { get; }
/// <summary>
/// Initializes the layer property
/// <para>
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json;
@@ -28,9 +27,7 @@ namespace Artemis.Core
_keyframes = new List<LayerPropertyKeyframe<T>>();
}
/// <summary>
/// Gets the description attribute applied to this property
/// </summary>
/// <inheritdoc />
public PropertyDescriptionAttribute PropertyDescription { get; internal set; }
/// <summary>
@@ -49,6 +46,15 @@ namespace Artemis.Core
OnUpdated();
}
/// <inheritdoc />
public void Dispose()
{
_disposed = true;
foreach (var dataBinding in _dataBindings)
dataBinding.Dispose();
}
/// <summary>
/// Returns the type of the property
/// </summary>
@@ -320,6 +326,20 @@ namespace Artemis.Core
/// </summary>
public bool DataBindingsSupported { get; protected internal set; } = true;
/// <summary>
/// Gets whether the layer has any active data bindings
/// </summary>
public bool HasDataBinding => GetAllDataBindingRegistrations().Any(r => r.GetDataBinding() != null);
/// <summary>
/// Gets a data binding registration by the expression used to register it
/// <para>Note: The expression must exactly match the one used to register the data binding</para>
/// </summary>
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(Expression<Func<T, TProperty>> propertyExpression)
{
return GetDataBindingRegistration<TProperty>(propertyExpression.ToString());
}
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(string expression)
{
if (_disposed)
@@ -327,6 +347,7 @@ namespace Artemis.Core
var match = _dataBindingRegistrations.FirstOrDefault(r => r is DataBindingRegistration<T, TProperty> registration &&
registration.PropertyExpression.ToString() == expression);
return (DataBindingRegistration<T, TProperty>) match;
}
@@ -367,6 +388,7 @@ namespace Artemis.Core
var dataBinding = new DataBinding<T, TProperty>(dataBindingRegistration);
_dataBindings.Add(dataBinding);
OnDataBindingEnabled(new LayerPropertyEventArgs<T>(dataBinding.LayerProperty));
return dataBinding;
}
@@ -380,6 +402,10 @@ namespace Artemis.Core
throw new ObjectDisposedException("LayerProperty");
_dataBindings.Remove(dataBinding);
dataBinding.Registration.DataBinding = null;
dataBinding.Dispose();
OnDataBindingDisabled(new LayerPropertyEventArgs<T>(dataBinding.LayerProperty));
}
private void UpdateDataBindings(double deltaTime)
@@ -532,6 +558,16 @@ namespace Artemis.Core
/// </summary>
public event EventHandler<LayerPropertyEventArgs<T>> KeyframeRemoved;
/// <summary>
/// Occurs when a data binding has been enabled
/// </summary>
public event EventHandler<LayerPropertyEventArgs<T>> DataBindingEnabled;
/// <summary>
/// Occurs when a data binding has been disabled
/// </summary>
public event EventHandler<LayerPropertyEventArgs<T>> DataBindingDisabled;
protected virtual void OnUpdated()
{
Updated?.Invoke(this, new LayerPropertyEventArgs<T>(this));
@@ -562,15 +598,16 @@ namespace Artemis.Core
KeyframeRemoved?.Invoke(this, new LayerPropertyEventArgs<T>(this));
}
#endregion
/// <inheritdoc />
public void Dispose()
protected virtual void OnDataBindingEnabled(LayerPropertyEventArgs<T> e)
{
_disposed = true;
foreach (var dataBinding in _dataBindings)
dataBinding.Dispose();
DataBindingEnabled?.Invoke(this, e);
}
protected virtual void OnDataBindingDisabled(LayerPropertyEventArgs<T> e)
{
DataBindingDisabled?.Invoke(this, e);
}
#endregion
}
}
@@ -7,10 +7,7 @@ namespace Artemis.Core
{
internal SKColorLayerProperty()
{
RegisterDataBindingProperty(color => color.Alpha, new SKColorArgbDataBindingConverter(SKColorArgbDataBindingConverter.Channel.Alpha));
RegisterDataBindingProperty(color => color.Red, new SKColorArgbDataBindingConverter(SKColorArgbDataBindingConverter.Channel.Red));
RegisterDataBindingProperty(color => color.Green, new SKColorArgbDataBindingConverter(SKColorArgbDataBindingConverter.Channel.Green));
RegisterDataBindingProperty(color => color.Blue, new SKColorArgbDataBindingConverter(SKColorArgbDataBindingConverter.Channel.Blue));
RegisterDataBindingProperty(value => value, new SKColorDataBindingConverter());
}
/// <summary>