1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 16:12:57 +08:00

Merge pull request #19278 from Cwazywierdo/timeline-relative-zoom

Make editor timeline zoom relative to song length
This commit is contained in:
Dean Herbert 2022-07-22 15:37:47 +09:00 committed by GitHub
commit 1774a96455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -118,7 +118,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
RelativeSizeAxes = Axes.Y,
Height = 0.5f,
Icon = FontAwesome.Solid.SearchPlus,
Action = () => changeZoom(1)
Action = () => Timeline.AdjustZoomRelatively(1)
},
new TimelineButton
{
@ -127,7 +127,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
RelativeSizeAxes = Axes.Y,
Height = 0.5f,
Icon = FontAwesome.Solid.SearchMinus,
Action = () => changeZoom(-1)
Action = () => Timeline.AdjustZoomRelatively(-1)
},
}
}
@ -153,7 +153,5 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Timeline.ControlPointsVisible.BindTo(controlPointsCheckbox.Current);
Timeline.TicksVisible.BindTo(ticksCheckbox.Current);
}
private void changeZoom(float change) => Timeline.Zoom += change;
}
}

View File

@ -127,7 +127,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (e.AltPressed)
{
// zoom when holding alt.
setZoomTarget(zoomTarget + e.ScrollDelta.Y, zoomedContent.ToLocalSpace(e.ScreenSpaceMousePosition).X);
AdjustZoomRelatively(e.ScrollDelta.Y, zoomedContent.ToLocalSpace(e.ScreenSpaceMousePosition).X);
return true;
}
@ -145,12 +145,19 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
zoomedContentWidthCache.Validate();
}
public void AdjustZoomRelatively(float change, float? focusPoint = null)
{
const float zoom_change_sensitivity = 0.02f;
setZoomTarget(zoomTarget + change * (MaxZoom - minZoom) * zoom_change_sensitivity, focusPoint);
}
private float zoomTarget = 1;
private void setZoomTarget(float newZoom, float focusPoint)
private void setZoomTarget(float newZoom, float? focusPoint = null)
{
zoomTarget = Math.Clamp(newZoom, MinZoom, MaxZoom);
transformZoomTo(zoomTarget, focusPoint, ZoomDuration, ZoomEasing);
transformZoomTo(zoomTarget, focusPoint ?? DrawWidth / 2, ZoomDuration, ZoomEasing);
OnZoomChanged();
}