Example #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);
                }
            }
        }
Example #2
0
 public GuiImage(NinePatchTexture2D background, TextureRepeatMode mode = TextureRepeatMode.Stretch)
 {
     Background            = background;
     Background.RepeatMode = mode;
     Width  = background.ClipBounds.Width;
     Height = background.ClipBounds.Height;
 }
Example #3
0
        protected override void OnInit(IGuiRenderer renderer)
        {
            var texture = renderer.GetTexture(GuiTextures.ProgressBar);
            var b       = texture.ClipBounds;

            _spriteSheetSegmentWidth = (int)Math.Round(b.Width / 4f);
            var bgBounds = new Rectangle(b.X, b.Y, _spriteSheetSegmentWidth * 3, b.Height);

            Background = new NinePatchTexture2D(texture.Texture.Slice(bgBounds), _spriteSheetSegmentWidth);

            Highlight = texture.Texture.Slice(new Rectangle(b.X + _spriteSheetSegmentWidth * 3, b.Y, _spriteSheetSegmentWidth, b.Height));
        }
Example #4
0
        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);
                }
            }
        }