Fix curve editor panning to be stable

This commit is contained in:
Wojtek Figat
2024-11-30 23:20:57 +01:00
parent 77184c7b52
commit 44d96ad100
2 changed files with 17 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ namespace FlaxEditor.GUI
internal Float2 _mousePos = Float2.Minimum; internal Float2 _mousePos = Float2.Minimum;
internal bool _isMovingSelection; internal bool _isMovingSelection;
internal bool _isMovingTangent; internal bool _isMovingTangent;
internal bool _movedView;
internal bool _movedKeyframes; internal bool _movedKeyframes;
private TangentPoint _movingTangent; private TangentPoint _movingTangent;
private Float2 _movingSelectionStart; private Float2 _movingSelectionStart;
@@ -189,17 +190,20 @@ namespace FlaxEditor.GUI
// Moving view // Moving view
if (_rightMouseDown) if (_rightMouseDown)
{ {
var delta = location - _movingViewLastPos; var movingViewPos = Parent.PointToParent(PointToParent(location));
var delta = movingViewPos - _movingViewLastPos;
if (_editor.CustomViewPanning != null) if (_editor.CustomViewPanning != null)
delta = _editor.CustomViewPanning(delta); delta = _editor.CustomViewPanning(delta);
delta *= GetUseModeMask(_editor.EnablePanning) * _editor.ViewScale; delta *= GetUseModeMask(_editor.EnablePanning);
if (delta.LengthSquared > 0.01f) if (delta.LengthSquared > 0.01f)
{ {
_editor._mainPanel.ViewOffset += delta; _editor._mainPanel.ViewOffset += delta;
_movingViewLastPos = location; _movingViewLastPos = movingViewPos;
_movedView = true;
if (_editor.CustomViewPanning != null) if (_editor.CustomViewPanning != null)
{ {
Cursor = CursorType.SizeAll; if (Cursor == CursorType.Default)
Cursor = CursorType.SizeAll;
} }
else else
{ {
@@ -292,7 +296,8 @@ namespace FlaxEditor.GUI
{ {
_rightMouseDown = true; _rightMouseDown = true;
_rightMouseDownPos = location; _rightMouseDownPos = location;
_movingViewLastPos = location; _movedView = false;
_movingViewLastPos = Parent.PointToParent(PointToParent(location));
} }
// Check if any node is under the mouse // Check if any node is under the mouse
@@ -437,7 +442,7 @@ namespace FlaxEditor.GUI
Cursor = CursorType.Default; Cursor = CursorType.Default;
// Check if no move has been made at all // Check if no move has been made at all
if (Float2.Distance(ref location, ref _rightMouseDownPos) < 2.0f) if (!_movedView)
{ {
var selectionCount = _editor.SelectionCount; var selectionCount = _editor.SelectionCount;
var point = GetChildAt(location) as KeyframePoint; var point = GetChildAt(location) as KeyframePoint;

View File

@@ -263,15 +263,21 @@ namespace FlaxEngine.GUI
/// <inheritdoc /> /// <inheritdoc />
protected override void SetViewOffset(ref Float2 value) protected override void SetViewOffset(ref Float2 value)
{ {
// Update scroll bars but with locked layout
bool wasLocked = _isLayoutLocked; bool wasLocked = _isLayoutLocked;
int layoutUpdateLock = _layoutUpdateLock;
_isLayoutLocked = true; _isLayoutLocked = true;
_layoutUpdateLock = 999;
if (HScrollBar != null) if (HScrollBar != null)
HScrollBar.TargetValue = -value.X; HScrollBar.TargetValue = -value.X;
if (VScrollBar != null) if (VScrollBar != null)
VScrollBar.TargetValue = -value.Y; VScrollBar.TargetValue = -value.Y;
_layoutUpdateLock = layoutUpdateLock;
_isLayoutLocked = wasLocked; _isLayoutLocked = wasLocked;
base.SetViewOffset(ref value); base.SetViewOffset(ref value);
PerformLayout();
} }
/// <summary> /// <summary>