Skip to content

Commit

Permalink
Fix Node EventHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Jul 12, 2024
1 parent 7ed2304 commit 8c7112b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
24 changes: 19 additions & 5 deletions NodifyM.Avalonia/Controls/BaseNode.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public Point Location
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
base.OnPointerReleased(e);
if (e.Handled)
{
return;
}

if (!isDragging) return;
// 停止拖动
isDragging = false;
Expand All @@ -59,11 +64,15 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e)
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
if (e.Handled)
{
return;
}

_editor.SelectItem(this);
if (!e.GetCurrentPoint(this)
.Properties.IsLeftButtonPressed) return;
e.GetCurrentPoint(this)
.Pointer.Capture(this);
.Properties.IsLeftButtonPressed) return;
e.GetCurrentPoint(this).Pointer.Capture(this);
// 启动拖动
isDragging = true;
// 记录当前坐标
Expand All @@ -78,9 +87,14 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
if (e.Handled)
{
return;
}

if (!e.GetCurrentPoint(((Visual)this.GetLogicalParent()).GetVisualParent())
.Properties
.IsLeftButtonPressed) return;
.Properties
.IsLeftButtonPressed) return;

// 如果没有启动拖动,则不执行
if (!isDragging) return;
Expand Down
13 changes: 10 additions & 3 deletions NodifyM.Avalonia/Controls/Connector.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,29 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
e.GetCurrentPoint(this)
.Pointer.Capture(this);
e.Handled = true;

var currentPoint = e.GetCurrentPoint(this);
if (currentPoint.Properties.IsLeftButtonPressed && e.KeyModifiers.HasFlag(KeyModifiers.Alt))
{
e.GetCurrentPoint(this)
.Pointer.Capture(this);
e.Handled = true;
OnDisconnect();
}
else if (currentPoint.Properties.IsLeftButtonPressed)
{
if (EnableStickyConnections && IsPendingConnection)
{
e.GetCurrentPoint(this)
.Pointer.Capture(this);
e.Handled = true;
OnConnectorDragCompleted(e.GetPosition(Editor));
}
else
{
e.GetCurrentPoint(this)
.Pointer.Capture(this);
e.Handled = true;
Editor.SelectItem(this.GetParentOfType<BaseNode>());

UpdateAnchor();
Expand Down

0 comments on commit 8c7112b

Please sign in to comment.