示例#1
0
        public void Draw(IGuiSprite sprite, Rectangle destinationRectangle)
        {
            var textureRegion = sprite.TextureRegion as TextureRegion;
            var texture = textureRegion.Texture;

            if (texture != null)
            {
                var sourceRectangle = textureRegion.Rectangle;
                var destRectangle = destinationRectangle;

                if (sprite.Scale != Vector2.One)
                {
                    var scaledWidth = sprite.Scale.X * destRectangle.Width;
                    var scaledHeight = sprite.Scale.Y * destRectangle.Height;
                    var offsetX = (int)(destRectangle.Width - scaledWidth) / 2;
                    var offsetY = (int)(destRectangle.Height - scaledHeight) / 2;
                    destRectangle = new Rectangle(offsetX + destRectangle.X, offsetY + destRectangle.Y, (int)scaledWidth, (int)scaledHeight);
                }

                var origin = new Vector2(sprite.Origin.X * destinationRectangle.Width, sprite.Origin.Y * destinationRectangle.Height);
                destRectangle.X += (int)origin.X;
                destRectangle.Y += (int)origin.Y;
                _spriteBatch.Draw(texture, destRectangle, sourceRectangle, sprite.Colour, sprite.Rotation, origin, sprite.Effect, sprite.Depth);
            }
        }
        public void Draw(IGuiSprite sprite, IRectangle destinationRectangle)
        {
            var textureRegion = sprite.TextureRegion as TextureRegion;
            var texture       = _textureMap[textureRegion.TextureAtlas.TextureName];

            if (texture != null)
            {
                var sourceRectangle = ToRectangle(textureRegion);
                var destRectangle   = ToRectangle(destinationRectangle);

                if (sprite.Scale != Vector2.One)
                {
                    var scaledWidth  = sprite.Scale.X * destRectangle.Width;
                    var scaledHeight = sprite.Scale.Y * destRectangle.Height;
                    var offsetX      = (int)(destRectangle.Width - scaledWidth) / 2;
                    var offsetY      = (int)(destRectangle.Height - scaledHeight) / 2;
                    destRectangle = new Rectangle(offsetX + destRectangle.X, offsetY + destRectangle.Y, (int)scaledWidth, (int)scaledHeight);
                }

                _spriteBatch.Draw(texture, destRectangle, sourceRectangle, sprite.Colour,
                                  sprite.Rotation, sprite.Origin, sprite.Effect, sprite.Depth);
            }
        }
示例#3
0
        public void Draw(IGuiSprite sprite, IRectangle destinationRectangle)
        {
            var textureRegion = sprite.TextureRegion as TextureRegion;
            var texture = _textureMap[textureRegion.TextureAtlas.TextureName];
            
            if(texture != null)
            {
                var sourceRectangle = ToRectangle(textureRegion);
                var destRectangle = ToRectangle(destinationRectangle);

                if(sprite.Scale != Vector2.One)
                {
                    var scaledWidth = sprite.Scale.X * destRectangle.Width;
                    var scaledHeight = sprite.Scale.Y * destRectangle.Height;
                    var offsetX = (int)(destRectangle.Width - scaledWidth) / 2;
                    var offsetY = (int)(destRectangle.Height - scaledHeight) / 2;
                    destRectangle = new Rectangle(offsetX + destRectangle.X, offsetY + destRectangle.Y, (int)scaledWidth, (int)scaledHeight);
                }

                _spriteBatch.Draw(texture, destRectangle, sourceRectangle, sprite.Colour, 
                                  sprite.Rotation, sprite.Origin, sprite.Effect, sprite.Depth);
            }
        }