Skip to content

Commit

Permalink
fixed empty nine patch regions stalling when using tile mode
Browse files Browse the repository at this point in the history
closes #17
  • Loading branch information
Ellpeck committed Jan 30, 2024
1 parent 17b6a32 commit ed5c4b4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions MLEM/Textures/NinePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ public static void Draw(this SpriteBatch batch, NinePatch texture, RectangleF de
case NinePatchMode.Tile:
var width = src.Width * patchScale;
var height = src.Height * patchScale;
for (var x = 0F; x < rect.Width; x += width) {
for (var y = 0F; y < rect.Height; y += height) {
var size = new Vector2(Math.Min(rect.Width - x, width), Math.Min(rect.Height - y, height));
var srcSize = (size / patchScale).CeilCopy().ToPoint();
batch.Draw(texture.Region.Texture, new RectangleF(rect.Location + new Vector2(x, y), size), new Rectangle(src.X, src.Y, srcSize.X, srcSize.Y), color, rotation, origin, effects, layerDepth);
if (width > 0 && height > 0) {
for (var x = 0F; x < rect.Width; x += width) {
for (var y = 0F; y < rect.Height; y += height) {
var size = new Vector2(Math.Min(rect.Width - x, width), Math.Min(rect.Height - y, height));
var srcSize = (size / patchScale).CeilCopy().ToPoint();
batch.Draw(texture.Region.Texture, new RectangleF(rect.Location + new Vector2(x, y), size), new Rectangle(src.X, src.Y, srcSize.X, srcSize.Y), color, rotation, origin, effects, layerDepth);
}
}
}
break;
Expand Down

0 comments on commit ed5c4b4

Please sign in to comment.