Example #1
0
 public void Draw(SpriteBatch spriteBatch, Rectangle rect, Color col, Rotation90 rotation)
 {
     foreach (RichImageLayer curLayer in layers)
     {
         curLayer.Draw(spriteBatch, rect, col, rotation);
     }
 }
Example #2
0
        public RichImageLayer_Texture(Texture2D aTexture, Color aColor, String aDrawMode, int aPadding, Rotation90 aRotation)
        {
            texture  = aTexture;
            color    = aColor;
            drawMode = drawModesByName[aDrawMode];
            padding  = aPadding;
            rotation = aRotation;
            offset   = Vector2.Zero;

            modifiesRect = (padding != 0 || offset.X != 0 || offset.Y != 0);
        }
Example #3
0
        public static int toInt(this Rotation90 rot)
        {
            switch (rot)
            {
            case Rotation90.Rot90: return(90);

            case Rotation90.Rot180: return(180);

            case Rotation90.Rot270: return(270);

            default: return(0);
            }
        }
Example #4
0
        public void Draw(SpriteBatch spriteBatch, Rectangle rect, Color inCol, Rotation90 aRotation)
        {
            Color finalColor = inCol.Multiply(color);

            if (modifiesRect)
            {
                drawMode.Draw(spriteBatch, new Rectangle(rect.X + (int)offset.X - padding, rect.Y + (int)offset.Y - padding, rect.Width + padding * 2, rect.Height + padding * 2), texture, finalColor, rotation.rotateBy(aRotation));
            }
            else
            {
                drawMode.Draw(spriteBatch, rect, texture, finalColor, rotation.rotateBy(aRotation));
            }
        }
Example #5
0
        public RichImageLayer_Texture(JSONTable template, ContentManager content)
        {
            texture  = content.Load <Texture2D>(template.getString("texture", "white"));
            color    = template.getString("color", "FFFFFF").toColor();
            drawMode = drawModesByName[template.getString("draw", "default")];
            padding  = template.getInt("padding", 0);

            JSONArray offsetArray = template.getArray("offset", null);

            if (offsetArray == null)
            {
                offset = new Vector2(0, 0);
            }
            else
            {
                offset = offsetArray.toVector2();
            }

            rotation = template.getRotation("rotation", Rotation90.None);

            modifiesRect = (padding != 0 || offset.X != 0 || offset.Y != 0);
        }
Example #6
0
        public static Rotation90 getRotation(this JSONTable table, string name, Rotation90 defaultValue)
        {
            int angle = table.getInt(name, defaultValue.toInt());

            return((Rotation90)(angle / 90));
        }
Example #7
0
 public void Draw(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture, Color color, Rotation90 rotation)
 {
     for (int X = rect.X; X < rect.X + rect.Width; X += texture.Width)
     {
         for (int Y = rect.Y; Y < rect.Y + rect.Height; Y += texture.Height)
         {
             spriteBatch.Draw(texture, new Vector2(X, Y), color);
         }
     }
 }
Example #8
0
        public void Draw(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture, Color color, Rotation90 rotation)
        {
            float rot       = 0.0f;
            int   rotWidth  = rect.Width;
            int   rotHeight = rect.Height;

            if (rotation == Rotation90.None)
            {
                spriteBatch.Draw(texture, rect, color);
                return;
            }

            if (rotation == Rotation90.Rot90)
            {
                rot       = (float)(Math.PI * 0.5);
                rotWidth  = rect.Height;
                rotHeight = rect.Width;
            }
            else if (rotation == Rotation90.Rot180)
            {
                rot = (float)Math.PI;
            }
            else if (rotation == Rotation90.Rot270)
            {
                rot       = (float)(Math.PI * 1.5);
                rotWidth  = rect.Height;
                rotHeight = rect.Width;
            }

            int halfWidth  = rect.Width / 2;
            int halfHeight = rect.Height / 2;

            Rectangle rotRect = new Rectangle((int)(rect.X + halfWidth), (int)(rect.Y + halfHeight), rotWidth, rotHeight);

            // origin would be <texture.Width/2, texture.Height/2>, if halfWidth and halfHeight weren't rounded
            Vector2 origin = new Vector2(texture.Width * (halfWidth / (float)rect.Width), texture.Height * (halfHeight / (float)rect.Height));

            spriteBatch.Draw(texture, rotRect, null, color, rot, origin, SpriteEffects.None, 0);
        }
Example #9
0
 public void Draw(SpriteBatch spriteBatch, Rectangle rect, Color col, Rotation90 aRotation)
 {
     image.Draw(spriteBatch, rect, col, rotation.rotateBy(aRotation));
 }
Example #10
0
        public void Draw(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture, Color color, Rotation90 rotation)
        {
            // man, this is fiddly
            int fragmentW   = texture.Width / 4;
            int fragmentH   = texture.Height / 4;
            int rightEdgeX  = rect.X + rect.Width - fragmentW;
            int bottomEdgeY = rect.Y + rect.Height - fragmentH;
            int X;
            int Y = rect.Y + fragmentH;

            for (X = rect.X + fragmentW; X <= rect.X + rect.Width - fragmentW * 3; X += fragmentW * 2)
            {
                // top
                spriteBatch.Draw(texture, new Rectangle(X, rect.Y, fragmentW * 2, fragmentH),
                                 new Rectangle(fragmentW, 0, fragmentW * 2, fragmentH), color);
                // middles
                for (Y = rect.Y + fragmentH; Y <= rect.Y + rect.Height - fragmentH * 3; Y += fragmentH * 2)
                {
                    spriteBatch.Draw(texture, new Rectangle(X, Y, fragmentW * 2, fragmentH * 2),
                                     new Rectangle(fragmentW, fragmentH, fragmentW * 2, fragmentH * 2), color);
                }
                // bottom gap-fill
                if (Y < bottomEdgeY)
                {
                    int fillY = bottomEdgeY - Y;
                    spriteBatch.Draw(texture, new Rectangle(X, Y, fragmentW * 2, fillY),
                                     new Rectangle(fragmentW, fragmentH, fragmentW * 2, fillY), color);
                }
                // bottom
                spriteBatch.Draw(texture, new Rectangle(X, bottomEdgeY, fragmentW * 2, fragmentH),
                                 new Rectangle(fragmentW, fragmentH * 3, fragmentW * 2, fragmentH), color);
            }

            int finalX = X;
            int finalY = Y;
            int fillW  = rightEdgeX - finalX;
            int fillH  = bottomEdgeY - finalY;

            // bottom-right corner gap fill
            if (fillW > 0 && fillH > 0)
            {
                spriteBatch.Draw(texture, new Rectangle(finalX, finalY, fillW, fillH),
                                 new Rectangle(fragmentW, fragmentH, fillW, fillH), color);
            }

            // edge gap fill
            if (fillW > 0)
            {
                // top
                spriteBatch.Draw(texture, new Rectangle(finalX, rect.Y, fillW, fragmentH),
                                 new Rectangle(fragmentW, 0, fillW, fragmentH), color);
                // bottom
                spriteBatch.Draw(texture, new Rectangle(finalX, bottomEdgeY, fillW, fragmentH),
                                 new Rectangle(fragmentW, fragmentH * 3, fillW, fragmentH), color);
            }
            if (fillH > 0)
            {
                // left
                spriteBatch.Draw(texture, new Rectangle(rect.X, finalY, fragmentW, fillH),
                                 new Rectangle(0, fragmentH, fragmentW, fillH), color);
                // right
                spriteBatch.Draw(texture, new Rectangle(rightEdgeX, finalY, fragmentW, fillH),
                                 new Rectangle(fragmentW * 3, fragmentH, fragmentW, fillH), color);
            }

            for (Y = rect.Y + fragmentH; Y <= rect.Y + rect.Height - fragmentH * 3; Y += fragmentH * 2)
            {
                // left
                spriteBatch.Draw(texture, new Rectangle(rect.X, Y, fragmentW, fragmentH * 2),
                                 new Rectangle(0, fragmentH, fragmentW, fragmentH * 2), color);
                // right
                spriteBatch.Draw(texture, new Rectangle(rightEdgeX, Y, fragmentW, fragmentH * 2),
                                 new Rectangle(fragmentW * 3, fragmentH, fragmentW, fragmentH * 2), color);
                // right gap-fill
                spriteBatch.Draw(texture, new Rectangle(finalX, Y, fillW, fragmentH * 2),
                                 new Rectangle(fragmentW, fragmentH, fillW, fragmentH * 2), color);
            }

            spriteBatch.Draw(texture, new Rectangle(rect.X, rect.Y, fragmentW, fragmentH),
                             new Rectangle(0, 0, fragmentW, fragmentH), color);
            spriteBatch.Draw(texture, new Rectangle(rightEdgeX, bottomEdgeY, fragmentW, fragmentH),
                             new Rectangle(fragmentW * 3, fragmentH * 3, fragmentW, fragmentH), color);
            spriteBatch.Draw(texture, new Rectangle(rect.X, bottomEdgeY, fragmentW, fragmentH),
                             new Rectangle(0, fragmentH * 3, fragmentW, fragmentH), color);
            spriteBatch.Draw(texture, new Rectangle(rightEdgeX, rect.Y, fragmentW, fragmentH),
                             new Rectangle(fragmentW * 3, 0, fragmentW, fragmentH), color);
        }
Example #11
0
        public void Draw(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture, Color color, Rotation90 rotation)
        {
            int leftEndWidth   = texture.Width / 4;
            int tileSize       = texture.Width / 2;
            int rightEndWidth  = texture.Width - tileSize - leftEndWidth;
            int tiledAreaWidth = rect.Width - leftEndWidth - rightEndWidth;
            int tileCount      = (int)Math.Round((float)tiledAreaWidth / tileSize);
            int tileSpacing    = (int)Math.Ceiling((float)tiledAreaWidth / tileCount);

            spriteBatch.Draw(texture, new Rectangle(rect.X, rect.Y, leftEndWidth, rect.Height), new Rectangle(0, 0, leftEndWidth, texture.Height), color);
            for (int X = 0; X < tiledAreaWidth; X += tileSpacing)
            {
                spriteBatch.Draw(texture, new Rectangle(rect.X + leftEndWidth + X, rect.Y, tileSpacing, rect.Height), new Rectangle(leftEndWidth, 0, tileSize, texture.Height), color);
            }
            spriteBatch.Draw(texture, new Rectangle(rect.X + rect.Width - rightEndWidth, rect.Y, rightEndWidth, rect.Height), new Rectangle(texture.Width - rightEndWidth, 0, rightEndWidth, texture.Height), color);
        }
Example #12
0
        public void Draw(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture, Color color, Rotation90 rotation)
        {
            float textureAspect = texture.Width / (float)texture.Height;
            float rectAspect    = rect.Width / (float)rect.Height;

            float scale;

            if (textureAspect > rectAspect)
            {
                // fit width
                scale = rect.Width / (float)texture.Width;
            }
            else
            {
                scale = rect.Height / (float)texture.Height;
            }

            Rectangle drawRect = new Rectangle((int)(rect.X + 0.5f * (rect.Width - texture.Width * scale)), (int)(rect.Y + 0.5f * (rect.Height - texture.Height * scale)), (int)(texture.Width * scale), (int)(texture.Height * scale));

            spriteBatch.Draw(texture, drawRect, color);
        }
Example #13
0
 public void Draw(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture, Color color, Rotation90 rotation)
 {
     spriteBatch.Draw(texture, new Vector2(rect.Left, rect.Top), color);
 }
Example #14
0
        public static Rotation90 rotateBy(this Rotation90 rotation, Rotation90 other)
        {
            int newRotation = (rotation.toInt() + other.toInt()) % 360;

            return((Rotation90)(newRotation / 90));
        }
Example #15
0
 public RichImageLayer_Image(RichImage aImage, Rotation90 aRotation)
 {
     image    = aImage;
     rotation = aRotation;
 }
Example #16
0
        public static Rotation90 invert(this Rotation90 rotation)
        {
            int newRotation = 360 - rotation.toInt();

            return((Rotation90)(newRotation / 90));
        }
Example #17
0
        public void Draw(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture, Color color, Rotation90 rotation)
        {
            int nonStretchWidth  = texture.Width / 2;
            int nonStretchHeight = texture.Height / 2;

            int texMiddleWidth  = texture.Width - nonStretchWidth * 2;
            int texMiddleHeight = texture.Height - nonStretchHeight * 2;
            int texRightEdgeX   = texture.Width - nonStretchWidth;
            int texBottomEdgeY  = texture.Height - nonStretchHeight;

            int screenMiddleWidth  = rect.Width - nonStretchWidth * 2;
            int screenMiddleHeight = rect.Height - nonStretchHeight * 2;
            int rightEdgeX         = rect.X + rect.Width - nonStretchWidth;
            int bottomEdgeY        = rect.Y + rect.Height - nonStretchHeight;

            // TL, top, TR
            spriteBatch.Draw(texture,
                             new Rectangle(rect.X, rect.Y, nonStretchWidth, nonStretchHeight),
                             new Rectangle(0, 0, nonStretchWidth, nonStretchHeight),
                             color);
            spriteBatch.Draw(texture,
                             new Rectangle(rect.X + nonStretchWidth, rect.Y, screenMiddleWidth, nonStretchHeight),
                             new Rectangle(nonStretchWidth, 0, texMiddleWidth, nonStretchHeight),
                             color);
            spriteBatch.Draw(texture,
                             new Rectangle(rightEdgeX, rect.Y, nonStretchWidth, nonStretchHeight),
                             new Rectangle(texRightEdgeX, 0, nonStretchWidth, nonStretchHeight),
                             color);

            // left, center, right
            spriteBatch.Draw(texture,
                             new Rectangle(rect.X, rect.Y + nonStretchHeight, nonStretchWidth, screenMiddleHeight),
                             new Rectangle(0, nonStretchHeight, nonStretchWidth, texMiddleHeight),
                             color);
            spriteBatch.Draw(texture,
                             new Rectangle(rect.X + nonStretchWidth, rect.Y + nonStretchHeight, screenMiddleWidth, screenMiddleHeight),
                             new Rectangle(nonStretchWidth, nonStretchHeight, texMiddleWidth, texMiddleHeight),
                             color);
            spriteBatch.Draw(texture,
                             new Rectangle(rightEdgeX, rect.Y + nonStretchHeight, nonStretchWidth, screenMiddleHeight),
                             new Rectangle(texRightEdgeX, nonStretchHeight, nonStretchWidth, texMiddleHeight),
                             color);

            // BL, bottom, BR
            spriteBatch.Draw(texture,
                             new Rectangle(rect.X, bottomEdgeY, nonStretchWidth, nonStretchHeight),
                             new Rectangle(0, texBottomEdgeY, nonStretchWidth, nonStretchHeight),
                             color);
            spriteBatch.Draw(texture,
                             new Rectangle(rect.X + nonStretchWidth, bottomEdgeY, screenMiddleWidth, nonStretchHeight),
                             new Rectangle(nonStretchWidth, texBottomEdgeY, texMiddleWidth, nonStretchHeight),
                             color);
            spriteBatch.Draw(texture,
                             new Rectangle(rightEdgeX, bottomEdgeY, nonStretchWidth, nonStretchHeight),
                             new Rectangle(texRightEdgeX, texBottomEdgeY, nonStretchWidth, nonStretchHeight),
                             color);
        }