diff --git a/osu.Game/Graphics/IHasAccentColour.cs b/osu.Game/Graphics/IHasAccentColour.cs index ac2117c517..0c6bf98db4 100644 --- a/osu.Game/Graphics/IHasAccentColour.cs +++ b/osu.Game/Graphics/IHasAccentColour.cs @@ -20,14 +20,19 @@ public interface IHasAccentColour : IDrawable public static class AccentedColourExtensions { /// - /// Tweens the accent colour of a drawable to another colour. + /// Smoothly adjusts over time. /// - /// The drawable to apply the accent colour to. - /// The new accent colour. - /// The tween duration. - /// The tween easing. + /// A to which further transforms can be added. public static TransformSequence FadeAccent(this T accentedDrawable, Color4 newColour, double duration = 0, Easing easing = Easing.None) where T : IHasAccentColour => accentedDrawable.TransformTo(nameof(accentedDrawable.AccentColour), newColour, duration, easing); + + /// + /// Smoothly adjusts over time. + /// + /// A to which further transforms can be added. + public static TransformSequence FadeAccent(this TransformSequence t, Color4 newColour, double duration = 0, Easing easing = Easing.None) + where T : Drawable, IHasAccentColour + => t.Append(o => o.FadeAccent(newColour, duration, easing)); } } diff --git a/osu.Game/Graphics/SpriteIcon.cs b/osu.Game/Graphics/SpriteIcon.cs index 93c85d67cb..d49814952c 100644 --- a/osu.Game/Graphics/SpriteIcon.cs +++ b/osu.Game/Graphics/SpriteIcon.cs @@ -9,6 +9,7 @@ using osu.Framework.IO.Stores; using OpenTK; using OpenTK.Graphics; +using osu.Framework.Caching; namespace osu.Game.Graphics { @@ -17,6 +18,7 @@ public class SpriteIcon : CompositeDrawable private readonly Sprite spriteShadow; private readonly Sprite spriteMain; + private Cached layout = new Cached(); private readonly Container shadowVisibility; public SpriteIcon() @@ -71,16 +73,23 @@ private void updateTexture() public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) { - if ((invalidation & Invalidation.Colour) > 0) + if ((invalidation & Invalidation.Colour) > 0 && Shadow) + layout.Invalidate(); + return base.Invalidate(invalidation, source, shallPropagate); + } + + protected override void Update() + { + if (!layout.IsValid) { //adjust shadow alpha based on highest component intensity to avoid muddy display of darker text. //squared result for quadratic fall-off seems to give the best result. var avgColour = (Color4)DrawInfo.Colour.AverageColour; spriteShadow.Alpha = (float)Math.Pow(Math.Max(Math.Max(avgColour.R, avgColour.G), avgColour.B), 2); - } - return base.Invalidate(invalidation, source, shallPropagate); + layout.Validate(); + } } public bool Shadow