From 7fad9ce34ac7a94847143b3a5ffeeb62fba5c1b9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Sep 2020 15:17:27 +0900 Subject: [PATCH] Simplify HandleScale method --- .../Edit/OsuSelectionHandler.cs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs b/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs index 1f250f078d..6b4f13db35 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs @@ -43,13 +43,7 @@ public override bool HandleMovement(MoveSelectionEvent moveEvent) => public override bool HandleScale(Vector2 scale, Anchor reference) { - // cancel out scale in axes we don't care about (based on which drag handle was used). - if ((reference & Anchor.x1) > 0) scale.X = 0; - if ((reference & Anchor.y1) > 0) scale.Y = 0; - - // reverse the scale direction if dragging from top or left. - if ((reference & Anchor.x0) > 0) scale.X = -scale.X; - if ((reference & Anchor.y0) > 0) scale.Y = -scale.Y; + adjustScaleFromAnchor(ref scale, reference); var hitObjects = selectedMovableObjects; @@ -58,11 +52,11 @@ public override bool HandleScale(Vector2 scale, Anchor reference) // is not looking to change the duration of the slider but expand the whole pattern. if (hitObjects.Length == 1 && hitObjects.First() is Slider slider) { - var quad = getSurroundingQuad(slider.Path.ControlPoints.Select(p => p.Position.Value)); - Vector2 delta = Vector2.One + new Vector2(scale.X / quad.Width, scale.Y / quad.Height); + 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 *= delta; + point.Position.Value *= pathRelativeDeltaScale; } else { @@ -72,23 +66,29 @@ public override bool HandleScale(Vector2 scale, Anchor reference) Quad quad = getSurroundingQuad(hitObjects); - Vector2 minPosition = quad.TopLeft; - - Vector2 size = quad.Size; - Vector2 newSize = size + scale; - foreach (var h in hitObjects) { - if (scale.X != 1) - h.Position = new Vector2(minPosition.X + (h.X - minPosition.X) / size.X * newSize.X, h.Y); - if (scale.Y != 1) - h.Position = new Vector2(h.X, minPosition.Y + (h.Y - minPosition.Y) / size.Y * newSize.Y); + h.Position = new Vector2( + quad.TopLeft.X + (h.X - quad.TopLeft.X) / quad.Width * (quad.Width + scale.X), + quad.TopLeft.Y + (h.Y - quad.TopLeft.Y) / quad.Height * (quad.Height + scale.Y) + ); } } return true; } + 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). + if ((reference & Anchor.x1) > 0) scale.X = 0; + if ((reference & Anchor.y1) > 0) scale.Y = 0; + + // reverse the scale direction if dragging from top or left. + if ((reference & Anchor.x0) > 0) scale.X = -scale.X; + if ((reference & Anchor.y0) > 0) scale.Y = -scale.Y; + } + public override bool HandleRotation(float delta) { var hitObjects = selectedMovableObjects;