コード例 #1
0
        private void UpdateRectangle(int ScreenMouseX, int ScreenMouseY, int ScreenDeltaX, int ScreenDeltaY)
        {
            BoundaryRectangle oRect  = BoundaryRectangleList.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 "rect":
                    oRect.Width  += ScreenDeltaX * CurrentZoom;
                    oRect.Height += ScreenDeltaY * CurrentZoom;
                    break;
                }
                break;
            }
        }
コード例 #2
0
        //----------------------------------------------------------------------------
        private bool TrySelectRectangle(LayoutHole oHole, int ScreenMouseX, int ScreenMouseY)
        {
            PointF MoveHandle   = new PointF(0, 0);
            PointF ResizeHandle = new PointF(0, 0);

            BoundaryRectangle oRect = BoundaryRectangleList.GetFrom(oHole.HoleTypeIndex);

            // The move handle  is the lower left
            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
            // the position of the handle is based on the zoom

            float HandleOffsetX = oRect.Width / this.CurrentZoom;
            float HandleOffsetY = oRect.Height / this.CurrentZoom;

            ResizeHandle = new PointF(MoveHandle.X + HandleOffsetX, MoveHandle.Y + HandleOffsetY);

            if (IsHitOnTarget(ScreenMouseX, ScreenMouseY, ResizeHandle))
            {
                CurrentlySelectedHole       = oHole;
                MostRecentlySelectedHole    = oHole;
                CurrentlySelectedHandleType = eHandleType.ResizeHandle;
                return(true);
            }

            return(false);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        public void AddRectangle(int ScreenOffsetX, int ScreenOffsetY, int Width, int Height)
        {
            if (MostRecentlySelectedHoleGroup == null)
            {
                return;
            }

            PointF WorldOffset = this.S2W(ScreenOffsetX, ScreenOffsetY);

            LayoutHole oHole = new LayoutHole();

            oHole.HoleType = "rect";
            oHole.OffsetX  = WorldOffset.X;
            oHole.OffsetY  = WorldOffset.Y;

            /*
             * Save this as the current and most recently selected
             */
            CurrentlySelectedHole    = oHole;
            MostRecentlySelectedHole = oHole;

            /*
             * The index is the at the end of the current list. This means we will have to manage the index values
             * when they are deleted
             */
            oHole.HoleTypeIndex = BoundaryRectangleList.Count;

            AddHoleToHoleGroup(MostRecentlySelectedHoleGroup, oHole);

            /*
             * Now create and add the rectangle
             */
            BoundaryRectangle rect = new BoundaryRectangle();

            rect.Width  = Width;
            rect.Height = Height;

            BoundaryRectangleList.Add(rect);

            // trigger draw shapes
            DrawShapes();
        }
コード例 #5
0
        //-------------------------------------------------------
        private void DrawShapes_Rectangle(LayoutHole oHole, bool IsCurrentHole)
        {
            BoundaryRectangle oRect = BoundaryRectangleList.GetFrom(oHole.HoleTypeIndex);

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

            string color = IsCurrentHole ? "#0000FF" : "#ff0000";

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

            // Adjust the width and height for zoom
            float SWidth  = oRect.Width / CurrentZoom;
            float SHeight = oRect.Height / CurrentZoom;

            // Draw the rectangle as a set of lines so we can control how its positioned. The offset is the lower left
            color = ShapeStrokeColor;

            // The offset is to the lower left
            PointF LowerLeft = Screen;

            PointF LowerRight = new PointF(LowerLeft.X + SWidth, LowerLeft.Y);

            this.DrawLine(color, 1, LowerLeft, LowerRight);

            PointF UpperRight = new PointF(LowerLeft.X + SWidth, LowerLeft.Y + SHeight);

            this.DrawLine(color, 1, LowerRight, UpperRight);

            PointF UpperLeft = new PointF(LowerLeft.X, LowerLeft.Y + SHeight);

            this.DrawLine(color, 1, UpperRight, UpperLeft);

            // Last line
            this.DrawLine(color, 1, UpperLeft, LowerLeft);

            // draw the resize handle
            this.DrawRectangle("#00FF00", HandleSize, HandleSize, Screen.X + SWidth, Screen.Y + SHeight - HandleSize);
        }
コード例 #6
0
        public void DeleteCurrentHole()
        {
            if (MostRecentlySelectedHole == null)
            {
                return;
            }

            int IndexToDelete = -1;

            switch (MostRecentlySelectedHole.HoleType)
            {
            case "ell":
                // Delete this index
                // Find all references to hole values greater than this one and reduce them by one so the indices are correct
                IndexToDelete = -1;

                for (int i = 0; i < GetHoleListLength(MostRecentlySelectedHoleGroup.HoleList); i++)
                {
                    LayoutHole oHole = MostRecentlySelectedHoleGroup.HoleList[i];

                    if (MostRecentlySelectedHole == oHole)
                    {
                        IndexToDelete = i;
                    }

                    if (oHole.HoleType == "ell" && oHole.HoleTypeIndex > MostRecentlySelectedHole.HoleTypeIndex)
                    {
                        oHole.HoleTypeIndex--;
                    }
                }

                // Delete this hole
                RemoveHoleFromHoleGroup(MostRecentlySelectedHoleGroup, IndexToDelete);

                // Delete this shape
                BoundaryEllipseList.RemoveAt(MostRecentlySelectedHole.HoleTypeIndex);
                break;

            case "rect":
                // Delete this index
                // Find all references to hole values greater than this one and reduce them by one so the indices are correct
                IndexToDelete = -1;
                for (int i = 0; i < GetHoleListLength(MostRecentlySelectedHoleGroup.HoleList); i++)
                {
                    LayoutHole oHole = MostRecentlySelectedHoleGroup.HoleList[i];

                    if (MostRecentlySelectedHole == oHole)
                    {
                        IndexToDelete = i;
                    }

                    if (oHole.HoleType == "rect" && oHole.HoleTypeIndex > MostRecentlySelectedHole.HoleTypeIndex)
                    {
                        oHole.HoleTypeIndex--;
                    }
                }

                // Delete this hole
                RemoveHoleFromHoleGroup(MostRecentlySelectedHoleGroup, IndexToDelete);

                // Delete this shape
                BoundaryRectangleList.RemoveAt(MostRecentlySelectedHole.HoleTypeIndex);
                break;

            case "poly":

                // Find all references to hole values greater than this one and reduce them by one so the indices are correct
                IndexToDelete = -1;

                for (int i = 0; i < GetHoleListLength(MostRecentlySelectedHoleGroup.HoleList); i++)
                {
                    LayoutHole oHole = MostRecentlySelectedHoleGroup.HoleList[i];

                    if (MostRecentlySelectedHole == oHole)
                    {
                        IndexToDelete = i;
                    }

                    if (oHole.HoleType == "poly" && oHole.HoleTypeIndex > MostRecentlySelectedHole.HoleTypeIndex)
                    {
                        oHole.HoleTypeIndex--;
                    }
                }

                // Delete this hole
                RemoveHoleFromHoleGroup(MostRecentlySelectedHoleGroup, IndexToDelete);

                // Delete this shape
                BoundaryPolygonList.RemoveAt(MostRecentlySelectedHole.HoleTypeIndex);
                break;
            }

            // trigger a repaint
            DrawShapes();
        }