1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 02:03:20 +08:00

Merge pull request #10606 from FamousPig/fix-timeline-drag-select-weirdness

Fix timeline zoom during drag-select causing unexpected behaviour
This commit is contained in:
Dan Balasescu 2020-11-02 13:04:26 +09:00 committed by GitHub
commit 8a768669ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 15 deletions

View File

@ -9,10 +9,10 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts; using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline namespace osu.Game.Screens.Edit.Compose.Components.Timeline
@ -137,8 +137,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private class TimelineDragBox : DragBox private class TimelineDragBox : DragBox
{ {
private Vector2 lastMouseDown; // the following values hold the start and end X positions of the drag box in the timeline's local space,
private float localMouseDown; // but with zoom unapplied in order to be able to compensate for positional changes
// while the timeline is being zoomed in/out.
private float? selectionStart;
private float selectionEnd;
[Resolved]
private Timeline timeline { get; set; }
public TimelineDragBox(Action<RectangleF> performSelect) public TimelineDragBox(Action<RectangleF> performSelect)
: base(performSelect) : base(performSelect)
@ -153,21 +159,34 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
public override bool HandleDrag(MouseButtonEvent e) public override bool HandleDrag(MouseButtonEvent e)
{ {
// store the original position of the mouse down, as we may be scrolled during selection. selectionStart ??= e.MouseDownPosition.X / timeline.CurrentZoom;
if (lastMouseDown != e.ScreenSpaceMouseDownPosition)
{
lastMouseDown = e.ScreenSpaceMouseDownPosition;
localMouseDown = e.MouseDownPosition.X;
}
float selection1 = localMouseDown; // only calculate end when a transition is not in progress to avoid bouncing.
float selection2 = e.MousePosition.X; if (Precision.AlmostEquals(timeline.CurrentZoom, timeline.Zoom))
selectionEnd = e.MousePosition.X / timeline.CurrentZoom;
Box.X = Math.Min(selection1, selection2); updateDragBoxPosition();
Box.Width = Math.Abs(selection1 - selection2); return true;
}
private void updateDragBoxPosition()
{
if (selectionStart == null)
return;
float rescaledStart = selectionStart.Value * timeline.CurrentZoom;
float rescaledEnd = selectionEnd * timeline.CurrentZoom;
Box.X = Math.Min(rescaledStart, rescaledEnd);
Box.Width = Math.Abs(rescaledStart - rescaledEnd);
PerformSelection?.Invoke(Box.ScreenSpaceDrawQuad.AABBFloat); PerformSelection?.Invoke(Box.ScreenSpaceDrawQuad.AABBFloat);
return true; }
public override void Hide()
{
base.Hide();
selectionStart = null;
} }
} }

View File

@ -29,9 +29,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private readonly Container zoomedContent; private readonly Container zoomedContent;
protected override Container<Drawable> Content => zoomedContent; protected override Container<Drawable> Content => zoomedContent;
private float currentZoom = 1; private float currentZoom = 1;
/// <summary>
/// The current zoom level of <see cref="ZoomableScrollContainer" />.
/// It may differ from <see cref="Zoom" /> during transitions.
/// </summary>
public float CurrentZoom => currentZoom;
[Resolved(canBeNull: true)] [Resolved(canBeNull: true)]
private IFrameBasedClock editorClock { get; set; } private IFrameBasedClock editorClock { get; set; }