Esempio n. 1
0
        /// <summary>
        /// Reads the <see cref="BackgroundImage"/> from an <see cref="IValueReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
        protected override void Read(IValueReader reader)
        {
            base.Read(reader);

            HorizontalLayout = reader.ReadEnum <BackgroundLayerLayout>(_horizontalLayoutKey);
            VerticalLayout   = reader.ReadEnum <BackgroundLayerLayout>(_verticalLayoutKey);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles drawing the <see cref="BackgroundImage"/>.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
        protected override void HandleDraw(ISpriteBatch sb)
        {
            var spriteSize = SpriteSourceSize;
            var pos = GetPosition(Map.Size, Camera, spriteSize);

            var vl = VerticalLayout;
            var hl = HorizontalLayout;

            if (hl == BackgroundLayerLayout.Stretched && vl == BackgroundLayerLayout.Stretched)
            {
                // Stretch both directions
                spriteSize.X = GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);
                spriteSize.Y = GetStretchedSize(Camera.Size.Y * Camera.Scale, Map.Size.Y, Depth);

                var rect = new Rectangle((int)pos.X, (int)pos.Y, (int)spriteSize.X, (int)spriteSize.Y);
                Sprite.Draw(sb, rect, Color);
            }
            else if (vl == BackgroundLayerLayout.Tiled &&
                     (hl == BackgroundLayerLayout.None || hl == BackgroundLayerLayout.Stretched))
            {
                // Stretch/none horizontal, tile vertical
                int drawWidth;
                if (hl == BackgroundLayerLayout.None)
                    drawWidth = (int)spriteSize.X;
                else
                    drawWidth = (int)GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);

                sb.DrawTiledY((int)pos.Y, (int)Camera.Max.Y + 64, (int)pos.X, Sprite, Color.White, drawWidth);
            }
            else if (hl == BackgroundLayerLayout.Tiled &&
                     (vl == BackgroundLayerLayout.None || vl == BackgroundLayerLayout.Stretched))
            {
                // Tile horizontal, stretch/none vertical
                int drawHeight;
                if (vl == BackgroundLayerLayout.None)
                    drawHeight = (int)spriteSize.Y;
                else
                    drawHeight = (int)GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);

                sb.DrawTiledX((int)pos.X, (int)Camera.Max.X + 64, (int)pos.Y, Sprite, Color.White, drawHeight);
            }
            else if (hl == BackgroundLayerLayout.Tiled && vl == BackgroundLayerLayout.Tiled)
            {
                // Tile both directions
                sb.DrawTiledXY((int)pos.X, (int)Camera.Max.X + 64, (int)pos.Y, (int)Camera.Max.Y + 64, Sprite, Color);
            }
            else if (hl == BackgroundLayerLayout.None && vl == BackgroundLayerLayout.None)
            {
                // None in both directions
                Sprite.Draw(sb, pos);
            }
            else
            {
                // Unknown or unhandled permutation
                const string errmsg =
                    "Unknown or unhandled BackgroundLayerLayout provided." +
                    " Changing layouts to BackgroundLayerLayout.None. HorizontalLayout: `{0}` VerticalLayout: `{1}`";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, HorizontalLayout, VerticalLayout);

                HorizontalLayout = BackgroundLayerLayout.None;
                VerticalLayout = BackgroundLayerLayout.None;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Reads the <see cref="BackgroundImage"/> from an <see cref="IValueReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
        protected override void Read(IValueReader reader)
        {
            base.Read(reader);

            HorizontalLayout = reader.ReadEnum<BackgroundLayerLayout>(_horizontalLayoutKey);
            VerticalLayout = reader.ReadEnum<BackgroundLayerLayout>(_verticalLayoutKey);
        }
Esempio n. 4
0
        /// <summary>
        /// Handles drawing the <see cref="BackgroundImage"/>.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
        protected override void HandleDraw(ISpriteBatch sb)
        {
            var spriteSize = SpriteSourceSize;
            var pos        = GetPosition(Map.Size, Camera, spriteSize);

            var vl = VerticalLayout;
            var hl = HorizontalLayout;

            if (hl == BackgroundLayerLayout.Stretched && vl == BackgroundLayerLayout.Stretched)
            {
                // Stretch both directions
                spriteSize.X = GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);
                spriteSize.Y = GetStretchedSize(Camera.Size.Y * Camera.Scale, Map.Size.Y, Depth);

                var rect = new Rectangle((int)pos.X, (int)pos.Y, (int)spriteSize.X, (int)spriteSize.Y);
                Sprite.Draw(sb, rect, Color);
            }
            else if (vl == BackgroundLayerLayout.Tiled &&
                     (hl == BackgroundLayerLayout.None || hl == BackgroundLayerLayout.Stretched))
            {
                // Stretch/none horizontal, tile vertical
                int drawWidth;
                if (hl == BackgroundLayerLayout.None)
                {
                    drawWidth = (int)spriteSize.X;
                }
                else
                {
                    drawWidth = (int)GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);
                }

                sb.DrawTiledY((int)pos.Y, (int)Camera.Max.Y + 64, (int)pos.X, Sprite, Color.White, drawWidth);
            }
            else if (hl == BackgroundLayerLayout.Tiled &&
                     (vl == BackgroundLayerLayout.None || vl == BackgroundLayerLayout.Stretched))
            {
                // Tile horizontal, stretch/none vertical
                int drawHeight;
                if (vl == BackgroundLayerLayout.None)
                {
                    drawHeight = (int)spriteSize.Y;
                }
                else
                {
                    drawHeight = (int)GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);
                }

                sb.DrawTiledX((int)pos.X, (int)Camera.Max.X + 64, (int)pos.Y, Sprite, Color.White, drawHeight);
            }
            else if (hl == BackgroundLayerLayout.Tiled && vl == BackgroundLayerLayout.Tiled)
            {
                // Tile both directions
                sb.DrawTiledXY((int)pos.X, (int)Camera.Max.X + 64, (int)pos.Y, (int)Camera.Max.Y + 64, Sprite, Color);
            }
            else if (hl == BackgroundLayerLayout.None && vl == BackgroundLayerLayout.None)
            {
                // None in both directions
                Sprite.Draw(sb, pos);
            }
            else
            {
                // Unknown or unhandled permutation
                const string errmsg =
                    "Unknown or unhandled BackgroundLayerLayout provided." +
                    " Changing layouts to BackgroundLayerLayout.None. HorizontalLayout: `{0}` VerticalLayout: `{1}`";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, HorizontalLayout, VerticalLayout);
                }

                HorizontalLayout = BackgroundLayerLayout.None;
                VerticalLayout   = BackgroundLayerLayout.None;
            }
        }