1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 17:02:55 +08:00

Implement magnification buttons

This commit is contained in:
smoogipoo 2017-10-12 17:31:21 +09:00
parent de8f9325a3
commit 4586877239
2 changed files with 32 additions and 7 deletions

View File

@ -85,12 +85,17 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
Padding = new MarginPadding { Vertical = 5 }, Padding = new MarginPadding { Vertical = 5 },
Children = new[] Children = new[]
{ {
new TimelineButton { Icon = FontAwesome.fa_search_plus }, new TimelineButton
{
Icon = FontAwesome.fa_search_plus,
Action = () => timelineContainer.Zoom++
},
new TimelineButton new TimelineButton
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Icon = FontAwesome.fa_search_minus Icon = FontAwesome.fa_search_minus,
Action = () => timelineContainer.Zoom--
}, },
} }
} }

View File

@ -90,23 +90,43 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
return; return;
zoom = value; zoom = value;
// Make the zoom target default to the center of the graph if it hasn't been set
if (relativeContentZoomTarget == null)
relativeContentZoomTarget = ToSpaceOfOtherDrawable(DrawSize / 2, Content).X / Content.DrawSize.X;
if (localZoomTarget == null)
localZoomTarget = DrawSize.X / 2;
Content.ResizeWidthTo(Zoom); Content.ResizeWidthTo(Zoom);
// Update the scroll position to focus on the zoom target
float scrollPos = Content.DrawSize.X * relativeContentZoomTarget.Value - localZoomTarget.Value;
ScrollTo(scrollPos, false);
relativeContentZoomTarget = null;
localZoomTarget = null;
} }
} }
/// <summary>
/// Zoom target as a relative position in the <see cref="Content"/> space.
/// </summary>
private float? relativeContentZoomTarget;
/// <summary>
/// Zoom target as a position in our local space.
/// </summary>
private float? localZoomTarget;
protected override bool OnWheel(InputState state) protected override bool OnWheel(InputState state)
{ {
if (!state.Keyboard.ControlPressed) if (!state.Keyboard.ControlPressed)
return base.OnWheel(state); return base.OnWheel(state);
float relativeContentPosition = Content.ToLocalSpace(state.Mouse.NativeState.Position).X / Content.DrawSize.X; relativeContentZoomTarget = Content.ToLocalSpace(state.Mouse.NativeState.Position).X / Content.DrawSize.X;
float position = ToLocalSpace(state.Mouse.NativeState.Position).X; localZoomTarget = ToLocalSpace(state.Mouse.NativeState.Position).X;
Zoom += state.Mouse.WheelDelta; Zoom += state.Mouse.WheelDelta;
float scrollPos = Content.DrawSize.X * relativeContentPosition - position;
ScrollTo(scrollPos, false);
return true; return true;
} }
} }