mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 22:37:26 +08:00
103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
|
// 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.Containers;
|
|||
|
using osu.Framework.Graphics.Shapes;
|
|||
|
using osu.Framework.Layout;
|
|||
|
using osuTK;
|
|||
|
|
|||
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|||
|
{
|
|||
|
public abstract partial class PositionSnapGrid : CompositeDrawable
|
|||
|
{
|
|||
|
private Vector2 startPosition;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// The position of the origin of this <see cref="PositionSnapGrid"/> in local coordinates.
|
|||
|
/// </summary>
|
|||
|
public Vector2 StartPosition
|
|||
|
{
|
|||
|
get => startPosition;
|
|||
|
set
|
|||
|
{
|
|||
|
startPosition = value;
|
|||
|
GridCache.Invalidate();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected readonly LayoutValue GridCache = new LayoutValue(Invalidation.RequiredParentSizeToFit);
|
|||
|
|
|||
|
protected PositionSnapGrid()
|
|||
|
{
|
|||
|
Masking = true;
|
|||
|
|
|||
|
AddLayout(GridCache);
|
|||
|
}
|
|||
|
|
|||
|
protected override void Update()
|
|||
|
{
|
|||
|
base.Update();
|
|||
|
|
|||
|
if (GridCache.IsValid) return;
|
|||
|
|
|||
|
ClearInternal();
|
|||
|
|
|||
|
if (DrawWidth > 0 && DrawHeight > 0)
|
|||
|
CreateContent();
|
|||
|
|
|||
|
GridCache.Validate();
|
|||
|
}
|
|||
|
|
|||
|
protected abstract void CreateContent();
|
|||
|
|
|||
|
protected void GenerateOutline(Vector2 drawSize)
|
|||
|
{
|
|||
|
// Make lines the same width independent of display resolution.
|
|||
|
float lineWidth = DrawWidth / ScreenSpaceDrawQuad.Width;
|
|||
|
|
|||
|
AddRangeInternal(new[]
|
|||
|
{
|
|||
|
new Box
|
|||
|
{
|
|||
|
Colour = Colour4.White,
|
|||
|
Alpha = 0.3f,
|
|||
|
Origin = Anchor.CentreLeft,
|
|||
|
RelativeSizeAxes = Axes.X,
|
|||
|
Height = lineWidth,
|
|||
|
Y = 0,
|
|||
|
},
|
|||
|
new Box
|
|||
|
{
|
|||
|
Colour = Colour4.White,
|
|||
|
Alpha = 0.3f,
|
|||
|
Origin = Anchor.CentreLeft,
|
|||
|
RelativeSizeAxes = Axes.X,
|
|||
|
Height = lineWidth,
|
|||
|
Y = drawSize.Y,
|
|||
|
},
|
|||
|
new Box
|
|||
|
{
|
|||
|
Colour = Colour4.White,
|
|||
|
Alpha = 0.3f,
|
|||
|
Origin = Anchor.TopCentre,
|
|||
|
RelativeSizeAxes = Axes.Y,
|
|||
|
Width = lineWidth,
|
|||
|
X = 0,
|
|||
|
},
|
|||
|
new Box
|
|||
|
{
|
|||
|
Colour = Colour4.White,
|
|||
|
Alpha = 0.3f,
|
|||
|
Origin = Anchor.TopCentre,
|
|||
|
RelativeSizeAxes = Axes.Y,
|
|||
|
Width = lineWidth,
|
|||
|
X = drawSize.X,
|
|||
|
},
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
public abstract Vector2 GetSnappedPosition(Vector2 original);
|
|||
|
}
|
|||
|
}
|