コード例 #1
0
        public void DrawNinePatch(Rectangle bounds, NinePatchTexture2D ninePatchTexture, TextureRepeatMode repeatMode, Vector2?scale = null)
        {
            if (scale == null)
            {
                scale = Vector2.One;
            }

            if (ninePatchTexture.Padding == Thickness.Zero)
            {
                FillRectangle(bounds, ninePatchTexture.Texture, repeatMode);
                return;
            }

            var sourceRegions = ninePatchTexture.SourceRegions;
            var destRegions   = ninePatchTexture.ProjectRegions(bounds);

            for (var i = 0; i < sourceRegions.Length; i++)
            {
                var srcPatch = sourceRegions[i];
                var dstPatch = destRegions[i];

                if (dstPatch.Width > 0 && dstPatch.Height > 0)
                {
                    SpriteBatch.Draw(ninePatchTexture, sourceRectangle: srcPatch, destinationRectangle: dstPatch);
                }
            }
        }
コード例 #2
0
ファイル: GuiSpriteBatch.cs プロジェクト: PocketGold-MP/Alex
        private void DrawTextureNinePatch(Rectangle rectangle, NinePatchTexture2D ninePatchTexture, Color mask)
        {
            if (ninePatchTexture.Padding == Thickness.Zero)
            {
                SpriteBatch.Draw(ninePatchTexture, rectangle);
                return;
            }

            var sourceRegions = ninePatchTexture.SourceRegions;
            var destRegions   = ninePatchTexture.ProjectRegions(rectangle);

            for (var i = 0; i < sourceRegions.Length; i++)
            {
                var srcPatch = sourceRegions[i];
                var dstPatch = destRegions[i];

                if (dstPatch.Width > 0 && dstPatch.Height > 0)
                {
                    SpriteBatch.Draw(ninePatchTexture, dstPatch, srcPatch, mask);
                }
            }
        }