Add preserving timeline position when zooming with a mouse wheel

#519
This commit is contained in:
Wojtek Figat
2021-08-23 14:37:48 +02:00
parent c0e8488b83
commit ee29a1bc91

View File

@@ -223,8 +223,16 @@ namespace FlaxEditor.GUI.Timeline.GUI
// Zoom in/out
if (IsMouseOver && Root.GetKey(KeyboardKeys.Control))
{
// TODO: preserve the view center point for easier zooming
var locationTimeOld = _timeline.MediaBackground.PointFromParent(_timeline, _timeline.Size * 0.5f).X;
var frame = (locationTimeOld - Timeline.StartOffset * 2.0f) / _timeline.Zoom / Timeline.UnitsPerSecond * _timeline.FramesPerSecond;
_timeline.Zoom += delta * 0.1f;
var locationTimeNew = frame / _timeline.FramesPerSecond * Timeline.UnitsPerSecond * _timeline.Zoom + Timeline.StartOffset * 2.0f;
var locationTimeDelta = locationTimeNew - locationTimeOld;
var scroll = _timeline.MediaBackground.HScrollBar;
if (scroll.Visible && scroll.Enabled)
scroll.TargetValue += locationTimeDelta;
return true;
}