mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Use alternative solution to avoid storing last zoom
This commit is contained in:
@ -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
|
||||||
@ -107,7 +107,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
OnDragHandled = handleScrollViaDrag
|
OnDragHandled = handleScrollViaDrag
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new TimelineDragBox(performSelect, this);
|
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new TimelineDragBox(performSelect);
|
||||||
|
|
||||||
private void handleScrollViaDrag(DragEvent e)
|
private void handleScrollViaDrag(DragEvent e)
|
||||||
{
|
{
|
||||||
@ -137,17 +137,18 @@ 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,
|
||||||
|
// 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;
|
||||||
|
|
||||||
private float? lastZoom;
|
[Resolved]
|
||||||
private float localMouseDown;
|
private Timeline timeline { get; set; }
|
||||||
|
|
||||||
private readonly TimelineBlueprintContainer parent;
|
public TimelineDragBox(Action<RectangleF> performSelect)
|
||||||
|
|
||||||
public TimelineDragBox(Action<RectangleF> performSelect, TimelineBlueprintContainer parent)
|
|
||||||
: base(performSelect)
|
: base(performSelect)
|
||||||
{
|
{
|
||||||
this.parent = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateBox() => new Box
|
protected override Drawable CreateBox() => new Box
|
||||||
@ -158,27 +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;
|
|
||||||
lastZoom = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Zooming the timeline shifts the coordinate system. zoomCorrection compensates for that
|
// only calculate end when a transition is not in progress to avoid bouncing.
|
||||||
float zoomCorrection = lastZoom.HasValue ? (parent.timeline.CurrentZoom / lastZoom.Value) : 1;
|
if (Precision.AlmostEquals(timeline.CurrentZoom, timeline.Zoom))
|
||||||
localMouseDown *= zoomCorrection;
|
selectionEnd = e.MousePosition.X / timeline.CurrentZoom;
|
||||||
lastZoom = parent.timeline.CurrentZoom;
|
|
||||||
|
|
||||||
float selection1 = localMouseDown;
|
updateDragBoxPosition();
|
||||||
float selection2 = e.MousePosition.X * zoomCorrection;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Box.X = Math.Min(selection1, selection2);
|
private void updateDragBoxPosition()
|
||||||
Box.Width = Math.Abs(selection1 - selection2);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user