diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..24a8e87 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/.idea/.idea.NodeEditor/.idea/contentModel.xml b/.idea/.idea.NodeEditor/.idea/contentModel.xml new file mode 100644 index 0000000..abfd5e9 --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/contentModel.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.NodeEditor/.idea/encodings.xml b/.idea/.idea.NodeEditor/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.NodeEditor/.idea/indexLayout.xml b/.idea/.idea.NodeEditor/.idea/indexLayout.xml new file mode 100644 index 0000000..27ba142 --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.NodeEditor/.idea/modules.xml b/.idea/.idea.NodeEditor/.idea/modules.xml new file mode 100644 index 0000000..cb0411a --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.NodeEditor/.idea/projectSettingsUpdater.xml b/.idea/.idea.NodeEditor/.idea/projectSettingsUpdater.xml new file mode 100644 index 0000000..4bb9f4d --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/projectSettingsUpdater.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.NodeEditor/.idea/riderModule.iml b/.idea/.idea.NodeEditor/.idea/riderModule.iml new file mode 100644 index 0000000..1a4e0d9 --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/riderModule.iml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.NodeEditor/.idea/vcs.xml b/.idea/.idea.NodeEditor/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.NodeEditor/.idea/workspace.xml b/.idea/.idea.NodeEditor/.idea/workspace.xml new file mode 100644 index 0000000..510e3c8 --- /dev/null +++ b/.idea/.idea.NodeEditor/.idea/workspace.xml @@ -0,0 +1,78 @@ + + + + NodeEditor.csproj + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1608418540783 + + + + + + + + + + \ No newline at end of file diff --git a/Controls/EditorCanvas.xaml b/Controls/EditorCanvas.xaml index 6b93224..2318208 100644 --- a/Controls/EditorCanvas.xaml +++ b/Controls/EditorCanvas.xaml @@ -6,8 +6,11 @@ xmlns:local="clr-namespace:NodeEditor" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - - + + + + + diff --git a/Controls/EditorCanvas.xaml.cs b/Controls/EditorCanvas.xaml.cs index 3f5d2dc..9f465c8 100644 --- a/Controls/EditorCanvas.xaml.cs +++ b/Controls/EditorCanvas.xaml.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Web.WebSockets; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -12,6 +13,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using MahApps.Metro.Controls; using NodeEditor.Extensions; namespace NodeEditor @@ -21,67 +23,63 @@ namespace NodeEditor /// public partial class EditorCanvas : UserControl { - Point dragStart = new Point(); - MatrixTransform dragMatrixTransform = new MatrixTransform(); - TranslateTransform dragTranslateTransform = new TranslateTransform(); + Point? dragStart = null; public EditorCanvas() { InitializeComponent(); m_EditorCanvas.MouseMove += MapCanvas_Drag; m_EditorCanvas.MouseDown += MapCanvas_StartDrag; + m_EditorCanvas.MouseUp += MapCanvas_StopDrag; m_EditorCanvas.MouseWheel += MapCanvas_OnScroll; - - mapCanvas.RenderTransform = MathExtensions.applyMultiTransform(dragTranslateTransform, dragMatrixTransform); } private void MapCanvas_StartDrag(object sender, MouseEventArgs e) { - dragStart = e.GetPosition(this); + var element = (UIElement) sender; + // dragStart = new Point(e.GetPosition(mapCanvas).X * st.ScaleX, e.GetPosition(mapCanvas).Y * st.ScaleY); + var transform = mapCanvas.RenderTransform as MatrixTransform; + dragStart = new Point(e.GetPosition(mapCanvas).X * transform.Value.M11, e.GetPosition(mapCanvas).Y * transform.Value.M22); + element.CaptureMouse(); + } + private void MapCanvas_StopDrag(object sender, MouseEventArgs e) + { + var element = (UIElement)sender; + dragStart = null; + element.ReleaseMouseCapture(); } private void MapCanvas_Drag(object sender, MouseEventArgs e) { - if (e.LeftButton == MouseButtonState.Pressed) + if (dragStart != null && e.LeftButton == MouseButtonState.Pressed) { - var element = sender as UIElement; - - var transform = dragTranslateTransform; - - var old = element.TranslatePoint(new Point(0, 0), map); - var new_point = old + Point.Subtract(e.GetPosition(this), dragStart); - transform.X = new_point.X; - transform.Y = new_point.Y; - - m_EditorCanvas.RenderTransform = MathExtensions.applyMultiTransform(dragTranslateTransform, dragMatrixTransform); - - test.Text = Point.Subtract(e.GetPosition(this), dragStart).ToString(); + var newPoint = e.GetPosition(m_EditorCanvas); + + Canvas.SetLeft(mapCanvas, newPoint.X - dragStart.Value.X); + Canvas.SetTop(mapCanvas, newPoint.Y - dragStart.Value.Y); } - - - if (e.LeftButton == MouseButtonState.Released) - test.Text = ""; - } - - private void MapCanvas_EndDrag(object sender, MouseEventArgs e) - { - dragStart = new Point(0, 0); } private void MapCanvas_OnScroll(object sender, MouseWheelEventArgs e) { + // if (e.Delta > 0) + // { + // st.ScaleX *= 1.1; + // st.ScaleY *= 1.1; + // } + // else + // { + // st.ScaleX /= 1.1; + // st.ScaleY /= 1.1; + // } var element = sender as UIElement; var position = e.GetPosition(element); - - var transform = dragMatrixTransform; - + var transform = mapCanvas.RenderTransform as MatrixTransform; var matrix = transform.Matrix; - var scale = e.Delta >= 0 ? 1.1 : (1.0 / 1.1); + var scale = e.Delta >= 0 ? 1.1 : (1.0 / 1.1); // choose appropriate scaling factor matrix.ScaleAtPrepend(scale, scale, position.X, position.Y); - transform.Matrix = matrix; - element.RenderTransform = MathExtensions.applyMultiTransform(dragTranslateTransform, dragMatrixTransform); } } } diff --git a/assets/main-map.png b/assets/main-map.png index 6e6e978..6c3eb06 100644 Binary files a/assets/main-map.png and b/assets/main-map.png differ diff --git a/main-map.png b/main-map.png index 6e6e978..0a5e7fa 100644 Binary files a/main-map.png and b/main-map.png differ