Example #1
0
        public override void Draw(GraphicsDevice device, SpriteBatch spriteBatch)
        {
            if (_boundObject == null || spriteBatch == null)
            {
                return;
            }

            SpriteRenderer.DrawRectangle(spriteBatch, device, new Rectangle((int)GetPosition().X, (int)GetPosition().Y, _boundObject.GetWidth(), _boundObject.GetHeight()), Color.White);
            spriteBatch.DrawString(MainWindowViewModel.MonogameWindow.DefaultFont, $"{_boundObject.GetRectangle().Width}, {_boundObject.GetRectangle().Height}", new Vector2((int)_boundObject.GetPosition().X, (int)_boundObject.GetPosition().Y - 15), Color.White);

            base.Draw(device, spriteBatch);
        }
Example #2
0
        public override void MouseMove(object sender, MouseEventArgs e, Vector2 worldMousePosition)
        {
            if (e == null)
            {
                return;
            }

            if (_selectionBox.GetBoundObject() == null)
            {
                return;
            }

            // Resizing object
            if (_selected)
            {
                // Vertical-Top
                if (VerticalPos == ResizeBoxEnumVertical.TOP)
                {
                    Vector2 NewPos = new Vector2(_selectionBox.GetBoundObject().GetPosition().X, worldMousePosition.Y + _distanceOnSelect.Y + GetHoverBox().Width / 2);

                    Vector2 SprOldPos = _selectionBox.GetBoundObject().GetPosition();

                    Spritebox sprBox = _selectionBox.GetBoundObject();

                    sprBox.SetPosition(NewPos);

                    int posDifference = ((int)sprBox.GetPosition().Y - (int)SprOldPos.Y);

                    sprBox.SetHeight(sprBox.GetHeight() - posDifference);
                    sprBox.SetSourceRectangle(new Rectangle(sprBox.GetSourceRectangle().X, sprBox.GetSourceRectangle().Y + posDifference, sprBox.GetSourceRectangle().Width, sprBox.GetHeight()));
                }

                // Vertical-Bottom
                if (VerticalPos == ResizeBoxEnumVertical.BOTTOM)
                {
                    Vector2 SprOldPos = _selectionBox.GetBoundObject().GetPosition();

                    Spritebox sprBox = _selectionBox.GetBoundObject();

                    int posDifference = ((int)(worldMousePosition.Y) - (int)oldMousePos.Y);

                    Rectangle newRect = sprBox.GetRectangle();


                    sprBox.SetHeight((int)worldMousePosition.Y - (int)sprBox.GetPosition().Y + (int)_distanceOnSelect.Y + GetHoverBox().Width / 2);

                    sprBox.SetSourceRectangle(new Rectangle(sprBox.GetSourceRectangle().X, sprBox.GetSourceRectangle().Y, sprBox.GetSourceRectangle().Width, sprBox.GetHeight()));
                }

                // Horizontal-Left
                if (HorizontalPos == ResizeBoxEnumHorizontal.LEFT)
                {
                    Vector2 NewPos = new Vector2(worldMousePosition.X + _distanceOnSelect.X + GetHoverBox().Width / 2, _selectionBox.GetBoundObject().GetPosition().Y);

                    Vector2 SprOldPos = _selectionBox.GetBoundObject().GetPosition();

                    Spritebox sprBox = _selectionBox.GetBoundObject();

                    sprBox.SetPosition(NewPos);

                    int posDifference = ((int)sprBox.GetPosition().X - (int)SprOldPos.X);

                    sprBox.SetWidth(sprBox.GetWidth() - posDifference);
                    sprBox.SetSourceRectangle(new Rectangle(sprBox.GetSourceRectangle().X + posDifference, sprBox.GetSourceRectangle().Y, sprBox.GetWidth(), sprBox.GetSourceRectangle().Height));
                }

                // Horizontal-Right
                if (HorizontalPos == ResizeBoxEnumHorizontal.RIGHT)
                {
                    Vector2 SprOldPos = _selectionBox.GetBoundObject().GetPosition();

                    Spritebox sprBox = _selectionBox.GetBoundObject();

                    int posDifference = ((int)(worldMousePosition.X) - (int)oldMousePos.X);

                    Rectangle newRect = sprBox.GetRectangle();

                    sprBox.SetWidth((int)worldMousePosition.X - (int)sprBox.GetPosition().X + (int)_distanceOnSelect.X + GetHoverBox().Width / 2);

                    sprBox.SetSourceRectangle(new Rectangle(sprBox.GetSourceRectangle().X, sprBox.GetSourceRectangle().Y, sprBox.GetWidth(), sprBox.GetSourceRectangle().Height));
                }
            }

            oldMousePos = worldMousePosition;

            base.MouseMove(sender, e, worldMousePosition);
        }