Merge pull request #2783 from smoogipoo/timeline-input-adjustment

Make the editor timeline zoom on mouse scroll
This commit is contained in:
Dean Herbert 2018-06-18 03:11:17 +09:00 committed by GitHub
commit e89155f87c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 52 deletions

View File

@ -13,7 +13,6 @@ using osu.Game.Graphics.Cursor;
using osu.Game.Screens.Edit.Screens.Compose.Timeline; using osu.Game.Screens.Edit.Screens.Compose.Timeline;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
@ -66,7 +65,7 @@ namespace osu.Game.Tests.Visual
{ {
reset(); reset();
AddStep("Set zoom = 10", () => scrollContainer.Zoom = 10); AddStep("Set zoom = 10", () => scrollContainer.Zoom = 10);
AddAssert("Box at 1/2", () => Precision.AlmostEquals(boxQuad.Centre, scrollQuad.Centre)); AddAssert("Box at 1/2", () => Precision.AlmostEquals(boxQuad.Centre, scrollQuad.Centre, 1));
AddAssert("Box width = 10x", () => Precision.AlmostEquals(boxQuad.Size.X, 10 * scrollQuad.Size.X)); AddAssert("Box width = 10x", () => Precision.AlmostEquals(boxQuad.Size.X, 10 * scrollQuad.Size.X));
} }
@ -77,16 +76,12 @@ namespace osu.Game.Tests.Visual
// Scroll in at 0.25 // Scroll in at 0.25
AddStep("Move mouse to 0.25x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X, scrollQuad.Centre.Y))); AddStep("Move mouse to 0.25x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X, scrollQuad.Centre.Y)));
AddStep("Press ctrl", () => InputManager.PressKey(Key.LControl)); AddStep("Scroll by 3", () => InputManager.ScrollBy(new Vector2(0, 3)));
AddStep("Scroll by 3", () => InputManager.ScrollBy(new Vector2(3, 0)));
AddStep("Release ctrl", () => InputManager.ReleaseKey(Key.LControl));
AddAssert("Box not at 0", () => !Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft)); AddAssert("Box not at 0", () => !Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft));
AddAssert("Box 1/4 at 1/4", () => Precision.AlmostEquals(boxQuad.TopLeft.X + 0.25f * boxQuad.Size.X, scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X)); AddAssert("Box 1/4 at 1/4", () => Precision.AlmostEquals(boxQuad.TopLeft.X + 0.25f * boxQuad.Size.X, scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X));
// Scroll out at 0.25 // Scroll out at 0.25
AddStep("Press ctrl", () => InputManager.PressKey(Key.LControl)); AddStep("Scroll by -3", () => InputManager.ScrollBy(new Vector2(0, -3)));
AddStep("Scroll by -3", () => InputManager.ScrollBy(new Vector2(-3, 0)));
AddStep("Release ctrl", () => InputManager.ReleaseKey(Key.LControl));
AddAssert("Box at 0", () => Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft)); AddAssert("Box at 0", () => Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft));
AddAssert("Box 1/4 at 1/4", () => Precision.AlmostEquals(boxQuad.TopLeft.X + 0.25f * boxQuad.Size.X, scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X)); AddAssert("Box 1/4 at 1/4", () => Precision.AlmostEquals(boxQuad.TopLeft.X + 0.25f * boxQuad.Size.X, scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X));
} }
@ -98,15 +93,11 @@ namespace osu.Game.Tests.Visual
// Scroll in at 0.25 // Scroll in at 0.25
AddStep("Move mouse to 0.25x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X, scrollQuad.Centre.Y))); AddStep("Move mouse to 0.25x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X, scrollQuad.Centre.Y)));
AddStep("Press ctrl", () => InputManager.PressKey(Key.LControl)); AddStep("Scroll by 1", () => InputManager.ScrollBy(new Vector2(0, 1)));
AddStep("Scroll by 1", () => InputManager.ScrollBy(new Vector2(1, 0)));
AddStep("Release ctrl", () => InputManager.ReleaseKey(Key.LControl));
// Scroll in at 0.6 // Scroll in at 0.6
AddStep("Move mouse to 0.75x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.75f * scrollQuad.Size.X, scrollQuad.Centre.Y))); AddStep("Move mouse to 0.75x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.75f * scrollQuad.Size.X, scrollQuad.Centre.Y)));
AddStep("Press ctrl", () => InputManager.PressKey(Key.LControl)); AddStep("Scroll by 1", () => InputManager.ScrollBy(new Vector2(0, 1)));
AddStep("Scroll by 1", () => InputManager.ScrollBy(new Vector2(1, 0)));
AddStep("Release ctrl", () => InputManager.ReleaseKey(Key.LControl));
AddAssert("Box not at 0", () => !Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft)); AddAssert("Box not at 0", () => !Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft));
// Very hard to determine actual position, so approximate // Very hard to determine actual position, so approximate
@ -115,15 +106,11 @@ namespace osu.Game.Tests.Visual
AddAssert("Box at correct position (3)", () => Precision.DefinitelyBigger(boxQuad.TopLeft.X + 0.6f * boxQuad.Size.X, scrollQuad.TopLeft.X + 0.6f * scrollQuad.Size.X)); AddAssert("Box at correct position (3)", () => Precision.DefinitelyBigger(boxQuad.TopLeft.X + 0.6f * boxQuad.Size.X, scrollQuad.TopLeft.X + 0.6f * scrollQuad.Size.X));
// Scroll out at 0.6 // Scroll out at 0.6
AddStep("Press ctrl", () => InputManager.PressKey(Key.LControl)); AddStep("Scroll by -1", () => InputManager.ScrollBy(new Vector2(0, -1)));
AddStep("Scroll by -1", () => InputManager.ScrollBy(new Vector2(-1, 0)));
AddStep("Release ctrl", () => InputManager.ReleaseKey(Key.LControl));
// Scroll out at 0.25 // Scroll out at 0.25
AddStep("Move mouse to 0.25x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X, scrollQuad.Centre.Y))); AddStep("Move mouse to 0.25x", () => InputManager.MoveMouseTo(new Vector2(scrollQuad.TopLeft.X + 0.25f * scrollQuad.Size.X, scrollQuad.Centre.Y)));
AddStep("Press ctrl", () => InputManager.PressKey(Key.LControl)); AddStep("Scroll by -1", () => InputManager.ScrollBy(new Vector2(0, -1)));
AddStep("Scroll by -1", () => InputManager.ScrollBy(new Vector2(-1, 0)));
AddStep("Release ctrl", () => InputManager.ReleaseKey(Key.LControl));
AddAssert("Box at 0", () => Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft)); AddAssert("Box at 0", () => Precision.AlmostEquals(boxQuad.TopLeft, scrollQuad.TopLeft));
} }

View File

@ -25,6 +25,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
ZoomDuration = 200; ZoomDuration = 200;
ZoomEasing = Easing.OutQuint; ZoomEasing = Easing.OutQuint;
Zoom = 10; Zoom = 10;
ScrollbarVisible = false;
} }
private WaveformGraph waveform; private WaveformGraph waveform;
@ -150,35 +151,5 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
if (trackWasPlaying) if (trackWasPlaying)
adjustableClock.Start(); adjustableClock.Start();
} }
protected override ScrollbarContainer CreateScrollbar(Direction direction) => new TimelineScrollbar(this, direction);
private class TimelineScrollbar : ScrollbarContainer
{
private readonly Timeline timeline;
public TimelineScrollbar(Timeline timeline, Direction scrollDir)
: base(scrollDir)
{
this.timeline = timeline;
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
if (base.OnMouseDown(state, args))
{
timeline.beginUserDrag();
return true;
}
return false;
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
timeline.endUserDrag();
return base.OnMouseUp(state, args);
}
}
} }
} }

View File

@ -99,10 +99,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
protected override bool OnScroll(InputState state) protected override bool OnScroll(InputState state)
{ {
if (!state.Keyboard.ControlPressed) if (state.Mouse.HasPreciseScroll)
// for now, we don't support zoom when using a precision scroll device. this needs gesture support.
return base.OnScroll(state); return base.OnScroll(state);
setZoomTarget(zoomTarget + state.Mouse.ScrollDelta.X, zoomedContent.ToLocalSpace(state.Mouse.NativeState.Position).X); setZoomTarget(zoomTarget + state.Mouse.ScrollDelta.Y, zoomedContent.ToLocalSpace(state.Mouse.NativeState.Position).X);
return true; return true;
} }