Ejemplo n.º 1
0
        public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color,
                                float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, Rectangle?clippingRectangle = null)
        {
            var sourceRectangle = textureRegion.Bounds;

            if (clippingRectangle.HasValue)
            {
                var x      = (int)(position.X - origin.X);
                var y      = (int)(position.Y - origin.Y);
                var width  = (int)(textureRegion.Width * scale.X);
                var height = (int)(textureRegion.Height * scale.Y);
                var destinationRectangle = new Rectangle(x, y, width, height);

                sourceRectangle = ClipSourceRectangle(textureRegion.Bounds, destinationRectangle, clippingRectangle.Value);
                position.X     += sourceRectangle.X - textureRegion.Bounds.X;
                position.Y     += sourceRectangle.Y - textureRegion.Bounds.Y;

                if (sourceRectangle.Width <= 0 || sourceRectangle.Height <= 0)
                {
                    return;
                }
            }

            spriteBatch.Draw(textureRegion.Texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth);
        }
Ejemplo n.º 2
0
        public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Rectangle destinationRectangle, Color color, Rectangle?clippingRectangle = null)
        {
            var ninePatchRegion = textureRegion as NinePatchRegion2D;

            if (ninePatchRegion != null)
            {
                Draw(spriteBatch, ninePatchRegion, destinationRectangle, color, clippingRectangle);
            }
            else
            {
                Draw(spriteBatch, textureRegion.Texture, textureRegion.Bounds, destinationRectangle, color, clippingRectangle);
            }
        }
Ejemplo n.º 3
0
 public NinePatchRegion2D(TextureRegion2D textureRegion, int leftPadding, int topPadding, int rightPadding, int bottomPadding)
     : this(textureRegion, new Thickness(leftPadding, topPadding, rightPadding, bottomPadding))
 {
 }
Ejemplo n.º 4
0
 public NinePatchRegion2D(TextureRegion2D textureRegion, int leftRightPadding, int topBottomPadding)
     : this(textureRegion, leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding)
 {
 }
Ejemplo n.º 5
0
 public NinePatchRegion2D(TextureRegion2D textureRegion, int padding)
     : this(textureRegion, padding, padding, padding, padding)
 {
 }
Ejemplo n.º 6
0
 public NinePatchRegion2D(TextureRegion2D textureRegion, Thickness padding)
     : base(textureRegion.Name, textureRegion.Texture, textureRegion.X, textureRegion.Y, textureRegion.Width, textureRegion.Height)
 {
     Padding = padding;
     CachePatches(textureRegion.Bounds, SourcePatches);
 }
Ejemplo n.º 7
0
 public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position, Color color, Rectangle?clippingRectangle = null)
 {
     Draw(spriteBatch, textureRegion, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0, clippingRectangle);
 }