From 82468416751b95be9dd3a1145abaa1ae87190343 Mon Sep 17 00:00:00 2001 From: Sebastian Nordgren Date: Mon, 2 Sep 2024 22:14:44 +0300 Subject: [PATCH] Fix bug when using `NinePatch` with `Texture2DRegion`. Resolves #943 --- source/MonoGame.Extended/Graphics/NinePatch.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/source/MonoGame.Extended/Graphics/NinePatch.cs b/source/MonoGame.Extended/Graphics/NinePatch.cs index 25d1ce62c..7a9e1069a 100644 --- a/source/MonoGame.Extended/Graphics/NinePatch.cs +++ b/source/MonoGame.Extended/Graphics/NinePatch.cs @@ -62,6 +62,9 @@ public class NinePatch /// public string Name { get; } + /// + /// The size of the border patches around the middle patch. + /// public Thickness Padding { get; } /// @@ -90,7 +93,11 @@ public NinePatch(Texture2DRegion[] patches) : this(patches, null) { } /// /// Initializes a new instance of the class with the specified patches and name. /// - /// An array of nine objects. + /// + /// An array of nine objects. + /// The top, left, bottom and right regions must to be of exactly the same size. + /// Mid patches can be as small as 1x1. + /// /// /// The name of the nine-patch. If null or empty, a default name will be generated based on the texture name of the /// top-left patch. @@ -113,8 +120,11 @@ public NinePatch(Texture2DRegion[] patches, string name) } _patches = patches; - Rectangle mid = patches[NinePatch.Middle].Bounds; - Padding = new Thickness(mid.Left, mid.Top, mid.Right, mid.Bottom); + + Size topLeft = patches[NinePatch.TopLeft].Size; + Size bottomRight = patches[NinePatch.BottomRight].Size; + Padding = new Thickness(topLeft.Width, topLeft.Height, bottomRight.Width, bottomRight.Height); + Name = name; } }