コード例 #1
0
        static ConnectionPoint ConnectionPointHitTest(UIElement element, Point hitPoint)
        {
            ConnectionPoint        hitConnectionPoint = null;
            List <ConnectionPoint> connectionPoints   = StateContainerEditor.GetConnectionPoints(element);

            foreach (ConnectionPoint connPoint in connectionPoints)
            {
                if (connPoint != null)
                {
                    // We need to transform the connection point location to be relative to the outmost panel
                    FreeFormPanel panel = GetVisualAncestor <FreeFormPanel>(element);
                    if (new Rect(panel.GetLocationRelativeToOutmostPanel(connPoint.Location) + connPoint.HitTestOffset, connPoint.HitTestSize).Contains(hitPoint))
                    {
                        hitConnectionPoint = connPoint;
                        break;
                    }
                }
            }
            return(hitConnectionPoint);
        }
コード例 #2
0
        static internal ConnectionPoint GetClosestConnectionPoint(ConnectionPoint srcConnPoint, List <ConnectionPoint> destConnPoints, out double minDist)
        {
            minDist = double.PositiveInfinity;
            double          dist         = 0;
            ConnectionPoint closestPoint = null;
            Point           srcPoint     = FreeFormPanel.GetLocationRelativeToOutmostPanel(srcConnPoint);

            foreach (ConnectionPoint destConnPoint in destConnPoints)
            {
                if (srcConnPoint != destConnPoint)
                {
                    dist = DesignerGeometryHelper.ManhattanDistanceBetweenPoints(srcPoint, FreeFormPanel.GetLocationRelativeToOutmostPanel(destConnPoint));
                    if (dist < minDist)
                    {
                        minDist      = dist;
                        closestPoint = destConnPoint;
                    }
                }
            }

            return(closestPoint);
        }