1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 14:02:54 +08:00
osu-lazer/osu.Game/Storyboards/Drawables/DrawablesExtensions.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
1.3 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2017-09-11 18:33:11 +08:00
using osu.Framework.Graphics;
2017-09-09 21:34:26 +08:00
using osu.Framework.Graphics.Transforms;
2018-04-13 17:19:50 +08:00
2017-09-09 21:34:26 +08:00
namespace osu.Game.Storyboards.Drawables
{
public static class DrawablesExtensions
{
/// <summary>
2017-09-11 18:33:11 +08:00
/// Adjusts <see cref="Drawable.Blending"/> after a delay.
2017-09-09 21:34:26 +08:00
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
2019-08-21 12:29:50 +08:00
public static TransformSequence<T> TransformBlendingMode<T>(this T drawable, BlendingParameters newValue, double delay = 0)
2017-09-09 21:34:26 +08:00
where T : Drawable
2019-08-21 12:29:50 +08:00
=> drawable.TransformTo(drawable.PopulateTransform(new TransformBlendingParameters(), newValue, delay));
2017-09-09 21:34:26 +08:00
}
2018-04-13 17:19:50 +08:00
2019-08-21 12:29:50 +08:00
public class TransformBlendingParameters : Transform<BlendingParameters, Drawable>
2017-09-09 21:34:26 +08:00
{
2019-08-21 12:29:50 +08:00
private BlendingParameters valueAt(double time)
2017-09-09 21:34:26 +08:00
=> time < EndTime ? StartValue : EndValue;
2018-04-13 17:19:50 +08:00
2017-09-11 18:23:32 +08:00
public override string TargetMember => nameof(Drawable.Blending);
2018-04-13 17:19:50 +08:00
2017-09-11 18:23:32 +08:00
protected override void Apply(Drawable d, double time) => d.Blending = valueAt(time);
2019-08-21 12:29:50 +08:00
protected override void ReadIntoStartValue(Drawable d) => StartValue = d.Blending;
2017-09-09 21:34:26 +08:00
}
}