Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into avalonia_port
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Jul 31, 2024
2 parents 2bcf811 + af0230c commit fb09a33
Show file tree
Hide file tree
Showing 37 changed files with 784 additions and 87 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
> - Features:
> - Bugfixes:
#### **Version 6.3.0**

> - Features:
> - Added a CuttingLine control that removes intersecting connections
> - Added CuttingLineStyle, CuttingStartedCommand, CuttingCompletedCommand, IsCutting, EnableCuttingLinePreview and CuttingConnectionTypes to NodifyEditor
> - Added EditorGestures.Editor.Cutting and EditorGestures.Editor.CancelAction
> - Bugfixes:
> - Fixed connection styles not inheriting from the BaseConnection style
#### **Version 6.2.0**

> - Features:
Expand Down
3 changes: 2 additions & 1 deletion Examples/Nodify.Calculator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Windows;
using System.Windows.Input;

namespace Nodify.Calculator
{
Expand All @@ -8,6 +7,8 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();

EditorGestures.Mappings.Editor.Cutting.Value = MultiGesture.None;
}
}
}
17 changes: 15 additions & 2 deletions Examples/Nodify.Playground/Editor/NodifyEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<SolidColorBrush x:Key="SquareConnectorColor" Color="MediumSlateBlue" />
<SolidColorBrush x:Key="TriangleConnectorColor" Color="MediumVioletRed" />

<!-- <UIElement x:Key="ConnectionAnimationPlaceholder" Opacity="1" /> -->

<!-- <Storyboard x:Key="HighlightConnection"> -->
<!-- <DoubleAnimation Storyboard.TargetProperty="StrokeThickness" -->
<!-- Duration="0:0:0.3" From="3" To="6" /> -->
Expand All @@ -52,7 +54,8 @@
<!-- Duration="0:0:0.3" From="1" To="0.3" /> -->
<!-- </Storyboard> -->

<ControlTheme x:Key="ConnectionStyle" TargetType="{x:Type nodify:BaseConnection}">
<ControlTheme x:Key="ConnectionStyle" TargetType="{x:Type nodify:BaseConnection}"
BasedOn="{StaticResource {x:Type nodify:BaseConnection}}">
<Setter Property="(Interaction.Behaviors)">
<BehaviorCollectionTemplate>
<BehaviorCollection>
Expand Down Expand Up @@ -166,6 +169,15 @@
</BehaviorCollectionTemplate>
</Setter>
</ControlTheme>

<ControlTheme x:Key="CuttingLineStyle"
TargetType="{x:Type nodify:CuttingLine}"
BasedOn="{StaticResource {x:Type nodify:CuttingLine}}">
<Setter Property="StrokeDashArray"
Value="1,1" />
<Setter Property="StrokeThickness"
Value="2" />
</ControlTheme>
</UserControl.Resources>

<Grid>
Expand All @@ -190,7 +202,8 @@
DisplayConnectionsOnTop="{Binding DisplayConnectionsOnTop, Source={x:Static local:EditorSettings.Instance}}"
BringIntoViewSpeed="{Binding BringIntoViewSpeed, Source={x:Static local:EditorSettings.Instance}}"
BringIntoViewMaxDuration="{Binding BringIntoViewMaxDuration, Source={x:Static local:EditorSettings.Instance}}"
SelectionRectangleStyle="{StaticResource SelectionRectangleStyle}">
SelectionRectangleStyle="{StaticResource SelectionRectangleStyle}"
CuttingLineStyle="{StaticResource CuttingLineStyle}">
<nodify:NodifyEditor.Theme>
<ControlTheme TargetType="{x:Type nodify:NodifyEditor}"
BasedOn="{StaticResource {x:Type nodify:NodifyEditor}}">
Expand Down
13 changes: 12 additions & 1 deletion Examples/Nodify.Playground/EditorInputMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public enum EditorInputMode
{
Default,
PanOnly,
SelectOnly
SelectOnly,
CutOnly
}

public enum EditorGesturesMappings
Expand All @@ -25,12 +26,22 @@ public static void Apply(this EditorGestures mappings, EditorInputMode inputMode
{
case EditorInputMode.PanOnly:
mappings.Editor.Selection.Apply(EditorGestures.SelectionGestures.None);
mappings.Editor.Cutting.Value = MultiGesture.None;
mappings.ItemContainer.Selection.Apply(EditorGestures.SelectionGestures.None);
mappings.ItemContainer.Drag.Value = MultiGesture.None;
mappings.Connector.Connect.Value = MultiGesture.None;
break;
case EditorInputMode.SelectOnly:
mappings.Editor.Pan.Value = MultiGesture.None;
mappings.Editor.Cutting.Value = MultiGesture.None;
mappings.ItemContainer.Drag.Value = MultiGesture.None;
mappings.Connector.Connect.Value = MultiGesture.None;
break;
case EditorInputMode.CutOnly:
mappings.Editor.Cutting.Value = new MouseGesture(MouseAction.LeftClick);
mappings.Editor.Selection.Apply(EditorGestures.SelectionGestures.None);
mappings.Editor.Pan.Value = MultiGesture.None;
mappings.ItemContainer.Selection.Apply(EditorGestures.SelectionGestures.None);
mappings.ItemContainer.Drag.Value = MultiGesture.None;
mappings.Connector.Connect.Value = MultiGesture.None;
break;
Expand Down
24 changes: 24 additions & 0 deletions Examples/Nodify.Playground/EditorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ private EditorSettings()
val => Instance.AutoPanningTickRate = val,
"Auto panning tick rate: ",
"How often is the new position calculated in milliseconds. Disable and enable auto panning for this to have effect."),
new ProxySettingViewModel<bool>(
() => Instance.AllowCuttingCancellation,
val => Instance.AllowCuttingCancellation = val,
"Allow cutting cancellation: ",
"Right click to cancel cutting."),
new ProxySettingViewModel<bool>(
() => Instance.AllowDraggingCancellation,
val => Instance.AllowDraggingCancellation = val,
Expand All @@ -193,6 +198,11 @@ private EditorSettings()
val => Instance.EnableSnappingCorrection = val,
"Enable snapping correction: ",
"Correct the final position when moving a selection"),
new ProxySettingViewModel<bool>(
() => Instance.EnableCuttingLinePreview,
val => Instance.EnableCuttingLinePreview = val,
"Enable cutting line preview: ",
"Applies custom connection style on intersection (hurts performance due to hit testing)."),
new ProxySettingViewModel<bool>(
() => Instance.EnableConnectorOptimizations,
val => Instance.EnableConnectorOptimizations = val,
Expand Down Expand Up @@ -239,6 +249,8 @@ private EditorSettings()
"Enable sticky connectors: ",
"The connection can be completed in two steps (e.g. click to create pending connection, click to connect)"),
};

EnableCuttingLinePreview = true;
}

public static EditorSettings Instance { get; } = new EditorSettings();
Expand Down Expand Up @@ -478,6 +490,12 @@ public double AutoPanningTickRate
set => NodifyEditor.AutoPanningTickRate = value;
}

public bool AllowCuttingCancellation
{
get => CuttingLine.AllowCuttingCancellation;
set => CuttingLine.AllowCuttingCancellation = value;
}

public bool AllowDraggingCancellation
{
get => ItemContainer.AllowDraggingCancellation;
Expand All @@ -496,6 +514,12 @@ public bool EnableSnappingCorrection
set => NodifyEditor.EnableSnappingCorrection = value;
}

public bool EnableCuttingLinePreview
{
get => NodifyEditor.EnableCuttingLinePreview;
set => NodifyEditor.EnableCuttingLinePreview = value;
}

public bool EnableConnectorOptimizations
{
get => Connector.EnableOptimizations;
Expand Down
1 change: 1 addition & 0 deletions Examples/Nodify.Shapes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public MainWindow()
InitializeComponent();

NodifyEditor.EnableDraggingContainersOptimizations = false;
NodifyEditor.EnableCuttingLinePreview = true;
}
}
}
1 change: 1 addition & 0 deletions Examples/Nodify.StateMachine/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
PendingConnection="{Binding PendingTransition}"
DisconnectConnectorCommand="{Binding DisconnectStateCommand}"
ConnectionCompletedCommand="{Binding CreateTransitionCommand}"
RemoveConnectionCommand="{Binding DeleteTransitionCommand}"
Grid.Column="1">
<nodify:NodifyEditor.PendingConnectionTemplate>
<DataTemplate DataType="{x:Type local:TransitionViewModel}">
Expand Down
3 changes: 3 additions & 0 deletions Examples/Nodify.StateMachine/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public MainWindow()
InitializeComponent();

Connector.EnableStickyConnections = true;
NodifyEditor.EnableCuttingLinePreview = true;

EditorGestures.Mappings.Connection.Disconnect.Value = MultiGesture.None;
}
}
}
22 changes: 21 additions & 1 deletion Nodify/Compatibility/VisualTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public static void HitTest(UIElement element,
topMost = GetParent(topMost);
}
}

public static void HitTest(UIElement element,
Func<DependencyObject, HitTestFilterBehavior> filter,
Func<HitTestResult, HitTestResultBehavior> test,
GeometryHitTestParameters parameters)
{
// unfortunately this is not supported in Avalonia
}
}

internal class PointHitTestParameters
Expand All @@ -38,7 +46,19 @@ internal enum HitTestFilterBehavior
{
Continue,
ContinueSkipSelfAndChildren,
Stop
Stop,
ContinueSkipChildren,
ContinueSkipSelf
}

internal class GeometryHitTestParameters
{
public GeometryHitTestParameters(Geometry geometry)
{
Geometry = geometry;
}

public Geometry Geometry { get; }
}

internal enum HitTestResultBehavior
Expand Down
69 changes: 38 additions & 31 deletions Nodify/Connections/BaseConnection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
Expand Down Expand Up @@ -685,44 +684,52 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
if (gestures.Split.Matches(e.Source, e))
{
Point splitLocation = e.GetPosition(this);
object? connection = DataContext;
var args = new ConnectionEventArgs(connection)
{
RoutedEvent = SplitEvent,
SplitLocation = splitLocation,
Source = this
};

RaiseEvent(args);

// Raise SplitCommand if SplitEvent is not handled
if (!args.Handled && (SplitCommand?.CanExecute(splitLocation) ?? false))
{
SplitCommand.Execute(splitLocation);
}
OnSplit(splitLocation);

e.Handled = true;
}
else if (gestures.Disconnect.Matches(e.Source, e))
{
Point splitLocation = e.GetPosition(this);
object? connection = DataContext;
var args = new ConnectionEventArgs(connection)
{
RoutedEvent = DisconnectEvent,
SplitLocation = splitLocation,
Source = this
};
OnDisconnect();

RaiseEvent(args);
e.Handled = true;
}
}

// Raise DisconnectCommand if DisconnectEvent is not handled
if (!args.Handled && (DisconnectCommand?.CanExecute(splitLocation) ?? false))
{
DisconnectCommand.Execute(splitLocation);
}
protected internal void OnSplit(Point splitLocation)
{
object? connection = DataContext;
var args = new ConnectionEventArgs(connection)
{
RoutedEvent = SplitEvent,
SplitLocation = splitLocation,
Source = this
};

e.Handled = true;
RaiseEvent(args);

// Raise SplitCommand if SplitEvent is not handled
if (!args.Handled && (SplitCommand?.CanExecute(splitLocation) ?? false))
{
SplitCommand.Execute(splitLocation);
}
}

protected internal void OnDisconnect()
{
object? connection = DataContext;
var args = new ConnectionEventArgs(connection)
{
RoutedEvent = DisconnectEvent,
Source = this
};

RaiseEvent(args);

// Raise DisconnectCommand if DisconnectEvent is not handled
if (!args.Handled && (DisconnectCommand?.CanExecute(null) ?? false))
{
DisconnectCommand.Execute(null);
}
}

Expand Down
1 change: 1 addition & 0 deletions Nodify/Connections/CircuitConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public double Angle
static CircuitConnection()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CircuitConnection), new FrameworkPropertyMetadata(typeof(CircuitConnection)));
NodifyEditor.CuttingConnectionTypes.Add(typeof(CircuitConnection));
AffectsRender<CircuitConnection>(AngleProperty);
}

Expand Down
1 change: 1 addition & 0 deletions Nodify/Connections/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Connection : BaseConnection
static Connection()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Connection), new FrameworkPropertyMetadata(typeof(Connection)));
NodifyEditor.CuttingConnectionTypes.Add(typeof(Connection));
}

private const double _baseOffset = 100d;
Expand Down
Loading

0 comments on commit fb09a33

Please sign in to comment.