Allow scrolling via drag while dragging a hold note handle

This commit is contained in:
Dean Herbert 2020-02-05 15:58:35 +09:00
parent cef45afbc8
commit 3d42973764
2 changed files with 41 additions and 15 deletions

View File

@ -49,20 +49,9 @@ protected override void LoadComplete()
protected override void OnDrag(DragEvent e)
{
if (timeline != null)
{
var timelineQuad = timeline.ScreenSpaceDrawQuad;
var mouseX = e.ScreenSpaceMousePosition.X;
// scroll if in a drag and dragging outside visible extents
if (mouseX > timelineQuad.TopRight.X)
timeline.ScrollBy((float)((mouseX - timelineQuad.TopRight.X) / 10 * Clock.ElapsedFrameTime));
else if (mouseX < timelineQuad.TopLeft.X)
timeline.ScrollBy((float)((mouseX - timelineQuad.TopLeft.X) / 10 * Clock.ElapsedFrameTime));
}
handleScrollViaDrag(e);
base.OnDrag(e);
lastDragEvent = e;
}
protected override void OnDragEnd(DragEndEvent e)
@ -74,7 +63,7 @@ protected override void OnDragEnd(DragEndEvent e)
protected override void Update()
{
// trigger every frame so drags continue to update selection while playback is scrolling the timeline.
if (IsDragged)
if (lastDragEvent != null)
OnDrag(lastDragEvent);
base.Update();
@ -82,10 +71,33 @@ protected override void Update()
protected override SelectionHandler CreateSelectionHandler() => new TimelineSelectionHandler();
protected override SelectionBlueprint CreateBlueprintFor(HitObject hitObject) => new TimelineHitObjectBlueprint(hitObject);
protected override SelectionBlueprint CreateBlueprintFor(HitObject hitObject) => new TimelineHitObjectBlueprint(hitObject)
{
OnDragHandled = handleScrollViaDrag
};
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new TimelineDragBox(performSelect);
private void handleScrollViaDrag(DragEvent e)
{
lastDragEvent = e;
if (lastDragEvent == null)
return;
if (timeline != null)
{
var timelineQuad = timeline.ScreenSpaceDrawQuad;
var mouseX = e.ScreenSpaceMousePosition.X;
// scroll if in a drag and dragging outside visible extents
if (mouseX > timelineQuad.TopRight.X)
timeline.ScrollBy((float)((mouseX - timelineQuad.TopRight.X) / 10 * Clock.ElapsedFrameTime));
else if (mouseX < timelineQuad.TopLeft.X)
timeline.ScrollBy((float)((mouseX - timelineQuad.TopLeft.X) / 10 * Clock.ElapsedFrameTime));
}
}
internal class TimelineSelectionHandler : SelectionHandler
{
// for now we always allow movement. snapping is provided by the Timeline's "distance" snap implementation

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -28,6 +29,8 @@ public class TimelineHitObjectBlueprint : SelectionBlueprint
[UsedImplicitly]
private readonly Bindable<double> startTime;
public Action<DragEvent> OnDragHandled;
public const float THICKNESS = 5;
private const float circle_size = 16;
@ -78,7 +81,7 @@ public TimelineHitObjectBlueprint(HitObject hitObject)
RelativeSizeAxes = Axes.Both,
}
},
new DragBar(hitObject),
new DragBar(hitObject) { OnDragHandled = e => OnDragHandled?.Invoke(e) }
});
}
}
@ -90,6 +93,8 @@ public class DragBar : CompositeDrawable
[Resolved]
private Timeline timeline { get; set; }
public Action<DragEvent> OnDragHandled;
public DragBar(HitObject hitObject)
{
this.hitObject = hitObject;
@ -155,6 +160,8 @@ protected override void OnDrag(DragEvent e)
{
base.OnDrag(e);
OnDragHandled?.Invoke(e);
var time = timeline.GetTimeFromScreenSpacePosition(e.ScreenSpaceMousePosition);
switch (hitObject)
@ -177,6 +184,13 @@ protected override void OnDrag(DragEvent e)
beatmap.UpdateHitObject(hitObject);
}
protected override void OnDragEnd(DragEndEvent e)
{
base.OnDragEnd(e);
OnDragHandled?.Invoke(null);
}
}
protected override void Update()