Example #1
0
        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;
        }
Example #2
0
        private void DrawTop(SpriteBatch batch, Texture2D texture, Color color, RectangleF rectangle, float drawDepth = 0)
        {
            float ypos = rectangle.y;

            if (drawMode == DrawMode.Stretch)
            {
                batch.Draw(texture, new RectangleF(rectangle.x + distLeft, ypos, rectangle.width - (distLeft + distRight), distTop).ToRectangle(), EdgeTop.ToRectangle(), color, 0, Vector2.Zero, SpriteEffects.None, drawDepth);
            }
            else
            {
                float num  = (rectangle.width - (distLeft + distRight)) / EdgeTop.width;                //number of times to tile the texture
                float over = num % 1;
                for (int i = 0; i < (int)num; i++)
                {
                    float xpos = EdgeTop.width * i;
                    batch.Draw(texture, new Vector2(rectangle.x + distLeft + xpos, ypos).ToPoint().ToVector2(), EdgeTop.ToRectangle(), color, 0, Vector2.Zero, 1, SpriteEffects.None, drawDepth);
                }

                Rectangle drawRect = new Rectangle(new Vector2(rectangle.x + distLeft + (EdgeTop.width * (int)num), ypos).ToPoint(),
                                                   new Vector2(over * EdgeTop.width, distTop).ToPoint());
                batch.Draw(texture, drawRect, EdgeTop.ToRectangle(), color, 0, Vector2.Zero, SpriteEffects.None, drawDepth);
            }
        }