Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve draw performance of editor grids #29476

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions osu.Game/Screens/Edit/Compose/Components/PositionSnapGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Layout;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Screens.Edit.Compose.Components
{
public abstract partial class PositionSnapGrid : CompositeDrawable
public abstract partial class PositionSnapGrid : BufferedContainer
{
/// <summary>
/// The position of the origin of this <see cref="PositionSnapGrid"/> in local coordinates.
Expand All @@ -20,7 +22,10 @@ public abstract partial class PositionSnapGrid : CompositeDrawable
protected readonly LayoutValue GridCache = new LayoutValue(Invalidation.RequiredParentSizeToFit);

protected PositionSnapGrid()
: base(cachedFrameBuffer: true)
{
BackgroundColour = Color4.White.Opacity(0);

StartPosition.BindValueChanged(_ => GridCache.Invalidate());

AddLayout(GridCache);
Expand All @@ -30,14 +35,16 @@ protected override void Update()
{
base.Update();

if (GridCache.IsValid) return;
if (GridCache.IsValid)
return;

ClearInternal();

if (DrawWidth > 0 && DrawHeight > 0)
CreateContent();

GridCache.Validate();
ForceRedraw();
}

protected abstract void CreateContent();
Expand All @@ -53,7 +60,6 @@ protected void GenerateOutline(Vector2 drawSize)
{
Colour = Colour4.White,
Alpha = 0.3f,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
Height = lineWidth,
Y = 0,
Expand All @@ -62,28 +68,26 @@ protected void GenerateOutline(Vector2 drawSize)
{
Colour = Colour4.White,
Alpha = 0.3f,
Origin = Anchor.CentreLeft,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = lineWidth,
Y = drawSize.Y,
Height = lineWidth
},
new Box
{
Colour = Colour4.White,
Alpha = 0.3f,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Y,
Width = lineWidth,
X = 0,
Width = lineWidth
},
new Box
{
Colour = Colour4.White,
Alpha = 0.3f,
Origin = Anchor.TopCentre,
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
Width = lineWidth,
X = drawSize.X,
Width = lineWidth
},
});
}
Expand Down
Loading