mirror of
https://github.com/ppy/osu
synced 2024-12-15 03:16:17 +00:00
Implement custom drag box and allow drag seeking once again
This commit is contained in:
parent
e3a2b20f63
commit
a6775d1bd3
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,17 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
public TimelineHitObjectDisplay(EditorBeatmap beatmap)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
Height = 0.4f;
|
||||
|
||||
AddInternal(new Box
|
||||
{
|
||||
Colour = Color4.Black,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0.1f,
|
||||
});
|
||||
}
|
||||
|
||||
protected override SelectionBlueprintContainer CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both };
|
||||
@ -49,14 +60,32 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
return new TimelineHitObjectRepresentation(hitObject);
|
||||
}
|
||||
|
||||
internal class NoDragDragBox : DragBox
|
||||
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new CustomDragBox(performSelect);
|
||||
|
||||
internal class CustomDragBox : DragBox
|
||||
{
|
||||
public NoDragDragBox(Action<RectangleF> performSelect)
|
||||
public CustomDragBox(Action<RectangleF> performSelect)
|
||||
: base(performSelect)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool UpdateDrag(MouseButtonEvent e) => false;
|
||||
protected override Drawable CreateBox() => new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Alpha = 0.3f
|
||||
};
|
||||
|
||||
public override bool UpdateDrag(MouseButtonEvent e)
|
||||
{
|
||||
float selection1 = e.MouseDownPosition.X;
|
||||
float selection2 = e.MousePosition.X;
|
||||
|
||||
Box.X = Math.Min(selection1, selection2);
|
||||
Box.Width = Math.Abs(selection1 - selection2);
|
||||
|
||||
PerformSelection?.Invoke(Box.ScreenSpaceDrawQuad.AABBFloat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class TimelineHitObjectRepresentation : SelectionBlueprint
|
||||
|
Loading…
Reference in New Issue
Block a user