1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Merge pull request #28257 from bdach/fix-skin-editor-spaz

Fix closest anchor selection spazzing out in multiple scenarios
This commit is contained in:
Dean Herbert 2024-05-21 14:35:29 +08:00 committed by GitHub
commit 3b86da443b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -421,13 +422,42 @@ namespace osu.Game.Overlays.SkinEditor
drawable.Position -= drawable.AnchorPosition - previousAnchor;
}
private static void applyOrigin(Drawable drawable, Anchor origin)
private static void applyOrigin(Drawable drawable, Anchor screenSpaceOrigin)
{
if (origin == drawable.Origin) return;
var boundingBox = drawable.ScreenSpaceDrawQuad.AABBFloat;
var previousOrigin = drawable.OriginPosition;
drawable.Origin = origin;
drawable.Position += drawable.OriginPosition - previousOrigin;
var targetScreenSpacePosition = screenSpaceOrigin.PositionOnQuad(boundingBox);
Anchor localOrigin = Anchor.TopLeft;
float smallestDistanceFromTargetPosition = float.PositiveInfinity;
void checkOrigin(Anchor originToTest)
{
Vector2 positionToTest = drawable.ToScreenSpace(originToTest.PositionOnQuad(drawable.DrawRectangle));
float testedDistance = Vector2.Distance(targetScreenSpacePosition, positionToTest);
if (testedDistance < smallestDistanceFromTargetPosition)
{
localOrigin = originToTest;
smallestDistanceFromTargetPosition = testedDistance;
}
}
checkOrigin(Anchor.TopLeft);
checkOrigin(Anchor.TopCentre);
checkOrigin(Anchor.TopRight);
checkOrigin(Anchor.CentreLeft);
checkOrigin(Anchor.Centre);
checkOrigin(Anchor.CentreRight);
checkOrigin(Anchor.BottomLeft);
checkOrigin(Anchor.BottomCentre);
checkOrigin(Anchor.BottomRight);
var previousOrigin = drawable.ToParentSpace(drawable.OriginPosition);
drawable.Origin = localOrigin;
drawable.Position += drawable.ToParentSpace(drawable.OriginPosition) - previousOrigin;
}
private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference)