public void GetTextures(Texture2D texture) { this.texture = texture; if (!hasTextures) { TexTopLeft = GetTexturePart(texture, CornerTopLeft.ToRectangle(), "topleft"); TexTopRight = GetTexturePart(texture, CornerTopRight.ToRectangle(), "topright"); TexBotLeft = GetTexturePart(texture, CornerBottomLeft.ToRectangle(), "botleft"); TexBotRight = GetTexturePart(texture, CornerBottomRight.ToRectangle(), "botright"); TexTop = GetTexturePart(texture, EdgeTop.ToRectangle(), "top"); TexLeft = GetTexturePart(texture, EdgeLeft.ToRectangle(), "left"); TexRight = GetTexturePart(texture, EdgeRight.ToRectangle(), "right"); TexBottom = GetTexturePart(texture, EdgeBottom.ToRectangle(), "bottom"); TexCenter = GetTexturePart(texture, Center.ToRectangle(), "center"); } hasTextures = true; }
private void DrawLeft(SpriteBatch batch, Texture2D texture, Color color, RectangleF rectangle, float drawDepth = 0) { float xpos = rectangle.x; if (drawMode == DrawMode.Stretch) { batch.Draw(texture, new RectangleF(xpos, rectangle.y + distTop, distLeft, rectangle.height - (distTop + distBottom)).ToRectangle(), EdgeLeft.ToRectangle(), color, 0, Vector2.Zero, SpriteEffects.None, drawDepth); } else { float num = (rectangle.height - (distTop + distBottom)) / EdgeLeft.height; //number of times to tile the texture float over = num % 1; for (int i = 0; i < (int)num; i++) { float ypos = EdgeLeft.height * i; batch.Draw(texture, new Vector2(xpos, rectangle.y + distTop + ypos).ToPoint().ToVector2(), EdgeLeft.ToRectangle(), color, 0, Vector2.Zero, 1, SpriteEffects.None, drawDepth); } Rectangle drawRect = new Rectangle(new Vector2(xpos, rectangle.y + distTop + (EdgeLeft.height * (int)num)).ToPoint(), new Vector2(distLeft, over * EdgeLeft.height).ToPoint()); batch.Draw(texture, drawRect, EdgeLeft.ToRectangle(), color, 0, Vector2.Zero, SpriteEffects.None, drawDepth); } }