Ejemplo n.º 1
0
        public NineSliceTexture(Image image, SliceRect sliceRect)
        {
            this.sliceRect = sliceRect;

            Vector2u textureSize = image.Size;

            // TOP

            topLeft          = new Texture(image, new IntRect(0, 0, sliceRect.Width, sliceRect.Height));
            topLeft.Repeated = false;

            topCentre          = new Texture(image, new IntRect(sliceRect.Left, 0, (int)textureSize.X - (sliceRect.Width * 2), sliceRect.Height));
            topCentre.Repeated = false;

            topRight          = new Texture(image, new IntRect((int)textureSize.X - sliceRect.Left, 0, sliceRect.Width, sliceRect.Height));
            topRight.Repeated = false;

            // CENTRE

            centreLeft          = new Texture(image, new IntRect(0, sliceRect.Top, sliceRect.Width, (int)textureSize.Y - (sliceRect.Height * 2)));
            centreLeft.Repeated = false;

            centre          = new Texture(image, new IntRect(sliceRect.Left, sliceRect.Top, (int)textureSize.X - (sliceRect.Width * 2), (int)textureSize.Y - (sliceRect.Height * 2)));
            centre.Repeated = false;

            centreRight          = new Texture(image, new IntRect((int)textureSize.X - sliceRect.Left, sliceRect.Top, sliceRect.Width, (int)textureSize.Y - (sliceRect.Height * 2)));
            centreRight.Repeated = false;

            // BOTTOM

            bottomLeft          = new Texture(image, new IntRect(0, (int)textureSize.Y - sliceRect.Top, sliceRect.Width, sliceRect.Height));
            bottomLeft.Repeated = false;

            bottomCentre          = new Texture(image, new IntRect(sliceRect.Left, (int)textureSize.Y - sliceRect.Top, (int)textureSize.Y - (sliceRect.Width * 2), sliceRect.Height));
            bottomCentre.Repeated = false;

            bottomRight          = new Texture(image, new IntRect((int)textureSize.X - sliceRect.Left, (int)textureSize.Y - sliceRect.Top, sliceRect.Width, sliceRect.Height));
            bottomRight.Repeated = false;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a NineSliceTexture from a texture (expensive)
 /// </summary>
 /// <param name="texture">The texture to load it from</param>
 /// <param name="sliceRect">The slice rect</param>
 public NineSliceTexture(Texture texture, SliceRect sliceRect) : this(texture.CopyToImage(), sliceRect)
 {
     sourceTexture = texture;
 }
Ejemplo n.º 3
0
 public static NineSliceTexture CreateSlicedSubTexture(this Texture texture, SliceRect rect)
 {
     return(new NineSliceTexture(texture, rect));
 }