diff --git a/CHANGELOG.md b/CHANGELOG.md
index 589868b3..7a74800a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
> - Breaking Changes:
> - Features:
> - Added ItemContainer.SelectedBorderThickness dependency property
+ - Added NodifyEditor.GetLocationInsideEditor
> - Bugfixes:
> - Fixed PendingConnection.PreviewTarget not being set to null when there is no actual target
> - Fixed PendingConnection.PreviewTarget not being set on Connector.PendingConnectionStartedEvent
diff --git a/Examples/Nodify.Calculator/EditorView.xaml b/Examples/Nodify.Calculator/EditorView.xaml
index 75ef8723..800698e3 100644
--- a/Examples/Nodify.Calculator/EditorView.xaml
+++ b/Examples/Nodify.Calculator/EditorView.xaml
@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:Nodify.Calculator"
xmlns:nodify="https://miroiu.github.io/nodify"
xmlns:shared="clr-namespace:Nodify;assembly=Nodify.Shared"
+ xmlns:sys="clr-namespace:System;assembly=System.Runtime"
d:DataContext="{d:DesignInstance Type=local:EditorViewModel}"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
@@ -98,7 +99,7 @@
-
+
+
+
+
+
+
+
+ Output
+
+
+
+
+
+
+
+
diff --git a/Examples/Nodify.Calculator/EditorView.xaml.cs b/Examples/Nodify.Calculator/EditorView.xaml.cs
index ed2dd2e4..a0004a4c 100644
--- a/Examples/Nodify.Calculator/EditorView.xaml.cs
+++ b/Examples/Nodify.Calculator/EditorView.xaml.cs
@@ -34,5 +34,27 @@ private void CloseOperationsMenu(object sender, RoutedEventArgs e)
calculator.OperationsMenu.Close();
}
}
+
+ private void OnDropNode(object sender, DragEventArgs e)
+ {
+ if(e.Source is NodifyEditor editor && editor.DataContext is CalculatorViewModel calculator
+ && e.Data.GetData(typeof(OperationInfoViewModel)) is OperationInfoViewModel operation)
+ {
+ OperationViewModel op = OperationFactory.GetOperation(operation);
+ op.Location = editor.GetLocationInsideEditor(e);
+ calculator.Operations.Add(op);
+
+ e.Handled = true;
+ }
+ }
+
+ private void OnNodeDrag(object sender, MouseEventArgs e)
+ {
+ if(e.LeftButton == MouseButtonState.Pressed && ((FrameworkElement)sender).DataContext is OperationInfoViewModel operation)
+ {
+ var data = new DataObject(typeof(OperationInfoViewModel), operation);
+ DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
+ }
+ }
}
}
diff --git a/Examples/Nodify.Calculator/MainWindow.xaml b/Examples/Nodify.Calculator/MainWindow.xaml
index a7ae5426..f6439b5b 100644
--- a/Examples/Nodify.Calculator/MainWindow.xaml
+++ b/Examples/Nodify.Calculator/MainWindow.xaml
@@ -54,77 +54,80 @@
-
+
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+ CTRL + N/W
+ : open/close editor
+
+
+ ALT + Click
+ : disconnect connector
+
+
+ Right Click
+ : show operations menu (create nodes)
+
+
+ Delete
+ : delete selection
+
+
+ CTRL + T
+ : change theme
+
+
+ C
+ : group selection (hold SHIFT and mouse drag the header to move the group node alone)
+
+
+
+
+
-
- ALT + Click
- : disconnect connector
-
-
- Right Click
- : show operations menu (create nodes)
-
-
- Delete
- : delete selection
-
-
- CTRL + T
- : change theme
-
-
- C
- : group selection (hold SHIFT and mouse drag the header to move the group node alone)
-
-
-
-
-
+
diff --git a/Nodify.sln b/Nodify.sln
index 3a14c53d..3947b565 100644
--- a/Nodify.sln
+++ b/Nodify.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.30406.217
+# Visual Studio Version 17
+VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nodify", "Nodify\Nodify.csproj", "{A4349FD1-2774-42F2-90FD-7D8F4CA8BB71}"
EndProject
@@ -13,7 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nodify.StateMachine", "Exam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nodify.Shared", "Examples\Nodify.Shared\Nodify.Shared.csproj", "{499C8539-9973-4102-B976-57DB3F3C7DF3}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nodify.Calculator", "Examples\Nodify.Calculator\Nodify.Calculator.csproj", "{7ADD1DAF-B589-4742-8E72-872D2842E73D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nodify.Calculator", "Examples\Nodify.Calculator\Nodify.Calculator.csproj", "{7ADD1DAF-B589-4742-8E72-872D2842E73D}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{88D231A7-D09F-492F-887F-DDBC46398284}"
+ ProjectSection(SolutionItems) = preProject
+ CHANGELOG.md = CHANGELOG.md
+ EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/Nodify/NodifyEditor.cs b/Nodify/NodifyEditor.cs
index 0e3bb218..1ace435a 100644
--- a/Nodify/NodifyEditor.cs
+++ b/Nodify/NodifyEditor.cs
@@ -1359,5 +1359,34 @@ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
OnViewportUpdated();
}
+
+ #region Utilities
+
+ ///
+ /// Translates the specified location to graph space coordinates (relative to the ).
+ ///
+ /// The location coordinates relative to
+ /// The element where the was calculated from.
+ /// A location inside the graph.
+ public Point GetLocationInsideEditor(Point location, UIElement relativeTo)
+ => relativeTo.TranslatePoint(location, ItemsHost);
+
+ ///
+ /// Translates the event location to graph space coordinates (relative to the ).
+ ///
+ /// The drag event.
+ /// A location inside the graph
+ public Point GetLocationInsideEditor(DragEventArgs args)
+ => args.GetPosition(ItemsHost);
+
+ ///
+ /// Translates the event location to graph space coordinates (relative to the ).
+ ///
+ /// The mouse event.
+ /// A location inside the graph
+ public Point GetLocationInsideEditor(MouseEventArgs args)
+ => args.GetPosition(ItemsHost);
+
+ #endregion
}
}