Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WI00737678---RemoveDragNodesBehavior #43

Merged
merged 6 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
Loading