using System; namespace Artemis.Core { /// /// Represents a data binding converter that acts as the bridge between a /// and a /// public abstract class DataBindingConverter : IDataBindingConverter { /// /// Gets the data binding this converter is applied to /// public DataBinding? DataBinding { get; private set; } /// /// Gets whether or not this data binding converter supports the method /// public bool SupportsSum { get; protected set; } /// /// Gets whether or not this data binding converter supports the method /// public bool SupportsInterpolate { get; protected set; } /// /// Returns the sum of and /// public abstract TProperty Sum(TProperty a, TProperty b); /// /// Returns the the interpolated value between and on a scale (generally) /// between 0.0 and 1.0 defined by the /// Note: The progress may go be negative or go beyond 1.0 depending on the easing method used /// /// The value to interpolate away from /// The value to interpolate towards /// The progress of the interpolation between 0.0 and 1.0 /// public abstract TProperty Interpolate(TProperty a, TProperty b, double progress); /// /// Applies the to the layer property /// /// public virtual void ApplyValue(TProperty value) { if (DataBinding?.Registration == null) throw new ArtemisCoreException("Data binding converter is not yet initialized"); DataBinding.Registration.Setter(value); } /// /// Returns the current base value of the data binding /// public virtual TProperty GetValue() { if (DataBinding?.Registration == null) throw new ArtemisCoreException("Data binding converter is not yet initialized"); return DataBinding.Registration.Getter(); } /// /// Converts the provided object to a type of /// public virtual TProperty ConvertFromObject(object? source) { return (TProperty) Convert.ChangeType(source, typeof(TProperty))!; } /// /// Called when the data binding converter has been initialized and the is available /// protected virtual void OnInitialized() { } internal void Initialize(DataBinding dataBinding) { if (dataBinding.Registration == null) throw new ArtemisCoreException("Cannot initialize a data binding converter for a data binding without a registration"); DataBinding = dataBinding; OnInitialized(); } /// public Type SupportedType => typeof(TProperty); } }