Exemple #1
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);
 }
Exemple #2
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);
        }
Exemple #3
0
 public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion,
                         Rectangle destinationRectangle, Color color, Rectangle?clippingRectangle = null)
 {
     if (textureRegion is NinePatchRegion2D ninePatchRegion)
     {
         spriteBatch.Draw(ninePatchRegion, destinationRectangle, color, clippingRectangle);
     }
     else
     {
         spriteBatch.Draw(textureRegion.Texture, textureRegion.Bounds, destinationRectangle, color,
                          clippingRectangle);
     }
 }
Exemple #4
0
 public NinePatchRegion2D(TextureRegion2D textureRegion, int leftPadding, int topPadding, int rightPadding,
                          int bottomPadding)
     : this(textureRegion, new Thickness(leftPadding, topPadding, rightPadding, bottomPadding))
 {
 }
Exemple #5
0
 public NinePatchRegion2D(TextureRegion2D textureRegion, int leftRightPadding, int topBottomPadding)
     : this(textureRegion, leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding)
 {
 }
Exemple #6
0
 public NinePatchRegion2D(TextureRegion2D textureRegion, int padding)
     : this(textureRegion, padding, padding, padding, padding)
 {
 }
Exemple #7
0
 public static void Draw(this SpriteBatch spriteBatch, TextureRegion2D textureRegion, Vector2 position,
                         Color color, Rectangle?clippingRectangle = null)
 {
     spriteBatch.Draw(textureRegion, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0,
                      clippingRectangle);
 }