1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 19:07:25 +08:00
osu-lazer/osu.Game/Graphics/Sprites/GlowingSpriteText.cs

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

96 lines
2.6 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.
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
2024-01-16 22:36:46 +08:00
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
2024-01-16 22:36:46 +08:00
using osu.Framework.Utils;
using osuTK;
namespace osu.Game.Graphics.Sprites
{
2024-01-16 22:36:46 +08:00
public partial class GlowingSpriteText : BufferedContainer, IHasText
{
2024-01-16 22:36:46 +08:00
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
{
2024-01-16 22:36:46 +08:00
get => text.Text;
set => text.Text = value;
}
2019-07-23 04:16:54 +08:00
public FontUsage Font
{
2024-01-16 22:36:46 +08:00
get => text.Font;
set => text.Font = value.With(fixedWidth: true);
}
public Vector2 TextSize
{
2024-01-16 22:36:46 +08:00
get => text.Size;
set => text.Size = value;
}
public ColourInfo TextColour
{
2024-01-16 22:36:46 +08:00
get => text.Colour;
set => text.Colour = value;
}
public ColourInfo GlowColour
{
2024-01-16 22:36:46 +08:00
get => EffectColour;
set
{
EffectColour = value;
BackgroundColour = value.MultiplyAlpha(0f);
}
}
2020-03-17 15:24:33 +08:00
public Vector2 Spacing
{
2024-01-16 22:36:46 +08:00
get => text.Spacing;
set => text.Spacing = value;
2020-03-17 15:24:33 +08:00
}
public bool UseFullGlyphHeight
{
2024-01-16 22:36:46 +08:00
get => text.UseFullGlyphHeight;
set => text.UseFullGlyphHeight = value;
2020-03-17 15:24:33 +08:00
}
public Bindable<string> Current
{
2024-01-16 22:36:46 +08:00
get => text.Current;
set => text.Current = value;
}
public GlowingSpriteText()
2024-01-16 22:36:46 +08:00
: base(cachedFrameBuffer: true)
{
AutoSizeAxes = Axes.Both;
2024-01-16 22:36:46 +08:00
BlurSigma = new Vector2(blur_sigma);
RedrawOnScale = false;
DrawOriginal = true;
EffectBlending = BlendingParameters.Additive;
EffectPlacement = EffectPlacement.InFront;
Child = text = new OsuSpriteText
{
2024-01-16 22:36:46 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Shadow = false,
};
}
}
}