From 54472e6452c61671d487f59d6e61af89daaa6d59 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 31 Mar 2024 01:20:27 +0300 Subject: [PATCH 1/3] Decouple GlowingDrawable from GlowingSpriteText --- osu.Game/Graphics/Sprites/GlowingDrawable.cs | 41 +++++++++++++++++++ .../Graphics/Sprites/GlowingSpriteText.cs | 39 ++++-------------- 2 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 osu.Game/Graphics/Sprites/GlowingDrawable.cs diff --git a/osu.Game/Graphics/Sprites/GlowingDrawable.cs b/osu.Game/Graphics/Sprites/GlowingDrawable.cs new file mode 100644 index 0000000000..10085ad38b --- /dev/null +++ b/osu.Game/Graphics/Sprites/GlowingDrawable.cs @@ -0,0 +1,41 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Utils; +using osuTK; + +namespace osu.Game.Graphics.Sprites +{ + public abstract partial class GlowingDrawable : BufferedContainer + { + // Inflate draw quad to prevent glow from trimming at the edges. + // Padding won't suffice since it will affect drawable position in cases when it's not centered. + protected override Quad ComputeScreenSpaceDrawQuad() + => base.ComputeScreenSpaceDrawQuad().AABBFloat.Inflate(new Vector2(Blur.KernelSize(BlurSigma.X), Blur.KernelSize(BlurSigma.Y))); + + public ColourInfo GlowColour + { + get => EffectColour; + set + { + EffectColour = value; + BackgroundColour = value.MultiplyAlpha(0f); + } + } + + protected GlowingDrawable() + : base(cachedFrameBuffer: true) + { + AutoSizeAxes = Axes.Both; + RedrawOnScale = false; + DrawOriginal = true; + Child = CreateDrawable(); + } + + protected abstract Drawable CreateDrawable(); + } +} diff --git a/osu.Game/Graphics/Sprites/GlowingSpriteText.cs b/osu.Game/Graphics/Sprites/GlowingSpriteText.cs index 669c5da01e..3ac13bf862 100644 --- a/osu.Game/Graphics/Sprites/GlowingSpriteText.cs +++ b/osu.Game/Graphics/Sprites/GlowingSpriteText.cs @@ -4,24 +4,17 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; -using osu.Framework.Utils; using osuTK; namespace osu.Game.Graphics.Sprites { - public partial class GlowingSpriteText : BufferedContainer, IHasText + public partial class GlowingSpriteText : GlowingDrawable, IHasText { private const float blur_sigma = 3f; - // Inflate draw quad to prevent glow from trimming at the edges. - // Padding won't suffice since it will affect text position in cases when it's not centered. - protected override Quad ComputeScreenSpaceDrawQuad() => base.ComputeScreenSpaceDrawQuad().AABBFloat.Inflate(Blur.KernelSize(blur_sigma)); - - private readonly OsuSpriteText text; + private OsuSpriteText text = null!; public LocalisableString Text { @@ -47,16 +40,6 @@ namespace osu.Game.Graphics.Sprites set => text.Colour = value; } - public ColourInfo GlowColour - { - get => EffectColour; - set - { - EffectColour = value; - BackgroundColour = value.MultiplyAlpha(0f); - } - } - public Vector2 Spacing { get => text.Spacing; @@ -76,20 +59,16 @@ namespace osu.Game.Graphics.Sprites } public GlowingSpriteText() - : base(cachedFrameBuffer: true) { - AutoSizeAxes = Axes.Both; BlurSigma = new Vector2(blur_sigma); - RedrawOnScale = false; - DrawOriginal = true; EffectBlending = BlendingParameters.Additive; - EffectPlacement = EffectPlacement.InFront; - Child = text = new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Shadow = false, - }; } + + protected override Drawable CreateDrawable() => text = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Shadow = false, + }; } } From 58a68e94af79205aa13989fb8b896c9d27c0f9c0 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 31 Mar 2024 01:30:08 +0300 Subject: [PATCH 2/3] Simplify glowing icons in break overlay --- osu.Game/Screens/Play/Break/BlurredIcon.cs | 44 ++--------------- osu.Game/Screens/Play/Break/GlowIcon.cs | 57 ++++++++-------------- 2 files changed, 23 insertions(+), 78 deletions(-) diff --git a/osu.Game/Screens/Play/Break/BlurredIcon.cs b/osu.Game/Screens/Play/Break/BlurredIcon.cs index 2bf59ea63b..9cd617d3e3 100644 --- a/osu.Game/Screens/Play/Break/BlurredIcon.cs +++ b/osu.Game/Screens/Play/Break/BlurredIcon.cs @@ -1,52 +1,16 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Game.Graphics; -using osuTK; namespace osu.Game.Screens.Play.Break { - public partial class BlurredIcon : BufferedContainer + public partial class BlurredIcon : GlowIcon { - private readonly SpriteIcon icon; - - public IconUsage Icon - { - set => icon.Icon = value; - get => icon.Icon; - } - - public override Vector2 Size - { - set - { - icon.Size = value; - base.Size = value + BlurSigma * 5; - ForceRedraw(); - } - get => base.Size; - } - public BlurredIcon() - : base(cachedFrameBuffer: true) { - RelativePositionAxes = Axes.X; - Child = icon = new SpriteIcon - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Shadow = false, - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - Colour = colours.BlueLighter; + EffectBlending = BlendingParameters.Additive; + DrawOriginal = false; } } } diff --git a/osu.Game/Screens/Play/Break/GlowIcon.cs b/osu.Game/Screens/Play/Break/GlowIcon.cs index 8e2b9da0ad..a68cfdac42 100644 --- a/osu.Game/Screens/Play/Break/GlowIcon.cs +++ b/osu.Game/Screens/Play/Break/GlowIcon.cs @@ -3,64 +3,45 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; using osuTK; namespace osu.Game.Screens.Play.Break { - public partial class GlowIcon : Container + public partial class GlowIcon : GlowingDrawable { - private readonly SpriteIcon spriteIcon; - private readonly BlurredIcon blurredIcon; - - public override Vector2 Size - { - get => base.Size; - set - { - blurredIcon.Size = spriteIcon.Size = value; - blurredIcon.ForceRedraw(); - } - } - - public Vector2 BlurSigma - { - get => blurredIcon.BlurSigma; - set => blurredIcon.BlurSigma = value; - } + private SpriteIcon icon = null!; public IconUsage Icon { - get => spriteIcon.Icon; - set => spriteIcon.Icon = blurredIcon.Icon = value; + set => icon.Icon = value; + get => icon.Icon; + } + + public new Vector2 Size + { + set => icon.Size = value; + get => icon.Size; } public GlowIcon() { RelativePositionAxes = Axes.X; - AutoSizeAxes = Axes.Both; - Children = new Drawable[] - { - blurredIcon = new BlurredIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - spriteIcon = new SpriteIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Shadow = false, - } - }; } [BackgroundDependencyLoader] private void load(OsuColour colours) { - blurredIcon.Colour = colours.Blue; + GlowColour = colours.BlueLighter; } + + protected override Drawable CreateDrawable() => icon = new SpriteIcon + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Shadow = false, + }; } } From 11b113580496fd979bfa083573e0e17ac6cb8f64 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 31 Mar 2024 01:55:34 +0300 Subject: [PATCH 3/3] Adjust blurred icons position due to size handling differences --- osu.Game/Screens/Play/Break/BreakArrows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/Break/BreakArrows.cs b/osu.Game/Screens/Play/Break/BreakArrows.cs index 41277c7557..40474a7137 100644 --- a/osu.Game/Screens/Play/Break/BreakArrows.cs +++ b/osu.Game/Screens/Play/Break/BreakArrows.cs @@ -18,7 +18,7 @@ namespace osu.Game.Screens.Play.Break private const int blurred_icon_blur_sigma = 20; private const int blurred_icon_size = 130; - private const float blurred_icon_final_offset = 0.35f; + private const float blurred_icon_final_offset = 0.38f; private const float blurred_icon_offscreen_offset = 0.7f; private readonly GlowIcon leftGlowIcon;