// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Transforms; using osu.Framework.Threading; using System; using JetBrains.Annotations; using osu.Framework.Bindables; namespace osu.Framework.Graphics { public static class TransformSequenceExtensions { public static TransformSequence Expire(this TransformSequence t, bool calculateLifetimeStart = false) where T : Drawable => t.Append(o => o.Expire(calculateLifetimeStart)); public static TransformSequence Schedule(this TransformSequence t, Action scheduledAction) where T : Drawable => t.Append(o => o.Schedule(scheduledAction)); public static TransformSequence Schedule(this TransformSequence t, Action scheduledAction, out ScheduledDelegate scheduledDelegate) where T : Drawable => t.Append(o => o.Schedule(scheduledAction), out scheduledDelegate); public static TransformSequence Spin(this TransformSequence t, double revolutionDuration, RotationDirection direction, float startRotation = 0) where T : Drawable => t.Loop(d => d.RotateTo(startRotation).RotateTo(startRotation + (direction == RotationDirection.Clockwise ? 360 : -360), revolutionDuration)); public static TransformSequence Spin(this TransformSequence t, double revolutionDuration, RotationDirection direction, float startRotation, int numRevolutions) where T : Drawable => t.Loop(0, numRevolutions, d => d.RotateTo(startRotation).RotateTo(startRotation + (direction == RotationDirection.Clockwise ? 360 : -360), revolutionDuration)); #region Easing /// /// Smoothly adjusts to 1 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeIn(this TransformSequence t, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.FadeIn(duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts from 0 to 1 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeInFromZero(this TransformSequence t, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.FadeInFromZero(duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts to 0 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeOut(this TransformSequence t, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.FadeOut(duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts from 1 to 0 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeOutFromOne(this TransformSequence t, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.FadeOutFromOne(duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence FadeTo(this TransformSequence t, float newAlpha, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.FadeTo(newAlpha, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence FadeColour(this TransformSequence t, ColourInfo newColour, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.FadeColour(newColour, duration, new DefaultEasingFunction(easing)); /// /// Instantaneously flashes , then smoothly changes it back over time. /// /// A to which further transforms can be added. public static TransformSequence FlashColour(this TransformSequence t, ColourInfo flashColour, double duration, Easing easing = Easing.None) where T : Drawable => t.FlashColour(flashColour, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence RotateTo(this TransformSequence t, float newRotation, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.RotateTo(newRotation, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ScaleTo(this TransformSequence t, float newScale, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.ScaleTo(newScale, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ScaleTo(this TransformSequence t, Vector2 newScale, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.ScaleTo(newScale, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeTo(this TransformSequence t, float newSize, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.ResizeTo(newSize, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeTo(this TransformSequence t, Vector2 newSize, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.ResizeTo(newSize, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeWidthTo(this TransformSequence t, float newWidth, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.ResizeWidthTo(newWidth, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeHeightTo(this TransformSequence t, float newHeight, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.ResizeHeightTo(newHeight, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence MoveTo(this TransformSequence t, Vector2 newPosition, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.MoveTo(newPosition, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts or over time. /// /// A to which further transforms can be added. public static TransformSequence MoveTo(this TransformSequence t, Direction direction, float destination, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.MoveTo(direction, destination, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence MoveToX(this TransformSequence t, float destination, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.MoveToX(destination, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence MoveToY(this TransformSequence t, float destination, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.MoveToY(destination, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts by an offset to its final value over time. /// /// A to which further transforms can be added. public static TransformSequence MoveToOffset(this TransformSequence t, Vector2 offset, double duration = 0, Easing easing = Easing.None) where T : Drawable => t.MoveToOffset(offset, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts the alpha channel of the colour of over time. /// /// A to which further transforms can be added. public static TransformSequence FadeEdgeEffectTo(this TransformSequence t, float newAlpha, double duration, Easing easing = Easing.None) where T : class, IContainer => t.FadeEdgeEffectTo(newAlpha, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts the colour of over time. /// /// A to which further transforms can be added. public static TransformSequence FadeEdgeEffectTo(this TransformSequence t, Color4 newColour, double duration = 0, Easing easing = Easing.None) where T : class, IContainer => t.FadeEdgeEffectTo(newColour, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence TransformRelativeChildSizeTo(this TransformSequence t, Vector2 newSize, double duration = 0, Easing easing = Easing.None) where T : class, IContainer => t.TransformRelativeChildSizeTo(newSize, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence TransformRelativeChildOffsetTo(this TransformSequence t, Vector2 newOffset, double duration = 0, Easing easing = Easing.None) where T : class, IContainer => t.TransformRelativeChildOffsetTo(newOffset, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence BlurTo(this TransformSequence t, Vector2 newBlurSigma, double duration = 0, Easing easing = Easing.None) where T : class, IBufferedContainer => t.BlurTo(newBlurSigma, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence TransformSpacingTo(this TransformSequence t, Vector2 newSpacing, double duration = 0, Easing easing = Easing.None) where T : class, IFillFlowContainer => t.TransformSpacingTo(newSpacing, duration, new DefaultEasingFunction(easing)); /// /// Smoothly adjusts the value of a over time. /// /// A to which further transforms can be added. public static TransformSequence TransformBindableTo(this TransformSequence t, [NotNull] Bindable bindable, TValue newValue, double duration = 0, Easing easing = Easing.None) where T : class, ITransformable => t.TransformBindableTo(bindable, newValue, duration, new DefaultEasingFunction(easing)); #endregion #region Generic Easing /// /// Smoothly adjusts to 1 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeIn(this TransformSequence t, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.FadeIn(duration, easing)); /// /// Smoothly adjusts from 0 to 1 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeInFromZero(this TransformSequence t, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.FadeInFromZero(duration, easing)); /// /// Smoothly adjusts to 0 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeOut(this TransformSequence t, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.FadeOut(duration, easing)); /// /// Smoothly adjusts from 1 to 0 over time. /// /// A to which further transforms can be added. public static TransformSequence FadeOutFromOne(this TransformSequence t, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.FadeOutFromOne(duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence FadeTo(this TransformSequence t, float newAlpha, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.FadeTo(newAlpha, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence FadeColour(this TransformSequence t, ColourInfo newColour, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.FadeColour(newColour, duration, easing)); /// /// Instantaneously flashes , then smoothly changes it back over time. /// /// A to which further transforms can be added. public static TransformSequence FlashColour(this TransformSequence t, ColourInfo flashColour, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.FlashColour(flashColour, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence RotateTo(this TransformSequence t, float newRotation, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.RotateTo(newRotation, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ScaleTo(this TransformSequence t, float newScale, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.ScaleTo(newScale, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ScaleTo(this TransformSequence t, Vector2 newScale, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.ScaleTo(newScale, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeTo(this TransformSequence t, float newSize, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.ResizeTo(newSize, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeTo(this TransformSequence t, Vector2 newSize, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.ResizeTo(newSize, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeWidthTo(this TransformSequence t, float newWidth, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.ResizeWidthTo(newWidth, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence ResizeHeightTo(this TransformSequence t, float newHeight, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.ResizeHeightTo(newHeight, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence MoveTo(this TransformSequence t, Vector2 newPosition, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.MoveTo(newPosition, duration, easing)); /// /// Smoothly adjusts or over time. /// /// A to which further transforms can be added. public static TransformSequence MoveTo(this TransformSequence t, Direction direction, float destination, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.MoveTo(direction, destination, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence MoveToX(this TransformSequence t, float destination, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.MoveToX(destination, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence MoveToY(this TransformSequence t, float destination, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.MoveToY(destination, duration, easing)); /// /// Smoothly adjusts by an offset to its final value over time. /// /// A to which further transforms can be added. public static TransformSequence MoveToOffset(this TransformSequence t, Vector2 offset, double duration, TEasing easing) where T : Drawable where TEasing : IEasingFunction => t.Append(o => o.MoveToOffset(offset, duration, easing)); /// /// Smoothly adjusts the alpha channel of the colour of over time. /// /// A to which further transforms can be added. public static TransformSequence FadeEdgeEffectTo(this TransformSequence t, float newAlpha, double duration, TEasing easing) where T : class, IContainer where TEasing : IEasingFunction => t.Append(o => o.FadeEdgeEffectTo(newAlpha, duration, easing)); /// /// Smoothly adjusts the colour of over time. /// /// A to which further transforms can be added. public static TransformSequence FadeEdgeEffectTo(this TransformSequence t, Color4 newColour, double duration, TEasing easing) where T : class, IContainer where TEasing : IEasingFunction => t.Append(o => o.FadeEdgeEffectTo(newColour, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence TransformRelativeChildSizeTo(this TransformSequence t, Vector2 newSize, double duration, TEasing easing) where T : class, IContainer where TEasing : IEasingFunction => t.Append(o => o.TransformRelativeChildSizeTo(newSize, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence TransformRelativeChildOffsetTo(this TransformSequence t, Vector2 newOffset, double duration, TEasing easing) where T : class, IContainer where TEasing : IEasingFunction => t.Append(o => o.TransformRelativeChildOffsetTo(newOffset, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence BlurTo(this TransformSequence t, Vector2 newBlurSigma, double duration, TEasing easing) where T : class, IBufferedContainer where TEasing : IEasingFunction => t.Append(o => o.BlurTo(newBlurSigma, duration, easing)); /// /// Smoothly adjusts over time. /// /// A to which further transforms can be added. public static TransformSequence TransformSpacingTo(this TransformSequence t, Vector2 newSpacing, double duration, TEasing easing) where T : class, IFillFlowContainer where TEasing : IEasingFunction => t.Append(o => o.TransformSpacingTo(newSpacing, duration, easing)); /// /// Smoothly adjusts the value of a over time. /// /// A to which further transforms can be added. public static TransformSequence TransformBindableTo(this TransformSequence t, [NotNull] Bindable bindable, TValue newValue, double duration, TEasing easing) where T : class, ITransformable where TEasing : IEasingFunction => t.Append(o => o.TransformBindableTo(bindable, newValue, duration, easing)); #endregion } }