1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 19:42:55 +08:00

Rework GlowingSpriteText

This commit is contained in:
Andrei Zavatski 2024-01-16 17:36:46 +03:00
parent c27f01dc14
commit 7920e93fa9

View File

@ -5,95 +5,90 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Utils;
using osuTK; using osuTK;
namespace osu.Game.Graphics.Sprites namespace osu.Game.Graphics.Sprites
{ {
public partial class GlowingSpriteText : Container, IHasText public partial class GlowingSpriteText : BufferedContainer, IHasText
{ {
private readonly OsuSpriteText spriteText, blurredText; 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;
public LocalisableString Text public LocalisableString Text
{ {
get => spriteText.Text; get => text.Text;
set => blurredText.Text = spriteText.Text = value; set => text.Text = value;
} }
public FontUsage Font public FontUsage Font
{ {
get => spriteText.Font; get => text.Font;
set => blurredText.Font = spriteText.Font = value.With(fixedWidth: true); set => text.Font = value.With(fixedWidth: true);
} }
public Vector2 TextSize public Vector2 TextSize
{ {
get => spriteText.Size; get => text.Size;
set => blurredText.Size = spriteText.Size = value; set => text.Size = value;
} }
public ColourInfo TextColour public ColourInfo TextColour
{ {
get => spriteText.Colour; get => text.Colour;
set => spriteText.Colour = value; set => text.Colour = value;
} }
public ColourInfo GlowColour public ColourInfo GlowColour
{ {
get => blurredText.Colour; get => EffectColour;
set => blurredText.Colour = value; set
{
EffectColour = value;
BackgroundColour = value.MultiplyAlpha(0f);
}
} }
public Vector2 Spacing public Vector2 Spacing
{ {
get => spriteText.Spacing; get => text.Spacing;
set => spriteText.Spacing = blurredText.Spacing = value; set => text.Spacing = value;
} }
public bool UseFullGlyphHeight public bool UseFullGlyphHeight
{ {
get => spriteText.UseFullGlyphHeight; get => text.UseFullGlyphHeight;
set => spriteText.UseFullGlyphHeight = blurredText.UseFullGlyphHeight = value; set => text.UseFullGlyphHeight = value;
} }
public Bindable<string> Current public Bindable<string> Current
{ {
get => spriteText.Current; get => text.Current;
set => spriteText.Current = value; set => text.Current = value;
} }
public GlowingSpriteText() public GlowingSpriteText()
: base(cachedFrameBuffer: true)
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
BlurSigma = new Vector2(blur_sigma);
Children = new Drawable[] RedrawOnScale = false;
{ DrawOriginal = true;
new BufferedContainer(cachedFrameBuffer: true) EffectBlending = BlendingParameters.Additive;
{ EffectPlacement = EffectPlacement.InFront;
Anchor = Anchor.Centre, Child = text = new OsuSpriteText
Origin = Anchor.Centre,
BlurSigma = new Vector2(4),
RedrawOnScale = false,
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive,
Size = new Vector2(3f),
Children = new[]
{
blurredText = new OsuSpriteText
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Shadow = false, Shadow = false,
},
},
},
spriteText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Shadow = false,
},
}; };
} }
} }