From 3d42973764434fbfe5359996e9edb270a56c759d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 5 Feb 2020 15:58:35 +0900 Subject: [PATCH] Allow scrolling via drag while dragging a hold note handle --- .../Timeline/TimelineBlueprintContainer.cs | 40 ++++++++++++------- .../Timeline/TimelineHitObjectBlueprint.cs | 16 +++++++- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs index 3b9cb1df24..9f3d776e5c 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineBlueprintContainer.cs @@ -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 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 diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index 8a6dd40bde..3de1cd3a4c 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . 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 startTime; + public Action 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 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()