Nez.Portable/Graphics/Textures/Subtexture.cs
/// <summary>
/// generates nine patch Rectangles. destArray should have 9 elements. renderRect is the final area in which the nine patch will be rendered.
/// To just get the source rects for rendering pass in the Subtexture.sourceRect. Pass in a larger Rectangle to get final destination
/// rendering Rectangles.
/// </summary>
/// <param name="renderRect">Render rect.</param>
/// <param name="destArray">Destination array.</param>
/// <param name="marginTop">Margin top.</param>
/// <param name="marginBottom">Margin bottom.</param>
/// <param name="marginLeft">Margin left.</param>
/// <param name="marginRight">Margin right.</param>
generates nine patch Rectangles. destArray should have 9 elements. renderRect is the final area in which the nine patch will be rendered.
To just get the source rects for rendering pass in the Subtexture.sourceRect. Pass in a larger Rectangle to get final destination
rendering Rectangles.
generates nine patch Rectangles . destArray should have 9 elements . renderRect is the final area in which the nine patch will be rendered . To just get the source rects for rendering pass in the Subtexture . sourceRect . Pass in a larger Rectangle to get final destination rendering Rectangles .
public void generateNinePatchRects(
            Rectangle renderRect,
            Rectangle[] destArray,
            int marginLeft,
            int marginRight,
            int marginTop,
            int marginBottom)
        {
            Assert.isTrue(destArray.Length == 9, "destArray does not have a length of 9");
            var stretchedCenterWidth = renderRect.Width - marginLeft - marginRight;
            var stretchedCenterHeight = renderRect.Height - marginTop - marginBottom;
            var bottomY = renderRect.Y + renderRect.Height - marginBottom;
            var rightX = renderRect.X + renderRect.Width - marginRight;
            var leftX = renderRect.X + marginLeft;
            var topY = renderRect.Y + marginTop;
            destArray[0] = new Rectangle(renderRect.X, renderRect.Y, marginLeft, marginTop); 
            destArray[1] = new Rectangle(leftX, renderRect.Y, stretchedCenterWidth, marginTop); 
            destArray[2] = new Rectangle(rightX, renderRect.Y, marginRight, marginTop); 
            destArray[3] = new Rectangle(renderRect.X, topY, marginLeft, stretchedCenterHeight); 
            destArray[4] = new Rectangle(leftX, topY, stretchedCenterWidth, stretchedCenterHeight); 
            destArray[5] = new Rectangle(rightX, topY, marginRight, stretchedCenterHeight); 
            destArray[6] = new Rectangle(renderRect.X, bottomY, marginLeft, marginBottom); 
            destArray[7] = new Rectangle(leftX, bottomY, stretchedCenterWidth, marginBottom); 
            destArray[8] = new Rectangle(rightX, bottomY, marginRight, marginBottom); 
        }
public void generateNinePatchRects ( Rectangle renderRect , Rectangle [ ] destArray , int marginLeft , int marginRight , int marginTop , int marginBottom ) { Assert . isTrue ( destArray . Length == 9 , " " ) ; var stretchedCenterWidth = renderRect . Width - marginLeft - marginRight ; var stretchedCenterHeight = renderRect . Height - marginTop - marginBottom ; var bottomY = renderRect . Y + renderRect . Height - marginBottom ; var rightX = renderRect . X + renderRect . Width - marginRight ; var leftX = renderRect . X + marginLeft ; var topY = renderRect . Y + marginTop ; destArray [ 0 ] = new Rectangle ( renderRect . X , renderRect . Y , marginLeft , marginTop ) ; destArray [ 1 ] = new Rectangle ( leftX , renderRect . Y , stretchedCenterWidth , marginTop ) ; destArray [ 2 ] = new Rectangle ( rightX , renderRect . Y , marginRight , marginTop ) ; destArray [ 3 ] = new Rectangle ( renderRect . X , topY , marginLeft , stretchedCenterHeight ) ; destArray [ 4 ] = new Rectangle ( leftX , topY , stretchedCenterWidth , stretchedCenterHeight ) ; destArray [ 5 ] = new Rectangle ( rightX , topY , marginRight , stretchedCenterHeight ) ; destArray [ 6 ] = new Rectangle ( renderRect . X , bottomY , marginLeft , marginBottom ) ; destArray [ 7 ] = new Rectangle ( leftX , bottomY , stretchedCenterWidth , marginBottom ) ; destArray [ 8 ] = new Rectangle ( rightX , bottomY , marginRight , marginBottom ) ; }
generates nine patch Rectangles.
generates nine patch Rectangles .
// top-left // top-center // top-right // middle-left // middle-center // middle-right // bottom-left // bottom-center // bottom-right
renderRect
Rectangle
None
destArray
Rectangle[]
None
marginLeft
int
None
marginRight
int
None
marginTop
int
None
marginBottom
int
None