using CMLeonOS.Gui; namespace CMLeonOS.UILib.Animations { /// /// A window animation. /// internal abstract class Animation { /// /// The easing type of the animation. /// internal EasingType EasingType { get; set; } = EasingType.Sine; /// /// The direction of the easing of the animation. /// internal EasingDirection EasingDirection { get; set; } = EasingDirection.Out; /// /// The duration of the animation. /// internal int Duration { get; set; } = 60; /// /// How many frames of the animation have been completed. /// internal int Position { get; set; } = 0; /// /// If the animation has finished. /// internal bool Finished { get { return Position >= Duration; } } /// /// The window associated with the animation. /// internal Window Window { get; set; } /// /// Advance the animation by one frame. /// /// Whether or not the animation is now finished. internal abstract bool Advance(); private int? timerId { get; set; } = null; /// /// Start the animation. /// internal void Start() { if (timerId == null) { timerId = Cosmos.HAL.Global.PIT.RegisterTimer(new Cosmos.HAL.PIT.PITTimer(() => { Advance(); if (Finished) { Stop(); } }, (ulong)((1000d /* ms */ / 60d) * 1e+6d /* ms -> ns */ ), true)); } } /// /// Stop the animation. /// internal void Stop() { if (timerId != null) { Cosmos.HAL.Global.PIT.UnregisterTimer((int)timerId); timerId = null; } } } }