예제 #1
0
        private static Point TestForConnection(DrawArea drawArea, Point p, out int objectID)
        {
            // Determine if within 5 pixels of a connection point
            // Step 1: see if a 5 x 5 rectangle centered on the mouse cursor intersects with an object
            // Step 2: If it does, then see if there is a connection point within the rectangle
            // Step 3: If there is, move the point to the connection point, record the object's id in the connector
            //
            objectID = -1;
            Rectangle    testRectangle  = new Rectangle(p.X - 2, p.Y - 2, 5, 5);
            bool         connectionHere = false;
            Point        h  = new Point(-1, -1);
            GraphicsList gl = drawArea.Pages.GraphicPagesList[drawArea.PageNo];

            for (int i = 1; i < gl.Count; i++)
            {
                if (gl[i].IntersectsWith(testRectangle))
                {
                    DrawObject obj = (DrawObject)gl[i];
                    for (int j = 1; j < obj.HandleCount + 1; j++)
                    {
                        h = obj.GetHandle(j);
                        if (testRectangle.Contains(h))
                        {
                            connectionHere = true;
                            p        = h;
                            objectID = obj.ID;
                            //			obj.DrawConnection(drawArea., j);
                            break;
                        }
                    }
                }
                if (connectionHere)
                {
                    break;
                }
            }
            return(p);
        }