Skip to content

Commit

Permalink
Make the grid layer for the composer.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jul 20, 2024
1 parent b1da561 commit 0095970
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Components.Lyrics;

public partial class GridLayer : Layer
{
private readonly RectangularPositionSnapGrid rectangularPositionSnapGrid;

public GridLayer(Lyric lyric)
: base(lyric)
{
InternalChild = rectangularPositionSnapGrid = new RectangularPositionSnapGrid
{
RelativeSizeAxes = Axes.Both,
};
}

public int Spacing
{
get => rectangularPositionSnapGrid.Spacing;
set => rectangularPositionSnapGrid.Spacing = value;
}

public override void UpdateDisableEditState(bool editable)
{
this.FadeTo(editable ? 1 : 0.5f, 100);
}

private partial class RectangularPositionSnapGrid : LinedPositionSnapGrid
{
protected override void CreateContent()
{
GenerateGridLines(new Vector2(0, -Spacing), DrawSize);
GenerateGridLines(new Vector2(0, Spacing), DrawSize);

GenerateGridLines(new Vector2(-Spacing, 0), DrawSize);
GenerateGridLines(new Vector2(Spacing, 0), DrawSize);

GenerateOutline(DrawSize);
}

public override Vector2 GetSnappedPosition(Vector2 original)
{
return StartPosition.Value + original;
}

private int spacing;

public int Spacing
{
get => spacing;
set
{
spacing = value;
GridCache.Invalidate();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public LyricEditor()
},
Layers = new Layer[]
{
new GridLayer(lyric)
{
Spacing = 10,
},
new LyricLayer(lyric),
new EditLyricLayer(lyric),
new TimeTagLayer(lyric),
Expand Down

0 comments on commit 0095970

Please sign in to comment.