public static void Draw(
            this SpriteBatch spriteBatch, NinePatchRegion2D ninePatchRegion, RectangleF destinationRectangle, Color color, RectangleF?clippingRectangle = null)
        {
            var destinationPatches = ninePatchRegion.CreatePatches(destinationRectangle);
            var sourcePatches      = ninePatchRegion.SourcePatches;

            for (var i = 0; i < sourcePatches.Length; i++)
            {
                var sourcePatch      = sourcePatches[i];
                var destinationPatch = destinationPatches[i];

                if (clippingRectangle.HasValue)
                {
                    sourcePatch      = ClipSourceRectangle(sourcePatch, destinationPatch, clippingRectangle.Value).ToRectangle();
                    destinationPatch = ClipDestinationRectangle(destinationPatch, clippingRectangle.Value).ToRectangle();
                    Draw(spriteBatch, ninePatchRegion.Texture, sourcePatch, destinationPatch, color, clippingRectangle);
                }
                else
                {
                    if (destinationPatch.Width > 0 && destinationPatch.Height > 0)
                    {
                        spriteBatch.Draw(ninePatchRegion.Texture, sourceRectangle: sourcePatch, destinationRectangle: destinationPatch, color: color);
                    }
                }
            }
        }
Beispiel #2
0
        public static void Draw(this SpriteBatch spriteBatch, NinePatchRegion2D ninePatchRegion,
                                Rectangle destinationRectangle, Color color)
        {
            var destinationPatches = ninePatchRegion.CreatePatches(destinationRectangle);
            var sourcePatches      = ninePatchRegion.SourcePatches;

            for (var i = 0; i < sourcePatches.Length; i++)
            {
                spriteBatch.Draw(ninePatchRegion.Texture, sourceRectangle: sourcePatches[i],
                                 destinationRectangle: destinationPatches[i], color: color);
            }
        }