Files
bluflame/aiwaz/AiwazAnimator/Animations/Animation.cs
2026-04-18 22:31:51 +02:00

81 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace AiwazAnimator
{
abstract public class Animation : INotifyPropertyChanged
{
public float StartTime { get; set; }
public float EndTime { get; set; }
public float StartValue { get; set; }
public float EndValue { get; set; }
public Func<float> ValueGetter;
public Action<float> ValueSetter;
public Func<string> ValueNamer;
public float Value
{
get { return ValueGetter(); }
set { ValueSetter(value); OnPropertyChanged("Value"); }
}
private float _time;
public float Time
{
get
{
return _time;
}
set
{
if (_time == value)
return;
_time = value;
OnPropertyChanged("Time");
}
}
public Animation()
{
AnimationName = "Erroneous";
}
public string ListString
{
get
{
return string.Format("Type: {0}, Time: [{1}, {2}], Value: [{3}, {4}], Target: {5}", AnimationName, StartTime, EndTime, StartValue, EndValue, ValueNamer());
}
}
public void Animate(float time)
{
if (time < StartTime)
{
return;
}
else if (time > EndTime)
{
return;
}
float NormalizedTime = (time - StartTime) / (EndTime - StartTime);
Time = NormalizedTime;
Value = Calculate(NormalizedTime);
}
protected abstract float Calculate(float NormalizedTime);
public string AnimationName;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
}