mirror of
https://github.com/ppy/osu.git
synced 2024-09-21 18:47:27 +08:00
Decouple GlowingDrawable from GlowingSpriteText
This commit is contained in:
parent
93f1578c10
commit
54472e6452
41
osu.Game/Graphics/Sprites/GlowingDrawable.cs
Normal file
41
osu.Game/Graphics/Sprites/GlowingDrawable.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// 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.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();
|
||||||
|
}
|
||||||
|
}
|
@ -4,24 +4,17 @@
|
|||||||
using osu.Framework.Bindables;
|
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.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 : BufferedContainer, IHasText
|
public partial class GlowingSpriteText : GlowingDrawable, IHasText
|
||||||
{
|
{
|
||||||
private const float blur_sigma = 3f;
|
private const float blur_sigma = 3f;
|
||||||
|
|
||||||
// Inflate draw quad to prevent glow from trimming at the edges.
|
private OsuSpriteText text = null!;
|
||||||
// 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
|
||||||
{
|
{
|
||||||
@ -47,16 +40,6 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
set => text.Colour = value;
|
set => text.Colour = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColourInfo GlowColour
|
|
||||||
{
|
|
||||||
get => EffectColour;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
EffectColour = value;
|
|
||||||
BackgroundColour = value.MultiplyAlpha(0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2 Spacing
|
public Vector2 Spacing
|
||||||
{
|
{
|
||||||
get => text.Spacing;
|
get => text.Spacing;
|
||||||
@ -76,20 +59,16 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GlowingSpriteText()
|
public GlowingSpriteText()
|
||||||
: base(cachedFrameBuffer: true)
|
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
BlurSigma = new Vector2(blur_sigma);
|
BlurSigma = new Vector2(blur_sigma);
|
||||||
RedrawOnScale = false;
|
|
||||||
DrawOriginal = true;
|
|
||||||
EffectBlending = BlendingParameters.Additive;
|
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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user