1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

accumulating negative scaling

This commit is contained in:
Wleter 2023-08-21 19:36:11 +02:00
parent d2798c7a1c
commit 9f4f81c150

View File

@ -31,6 +31,8 @@ namespace osu.Game.Overlays.SkinEditor
UpdatePosition = updateDrawablePosition
};
private float accumulatedNegativeScaling;
public override bool HandleScale(Vector2 scale, Anchor anchor)
{
// convert scale to screen space
@ -71,8 +73,25 @@ namespace osu.Game.Overlays.SkinEditor
scale.Y = scale.X / selectionRect.Width * selectionRect.Height;
}
// If scaling reverses the selection, don't scale.
if (adjustedRect.Width + scale.X < 0 || adjustedRect.Height + scale.Y < 0) return true;
// If scaling reverses the selection, don't scale and accumulate the amount of scaling.
if (adjustedRect.Width + scale.X < 0 || adjustedRect.Height + scale.Y < 0)
{
accumulatedNegativeScaling += scale.Length; // - new Vector2(selectionRect.Width, selectionRect.Height).Length;
return true;
}
// Compensate for accumulated negative scaling.
if (Precision.AlmostBigger(accumulatedNegativeScaling, 0) && !Precision.AlmostEquals(accumulatedNegativeScaling, 0))
{
float length = scale.Length;
accumulatedNegativeScaling -= length;
// If the accumulated negative scaling is still positive, don't scale.
if (Precision.AlmostBigger(accumulatedNegativeScaling, 0)) return true;
scale *= Math.Abs(accumulatedNegativeScaling) / length;
accumulatedNegativeScaling = 0;
}
if (anchor.HasFlagFast(Anchor.x0)) adjustedRect.X -= scale.X;
if (anchor.HasFlagFast(Anchor.y0)) adjustedRect.Y -= scale.Y;
@ -150,6 +169,12 @@ namespace osu.Game.Overlays.SkinEditor
public static void ApplyClosestAnchor(Drawable drawable) => applyAnchor(drawable, getClosestAnchor(drawable));
protected override void OnOperationEnded()
{
base.OnOperationEnded();
accumulatedNegativeScaling = 0;
}
protected override void OnSelectionChanged()
{
base.OnSelectionChanged();