Skip to content

Commit

Permalink
Merge pull request #43 from WiseTechGlobal/WI00737678---RemoveDragNod…
Browse files Browse the repository at this point in the history
…esBehaviorUpdate

WI00737678---RemoveDragNodesBehavior
  • Loading branch information
gnawisetech committed Jul 11, 2024
2 parents ef6a892 + 87b6778 commit 5082e89
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Blazor.Diagrams.Core/Behaviors/DragMovablesBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Blazor.Diagrams.Core.Behaviors;

public class DragMovablesBehavior : DragBehavior
{
private readonly Dictionary<MovableModel, Point> _initialPositions;
protected readonly Dictionary<MovableModel, Point> _initialPositions;
protected double? _lastClientX;
protected double? _lastClientY;
protected bool _moved;
Expand Down Expand Up @@ -58,7 +58,6 @@ protected override void OnPointerMove(Model? model, PointerEventArgs e)
if (_initialPositions.Count == 0 || _lastClientX == null || _lastClientY == null)
return;

_moved = true;
var deltaX = (e.ClientX - _lastClientX.Value) / Diagram.Zoom;
var deltaY = (e.ClientY - _lastClientY.Value) / Diagram.Zoom;

Expand All @@ -67,21 +66,23 @@ protected override void OnPointerMove(Model? model, PointerEventArgs e)

MoveNodes(_totalMovedX, _totalMovedY);

_moved = true;
_lastClientX = e.ClientX;
_lastClientY = e.ClientY;

}

protected virtual void OnPanChanged(double deltaX, double deltaY)
{
if (_initialPositions.Count == 0 || _lastClientX == null || _lastClientY == null)
return;

_moved = true;

_totalMovedX += deltaX;
_totalMovedY += deltaY;
_totalMovedX += deltaX / Diagram.Zoom;
_totalMovedY += deltaY / Diagram.Zoom;

MoveNodes(_totalMovedX, _totalMovedY);

_moved = true;
}

protected virtual void MoveNodes(double deltaX, double deltaY)
Expand Down Expand Up @@ -118,6 +119,7 @@ protected override void OnPointerUp(Model? model, PointerEventArgs e)
_totalMovedY = 0;
_lastClientX = null;
_lastClientY = null;
_moved = false;
}

private double ApplyGridSize(double n)
Expand All @@ -134,4 +136,4 @@ public override void Dispose()
_initialPositions.Clear();
Diagram.PanChanged -= OnPanChanged;
}
}
}

0 comments on commit 5082e89

Please sign in to comment.