1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 14:07:25 +08:00

Fix gridline centering and ensure lines are always rendered using a fixed screen-space width

This commit is contained in:
Dean Herbert 2022-05-04 13:41:55 +09:00
parent bb086800b1
commit 0bb90c7b07

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Layout;
using osu.Framework.Utils;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components
@ -72,25 +73,29 @@ namespace osu.Game.Screens.Edit.Compose.Components
int index = 0;
float currentPosition = startPosition;
while ((endPosition - currentPosition) * Math.Sign(step) > 0)
// Make lines the same width independent of display resolution.
float lineWidth = DrawWidth / ScreenSpaceDrawQuad.Width;
while (Precision.AlmostBigger((endPosition - currentPosition) * Math.Sign(step), 0))
{
var gridLine = new Box
{
Colour = Colour4.White,
Alpha = index == 0 ? 0.3f : 0.1f,
EdgeSmoothness = new Vector2(0.2f)
};
if (direction == Direction.Horizontal)
{
gridLine.Origin = Anchor.CentreLeft;
gridLine.RelativeSizeAxes = Axes.X;
gridLine.Height = 1;
gridLine.Height = lineWidth;
gridLine.Y = currentPosition;
}
else
{
gridLine.Origin = Anchor.TopCentre;
gridLine.RelativeSizeAxes = Axes.Y;
gridLine.Width = 1;
gridLine.Width = lineWidth;
gridLine.X = currentPosition;
}