public NinePatch(params TextureRegion[] patches)
: this()
{
if (patches.Length == 1) {
Load(new TextureRegion[] {
null, null, null,
null, patches[0], null,
null, null, null,
});
return;
}
if (patches.Length != 9)
throw new ArgumentException("NinePatch needs nine TextureRegions.");
Load(patches);
float leftWidth = LeftWidth;
if ((patches[TopLeft] != null && patches[TopLeft].RegionWidth != leftWidth)
|| (patches[MiddleLeft] != null && patches[MiddleLeft].RegionWidth != leftWidth)
|| (patches[BottomLeft] != null && patches[BottomLeft].RegionWidth != leftWidth))
throw new Exception("Left side patches must have same width.");
float rightWidth = RightWidth;
if ((patches[TopRight] != null && patches[TopRight].RegionWidth != rightWidth)
|| (patches[MiddleRight] != null && patches[MiddleRight].RegionWidth != rightWidth)
|| (patches[BottomRight] != null && patches[BottomRight].RegionWidth != rightWidth))
throw new Exception("Right side patches must have same width.");
float bottomHeight = BottomHeight;
if ((patches[BottomLeft] != null && patches[BottomLeft].RegionHeight != bottomHeight)
|| (patches[BottomCenter] != null && patches[BottomCenter].RegionHeight != bottomHeight)
|| (patches[BottomRight] != null && patches[BottomRight].RegionHeight != bottomHeight))
throw new Exception("Bottom side patches must have same height.");
float topHeight = TopHeight;
if ((patches[TopLeft] != null && patches[TopLeft].RegionHeight != topHeight)
|| (patches[TopCenter] != null && patches[TopCenter].RegionHeight != topHeight)
|| (patches[TopRight] != null && patches[TopRight].RegionHeight != topHeight))
throw new Exception("Top side patches must have same height.");
}