Пример #1
0
        // Performs a deep copy the selected GameEntity
        private void clone_btn_Click(object sender, EventArgs e)
        {
            GameEntity ge     = selectedObject_pg.SelectedObject as GameEntity;
            EntityType entity = ge.Type;
            Rectangle  bb     = ge.GetBoundingBox();


            GameEntity geCopy = null;

            // Create new GameEntity
            if (entity == EntityType.RECT)
            {
                geCopy = GameEntity.CreateRectangle(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height);
            }

            if (entity == EntityType.CIRCLE)
            {
                geCopy = GameEntity.CreateCircle(bb.Width, bb.Location);
            }

            if (entity == EntityType.SPRITE)
            {
                geCopy = GameEntity.CreateSprite(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height);
            }

            if (entity == EntityType.LINETRACK)
            {
                geCopy = GameEntity.CreateLineTrack(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height);
            }

            if (entity == EntityType.CONVEYBELT)
            {
                geCopy = GameEntity.CreateConveyBelt(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height);
            }

            if (entity == EntityType.LINESIN)
            {
                geCopy = GameEntity.CreateLineSin(bb.Location.Y, bb.Location.Y, bb.Width, bb.Height);
            }

            geCopy.SetBoundingBox(bb); // Sets bounding box
            geCopy.Props = ge.Props;   // Deep copy of properties

            // Adds the gameentity to the list of entities if not null
            if (geCopy != null)
            {
                gameEntities_lb.Items.Add(geCopy);
                gameEntities_lb.SelectedIndex    = gameEntities_lb.Items.Count - 1;
                selectedObject_pg.SelectedObject = geCopy;
                RefreshAll();
            }
        }
Пример #2
0
        private void TabPanel_MouseMove(object sender, MouseEventArgs me)
        {
            //MIDTERM: This needs to be modified to distinguish between moving an object and
            // resizing it using the corners.

            /* Get the selected game object, used by almost everything below. */
            GameEntity ge = selectedObject_pg.SelectedObject as GameEntity;

            /* Detect any change in mouse movement. */
            int change = (MousePrevPos.X - me.Location.X) + (MousePrevPos.Y - me.Location.Y);

            if (LMBDown && Dragging)
            {
                Rectangle r = ge.GetBoundingBox();
                r.Location = new Point(me.Location.X - MouseDragOffset.X, me.Location.Y - MouseDragOffset.Y);
                ge.SetBoundingBox(r);

                if (change != 0)
                {
                    RefreshAll();
                }
            }
            else if (LMBDown && Resizing >= 0)
            {
                Rectangle r = ge.GetBoundingBox();

                Point offset = new Point(me.Location.X - BeforeResize.Location.X, me.Location.Y - BeforeResize.Location.Y);

                /* Resizing changes based on entity type. */
                if (ge.Type == EntityType.RECT)
                {
                    /* Rectangles are easy. Just find the corner.
                     * This should also work with any other object whose width and height are independent. */
                    if (Resizing == 0)
                    {
                        r = new Rectangle(me.Location.X, me.Location.Y, BeforeResize.Size.Width - offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 1)
                    {
                        r = new Rectangle(BeforeResize.Location.X, me.Location.Y, offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 2)
                    {
                        r = new Rectangle(BeforeResize.Location.X, BeforeResize.Location.Y, offset.X, offset.Y);
                    }
                    else if (Resizing == 3)
                    {
                        r = new Rectangle(me.Location.X, BeforeResize.Location.Y, BeforeResize.Size.Width - offset.X, offset.Y);
                    }
                }
                else if (ge.Type == EntityType.CIRCLE)
                {
                    /* Circles only have radius, so resizing must be uniform with regards to width and height. */
                    if (Resizing == 0)
                    {
                        r = new Rectangle(me.Location.X, BeforeResize.Location.Y + offset.X, BeforeResize.Size.Width - offset.X, BeforeResize.Size.Width - offset.X);
                    }
                    else if (Resizing == 1)
                    {
                        r = new Rectangle(BeforeResize.Location.X, me.Location.Y, BeforeResize.Size.Height - offset.Y, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 2)
                    {
                        r = new Rectangle(BeforeResize.Location.X, BeforeResize.Location.Y, offset.Y, offset.Y);
                    }
                    else if (Resizing == 3)
                    {
                        r = new Rectangle(me.Location.X, BeforeResize.Location.Y, BeforeResize.Size.Width - offset.X, BeforeResize.Size.Width - offset.X);
                    }
                }
                else if (ge.Type == EntityType.WAVE_TRACK)
                {
                    if (Resizing == 0)
                    {
                        r = new Rectangle(me.Location.X, me.Location.Y, BeforeResize.Size.Width - offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 1)
                    {
                        r = new Rectangle(BeforeResize.Location.X, me.Location.Y, offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 2)
                    {
                        r = new Rectangle(BeforeResize.Location.X, BeforeResize.Location.Y, offset.X, offset.Y);
                    }
                    else if (Resizing == 3)
                    {
                        r = new Rectangle(me.Location.X, BeforeResize.Location.Y, BeforeResize.Size.Width - offset.X, offset.Y);
                    }
                }
                else if (ge.Type == EntityType.CONVERYOR_TRACK)
                {
                    if (Resizing == 0)
                    {
                        r = new Rectangle(me.Location.X, me.Location.Y, BeforeResize.Size.Width - offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 1)
                    {
                        r = new Rectangle(BeforeResize.Location.X, me.Location.Y, offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 2)
                    {
                        r = new Rectangle(BeforeResize.Location.X, BeforeResize.Location.Y, offset.X, offset.Y);
                    }
                    else if (Resizing == 3)
                    {
                        r = new Rectangle(me.Location.X, BeforeResize.Location.Y, BeforeResize.Size.Width - offset.X, offset.Y);
                    }
                }
                else if (ge.Type == EntityType.FUNCTION_TRACK)
                {
                    if (Resizing == 0)
                    {
                        r = new Rectangle(me.Location.X, me.Location.Y, BeforeResize.Size.Width - offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 1)
                    {
                        r = new Rectangle(BeforeResize.Location.X, me.Location.Y, offset.X, BeforeResize.Size.Height - offset.Y);
                    }
                    else if (Resizing == 2)
                    {
                        r = new Rectangle(BeforeResize.Location.X, BeforeResize.Location.Y, offset.X, offset.Y);
                    }
                    else if (Resizing == 3)
                    {
                        r = new Rectangle(me.Location.X, BeforeResize.Location.Y, BeforeResize.Size.Width - offset.X, offset.Y);
                    }
                }


                /* Fix the shape. Prevents a shape from having negative width or height. */
                int adjustWidth = 0;
                if (r.Size.Width < 0)
                {
                    adjustWidth = r.Size.Width;
                }

                int adjustHeight = 0;
                if (r.Size.Height < 0)
                {
                    adjustHeight = r.Size.Height;
                }

                r = new Rectangle(r.Location.X + adjustWidth, r.Location.Y + adjustHeight, Math.Abs(r.Size.Width), Math.Abs(r.Size.Height));
                ge.SetBoundingBox(r);

                /* Refresh the shape. Doing this too often seems to cause flicker. */
                if (change != 0)
                {
                    RefreshAll();
                }
            }
            else
            {
                /* No action. Set cursor state. */
                if (toolsPointer_rb.Checked)
                {
                    if (ge != null)
                    {
                        tabControl1.Cursor = Cursors.Arrow;

                        if (ge.GetBoundingBox().Contains(me.Location))
                        {
                            tabControl1.Cursor = Cursors.SizeAll;
                        }

                        for (int i = 0; i < 4; i++)
                        {
                            if (ge.CornerHandles[i].Contains(me.Location))
                            {
                                if (i % 2 == 0)
                                {
                                    tabControl1.Cursor = Cursors.SizeNWSE;
                                }
                                else
                                {
                                    tabControl1.Cursor = Cursors.SizeNESW;
                                }
                            }
                        }
                    }
                }
            }

            /* Save last position of mouse. Helps prevent idle flicker. */
            MousePrevPos = me.Location;
        }
Пример #3
0
        private void TabPanel_MouseMove(object sender, MouseEventArgs me)
        {
            //MIDTERM: This needs to be modified to distinguish between moving an object and
            // resizing it using the corners.
            if (LMBDown && Dragging)
            {
                GameEntity ge = selectedObject_pg.SelectedObject as GameEntity;
                Rectangle  r  = ge.GetBoundingBox();
                r.Location = new Point(me.Location.X - MouseDragOffset.X, me.Location.Y - MouseDragOffset.Y);
                ge.SetBoundingBox(r);
                RefreshAll();
            }
            else if (LMBDown && Resizing)
            {
                switch (resizeCorner)
                {
                case Constants.TOP_LEFT:
                {
                    // get the selected entity
                    GameEntity ge = (selectedObject_pg.SelectedObject as GameEntity);

                    // calculate drag of mouse
                    int changeInX = me.Location.X - MouseDownPos.X;
                    int changeInY = me.Location.Y - MouseDownPos.Y;

                    // get current bounding box
                    Rectangle bound = ge.GetBoundingBox();

                    // change X and widht of Bouding Box
                    bound.X     = prevRec.X + changeInX;
                    bound.Width = prevRec.Width - changeInX;
                    // Change Y and Height of bounding Box
                    bound.Y      = prevRec.Y + changeInY;
                    bound.Height = prevRec.Height - changeInY;

                    // make sure  the width and height stay positive
                    if (bound.Width < 1)
                    {
                        bound.Width = 1;
                    }
                    if (bound.Height < 1)
                    {
                        bound.Height = 1;
                    }

                    // make sure the position of box doesn't change even if we drag mouse away
                    bound.X = bound.X > prevRec.Right ? prevRec.Right : bound.X;
                    bound.Y = bound.Y > prevRec.Bottom ? prevRec.Bottom : bound.Y;

                    ge.SetBoundingBox(bound);

                    RefreshAll();
                }
                break;

                case Constants.TOP_RIGHT:
                {
                    // get the selected entity
                    GameEntity ge1 = (selectedObject_pg.SelectedObject as GameEntity);

                    // calculate drag of mouse
                    int changeInX1 = me.Location.X - MouseDownPos.X;
                    int changeInY1 = me.Location.Y - MouseDownPos.Y;

                    // get current bounding box
                    Rectangle bound1 = ge1.GetBoundingBox();

                    bound1.Y = prevRec.Y + changeInY1;

                    // change height and widht of Bouding Box
                    bound1.Width  = prevRec.Width + changeInX1;
                    bound1.Height = prevRec.Height - changeInY1;

                    // make sure  the width and height stay positive
                    if (bound1.Width < 1)
                    {
                        bound1.Width = 1;
                    }
                    if (bound1.Height < 1)
                    {
                        bound1.Height = 1;
                    }

                    // make sure the position of box doesn't change even if we drag mouse away
                    bound1.Y = bound1.Y > prevRec.Bottom ? prevRec.Bottom : bound1.Y;

                    ge1.SetBoundingBox(bound1);

                    RefreshAll();
                }
                break;

                case Constants.BOTTOM_RIGHT:
                {
                    // get the selected entity
                    GameEntity ge1 = (selectedObject_pg.SelectedObject as GameEntity);

                    // calculate drag of mouse
                    int changeInX1 = me.Location.X - MouseDownPos.X;
                    int changeInY1 = me.Location.Y - MouseDownPos.Y;

                    // get current bounding box
                    Rectangle bound1 = ge1.GetBoundingBox();


                    // change height and widht of Bouding Box
                    bound1.Width  = prevRec.Width + changeInX1;
                    bound1.Height = prevRec.Height + changeInY1;

                    // make sure  the width and height stay positive
                    if (bound1.Width < 1)
                    {
                        bound1.Width = 1;
                    }
                    if (bound1.Height < 1)
                    {
                        bound1.Height = 1;
                    }


                    ge1.SetBoundingBox(bound1);

                    RefreshAll();
                    break;
                }

                case Constants.BOTTOM_LEFT:
                {
                    // get the selected entity
                    GameEntity ge1 = (selectedObject_pg.SelectedObject as GameEntity);

                    // calculate drag of mouse
                    int changeInX1 = me.Location.X - MouseDownPos.X;
                    int changeInY1 = me.Location.Y - MouseDownPos.Y;

                    // get current bounding box
                    Rectangle bound1 = ge1.GetBoundingBox();

                    // change X and widht of Bouding Box
                    bound1.X = prevRec.X + changeInX1;

                    // change height and widht of Bouding Box
                    bound1.Width  = prevRec.Width - changeInX1;
                    bound1.Height = prevRec.Height + changeInY1;

                    // make sure  the width and height stay positive
                    if (bound1.Width < 1)
                    {
                        bound1.Width = 1;
                    }
                    if (bound1.Height < 1)
                    {
                        bound1.Height = 1;
                    }

                    // make sure the position of box doesn't change even if we drag mouse away
                    bound1.X = bound1.X > prevRec.Right ? prevRec.Right : bound1.X;

                    ge1.SetBoundingBox(bound1);

                    RefreshAll();
                    break;
                }

                default:
                    break;
                }
            }
        }