mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 01:42:55 +08:00
Improve closest origin selection to include effects of rotation/flip
Closes https://github.com/ppy/osu/issues/28237. Solution as proposed here: https://github.com/ppy/osu/pull/28089#issuecomment-2095372157 For flips and rotations by 90 degrees this does what you would expect it to. For arbitrary rotations it *sort of kind of* attempts to do this but the results are a bit wonky - probably still better than what was there before, though?
This commit is contained in:
parent
c03f68413a
commit
3da3b91be5
@ -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,12 +422,41 @@ 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 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 = origin;
|
||||
drawable.Origin = localOrigin;
|
||||
drawable.Position += drawable.ToParentSpace(drawable.OriginPosition) - previousOrigin;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user