Пример #1
0
        public static SpriteboxJson ToJsonElement(Spritebox spriteBox)
        {
            if (spriteBox == null)
            {
                return(null);
            }

            SpriteboxJson sprBoxJson = new SpriteboxJson()
            {
                posX         = spriteBox.GetPosition().X,
                posY         = spriteBox.GetPosition().Y,
                width        = spriteBox.GetWidth(),
                height       = spriteBox.GetHeight(),
                rotation     = spriteBox._rotation,
                sourceHeight = spriteBox.GetSourceRectangle().Height,
                sourceWidth  = spriteBox.GetSourceRectangle().Width,
                sourceX      = spriteBox.GetSourceRectangle().X,
                sourceY      = spriteBox.GetSourceRectangle().Y,
                textureKey   = spriteBox.GetTextureKey(),
                layer        = spriteBox.GetLayer(),
                visible      = spriteBox.Visible()
            };

            return(sprBoxJson);
        }
Пример #2
0
        public virtual bool RemoveSpriteBox(Spritebox spriteBox)
        {
            foreach (KeyValuePair <string, Spritebox> pair in SpriteBoxes)
            {
                if (pair.Value == spriteBox)
                {
                    SpriteBoxes.Remove(pair.Key);

                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        public static Spritebox FromJsonElement(SpriteboxJson spriteBoxJson)
        {
            if (spriteBoxJson == null)
            {
                return(null);
            }

            Spritebox sprBox = new Spritebox(new Vector2((float)spriteBoxJson.posX, (float)spriteBoxJson.posY), spriteBoxJson.width, spriteBoxJson.height, spriteBoxJson.rotation,
                                             spriteBoxJson.textureKey, spriteBoxJson.layer, new Rectangle(spriteBoxJson.sourceX, spriteBoxJson.sourceY, spriteBoxJson.sourceWidth, spriteBoxJson.sourceHeight),
                                             null);

            sprBox.SetVisible(spriteBoxJson.visible);

            return(sprBox);
        }
Пример #4
0
        public SelectionBox(Spritebox boundOject)
        {
            _boundObject = boundOject;

            // Resize boxes for resizing sprite
            ResizeBox box1 = new ResizeBox(ResizeBoxEnumVertical.TOP, ResizeBoxEnumHorizontal.LEFT, this);
            ResizeBox box2 = new ResizeBox(ResizeBoxEnumVertical.BOTTOM, ResizeBoxEnumHorizontal.LEFT, this);
            ResizeBox box3 = new ResizeBox(ResizeBoxEnumVertical.TOP, ResizeBoxEnumHorizontal.RIGHT, this);
            ResizeBox box4 = new ResizeBox(ResizeBoxEnumVertical.BOTTOM, ResizeBoxEnumHorizontal.RIGHT, this);

            // Add the resize boxes as children
            AddChild(box1);
            AddChild(box2);
            AddChild(box3);
            AddChild(box4);
        }
Пример #5
0
        /// <summary>
        /// Overridable, allows us to control how to draw this object directly.
        /// Not recommended if you can achieve your goal with more higher level methods.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="spriteBatch"></param>
        public virtual void Draw(GraphicsDevice device, SpriteBatch spriteBatch)
        {
            var orderedSprites = SpriteBoxes.OrderBy(f => f.Value.GetLayer()).ToList();

            foreach (KeyValuePair <string, Spritebox> pair in orderedSprites)
            {
                Spritebox spriteBox = pair.Value;

                if (spriteBatch != null && ContentManager.GetTexture(spriteBox.GetTextureKey()) != null && spriteBox.Visible())
                {
                    spriteBatch.Draw(ContentManager.GetTexture(spriteBox.GetTextureKey()), new Rectangle((int)(spriteBox.GetPosition().X + GetPosition().X), (int)(spriteBox.GetPosition().Y + GetPosition().Y), spriteBox.GetWidth(), spriteBox.GetHeight()), spriteBox.GetSourceRectangle(), Color.White);
                }
            }

            // Draw children
            foreach (Drawable d in _children)
            {
                d.Draw(device, spriteBatch);
            }
        }
Пример #6
0
 public void SetBoundObject(Spritebox spritebox)
 {
     _boundObject = spritebox;
 }
Пример #7
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);
        }