Skip to content

Commit

Permalink
Merge pull request #28 from WiseTechGlobal/RAL/WI00655146/Refactor_Bl…
Browse files Browse the repository at this point in the history
…azor_Diagrams

Refactor Resizer Provider
  • Loading branch information
Alvarenga1 authored Mar 7, 2024
2 parents d9b1a63 + 8967512 commit 02e3564
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Blazor.Diagrams.Core/Positions/Resizing/ResizerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public abstract class ResizerProvider : IPositionProvider
{
abstract public string? Class { get; }

private Size? _originalSize = null;
private Point? _originalPosition = null;
protected Size? _originalSize { get; set; }
protected Point? _originalPosition { get; set; }
private double? _lastClientX;
private double? _lastClientY;
private NodeModel? _nodeModel = null;
protected NodeModel? _nodeModel { get; set; }
private double _totalMovedX = 0;
private double _totalMovedY = 0;
private Diagram? _diagram;
protected Diagram? _diagram { get; set; }

abstract public bool ShouldChangeXPositionOnResize { get; }
abstract public bool ShouldChangeYPositionOnResize { get; }
Expand All @@ -27,7 +27,7 @@ public abstract class ResizerProvider : IPositionProvider

abstract public Point? GetPosition(Model model);

virtual public void ResizeNode(double deltaX, double deltaY)
virtual public (Size size, Point position) CalculateNewSizeAndPosition(double deltaX, double deltaY)
{
_totalMovedX += deltaX;
_totalMovedY += deltaY;
Expand All @@ -49,8 +49,13 @@ virtual public void ResizeNode(double deltaX, double deltaY)
positionY = _nodeModel.Position.Y;
}

_nodeModel.SetPosition(positionX, positionY);
_nodeModel.SetSize(width, height);
return (new Size(width, height), new Point(positionX, positionY));
}

virtual public void SetSizeAndPosition(Size size, Point position)
{
_nodeModel!.SetPosition(position.X, position.Y);
_nodeModel.SetSize(size.Width, size.Height);
}

virtual public void OnResizeStart(Diagram diagram, Model model, PointerEventArgs e)
Expand Down Expand Up @@ -79,14 +84,16 @@ virtual public void OnPointerMove(Model? model, PointerEventArgs e)
_lastClientX = e.ClientX;
_lastClientY = e.ClientY;

ResizeNode(deltaX, deltaY);
var result = CalculateNewSizeAndPosition(deltaX, deltaY);
SetSizeAndPosition(result.size, result.position);
}

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

ResizeNode(deltaX, deltaY);
var result = CalculateNewSizeAndPosition(deltaX, deltaY);
SetSizeAndPosition(result.size, result.position);
}

virtual public void OnResizeEnd(Model? model, PointerEventArgs args)
Expand Down

0 comments on commit 02e3564

Please sign in to comment.