コード例 #1
0
        // 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);
                    }
                }
            }
        }
コード例 #2
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            double height = 0;
            double width  = 0;

            for (int i = 0; i < Children.Count; i++)
            {
                Point pt   = new Point(0, 0);
                Size  size = Children[i].DesiredSize;
                if (Children[i].GetType() == typeof(Connector))
                {
                    ((UIElement)Children[i]).Arrange(new Rect(pt, size));
                }
                else
                {
                    pt = FreeFormPanel.GetLocation(Children[i]);
                    ((UIElement)Children[i]).Arrange(new Rect(pt, size));
                }
                if (width < (size.Width + pt.X))
                {
                    width = size.Width + pt.X;
                }
                if (height < (size.Height + pt.Y))
                {
                    height = size.Height + pt.Y;
                }
            }
            width = (width < this.MinWidth) ? this.MinWidth : width;
            width = (width < this.Width) ? (this.Width < Double.MaxValue ? this.Width : width) : width;

            height = (height < this.MinHeight) ? this.MinHeight : height;
            height = (height < this.Height) ? (this.Height < Double.MaxValue ? this.Height : height) : height;

            return(new Size(width, height));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: AutoSplitHelper.cs プロジェクト: dox0/DotNet471RS3
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: AutoSplitHelper.cs プロジェクト: dox0/DotNet471RS3
        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;
                }
            }
        }
コード例 #8
0
        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;
        }