private void UpdateEllipse(int ScreenMouseX, int ScreenMouseY, int ScreenDeltaX, int ScreenDeltaY)
        {
            BoundaryEllipse oEllipse = BoundaryEllipseList.GetFrom(CurrentlySelectedHole.HoleTypeIndex);
            PointF          pWorld   = this.S2W(ScreenMouseX, ScreenMouseY);

            float newx = pWorld.X;
            float newy = pWorld.Y;

            // Update the world points to the nearest grid
            if (this.GridSize > 1)
            {
                newx = this.RoundToGrid((int)pWorld.X);
                newy = this.RoundToGrid((int)pWorld.Y);
            }

            switch (CurrentlySelectedHandleType)
            {
            case eHandleType.MoveHandle:

                CurrentlySelectedHole.OffsetX = newx;
                CurrentlySelectedHole.OffsetY = newy;
                break;

            case eHandleType.ResizeHandle:
                // Get the hole struct and change the size
                switch (CurrentlySelectedHole.HoleType)
                {
                case "ell":
                    oEllipse.Width  += ScreenDeltaX * 2;
                    oEllipse.Height += ScreenDeltaY * 2;
                    break;
                }
                break;
            }
        }
        //----------------------------------------------------------------------------
        private bool TrySelectEllipse(LayoutHole oHole, int ScreenMouseX, int ScreenMouseY)
        {
            PointF MoveHandle   = new PointF(0, 0);
            PointF ResizeHandle = new PointF(0, 0);

            BoundaryEllipse oEllipse = BoundaryEllipseList.GetFrom(oHole.HoleTypeIndex);

            // The move handle  is the center
            MoveHandle = this.W2S(oHole.OffsetX, oHole.OffsetY);
            if (IsHitOnTarget(ScreenMouseX, ScreenMouseY, MoveHandle))
            {
                CurrentlySelectedHole       = oHole;
                MostRecentlySelectedHole    = oHole;
                CurrentlySelectedHandleType = eHandleType.MoveHandle;
                return(true);
            }

            // The resize handle is the lower right corner
            ResizeHandle = this.W2S(oHole.OffsetX + oEllipse.Width / 2, oHole.OffsetY + oEllipse.Height / 2);
            if (IsHitOnTarget(ScreenMouseX, ScreenMouseY, ResizeHandle))
            {
                CurrentlySelectedHole       = oHole;
                MostRecentlySelectedHole    = oHole;
                CurrentlySelectedHandleType = eHandleType.ResizeHandle;
                return(true);
            }

            return(false);
        }
        public void DuplicateCurrentHole()
        {
            if (MostRecentlySelectedHole == null)
            {
                return;
            }

            LayoutHole oHole = LayoutHole.CopyFrom(MostRecentlySelectedHole);

            // Add at an offset so it will be easy to see
            oHole.OffsetX += 10;
            oHole.OffsetY += 10;

            // Create a new version of the instance of the hole

            int ndx = MostRecentlySelectedHole.HoleTypeIndex;

            switch (MostRecentlySelectedHole.HoleType)
            {
            case "ell":
                oHole.HoleTypeIndex = BoundaryEllipseList.Count;
                BoundaryEllipse e = BoundaryEllipseList.GetFrom(ndx);
                BoundaryEllipseList.Add(BoundaryEllipse.CopyFrom(e));
                break;

            case "rect":
                oHole.HoleTypeIndex = BoundaryRectangleList.Count;
                BoundaryRectangle r = BoundaryRectangleList.GetFrom(ndx);
                BoundaryRectangleList.Add(BoundaryRectangle.CopyFrom(r));
                break;

            case "poly":
                oHole.HoleTypeIndex = BoundaryPolygonList.Count;
                BoundaryPolygon p = BoundaryPolygonList.GetFrom(ndx);
                BoundaryPolygonList.Add(BoundaryPolygon.CopyFrom(p));
                break;
            }

            // Add the new hole to the hole group
            AddHoleToHoleGroup(MostRecentlySelectedHoleGroup, oHole);

            // trigger a repaint
            DrawShapes();
        }
        //-------------------------------------------------------
        private void DrawShapes_Ellipse(LayoutHole oHole, bool IsCurrentHole)
        {
            BoundaryEllipse oEllipse = BoundaryEllipseList.GetFrom(oHole.HoleTypeIndex);

            PointF Screen = this.W2S(oHole.OffsetX, oHole.OffsetY);

            float SWidth  = oEllipse.Width / CurrentZoom;
            float SHeight = oEllipse.Height / CurrentZoom;

            string color = IsCurrentHole ? "#0000FF" : "rgba(255,0,0,.5)";

            // Draw the move handle
            this.DrawCircle(color, 10, Screen.X, Screen.Y);

            // draw the actual ellipse
            this.DrawEllipse(ShapeStrokeColor, SWidth, SHeight, Screen.X, Screen.Y);

            // draw the resize handle
            this.DrawRectangle("rgba(0,255,0,.5)", 10, 10, Screen.X + SWidth / 2, Screen.Y + SHeight / 2);
        }