Commits

Anonymous committed b54de4d

Trying to get a grip on manual positioning of a vertex.

Comments (0)

Files changed (6)

UserProjects/sprucely/CSharp/Composer/Composer/Composer.csproj

     <Compile Include="UI\Behaviors\DragAndDrop\DropTargetInsertionAdorner.cs" />
     <Compile Include="UI\Behaviors\DragAndDrop\IDragSource.cs" />
     <Compile Include="UI\Behaviors\DragAndDrop\IDropTarget.cs" />
+    <Compile Include="UI\DispatcherHelper.cs" />
     <Compile Include="UI\ItemsControlExtensions.cs" />
     <Compile Include="UI\Screens\GraphEditor\LayoutAlgorithmFactory.cs" />
     <Compile Include="UI\Screens\GraphEditor\LayoutAlgorithm_Manual.cs" />

UserProjects/sprucely/CSharp/Composer/Composer/UI/DispatcherHelper.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Threading;
+using System.Windows;
+using System.Threading;
+
+namespace Composer.UI
+{
+	public static class DispatcherHelper
+	{
+		/// <summary>
+		/// Processes all messages currently in the message queue.
+		/// </summary>
+		/// <remarks>
+		/// This method can potentially cause code re-entrancy problem, so use it with great care.
+		/// </remarks>
+		public static void DoEvents()
+		{
+			Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
+		}
+	
+		/// <summary>
+		/// Yields execution to the WPF Dispatcher operations that have a higher priority than what is specified in <paramref name="priority"/>
+		/// </summary>
+		/// <param name="priority"></param>
+		/// <remarks>
+		/// Similar in concept to <see cref="System.Windows.Forms.Application.DoEvents"/>
+		/// </remarks>
+		public static void WaitForPriority(DispatcherPriority priority)
+		{
+			DispatcherFrame frame = new DispatcherFrame();
+			DispatcherOperation dispatcherOperation = Dispatcher.CurrentDispatcher.BeginInvoke(priority, new DispatcherOperationCallback(ExitFrameOperation), frame);
+			Dispatcher.PushFrame(frame);
+			if (dispatcherOperation.Status != DispatcherOperationStatus.Completed)
+			{
+				dispatcherOperation.Abort();
+			}
+		}
+
+		private static object ExitFrameOperation(object obj)
+		{
+			((DispatcherFrame)obj).Continue = false;
+			return null;
+		}
+	}
+}

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/GraphEditor/ComponentLayout.cs

 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Windows;
+
+using Composer.Graph;
+
+using GraphSharp;
 using GraphSharp.Controls;
-using Composer.Graph;
+
+using QuickGraph;
 
 namespace Composer.UI.Screens
 {
 		{
 			return this.GetOrCreateEdgeControl(edge);
 		}
+
+		private Point topLeft;
+		private Point bottomRight;
+
+		protected override Size MeasureOverride(Size constraint)
+		{
+			this.topLeft = new Point(double.PositiveInfinity, double.PositiveInfinity);
+			this.bottomRight = new Point(double.NegativeInfinity, double.NegativeInfinity);
+			foreach (UIElement uIElement in base.InternalChildren)
+			{
+				uIElement.Measure(constraint);
+				double num = GraphCanvas.GetX(uIElement);
+				double num2 = GraphCanvas.GetY(uIElement);
+				double num3 = uIElement.DesiredSize.Width * 0.5;
+				double num4 = uIElement.DesiredSize.Height * 0.5;
+				if (double.IsNaN(num) || double.IsNaN(num2))
+				{
+					num = num3;
+					num2 = num4;
+				}
+				this.topLeft.X = Math.Min(this.topLeft.X, num - num3 - this.Origo.X);
+				this.topLeft.Y = Math.Min(this.topLeft.Y, num2 - num4 - this.Origo.Y);
+				this.bottomRight.X = Math.Max(this.bottomRight.X, num + num3 - this.Origo.X);
+				this.bottomRight.Y = Math.Max(this.bottomRight.Y, num2 + num4 - this.Origo.Y);
+			}
+			Size result = (Size)(this.bottomRight - this.topLeft);
+			result.Width = Math.Max(0.0, result.Width);
+			result.Height = Math.Max(0.0, result.Height);
+			if (double.IsNaN(result.Width) || double.IsNaN(result.Height) || double.IsInfinity(result.Width) || double.IsInfinity(result.Height))
+			{
+				return new Size(0.0, 0.0);
+			}
+			return result;
+		}
+
+		protected override Size ArrangeOverride(Size arrangeSize)
+		{
+			Vector translation = new Vector(-this.topLeft.X, -this.topLeft.Y);
+			Vector vector = this.bottomRight - this.topLeft;
+			if (double.IsNaN(vector.X) || double.IsNaN(vector.Y) || double.IsInfinity(vector.X) || double.IsInfinity(vector.Y))
+			{
+				translation = new Vector(0.0, 0.0);
+			}
+			this.Translation = translation;
+			vector = ((base.InternalChildren.Count > 0) ? new Vector(double.NegativeInfinity, double.NegativeInfinity) : new Vector(0.0, 0.0));
+			foreach (UIElement uIElement in base.InternalChildren)
+			{
+				double num = GraphCanvas.GetX(uIElement);
+				double num2 = GraphCanvas.GetY(uIElement);
+				if (double.IsNaN(num) || double.IsNaN(num2))
+				{
+					num = (double.IsNaN(num) ? translation.X : num);
+					num2 = (double.IsNaN(num2) ? translation.Y : num2);
+				}
+				else
+				{
+					num += translation.X;
+					num2 += translation.Y;
+					num -= uIElement.DesiredSize.Width * 0.5;
+					num2 -= uIElement.DesiredSize.Height * 0.5;
+				}
+				uIElement.Arrange(new Rect(new Point(num, num2), uIElement.DesiredSize));
+				vector.X = Math.Max(0.0, Math.Max(vector.X, num + uIElement.DesiredSize.Width));
+				vector.Y = Math.Max(0.0, Math.Max(vector.Y, num2 + uIElement.DesiredSize.Height));
+			}
+			return new Size(vector.X, vector.Y);
+		}
 	}
 }

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/GraphEditor/GraphEditorView.xaml

              xmlns:dnd="clr-namespace:Composer.UI.Behaviors.DragAndDrop"
              xmlns:graph="clr-namespace:Composer.Graph"
              xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
+             xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
              xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
              xmlns:impl="clr-namespace:Composer.UI.Screens.GraphEditor"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             IsDropTarget="True" />
             </i:Interaction.Behaviors>
         -->
-        <!--
-            <zoom:ZoomControl  Grid.Row="1"
+        
+            <!--<zoom:ZoomControl  Grid.Row="1"
             Mode="Original"
             ZoomBoxOpacity="0.5"
-            Background="#ff656565">
-        -->
+            Background="#ff656565">-->
+        
 
         <ctrls:ComponentLayout x:Name="graphLayout"
                                Grid.Column="1"
                                LayoutAlgorithmFactory="{StaticResource layoutAlgorithmFactory}"
                                LayoutAlgorithmType="Manual"
                                OverlapRemovalAlgorithmType="FSA" />
-        <!--  </zoom:ZoomControl>  -->
+          <!--</zoom:ZoomControl>-->  
 
     </Grid>
 </UserControl>

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/GraphEditor/GraphEditorView.xaml.cs

 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using GraphSharp.Controls;
+using System.Diagnostics;
 
 namespace Composer.UI.Screens
 {

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/GraphEditor/GraphEditorViewModel.cs

 			if (view == null)
 				return;
 
+			DispatcherHelper.DoEvents();
+
+			var halfWidth = view.ActualWidth / 2;
+			var halfHeight = view.ActualHeight / 2;
+			
 			var vertexControl = view.graphLayout.GetVertexControl(cellVertex);
-			GraphLayout.SetX(vertexControl, 100);
-			GraphLayout.SetY(vertexControl, 100);
+			GraphLayout.SetX(vertexControl, dropInfo.DropPosition.X - halfWidth - vertexControl.ActualWidth * 0.5);
+			GraphLayout.SetY(vertexControl, dropInfo.DropPosition.Y - halfHeight - vertexControl.ActualHeight * 0.5);
 
 		}