// Check if hit test rects collide with any children of the FreeFormPanel, and remove that direction in case a collision is found. private static void RemoveDirectionsInCollision(List <DependencyObject> childShapes, DependencyObject target, List <Rect> hitTestRects, ref AutoConnectDirections directions) { foreach (DependencyObject shape in childShapes) { if (directions == AutoConnectDirections.None) { break; } if (object.Equals(shape, target)) { continue; } Point shapeLocation = FreeFormPanel.GetLocation(shape); Size shapeSize = FreeFormPanel.GetChildSize(shape); Rect shapeRect = new Rect(shapeLocation, shapeSize); for (int i = 0; i < hitTestRects.Count; i++) { if (hitTestRects[i].IntersectsWith(shapeRect)) { directions &= ~AutoConnectHelper.GetAutoConnectDirection(i); } } } }
internal void UpdateHighlightedDirection(Point position) { Size size = FreeFormPanel.GetChildSize(this.AdornedElement); if (position.X < 0 && this.highlightedDirection != AutoConnectDirections.Left) { this.highlightedDirection = AutoConnectDirections.Left; this.InvalidateVisual(); } else if (position.X > size.Width && this.highlightedDirection != AutoConnectDirections.Right) { this.highlightedDirection = AutoConnectDirections.Right; this.InvalidateVisual(); } else if (position.Y < 0 && this.highlightedDirection != AutoConnectDirections.Top) { this.highlightedDirection = AutoConnectDirections.Top; this.InvalidateVisual(); } else if (position.Y > size.Height && this.highlightedDirection != AutoConnectDirections.Bottom) { this.highlightedDirection = AutoConnectDirections.Bottom; this.InvalidateVisual(); } }
public AutoSplitAdorner(UIElement adornedElement) : base(adornedElement) { Size size = FreeFormPanel.GetChildSize(this.AdornedElement); this.adornedElementRect = new Rect(new Point(0, 0), size); }
internal static Rect GetAutoConnectHitRect(DependencyObject target) { Size size = FreeFormPanel.GetChildSize(target); Point location = FreeFormPanel.GetLocation(target); Rect rect = new Rect(new Point(location.X - HitRegionOffset, location.Y - HitRegionOffset), new Size(size.Width + (HitRegionOffset * 2), size.Height + (HitRegionOffset * 2))); return(rect); }
public static Point CalculateDropLocation(Point mousePosition, Point originalDropLocation, Connector connector, Size droppedSize, HashSet <Point> shapeLocations) { UIElement srcShape = FreeFormPanel.GetSourceConnectionPoint(connector).ParentDesigner; UIElement destShape = FreeFormPanel.GetDestinationConnectionPoint(connector).ParentDesigner; Point srcLocation = FreeFormPanel.GetLocation(srcShape); Point destLocation = FreeFormPanel.GetLocation(destShape); Size srcSize = FreeFormPanel.GetChildSize(srcShape); Size destSize = FreeFormPanel.GetChildSize(destShape); return(CalculateDropLocation(mousePosition, originalDropLocation, droppedSize, srcLocation, destLocation, srcSize, destSize, shapeLocations)); }
internal static Point CalculateDropLocation(Size droppedSize, DependencyObject autoConnectTarget, AutoConnectDirections direction, HashSet <Point> shapeLocations) { Point dropPoint = new Point(-1, -1); if (autoConnectTarget != null) { Point location = FreeFormPanel.GetLocation(autoConnectTarget); Size size = FreeFormPanel.GetChildSize(autoConnectTarget); switch (direction) { case AutoConnectDirections.Left: dropPoint = new Point(location.X - DropPointOffset - droppedSize.Width, location.Y + ((size.Height - droppedSize.Height) / 2)); break; case AutoConnectDirections.Right: dropPoint = new Point(location.X + size.Width + DropPointOffset, location.Y + ((size.Height - droppedSize.Height) / 2)); break; case AutoConnectDirections.Top: dropPoint = new Point(location.X + ((size.Width - droppedSize.Width) / 2), location.Y - DropPointOffset - droppedSize.Height); break; case AutoConnectDirections.Bottom: dropPoint = new Point(location.X + ((size.Width - droppedSize.Width) / 2), location.Y + DropPointOffset + size.Height); break; default: Fx.Assert(false, "Should not be here"); break; } dropPoint = new Point(dropPoint.X < 0 ? 0 : dropPoint.X, dropPoint.Y < 0 ? 0 : dropPoint.Y); if (shapeLocations != null) { while (shapeLocations.Contains(dropPoint)) { dropPoint.Offset(FreeFormPanel.GridSize, FreeFormPanel.GridSize); } } } return(dropPoint); }
public static void CalculateEntryExitEdges(Point mousePosition, Connector connector, out EdgeLocation entryEdge, out EdgeLocation exitEdge) { UIElement srcShape = FreeFormPanel.GetSourceConnectionPoint(connector).ParentDesigner; UIElement destShape = FreeFormPanel.GetDestinationConnectionPoint(connector).ParentDesigner; Point srcLocation = FreeFormPanel.GetLocation(srcShape); Point destLocation = FreeFormPanel.GetLocation(destShape); Size srcSize = FreeFormPanel.GetChildSize(srcShape); Size destSize = FreeFormPanel.GetChildSize(destShape); Point srcCenter = new Point(srcLocation.X + (srcSize.Width / 2), srcLocation.Y + (srcSize.Height / 2)); Point destCenter = new Point(destLocation.X + (destSize.Width / 2), destLocation.Y + (destSize.Height / 2)); entryEdge = CalculateEdgeLocation(mousePosition, srcCenter); exitEdge = CalculateEdgeLocation(mousePosition, destCenter); if (exitEdge == entryEdge) { switch (entryEdge) { case EdgeLocation.Top: exitEdge = EdgeLocation.Bottom; break; case EdgeLocation.Bottom: exitEdge = EdgeLocation.Top; break; case EdgeLocation.Left: exitEdge = EdgeLocation.Right; break; case EdgeLocation.Right: exitEdge = EdgeLocation.Left; break; } } }
public AutoConnectAdorner(UIElement adornedElement, FreeFormPanel panel, AutoConnectDirections directions) : base(adornedElement) { this.panel = panel; this.directions = directions; Size size = FreeFormPanel.GetChildSize(this.AdornedElement); this.adornedElementRect = new Rect(new Point(0, 0), size); this.hitTestRects = new Rect[] { new Rect(-HitTestHeight, (size.Height / 2) - (HitTestWidth / 2), HitTestHeight, HitTestWidth), new Rect(size.Width, (size.Height / 2) - (HitTestWidth / 2), HitTestHeight, HitTestWidth), new Rect((size.Width / 2) - (HitTestWidth / 2), -HitTestHeight, HitTestWidth, HitTestHeight), new Rect((size.Width / 2) - (HitTestWidth / 2), size.Height, HitTestWidth, HitTestHeight) }; this.renderGeometries = new PathGeometry[] { new PathGeometry() { Figures = { new PathFigure() { StartPoint = new Point(-DropTargetOffset - TriangleHeight, size.Height / 2), Segments = { new LineSegment() { Point = new Point(-DropTargetOffset, (size.Height / 2) - (TriangleBaseLength / 2)) }, new LineSegment() { Point = new Point(-DropTargetOffset, (size.Height / 2) + (TriangleBaseLength / 2)) }, new LineSegment() { Point = new Point(-DropTargetOffset - TriangleHeight, size.Height / 2) } } } } }, new PathGeometry() { Figures = { new PathFigure() { StartPoint = new Point(size.Width + DropTargetOffset, (size.Height / 2) - (TriangleBaseLength / 2)), Segments = { new LineSegment() { Point = new Point(size.Width + DropTargetOffset + TriangleHeight, size.Height / 2) }, new LineSegment() { Point = new Point(size.Width + DropTargetOffset, (size.Height / 2) + (TriangleBaseLength / 2)) }, new LineSegment() { Point = new Point(size.Width + DropTargetOffset, (size.Height / 2) - (TriangleBaseLength / 2)) } } } } }, new PathGeometry() { Figures = { new PathFigure() { StartPoint = new Point((size.Width / 2) - (TriangleBaseLength / 2), -DropTargetOffset), Segments = { new LineSegment() { Point = new Point((size.Width / 2), -DropTargetOffset - TriangleHeight) }, new LineSegment() { Point = new Point((size.Width / 2) + (TriangleBaseLength / 2), -DropTargetOffset) }, new LineSegment() { Point = new Point((size.Width / 2) - (TriangleBaseLength / 2), -DropTargetOffset) } } } } }, new PathGeometry() { Figures = { new PathFigure() { StartPoint = new Point((size.Width / 2) - (TriangleBaseLength / 2), size.Height + DropTargetOffset), Segments = { new LineSegment() { Point = new Point((size.Width / 2) + (TriangleBaseLength / 2), size.Height + DropTargetOffset) }, new LineSegment() { Point = new Point((size.Width / 2), size.Height + TriangleHeight + DropTargetOffset) }, new LineSegment() { Point = new Point((size.Width / 2) - (TriangleBaseLength / 2), size.Height + DropTargetOffset) } } } } } }; }
private AutoConnectDirections GetAutoConnectDirections(AutoConnectDirections directions, List <DependencyObject> childShapes, DependencyObject target) { directions = AutoConnectDirections.Top | AutoConnectDirections.Bottom | AutoConnectDirections.Left | AutoConnectDirections.Right; List <Rect> hitTestRects = CreateHitTestRects(FreeFormPanel.GetLocation(target), FreeFormPanel.GetChildSize(target)); this.RemoveDirectionsOutsideOfPanel(hitTestRects, ref directions); RemoveDirectionsInCollision(childShapes, target, hitTestRects, ref directions); return(directions); }
private void MeasureChildren(out double height, out double width) { height = 0; width = 0; Point pt = new Point(0, 0); bool isOutmostPanel = this.IsOutmostPanel(); foreach (UIElement child in Children) { Connector connectorChild = child as Connector; if (connectorChild != null && isOutmostPanel) { pt = new Point(0, 0); if (measureConnectors) { Point srcPoint = FreeFormPanel.GetLocationRelativeToOutmostPanel(FreeFormPanel.GetSourceConnectionPoint(connectorChild)); Point destPoint = FreeFormPanel.GetLocationRelativeToOutmostPanel(FreeFormPanel.GetDestinationConnectionPoint(connectorChild)); if (connectorChild.Points.Count == 0 || !this.Disabled && ((DesignerGeometryHelper.ManhattanDistanceBetweenPoints(connectorChild.Points[0], srcPoint) > ConnectorRouter.EndPointTolerance) || (DesignerGeometryHelper.ManhattanDistanceBetweenPoints(connectorChild.Points[connectorChild.Points.Count - 1], destPoint) > ConnectorRouter.EndPointTolerance))) { connectorChild.Points = new PointCollection(); RoutePolyLine(connectorChild); } connectorChild.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); } else { continue; } } else //Measure non-connector elements. { child.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); if (!child.DesiredSize.Equals(((Size)FreeFormPanel.GetChildSize(child)))) { FreeFormPanel.SetChildSize(child, child.DesiredSize); } pt = FreeFormPanel.GetLocation(child); if (!IsLocationValid(pt)) { pt = new Point(LeftStackingMargin, lastYPosition); OnLocationChanged(child, new LocationChangedEventArgs(pt)); FreeFormPanel.SetLocation(child, pt); lastYPosition += child.DesiredSize.Height + VerticalStackingDistance; } } if (height < child.DesiredSize.Height + pt.Y) { height = child.DesiredSize.Height + pt.Y; } if (width < child.DesiredSize.Width + pt.X) { width = child.DesiredSize.Width + pt.X; } } width = (width < this.MinWidth) ? this.MinWidth : width; height = (height < this.MinHeight) ? this.MinHeight : height; }