// The CMLeonOS Project (https://github.com/Leonmmcoset/CMLeonOS) // Copyright (C) 2025-present LeonOS 2 Developer Team // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . 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; } } } }