1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:02:55 +08:00

Change selection handling to adjust Size instead of Scale for edge nodes

This commit is contained in:
Dean Herbert 2023-11-10 14:17:11 +09:00
parent b0c5b3cb10
commit ec3b6e47fb
No known key found for this signature in database
3 changed files with 56 additions and 4 deletions

View File

@ -42,6 +42,7 @@ namespace osu.Game.Rulesets.Osu.Edit
SelectionBox.CanFlipX = SelectionBox.CanScaleX = quad.Width > 0;
SelectionBox.CanFlipY = SelectionBox.CanScaleY = quad.Height > 0;
SelectionBox.CanScaleProportionally = SelectionBox.CanScaleX && SelectionBox.CanScaleY;
SelectionBox.CanReverse = EditorBeatmap.SelectedHitObjects.Count > 1 || EditorBeatmap.SelectedHitObjects.Any(s => s is Slider);
}

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Utils;
@ -31,8 +32,38 @@ namespace osu.Game.Overlays.SkinEditor
UpdatePosition = updateDrawablePosition
};
private bool allSelectedSupportManualSizing => SelectedItems.All(b => (b as CompositeDrawable)?.AutoSizeAxes == Axes.None);
public override bool HandleScale(Vector2 scale, Anchor anchor)
{
bool adjustSize;
switch (anchor)
{
// for corners, adjust scale.
case Anchor.TopLeft:
case Anchor.TopRight:
case Anchor.BottomLeft:
case Anchor.BottomRight:
adjustSize = false;
break;
// for edges, adjust size.
case Anchor.TopCentre:
case Anchor.CentreLeft:
case Anchor.CentreRight:
case Anchor.BottomCentre:
// autosize elements can't be easily handled so just disable sizing for now.
if (!allSelectedSupportManualSizing)
return false;
adjustSize = true;
break;
default:
throw new ArgumentOutOfRangeException(nameof(anchor), anchor, null);
}
// convert scale to screen space
scale = ToScreenSpace(scale) - ToScreenSpace(Vector2.Zero);
@ -120,7 +151,10 @@ namespace osu.Game.Overlays.SkinEditor
if (Precision.AlmostEquals(MathF.Abs(drawableItem.Rotation) % 180, 90))
currentScaledDelta = new Vector2(scaledDelta.Y, scaledDelta.X);
drawableItem.Scale *= currentScaledDelta;
if (adjustSize)
drawableItem.Size *= currentScaledDelta;
else
drawableItem.Scale *= currentScaledDelta;
}
return true;
@ -169,8 +203,8 @@ namespace osu.Game.Overlays.SkinEditor
{
base.OnSelectionChanged();
SelectionBox.CanScaleX = true;
SelectionBox.CanScaleY = true;
SelectionBox.CanScaleX = SelectionBox.CanScaleY = allSelectedSupportManualSizing;
SelectionBox.CanScaleProportionally = true;
SelectionBox.CanFlipX = true;
SelectionBox.CanFlipY = true;
SelectionBox.CanReverse = false;

View File

@ -91,6 +91,23 @@ namespace osu.Game.Screens.Edit.Compose.Components
}
}
private bool canScaleProportionally;
/// <summary>
/// Whether vertical scaling support should be enabled.
/// </summary>
public bool CanScaleProportionally
{
get => canScaleProportionally;
set
{
if (canScaleProportionally == value) return;
canScaleProportionally = value;
recreate();
}
}
private bool canFlipX;
/// <summary>
@ -245,7 +262,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
};
if (CanScaleX) addXScaleComponents();
if (CanScaleX && CanScaleY) addFullScaleComponents();
if (CanScaleProportionally) addFullScaleComponents();
if (CanScaleY) addYScaleComponents();
if (CanFlipX) addXFlipComponents();
if (CanFlipY) addYFlipComponents();