1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Use closest origin along with closest anchor

This commit is contained in:
Dean Herbert 2024-04-12 15:52:36 +08:00
parent 5cdaafdb1e
commit 0b61e2cd42
No known key found for this signature in database
2 changed files with 23 additions and 14 deletions

View File

@ -457,7 +457,7 @@ namespace osu.Game.Overlays.SkinEditor
}
SelectedComponents.Add(component);
SkinSelectionHandler.ApplyClosestAnchor(drawableComponent);
SkinSelectionHandler.ApplyClosestAnchorOrigin(drawableComponent);
return true;
}

View File

@ -204,15 +204,20 @@ namespace osu.Game.Overlays.SkinEditor
drawable.Position += drawable.ScreenSpaceDeltaToParentSpace(moveEvent.ScreenSpaceDelta);
if (item.UsesFixedAnchor) continue;
ApplyClosestAnchor(drawable);
if (!item.UsesFixedAnchor)
ApplyClosestAnchorOrigin(drawable);
}
return true;
}
public static void ApplyClosestAnchor(Drawable drawable) => applyAnchor(drawable, getClosestAnchor(drawable));
public static void ApplyClosestAnchorOrigin(Drawable drawable)
{
var closest = getClosestAnchor(drawable);
applyAnchor(drawable, closest);
applyOrigin(drawable, closest);
}
protected override void OnSelectionChanged()
{
@ -325,15 +330,10 @@ namespace osu.Game.Overlays.SkinEditor
{
var drawable = (Drawable)item;
if (origin == drawable.Origin) continue;
applyOrigin(drawable, origin);
var previousOrigin = drawable.OriginPosition;
drawable.Origin = origin;
drawable.Position += drawable.OriginPosition - previousOrigin;
if (item.UsesFixedAnchor) continue;
ApplyClosestAnchor(drawable);
if (item.UsesFixedAnchor)
ApplyClosestAnchorOrigin(drawable);
}
OnOperationEnded();
@ -368,7 +368,7 @@ namespace osu.Game.Overlays.SkinEditor
foreach (var item in SelectedItems)
{
item.UsesFixedAnchor = false;
ApplyClosestAnchor((Drawable)item);
ApplyClosestAnchorOrigin((Drawable)item);
}
OnOperationEnded();
@ -414,6 +414,15 @@ namespace osu.Game.Overlays.SkinEditor
drawable.Position -= drawable.AnchorPosition - previousAnchor;
}
private static void applyOrigin(Drawable drawable, Anchor origin)
{
if (origin == drawable.Origin) return;
var previousOrigin = drawable.OriginPosition;
drawable.Origin = origin;
drawable.Position += drawable.OriginPosition - previousOrigin;
}
private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference)
{
// cancel out scale in axes we don't care about (based on which drag handle was used).