mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Expose thickness property
This commit is contained in:
parent
9a330c3cdb
commit
14a4de36f4
@ -14,6 +14,8 @@ namespace osu.Game.Tests.Visual.Background
|
||||
{
|
||||
public class TestSceneTriangleBorderShader : OsuTestScene
|
||||
{
|
||||
private readonly TriangleBorder border;
|
||||
|
||||
public TestSceneTriangleBorderShader()
|
||||
{
|
||||
Children = new Drawable[]
|
||||
@ -23,7 +25,7 @@ namespace osu.Game.Tests.Visual.Background
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.DarkGreen
|
||||
},
|
||||
new TriangleBorder
|
||||
border = new TriangleBorder
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
@ -32,8 +34,27 @@ namespace osu.Game.Tests.Visual.Background
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
AddSliderStep("Thickness", 0f, 1f, 0.02f, t => border.Thickness = t);
|
||||
}
|
||||
|
||||
private class TriangleBorder : Sprite
|
||||
{
|
||||
private float thickness = 0.02f;
|
||||
|
||||
public float Thickness
|
||||
{
|
||||
get => thickness;
|
||||
set
|
||||
{
|
||||
thickness = value;
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ShaderManager shaders, IRenderer renderer)
|
||||
{
|
||||
@ -45,11 +66,29 @@ namespace osu.Game.Tests.Visual.Background
|
||||
|
||||
private class TriangleBorderDrawNode : SpriteDrawNode
|
||||
{
|
||||
public new TriangleBorder Source => (TriangleBorder)base.Source;
|
||||
|
||||
public TriangleBorderDrawNode(TriangleBorder source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
private float thickness;
|
||||
|
||||
public override void ApplyState()
|
||||
{
|
||||
base.ApplyState();
|
||||
|
||||
thickness = Source.thickness;
|
||||
}
|
||||
|
||||
public override void Draw(IRenderer renderer)
|
||||
{
|
||||
TextureShader.GetUniform<float>("thickness").UpdateValue(ref thickness);
|
||||
|
||||
base.Draw(renderer);
|
||||
}
|
||||
|
||||
protected override bool CanDrawOpaqueInterior => false;
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ namespace osu.Game.Tests.Visual.Background
|
||||
base.LoadComplete();
|
||||
|
||||
AddSliderStep("Spawn ratio", 0f, 2f, 1f, s => triangles.SpawnRatio = s);
|
||||
AddSliderStep("Thickness", 0f, 1f, 0.02f, t => triangles.Thickness = t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,21 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
set => colourBottom.Value = value;
|
||||
}
|
||||
|
||||
private float thickness = 0.02f;
|
||||
|
||||
public float Thickness
|
||||
{
|
||||
get => thickness;
|
||||
set
|
||||
{
|
||||
if (thickness == value)
|
||||
return;
|
||||
|
||||
thickness = value;
|
||||
// No need for invalidation since it's happening in Update()
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether we should create new triangles as others expire.
|
||||
/// </summary>
|
||||
@ -226,6 +241,7 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
|
||||
private readonly List<TriangleParticle> parts = new List<TriangleParticle>();
|
||||
private Vector2 size;
|
||||
private float thickness;
|
||||
|
||||
private IVertexBatch<TexturedVertex2D>? vertexBatch;
|
||||
|
||||
@ -241,6 +257,7 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
shader = Source.shader;
|
||||
texture = Source.texture;
|
||||
size = Source.DrawSize;
|
||||
thickness = Source.thickness;
|
||||
|
||||
parts.Clear();
|
||||
parts.AddRange(Source.parts);
|
||||
@ -260,6 +277,7 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
}
|
||||
|
||||
shader.Bind();
|
||||
shader.GetUniform<float>("thickness").UpdateValue(ref thickness);
|
||||
|
||||
foreach (TriangleParticle particle in parts)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user