Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when using NinePatch with Texture2DRegion. #945

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions source/MonoGame.Extended/Graphics/NinePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class NinePatch
/// </summary>
public string Name { get; }

/// <summary>
/// The size of the border patches around the middle patch.
/// </summary>
public Thickness Padding { get; }

/// <summary>
Expand Down Expand Up @@ -90,7 +93,11 @@ public NinePatch(Texture2DRegion[] patches) : this(patches, null) { }
/// <summary>
/// Initializes a new instance of the <see cref="NinePatch"/> class with the specified patches and name.
/// </summary>
/// <param name="patches">An array of nine <see cref="Texture2DRegion"/> objects.</param>
/// <param name="patches">
/// An array of nine <see cref="Texture2DRegion"/> objects.
/// The top, left, bottom and right regions must to be of exactly the same size.
/// Mid patches can be as small as 1x1.
/// </param>
/// <param name="name">
/// 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.
Expand All @@ -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;
}
}
Loading