Skip to content

Commit

Permalink
Merge pull request ppy#12650 from frenzibyte/selection-box-use-aabb
Browse files Browse the repository at this point in the history
Compute selection box area using the bounding box of the blueprints instead
  • Loading branch information
peppy authored May 2, 2021
2 parents 2e24b69 + b83aa0b commit a8db634
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
Expand Down Expand Up @@ -327,20 +328,15 @@ protected override void Update()
return;

// Move the rectangle to cover the items
var topLeft = new Vector2(float.MaxValue, float.MaxValue);
var bottomRight = new Vector2(float.MinValue, float.MinValue);
RectangleF selectionRect = ToLocalSpace(selectedBlueprints[0].SelectionQuad).AABBFloat;

foreach (var blueprint in selectedBlueprints)
{
topLeft = Vector2.ComponentMin(topLeft, ToLocalSpace(blueprint.SelectionQuad.TopLeft));
bottomRight = Vector2.ComponentMax(bottomRight, ToLocalSpace(blueprint.SelectionQuad.BottomRight));
}
for (int i = 1; i < selectedBlueprints.Count; i++)
selectionRect = RectangleF.Union(selectionRect, ToLocalSpace(selectedBlueprints[i].SelectionQuad).AABBFloat);

topLeft -= new Vector2(5);
bottomRight += new Vector2(5);
selectionRect = selectionRect.Inflate(5f);

content.Size = bottomRight - topLeft;
content.Position = topLeft;
content.Position = selectionRect.Location;
content.Size = selectionRect.Size;
}

#endregion
Expand Down

0 comments on commit a8db634

Please sign in to comment.