Skip to content

Commit

Permalink
Merge pull request #41 from WiseTechGlobal/WI00737678---RemoveTheDrag…
Browse files Browse the repository at this point in the history
…NodesBehavior

WI00737678---RemoveDragNodesBehavior
  • Loading branch information
gnawisetech committed Jun 19, 2024
2 parents 497ec4e + 2866a8b commit 7182eaa
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/Blazor.Diagrams.Core/Behaviors/DragMovablesBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@

namespace Blazor.Diagrams.Core.Behaviors;

public class DragMovablesBehavior : Behavior
public class DragMovablesBehavior : DragBehavior
{
private readonly Dictionary<MovableModel, Point> _initialPositions;
private double? _lastClientX;
private double? _lastClientY;
private bool _moved;
private double _totalMovedX = 0;
private double _totalMovedY = 0;
protected double? _lastClientX;
protected double? _lastClientY;
protected bool _moved;
protected double _totalMovedX = 0;
protected double _totalMovedY = 0;

public DragMovablesBehavior(Diagram diagram) : base(diagram)
{
_initialPositions = new Dictionary<MovableModel, Point>();
Diagram.PointerDown += OnPointerDown;
Diagram.PointerMove += OnPointerMove;
Diagram.PointerUp += OnPointerUp;
Diagram.PanChanged += OnPanChanged;
}

private void OnPointerDown(Model? model, PointerEventArgs e)
protected override void OnPointerDown(Model? model, PointerEventArgs e)
{
if (model is not MovableModel)
return;
Expand Down Expand Up @@ -56,7 +53,7 @@ private void OnPointerDown(Model? model, PointerEventArgs e)
_moved = false;
}

private void OnPointerMove(Model? model, PointerEventArgs e)
protected override void OnPointerMove(Model? model, PointerEventArgs e)
{
if (_initialPositions.Count == 0 || _lastClientX == null || _lastClientY == null)
return;
Expand All @@ -68,13 +65,13 @@ private void OnPointerMove(Model? model, PointerEventArgs e)
_totalMovedX += deltaX;
_totalMovedY += deltaY;

MoveNodes(model, _totalMovedX, _totalMovedY);
MoveNodes(_totalMovedX, _totalMovedY);

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

}
public void OnPanChanged(double deltaX, double deltaY)
protected virtual void OnPanChanged(double deltaX, double deltaY)
{
if (_initialPositions.Count == 0 || _lastClientX == null || _lastClientY == null)
return;
Expand All @@ -84,10 +81,10 @@ public void OnPanChanged(double deltaX, double deltaY)
_totalMovedX += deltaX;
_totalMovedY += deltaY;

MoveNodes(null, _totalMovedX, _totalMovedY);
MoveNodes(_totalMovedX, _totalMovedY);
}

private void MoveNodes(Model? model, double deltaX, double deltaY)
protected virtual void MoveNodes(double deltaX, double deltaY)
{
foreach (var (movable, initialPosition) in _initialPositions)
{
Expand All @@ -104,7 +101,7 @@ private void MoveNodes(Model? model, double deltaX, double deltaY)
}
}

private void OnPointerUp(Model? model, PointerEventArgs e)
protected override void OnPointerUp(Model? model, PointerEventArgs e)
{
if (_initialPositions.Count == 0)
return;
Expand Down Expand Up @@ -135,9 +132,6 @@ private double ApplyGridSize(double n)
public override void Dispose()
{
_initialPositions.Clear();
Diagram.PointerDown -= OnPointerDown;
Diagram.PointerMove -= OnPointerMove;
Diagram.PointerUp -= OnPointerUp;
Diagram.PanChanged -= OnPanChanged;
}
}

0 comments on commit 7182eaa

Please sign in to comment.