fix adjust axes detection

This commit is contained in:
OliBomby 2024-01-20 15:39:38 +01:00
parent 1596776a81
commit 9b9485f656
4 changed files with 40 additions and 21 deletions

View File

@ -7,6 +7,7 @@
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
@ -82,7 +83,7 @@ public override void Begin()
obj => obj.Path.ControlPoints.Select(p => p.Type).ToArray()); obj => obj.Path.ControlPoints.Select(p => p.Type).ToArray());
} }
public override void Update(Vector2 scale, Vector2? origin = null) public override void Update(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both)
{ {
if (objectsInScale == null) if (objectsInScale == null)
throw new InvalidOperationException($"Cannot {nameof(Update)} a scale operation without calling {nameof(Begin)} first!"); throw new InvalidOperationException($"Cannot {nameof(Update)} a scale operation without calling {nameof(Begin)} first!");

View File

@ -83,7 +83,7 @@ public override void Begin()
isFlippedY = false; isFlippedY = false;
} }
public override void Update(Vector2 scale, Vector2? origin = null) public override void Update(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both)
{ {
if (objectsInScale == null) if (objectsInScale == null)
throw new InvalidOperationException($"Cannot {nameof(Update)} a scale operation without calling {nameof(Begin)} first!"); throw new InvalidOperationException($"Cannot {nameof(Update)} a scale operation without calling {nameof(Begin)} first!");
@ -91,7 +91,6 @@ public override void Update(Vector2 scale, Vector2? origin = null)
Debug.Assert(originalWidths != null && originalHeights != null && originalScales != null && originalPositions != null && defaultOrigin != null && OriginalSurroundingQuad != null); Debug.Assert(originalWidths != null && originalHeights != null && originalScales != null && originalPositions != null && defaultOrigin != null && OriginalSurroundingQuad != null);
var actualOrigin = origin ?? defaultOrigin.Value; var actualOrigin = origin ?? defaultOrigin.Value;
Axes adjustAxis = scale.X == 1 ? Axes.Y : scale.Y == 1 ? Axes.X : Axes.Both;
if ((adjustAxis == Axes.Y && !allSelectedSupportManualSizing(Axes.Y)) || if ((adjustAxis == Axes.Y && !allSelectedSupportManualSizing(Axes.Y)) ||
(adjustAxis == Axes.X && !allSelectedSupportManualSizing(Axes.X))) (adjustAxis == Axes.X && !allSelectedSupportManualSizing(Axes.X)))

View File

@ -38,20 +38,6 @@ protected override bool OnDragStart(DragStartEvent e)
return true; return true;
} }
private Vector2 getOriginPosition()
{
var quad = scaleHandler!.OriginalSurroundingQuad!.Value;
Vector2 origin = quad.TopLeft;
if ((originalAnchor & Anchor.x0) > 0)
origin.X += quad.Width;
if ((originalAnchor & Anchor.y0) > 0)
origin.Y += quad.Height;
return origin;
}
private Vector2 rawScale; private Vector2 rawScale;
protected override void OnDrag(DragEvent e) protected override void OnDrag(DragEvent e)
@ -113,7 +99,38 @@ private void applyScale(bool shouldKeepAspectRatio)
? new Vector2((rawScale.X + rawScale.Y) * 0.5f) ? new Vector2((rawScale.X + rawScale.Y) * 0.5f)
: rawScale; : rawScale;
scaleHandler!.Update(newScale, getOriginPosition()); scaleHandler!.Update(newScale, getOriginPosition(), getAdjustAxis());
}
private Vector2 getOriginPosition()
{
var quad = scaleHandler!.OriginalSurroundingQuad!.Value;
Vector2 origin = quad.TopLeft;
if ((originalAnchor & Anchor.x0) > 0)
origin.X += quad.Width;
if ((originalAnchor & Anchor.y0) > 0)
origin.Y += quad.Height;
return origin;
}
private Axes getAdjustAxis()
{
switch (originalAnchor)
{
case Anchor.TopCentre:
case Anchor.BottomCentre:
return Axes.Y;
case Anchor.CentreLeft:
case Anchor.CentreRight:
return Axes.X;
default:
return Axes.Both;
}
} }
} }
} }

View File

@ -46,10 +46,11 @@ public partial class SelectionScaleHandler : Component
/// The origin point to scale from. /// The origin point to scale from.
/// If the default <see langword="null"/> value is supplied, a sane implementation-defined default will be used. /// If the default <see langword="null"/> value is supplied, a sane implementation-defined default will be used.
/// </param> /// </param>
public void ScaleSelection(Vector2 scale, Vector2? origin = null) /// <param name="adjustAxis">The axes to adjust the scale in.</param>
public void ScaleSelection(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both)
{ {
Begin(); Begin();
Update(scale, origin); Update(scale, origin, adjustAxis);
Commit(); Commit();
} }
@ -83,7 +84,8 @@ public virtual void Begin()
/// The origin point to scale from. /// The origin point to scale from.
/// If the default <see langword="null"/> value is supplied, a sane implementation-defined default will be used. /// If the default <see langword="null"/> value is supplied, a sane implementation-defined default will be used.
/// </param> /// </param>
public virtual void Update(Vector2 scale, Vector2? origin = null) /// <param name="adjustAxis">The axes to adjust the scale in.</param>
public virtual void Update(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both)
{ {
} }