mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 00:42:55 +08:00
Merge pull request #3546 from smoogipoo/smooth-path
Use the new SmoothedPath in sliders/user profile graph
This commit is contained in:
commit
50aaad809a
@ -8,26 +8,23 @@ using osu.Framework.Configuration;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Lines;
|
using osu.Framework.Graphics.Lines;
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using OpenTK.Graphics.ES30;
|
using OpenTK.Graphics.ES30;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using SixLabors.ImageSharp;
|
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||||
{
|
{
|
||||||
public class SliderBody : Container, ISliderProgress
|
public class SliderBody : Container, ISliderProgress
|
||||||
{
|
{
|
||||||
private readonly Path path;
|
private readonly SliderPath path;
|
||||||
private readonly BufferedContainer container;
|
private readonly BufferedContainer container;
|
||||||
|
|
||||||
public float PathWidth
|
public float PathWidth
|
||||||
{
|
{
|
||||||
get { return path.PathWidth; }
|
get => path.PathWidth;
|
||||||
set { path.PathWidth = value; }
|
set => path.PathWidth = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -43,48 +40,40 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
public double? SnakedStart { get; private set; }
|
public double? SnakedStart { get; private set; }
|
||||||
public double? SnakedEnd { get; private set; }
|
public double? SnakedEnd { get; private set; }
|
||||||
|
|
||||||
private Color4 accentColour = Color4.White;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to colour the path.
|
/// Used to colour the path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color4 AccentColour
|
public Color4 AccentColour
|
||||||
{
|
{
|
||||||
get { return accentColour; }
|
get => path.AccentColour;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (accentColour == value)
|
if (path.AccentColour == value)
|
||||||
return;
|
return;
|
||||||
accentColour = value;
|
path.AccentColour = value;
|
||||||
|
|
||||||
if (LoadState >= LoadState.Ready)
|
container.ForceRedraw();
|
||||||
reloadTexture();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color4 borderColour = Color4.White;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to colour the path border.
|
/// Used to colour the path border.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public new Color4 BorderColour
|
public new Color4 BorderColour
|
||||||
{
|
{
|
||||||
get { return borderColour; }
|
get => path.BorderColour;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (borderColour == value)
|
if (path.BorderColour == value)
|
||||||
return;
|
return;
|
||||||
borderColour = value;
|
path.BorderColour = value;
|
||||||
|
|
||||||
if (LoadState >= LoadState.Ready)
|
container.ForceRedraw();
|
||||||
reloadTexture();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quad PathDrawQuad => container.ScreenSpaceDrawQuad;
|
public Quad PathDrawQuad => container.ScreenSpaceDrawQuad;
|
||||||
|
|
||||||
private int textureWidth => (int)PathWidth * 2;
|
|
||||||
|
|
||||||
private Vector2 topLeftOffset;
|
private Vector2 topLeftOffset;
|
||||||
|
|
||||||
private readonly Slider slider;
|
private readonly Slider slider;
|
||||||
@ -101,7 +90,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
CacheDrawnFrameBuffer = true,
|
CacheDrawnFrameBuffer = true,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
path = new Path
|
path = new SliderPath
|
||||||
{
|
{
|
||||||
Blending = BlendingMode.None,
|
Blending = BlendingMode.None,
|
||||||
},
|
},
|
||||||
@ -134,46 +123,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
reloadTexture();
|
|
||||||
computeSize();
|
computeSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadTexture()
|
|
||||||
{
|
|
||||||
var texture = new Texture(textureWidth, 1);
|
|
||||||
|
|
||||||
//initialise background
|
|
||||||
var raw = new Image<Rgba32>(textureWidth, 1);
|
|
||||||
|
|
||||||
const float aa_portion = 0.02f;
|
|
||||||
const float border_portion = 0.128f;
|
|
||||||
const float gradient_portion = 1 - border_portion;
|
|
||||||
|
|
||||||
const float opacity_at_centre = 0.3f;
|
|
||||||
const float opacity_at_edge = 0.8f;
|
|
||||||
|
|
||||||
for (int i = 0; i < textureWidth; i++)
|
|
||||||
{
|
|
||||||
float progress = (float)i / (textureWidth - 1);
|
|
||||||
|
|
||||||
if (progress <= border_portion)
|
|
||||||
{
|
|
||||||
raw[i, 0] = new Rgba32(BorderColour.R, BorderColour.G, BorderColour.B, Math.Min(progress / aa_portion, 1) * BorderColour.A);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
progress -= border_portion;
|
|
||||||
raw[i, 0] = new Rgba32(AccentColour.R, AccentColour.G, AccentColour.B,
|
|
||||||
(opacity_at_edge - (opacity_at_edge - opacity_at_centre) * progress / gradient_portion) * AccentColour.A);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
texture.SetData(new TextureUpload(raw));
|
|
||||||
path.Texture = texture;
|
|
||||||
|
|
||||||
container.ForceRedraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void computeSize()
|
private void computeSize()
|
||||||
{
|
{
|
||||||
// Generate the entire curve
|
// Generate the entire curve
|
||||||
@ -226,5 +178,53 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
|
|
||||||
SetRange(start, end);
|
SetRange(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SliderPath : SmoothPath
|
||||||
|
{
|
||||||
|
private const float border_portion = 0.128f;
|
||||||
|
private const float gradient_portion = 1 - border_portion;
|
||||||
|
|
||||||
|
private const float opacity_at_centre = 0.3f;
|
||||||
|
private const float opacity_at_edge = 0.8f;
|
||||||
|
|
||||||
|
private Color4 borderColour = Color4.White;
|
||||||
|
|
||||||
|
public Color4 BorderColour
|
||||||
|
{
|
||||||
|
get => borderColour;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (borderColour == value)
|
||||||
|
return;
|
||||||
|
borderColour = value;
|
||||||
|
|
||||||
|
InvalidateTexture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color4 accentColour = Color4.White;
|
||||||
|
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get => accentColour;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (accentColour == value)
|
||||||
|
return;
|
||||||
|
accentColour = value;
|
||||||
|
|
||||||
|
InvalidateTexture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Color4 ColourAt(float position)
|
||||||
|
{
|
||||||
|
if (position <= border_portion)
|
||||||
|
return BorderColour;
|
||||||
|
|
||||||
|
position -= border_portion;
|
||||||
|
return new Color4(AccentColour.R, AccentColour.G, AccentColour.B, (opacity_at_edge - (opacity_at_edge - opacity_at_centre) * position / gradient_portion) * AccentColour.A);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
Masking = true,
|
Masking = true,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = path = new Path { RelativeSizeAxes = Axes.Both, PathWidth = 1 }
|
Child = path = new SmoothPath { RelativeSizeAxes = Axes.Both, PathWidth = 1 }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.2" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.2" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.3" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.3" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="ppy.osu.Framework" Version="2018.1002.0" />
|
<PackageReference Include="ppy.osu.Framework" Version="2018.1012.0" />
|
||||||
<PackageReference Include="SharpCompress" Version="0.22.0" />
|
<PackageReference Include="SharpCompress" Version="0.22.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
<PackageReference Include="NUnit" Version="3.10.1" />
|
||||||
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user