From ee29a1bc91b0bc679d34ebdf7444036ff309779c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 23 Aug 2021 14:37:48 +0200 Subject: [PATCH] Add preserving timeline position when zooming with a mouse wheel #519 --- Source/Editor/GUI/Timeline/GUI/Background.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Editor/GUI/Timeline/GUI/Background.cs b/Source/Editor/GUI/Timeline/GUI/Background.cs index cc143e945..62c6b3b31 100644 --- a/Source/Editor/GUI/Timeline/GUI/Background.cs +++ b/Source/Editor/GUI/Timeline/GUI/Background.cs @@ -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; }