Skip to content

Commit

Permalink
Started using Pan Changed for DragNewLinkBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvarenga1 committed Jan 4, 2024
1 parent b6ac41b commit 0e8e39a
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams.Core/Behaviors/DebugEventsBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void Nodes_Added(NodeModel obj)
Console.WriteLine($"Nodes.Added, Nodes=[{obj}]");
}

private void Diagram_PanChanged(double deltaX, double deltaY)
private void Diagram_PanChanged(double deltaX, double deltaY, double clientX, double clientY)
{
Console.WriteLine($"PanChanged, Pan={Diagram.Pan}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams.Core/Behaviors/DragMovablesBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void OnPointerMove(Model? model, PointerEventArgs e)
_lastClientY = e.ClientY;

}
public void OnPanChanged(double deltaX, double deltaY)
public void OnPanChanged(double deltaX, double deltaY, double clientX, double clientY)
{
if (_initialPositions.Count == 0 || _lastClientX == null || _lastClientY == null)
return;
Expand Down
8 changes: 4 additions & 4 deletions src/Blazor.Diagrams.Core/Behaviors/DragNewLinkBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DragNewLinkBehavior(Diagram diagram) : base(diagram)
Diagram.PointerDown += OnPointerDown;
Diagram.PointerMove += OnPointerMove;
Diagram.PointerUp += OnPointerUp;
Diagram.Wheel += OnWheel;
Diagram.PanChanged += OnPanChanged;
}

public void StartFrom(ILinkable source, double clientX, double clientY)
Expand Down Expand Up @@ -79,12 +79,12 @@ private void OnPointerMove(Model? model, MouseEventArgs e)
UpdateLinkPosition(e.ClientX, e.ClientY);
}

private void OnWheel(WheelEventArgs e)
private void OnPanChanged(double deltaX, double deltaY, double clientX, double clientY)
{
if (OngoingLink == null)
return;

UpdateLinkPosition(e.ClientX + e.DeltaX, e.ClientY + e.DeltaY);
UpdateLinkPosition(clientX + deltaX, clientY + deltaY);
}

private void UpdateLinkPosition(double clientX, double clientY)
Expand Down Expand Up @@ -183,6 +183,6 @@ public override void Dispose()
Diagram.PointerDown -= OnPointerDown;
Diagram.PointerMove -= OnPointerMove;
Diagram.PointerUp -= OnPointerUp;
Diagram.Wheel -= OnWheel;
Diagram.PanChanged -= OnPanChanged;
}
}
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams.Core/Behaviors/ScrollBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override void OnDiagramWheel(WheelEventArgs e)
var deltaX = e.ClientX - _lastClientX + (Diagram.Pan.X - x);
var deltaY = e.ClientY - _lastClientY + (Diagram.Pan.Y - y);

Diagram.SetPan(x, y, deltaX, deltaY);
Diagram.SetPan(x, y, deltaX, deltaY, _lastClientX, _lastClientY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public VirtualizationBehavior(Diagram diagram) : base(diagram)
Diagram.ContainerChanged += CheckVisibility;
}

private void CheckVisibility(double deltaX, double deltaY)
private void CheckVisibility(double deltaX, double deltaY, double clientX, double clientY)
{
CheckVisibility();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams.Core/Behaviors/ZoomBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override void OnDiagramWheel(WheelEventArgs e)

Diagram.Batch(() =>
{
Diagram.SetPan(newPanX, newPanY, 0, 0);
Diagram.SetPan(newPanX, newPanY, 0, 0, 0, 0);
Diagram.SetZoom(newZoom);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/Blazor.Diagrams.Core/Diagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class Diagram
public event Action<Model?, PointerEventArgs>? PointerDoubleClick;

public event Action<SelectableModel>? SelectionChanged;
public event Action<double, double>? PanChanged;
public event Action<double, double, double, double>? PanChanged;
public event Action? ZoomChanged;
public event Action? ContainerChanged;
public event Action? Changed;
Expand Down Expand Up @@ -237,17 +237,17 @@ public void ZoomToFit(double margin = 10)
Refresh();
}

public void SetPan(double x, double y, double deltaX, double deltaY)
public void SetPan(double x, double y, double deltaX, double deltaY, double clientX, double clientY)
{
Pan = new Point(x, y);
PanChanged?.Invoke(deltaX, deltaY);
PanChanged?.Invoke(deltaX, deltaY, clientX, clientY);
Refresh();
}

public void UpdatePan(double deltaX, double deltaY)
{
Pan = Pan.Add(deltaX, deltaY);
PanChanged?.Invoke(deltaX, deltaY);
PanChanged?.Invoke(deltaX, deltaY, 0, 0);
Refresh();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void OnPointerMove(Model? model, PointerEventArgs e)
ResizeNode(deltaX, deltaY);
}

public void OnPanChanged(double deltaX, double deltaY)
public void OnPanChanged(double deltaX, double deltaY, double clientX, double clientY)
{
if (_nodeModel is null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void OnPointerMove(Model? model, PointerEventArgs e)
ResizeNode(deltaX, deltaY);
}

public void OnPanChanged(double deltaX, double deltaY)
public void OnPanChanged(double deltaX, double deltaY, double clientX, double clientY)
{
if (_nodeModel is null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IResizerProvider : IPositionProvider
public string? Class { get; }
public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs eventArgs);
public void OnPointerMove(Model? model, PointerEventArgs args);
public void OnPanChanged(double deltaX, double deltaY);
public void OnPanChanged(double deltaX, double deltaY, double clientX, double clientY);
public void OnResizeEnd(Model? model, PointerEventArgs args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void OnPointerMove(Model? model, PointerEventArgs e)
ResizeNode(deltaX, deltaY);
}

public void OnPanChanged(double deltaX, double deltaY)
public void OnPanChanged(double deltaX, double deltaY, double clientX, double clientY)
{
if (_nodeModel is null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void OnPointerMove(Model? model, PointerEventArgs e)
ResizeNode(deltaX, deltaY);
}

public void OnPanChanged(double deltaX, double deltaY)
public void OnPanChanged(double deltaX, double deltaY, double clientX, double clientY)
{
if (_nodeModel is null) return;

Expand Down
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams/Components/Widgets/GridWidget.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void OnParametersSet()
_visible = BlazorDiagram.Zoom > ZoomThreshold;
}

private void RefreshPosition(double deltaX, double deltaY)
private void RefreshPosition(double deltaX, double deltaY, double clientX, double clientY)
{
RefreshPosition();
}
Expand Down

0 comments on commit 0e8e39a

Please sign in to comment.