1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Combine both calls to use same pathway

This commit is contained in:
Dean Herbert 2022-07-22 14:44:48 +09:00
parent 997fe00cdc
commit 4cec9a085a
2 changed files with 12 additions and 11 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 += Timeline.CalculateZoomChange(change);
}
}

View File

@ -104,8 +104,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
set => updateZoom(value);
}
private const float zoom_change_sensitivity = 0.02f;
private void updateZoom(float? value = null)
{
float newZoom = Math.Clamp(value ?? Zoom, MinZoom, MaxZoom);
@ -129,7 +127,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (e.AltPressed)
{
// zoom when holding alt.
setZoomTarget(zoomTarget + CalculateZoomChange(e.ScrollDelta.Y), zoomedContent.ToLocalSpace(e.ScreenSpaceMousePosition).X);
AdjustZoomRelatively(e.ScrollDelta.Y, zoomedContent.ToLocalSpace(e.ScreenSpaceMousePosition).X);
return true;
}
@ -147,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();
}
@ -167,8 +172,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
}
public float CalculateZoomChange(float rawChange) => rawChange * (MaxZoom - minZoom) * zoom_change_sensitivity;
private class TransformZoom : Transform<float, ZoomableScrollContainer>
{
/// <summary>