public static void DrawImageFromAtlas(this IBatchedDrawingService ds,
                                       IUITexture image,
                                       Rectangle destinationRectangle,
                                       Rectangle?sourceRectangle,
                                       Color color)
 {
     ds.Draw(image, destinationRectangle, sourceRectangle, color, 0.0f, Vector2.Zero, SpriteEffects.None, 0.0f);
 }
        protected override void DrawWidget(IBatchedDrawingService drawingService)
        {
            if (Texture == null)
            {
                return;
            }

            var origin     = new Vector2(Texture.Width / 2f, Texture.Height / 2f);
            var fadedColor = Color;

            if (FadeIn)
            {
                fadedColor *= fadeInAnim.CurrentValue;
            }

            if (Stretch == ScaleMode.None)
            {
                var contentRect = ContentRect;
                drawingService.Draw(
                    Texture,
                    new Vector2(contentRect.Center.X - DesiredSize.Width / 2, contentRect.Center.Y - DesiredSize.Height / 2) + origin,
                    null,
                    fadedColor,
                    rotationValue.CurrentValue,
                    origin,
                    1f,
                    SpriteEffects.None,
                    1f);
            }
            else
            {
                var contentRect = CalculateImageSize(ContentRect);
                drawingService.Draw(
                    Texture,
                    new Rectangle(contentRect.Left + (int)origin.X, contentRect.Top + (int)origin.Y, contentRect.Width, contentRect.Height),
                    null,
                    fadedColor,
                    rotationValue.CurrentValue,
                    origin,
                    SpriteEffects.None,
                    1f);
            }
        }
Beispiel #3
0
        protected override void DrawFrameOverlay(IBatchedDrawingService drawingService)
        {
            var texture = FrameOverlayTexture;

            if (texture == null)
            {
                return;
            }

            float handleAngle;

            switch (Direction)
            {
            case Direction.Left:
            {
                handleAngle = Collapsed ? 0f : MathHelper.Pi;
                break;
            }

            case Direction.Right:
            {
                handleAngle = Collapsed ? MathHelper.Pi : 0f;
                break;
            }

            case Direction.Up:
            {
                handleAngle = Collapsed ? MathHelper.PiOver2 : 3f * MathHelper.PiOver2;
                break;
            }

            case Direction.Down:
            {
                handleAngle = Collapsed ? 3f * MathHelper.PiOver2 : MathHelper.PiOver2;
                break;
            }

            default:
            {
                throw new NotSupportedException();
            }
            }

            drawingService.Draw(
                texture,
                new Vector2(ContentRect.Center.X, ContentRect.Center.Y),
                null,
                FrameOverlayColor,
                handleAngle,
                new Vector2(texture.Width / 2f, texture.Height / 2f),
                1f,
                SpriteEffects.None,
                0f);
        }
        public static void Draw([NotNull] this IBatchedDrawingService ds,
                                [CanBeNull] IUITexture texture,
                                Vector2 position,
                                Rectangle?sourceRectangle,
                                Color color,
                                float rotation,
                                Vector2 origin,
                                float scale,
                                SpriteEffects effects,
                                float layerDepth)
        {
            if (texture == null)
            {
                return;
            }

            var rect = new Rectangle((int)position.X, (int)position.Y, (int)(texture.Width * scale),
                                     (int)(texture.Height * scale));

            ds.Draw(texture, rect, sourceRectangle, color, rotation, origin, effects, layerDepth);
        }
        public void Draw(IBatchedDrawingService d, Rectangle rectangle, Vector2 offset, Vector2 viewportPosition, float opacity, float scale)
        {
            int minX = (int)Math.Floor(viewportPosition.X);
            int minY = (int)Math.Floor(viewportPosition.Y);
            int maxX = (int)Math.Ceiling((rectangle.Width + viewportPosition.X));
            int maxY = (int)Math.Ceiling((rectangle.Height + viewportPosition.Y));

            if (this.X + offset.X + this.Width > minX && this.X + offset.X < maxX)
            {
                if (this.Y + offset.Y + this.Height > minY && this.Y + offset.Y < maxY)
                {
                    float test = (scale - 1) / 2;
                    int   x    = (int)(this.X + offset.X);
                    int   y    = (int)(this.Y + offset.Y);
                    float fx   = (x * scale) - (viewportPosition.X * scale) - (rectangle.Width * test);
                    float fy   = (y * scale) - (viewportPosition.Y * scale) - (rectangle.Height * test);
                    float fw   = this.Width * scale;
                    float fh   = this.Height * scale;
                    Console.WriteLine(new Vector2(x, y) + " " + new Vector2(fx, fy) + " " + test);
                    d.Draw(new UITexture(this.Texture), new Rectangle((int)fx, (int)fy, (int)fw, (int)fh), new Rectangle(0, 0, _Texture.Width, _Texture.Height),
                           Color.White, 0f, new Vector2(fw / 2, fh / 2), SpriteEffects.None, 0);
                }
            }
        }
        public void Draw(IBatchedDrawingService d, IList <Tileset> tilesets, Rectangle rectangle, Vector2 viewportPosition, int tileWidth, int tileHeight, float scale)
        {
            int     i       = 0;
            Vector2 destPos = new Vector2(rectangle.Left, rectangle.Top);
            Vector2 viewPos = viewportPosition;

            int minX = (int)Math.Floor(viewportPosition.X / tileWidth);
            int minY = (int)Math.Floor(viewportPosition.Y / tileHeight);
            int maxX = (int)Math.Ceiling((rectangle.Width + viewportPosition.X) / tileWidth);
            int maxY = (int)Math.Ceiling((rectangle.Height + viewportPosition.Y) / tileHeight);

            if (minX < 0)
            {
                minX = 0;
            }
            if (minY < 0)
            {
                minY = 0;
            }
            if (maxX >= Width)
            {
                maxX = Width - 1;
            }
            if (maxY >= Height)
            {
                maxY = Height - 1;
            }

            if (viewPos.X > 0)
            {
                viewPos.X = ((int)Math.Floor(viewPos.X)) % tileWidth;
            }
            else
            {
                viewPos.X = (float)Math.Floor(viewPos.X);
            }

            if (viewPos.Y > 0)
            {
                viewPos.Y = ((int)Math.Floor(viewPos.Y)) % tileHeight;
            }
            else
            {
                viewPos.Y = (float)Math.Floor(viewPos.Y);
            }

            TileInfo info = new TileInfo();

            if (_TileInfoCache == null)
            {
                BuildTileInfoCache(tilesets);
            }

            foreach (Tileset tileset in tilesets)
            {
                if (tileset.tiles == null)
                {
                    Texture2D[] tiles = new Texture2D[_TileInfoCache.Length];
                    for (int k = 0; k < _TileInfoCache.Length; k++)
                    {
                        Texture2D test = new Texture2D(d.GraphicsDevice, tileWidth, tileHeight);
                        test     = GetTileTexture(k + 1, tileset, test);
                        tiles[k] = test;
                    }

                    tileset.tiles = tiles;
                    Console.WriteLine("tiles added");
                }
            }

            // We're drawing at the center of the tile, so adjust our y offset
            destPos.Y += (tileHeight) / 2f;

            for (int y = minY; y <= maxY; y++)
            {
                // We're drawing at the center of the tile, so adjust the x offset
                destPos.X = rectangle.Left + (tileWidth) / 2f;

                for (int x = minX; x <= maxX; x++)
                {
                    i = (y * Width) + x;

                    byte          flipAndRotate = FlipAndRotate[i];
                    SpriteEffects flipEffect    = SpriteEffects.None;
                    float         rotation      = 0f;

                    if ((flipAndRotate & Layer.HorizontalFlipDrawFlag) != 0)
                    {
                        flipEffect |= SpriteEffects.FlipHorizontally;
                    }
                    if ((flipAndRotate & Layer.VerticalFlipDrawFlag) != 0)
                    {
                        flipEffect |= SpriteEffects.FlipVertically;
                    }
                    if ((flipAndRotate & Layer.DiagonallyFlipDrawFlag) != 0)
                    {
                        if ((flipAndRotate & Layer.HorizontalFlipDrawFlag) != 0 &&
                            (flipAndRotate & Layer.VerticalFlipDrawFlag) != 0)
                        {
                            rotation    = (float)(Math.PI / 2);
                            flipEffect ^= SpriteEffects.FlipVertically;
                        }
                        else if ((flipAndRotate & Layer.HorizontalFlipDrawFlag) != 0)
                        {
                            rotation    = (float)-(Math.PI / 2);
                            flipEffect ^= SpriteEffects.FlipVertically;
                        }
                        else if ((flipAndRotate & Layer.VerticalFlipDrawFlag) != 0)
                        {
                            rotation    = (float)(Math.PI / 2);
                            flipEffect ^= SpriteEffects.FlipHorizontally;
                        }
                        else
                        {
                            rotation    = -(float)(Math.PI / 2);
                            flipEffect ^= SpriteEffects.FlipHorizontally;
                        }
                    }

                    int     index = Tiles[i] - 1;
                    float   test  = (scale - 1) / 2;
                    Vector2 adj   = new Vector2(rectangle.Width * test, rectangle.Height * test);
                    if ((index >= 0) && (index < _TileInfoCache.Length))
                    {
                        d.Draw(new UITexture(tilesets[0].tiles[index]), destPos - viewPos - adj, null,
                               Color.White * this.Opacity, rotation, new Vector2(tileWidth / 2f, tileHeight / 2f),
                               scale, flipEffect, 0);
                    }

                    destPos.X += (tileWidth * scale);
                }

                destPos.Y += (tileHeight * scale);
            }
        }
        public void DrawIso(IBatchedDrawingService d, IList <Tileset> tilesets, Rectangle rectangle, Vector2 viewportPosition, int tileWidth, int tileHeight)
        {
            int     i       = 0;
            Vector2 destPos = new Vector2(0, 0);

            Vector2 centTile = new Vector2((int)viewportPosition.X / tileHeight, (int)viewportPosition.Y / tileHeight);

            Console.WriteLine(centTile + " " + viewportPosition);

            TileInfo info = new TileInfo();

            if (_TileInfoCache == null)
            {
                BuildTileInfoCache(tilesets);
            }

            foreach (Tileset tileset in tilesets)
            {
                if (tileset.tiles == null)
                {
                    Texture2D[] tiles = new Texture2D[_TileInfoCache.Length];
                    for (int k = 0; k < _TileInfoCache.Length; k++)
                    {
                        Texture2D test = new Texture2D(d.GraphicsDevice, tileWidth, tileHeight);
                        test     = GetTileTexture(k + 1, tileset, test);
                        tiles[k] = test;
                    }

                    tileset.tiles = tiles;
                    Console.WriteLine("tiles added");
                }
            }

            for (int y = (int)centTile.Y - (Height / 2); y <= (int)centTile.Y + (Height / 2); y++)
            {
                for (int x = (int)centTile.X - (Width / 2); x <= (int)centTile.X + (Width / 2); x++)
                {
                    destPos.X  = (x - centTile.X) * tileHeight;
                    destPos.Y  = (y - centTile.Y) * tileHeight;
                    destPos    = Isometric.TwoDToIso(destPos);
                    destPos.X += (rectangle.Width) / 2;
                    destPos.Y += (rectangle.Height) / 2;

                    if (destPos.X > (0 - tileWidth) && destPos.X < (rectangle.Width + tileWidth) && destPos.Y > (0 - tileWidth) && destPos.Y < (rectangle.Height + tileHeight))
                    {
                        Vector2 testtile = new Vector2(x, y);

                        if (testtile.X >= 0 && testtile.X < Width && testtile.Y >= 0 && testtile.Y < Height)
                        {
                            i = ((int)testtile.Y * Width) + (int)testtile.X;

                            int index = Tiles[i] - 1;

                            if ((index >= 0) && (index < _TileInfoCache.Length))
                            {
                                d.Draw(new UITexture(tilesets[0].tiles[index]), destPos, null,
                                       Color.White * this.Opacity, 0f, new Vector2(tileWidth / 2f, tileHeight / 2f),
                                       1f, 0f, 0);
                            }
                        }
                    }
                }
            }
        }