2018-02-12 17:19:55 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-02-14 16:54:43 +08:00
|
|
|
|
/// A box which encloses <see cref="DrawableHitObject"/>s.
|
2018-02-12 17:19:55 +08:00
|
|
|
|
/// </summary>
|
2018-02-15 17:06:33 +08:00
|
|
|
|
public class CaptureBox : VisibilityContainer
|
2018-02-12 17:19:55 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly IDrawable captureArea;
|
|
|
|
|
private readonly IReadOnlyList<DrawableHitObject> capturedObjects;
|
|
|
|
|
|
2018-02-15 17:06:33 +08:00
|
|
|
|
public CaptureBox(IDrawable captureArea, IReadOnlyList<DrawableHitObject> capturedObjects)
|
2018-02-12 17:19:55 +08:00
|
|
|
|
{
|
|
|
|
|
this.captureArea = captureArea;
|
|
|
|
|
this.capturedObjects = capturedObjects;
|
|
|
|
|
|
2018-02-12 18:00:44 +08:00
|
|
|
|
Masking = true;
|
2018-02-20 13:25:42 +08:00
|
|
|
|
BorderThickness = SelectionBox.BORDER_RADIUS;
|
2018-02-12 17:19:55 +08:00
|
|
|
|
|
2018-02-12 18:00:44 +08:00
|
|
|
|
InternalChild = new Box
|
2018-02-12 17:19:55 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-02-12 18:00:44 +08:00
|
|
|
|
AlwaysPresent = true,
|
|
|
|
|
Alpha = 0
|
2018-02-12 17:19:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
State = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2018-02-12 18:00:44 +08:00
|
|
|
|
BorderColour = colours.Yellow;
|
2018-02-12 17:19:55 +08:00
|
|
|
|
|
|
|
|
|
// Move the rectangle to cover the hitobjects
|
|
|
|
|
var topLeft = new Vector2(float.MaxValue, float.MaxValue);
|
|
|
|
|
var bottomRight = new Vector2(float.MinValue, float.MinValue);
|
|
|
|
|
|
|
|
|
|
foreach (var obj in capturedObjects)
|
|
|
|
|
{
|
|
|
|
|
topLeft = Vector2.ComponentMin(topLeft, captureArea.ToLocalSpace(obj.SelectionQuad.TopLeft));
|
|
|
|
|
bottomRight = Vector2.ComponentMax(bottomRight, captureArea.ToLocalSpace(obj.SelectionQuad.BottomRight));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topLeft -= new Vector2(5);
|
|
|
|
|
bottomRight += new Vector2(5);
|
|
|
|
|
|
2018-02-15 17:06:33 +08:00
|
|
|
|
Size = bottomRight - topLeft;
|
|
|
|
|
Position = topLeft;
|
2018-02-14 13:38:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 18:11:29 +08:00
|
|
|
|
public override bool DisposeOnDeathRemoval => true;
|
2018-02-14 13:38:37 +08:00
|
|
|
|
|
2018-02-15 18:11:29 +08:00
|
|
|
|
protected override void PopIn() => this.FadeIn();
|
2018-02-15 17:06:33 +08:00
|
|
|
|
protected override void PopOut() => this.FadeOut();
|
2018-02-12 17:19:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|