Implement custom drag box and allow drag seeking once again

This commit is contained in:
Dean Herbert
2020-01-22 14:58:15 +09:00
parent e3a2b20f63
commit a6775d1bd3
2 changed files with 51 additions and 20 deletions

View File

@ -17,9 +17,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
public class DragBox : CompositeDrawable
{
private readonly Action<RectangleF> performSelection;
protected readonly Action<RectangleF> PerformSelection;
private Drawable box;
protected Drawable Box;
/// <summary>
/// Creates a new <see cref="DragBox"/>.
@ -27,7 +27,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="performSelection">A delegate that performs drag selection.</param>
public DragBox(Action<RectangleF> performSelection)
{
this.performSelection = performSelection;
PerformSelection = performSelection;
RelativeSizeAxes = Axes.Both;
AlwaysPresent = true;
@ -37,19 +37,21 @@ namespace osu.Game.Screens.Edit.Compose.Components
[BackgroundDependencyLoader]
private void load()
{
InternalChild = box = new Container
{
Masking = true,
BorderColour = Color4.White,
BorderThickness = SelectionHandler.BORDER_RADIUS,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.1f
}
};
InternalChild = Box = CreateBox();
}
protected virtual Drawable CreateBox() => new Container
{
Masking = true,
BorderColour = Color4.White,
BorderThickness = SelectionHandler.BORDER_RADIUS,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.1f
}
};
/// <summary>
/// Handle a forwarded mouse event.
/// </summary>
@ -68,10 +70,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
var topLeft = ToLocalSpace(dragRectangle.TopLeft);
var bottomRight = ToLocalSpace(dragRectangle.BottomRight);
box.Position = topLeft;
box.Size = bottomRight - topLeft;
Box.Position = topLeft;
Box.Size = bottomRight - topLeft;
performSelection?.Invoke(dragRectangle);
PerformSelection?.Invoke(dragRectangle);
return true;
}
}