mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Simplify HandleScale by extracting methods
This commit is contained in:
parent
0b8009938a
commit
562a4cefdb
@ -143,41 +143,18 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
if ((newHeight > DrawHeight) || (newWidth > DrawWidth))
|
if ((newHeight > DrawHeight) || (newWidth > DrawWidth))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool result;
|
||||||
// for the time being, allow resizing of slider paths only if the slider is
|
// for the time being, allow resizing of slider paths only if the slider is
|
||||||
// the only hit object selected. with a group selection, it's likely the user
|
// the only hit object selected. with a group selection, it's likely the user
|
||||||
// is not looking to change the duration of the slider but expand the whole pattern.
|
// is not looking to change the duration of the slider but expand the whole pattern.
|
||||||
if (hitObjects.Length == 1 && hitObjects.First() is Slider slider)
|
if (hitObjects.Length == 1 && hitObjects.First() is Slider slider)
|
||||||
{
|
result = scaleSlider(slider, scale);
|
||||||
Quad sliderQuad = getSurroundingQuad(slider.Path.ControlPoints.Select(p => p.Position.Value));
|
|
||||||
Vector2 pathRelativeDeltaScale = new Vector2(1 + scale.X / sliderQuad.Width, 1 + scale.Y / sliderQuad.Height);
|
|
||||||
|
|
||||||
foreach (var point in slider.Path.ControlPoints)
|
|
||||||
point.Position.Value *= pathRelativeDeltaScale;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
result = scaleHitObjects(hitObjects, reference, scale);
|
||||||
// move the selection before scaling if dragging from top or left anchors.
|
|
||||||
if ((reference & Anchor.x0) > 0 && !moveSelection(new Vector2(-scale.X, 0))) return false;
|
|
||||||
if ((reference & Anchor.y0) > 0 && !moveSelection(new Vector2(0, -scale.Y))) return false;
|
|
||||||
|
|
||||||
foreach (var h in hitObjects)
|
|
||||||
{
|
|
||||||
var newPosition = h.Position;
|
|
||||||
|
|
||||||
// guard against no-ops and NaN.
|
|
||||||
if (scale.X != 0 && selectionQuad.Width > 0)
|
|
||||||
newPosition.X = selectionQuad.TopLeft.X + (h.X - selectionQuad.TopLeft.X) / selectionQuad.Width * (selectionQuad.Width + scale.X);
|
|
||||||
|
|
||||||
if (scale.Y != 0 && selectionQuad.Height > 0)
|
|
||||||
newPosition.Y = selectionQuad.TopLeft.Y + (h.Y - selectionQuad.TopLeft.Y) / selectionQuad.Height * (selectionQuad.Height + scale.Y);
|
|
||||||
|
|
||||||
h.Position = newPosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
moveSelectionInBounds();
|
moveSelectionInBounds();
|
||||||
|
|
||||||
return true;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference)
|
private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference)
|
||||||
@ -214,6 +191,42 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool scaleSlider(Slider slider, Vector2 scale)
|
||||||
|
{
|
||||||
|
Quad quad = getSurroundingQuad(slider.Path.ControlPoints.Select(p => p.Position.Value));
|
||||||
|
Vector2 pathRelativeDeltaScale = new Vector2(1 + scale.X / quad.Width, 1 + scale.Y / quad.Height);
|
||||||
|
|
||||||
|
foreach (var point in slider.Path.ControlPoints)
|
||||||
|
point.Position.Value *= pathRelativeDeltaScale;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool scaleHitObjects(OsuHitObject[] hitObjects, Anchor reference, Vector2 scale)
|
||||||
|
{
|
||||||
|
// move the selection before scaling if dragging from top or left anchors.
|
||||||
|
if ((reference & Anchor.x0) > 0 && !moveSelection(new Vector2(-scale.X, 0))) return false;
|
||||||
|
if ((reference & Anchor.y0) > 0 && !moveSelection(new Vector2(0, -scale.Y))) return false;
|
||||||
|
|
||||||
|
Quad selectionQuad = getSurroundingQuad(hitObjects);
|
||||||
|
|
||||||
|
foreach (var h in hitObjects)
|
||||||
|
{
|
||||||
|
var newPosition = h.Position;
|
||||||
|
|
||||||
|
// guard against no-ops and NaN.
|
||||||
|
if (scale.X != 0 && selectionQuad.Width > 0)
|
||||||
|
newPosition.X = selectionQuad.TopLeft.X + (h.X - selectionQuad.TopLeft.X) / selectionQuad.Width * (selectionQuad.Width + scale.X);
|
||||||
|
|
||||||
|
if (scale.Y != 0 && selectionQuad.Height > 0)
|
||||||
|
newPosition.Y = selectionQuad.TopLeft.Y + (h.Y - selectionQuad.TopLeft.Y) / selectionQuad.Height * (selectionQuad.Height + scale.Y);
|
||||||
|
|
||||||
|
h.Position = newPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private bool moveSelection(Vector2 delta)
|
private bool moveSelection(Vector2 delta)
|
||||||
{
|
{
|
||||||
var hitObjects = selectedMovableObjects;
|
var hitObjects = selectedMovableObjects;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user