using System;
namespace Microsoft.Windows.Forms.Animate
{
///
/// 动画
///
/// 动画类型
public abstract class Animation : DisposableMini, IAnimation
{
///
/// 标识动画停止的百分比
///
protected const double STOPPED = 1d;
private bool m_Stopped = true;
///
/// 获取动画是否已停止
///
public virtual bool Stopped
{
get
{
return this.m_Stopped;
}
}
private DateTime m_StartTime;
///
/// 获取动画开始时间
///
public virtual DateTime StartTime
{
get
{
return this.m_StartTime;
}
}
private TimeSpan m_Span;
///
/// 获取或设置动画执行时间段,毫秒
///
public virtual int Span
{
get
{
return (int)this.m_Span.TotalMilliseconds;
}
set
{
this.m_Span = new TimeSpan(0, 0, 0, 0, value);
}
}
///
/// 获取当前帧
///
public abstract T Current
{
get;
}
///
/// 获取动画完成百分比,如果等于 1 标志已结束
///
protected virtual double Percentage
{
get
{
if (this.m_Stopped)
return STOPPED;
DateTime now = DateTime.Now;
if (now >= this.m_StartTime + this.m_Span)
{
this.m_Stopped = true;
return STOPPED;
}
return (now - this.m_StartTime).TotalMilliseconds / this.m_Span.TotalMilliseconds;
}
}
///
/// 开始动画
///
protected virtual void Start()
{
this.m_Stopped = false;
this.m_StartTime = DateTime.Now;
}
///
/// 停止动画
///
protected virtual void Stop()
{
this.m_Stopped = true;
}
}
}