Esempio n. 1
0
        /// <summary>
        /// Draws a <see cref="ISprite"/> tiled on the X axis.
        /// The <see cref="ISprite"/> is never scaled. If a fraction of a sprite must be drawn (the amount to draw is not
        /// perfectly divisible by the sprite's size) then only a portion of the sprite will be drawn.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="minX">The starting X coordinate to draw at.</param>
        /// <param name="maxX">The ending X coordinate to draw at.</param>
        /// <param name="y">The Y coordinate to draw at.</param>
        /// <param name="s">The <see cref="ISprite"/> to draw.</param>
        /// <param name="color">The color to draw the <see cref="ISprite"/>.</param>
        /// <param name="drawHeight">When a value greater than 0 is given, this will be used as the height of the drawn sprite instead
        /// of the default height for the <paramref name="s"/>. This has no affect on the actual tiling.</param>
        public static void DrawTiledX(this ISpriteBatch sb, int minX, int maxX, int y, ISprite s, Color color, int drawHeight = 0)
        {
            if (!CanDrawSprite(s))
            {
                return;
            }

            if (maxX < minX)
            {
                const string errmsg = "Unable to draw sprite `{0}` since MaxX ({1}) < MinX ({2}).";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, s, maxX, minX);
                }
                return;
            }

            var src         = s.Source;
            var destSize    = maxX - minX;
            var fullSprites = destSize / s.Source.Width;
            var remainder   = destSize % s.Source.Width;

            if (drawHeight <= 0)
            {
                drawHeight = (int)s.Size.Y;
            }

            // Set the sprite in general
            _repeatSprite.Color  = color;
            _repeatSprite.Image  = s.Texture;
            _repeatSprite.Scale  = Vector2.One;
            _repeatSprite.Height = drawHeight;

            // Set up the sprite for the full pieces
            if (fullSprites > 0)
            {
                _repeatSprite.SubRect = new IntRect(src.X, src.Y, src.Width, src.Height);

                // Draw all the full pieces
                for (var x = 0; x < fullSprites; x++)
                {
                    _repeatSprite.Position = new Vector2(minX + (x * src.Width), y);
                    sb.Draw(_repeatSprite);
                }
            }

            // Draw the remaining partial piece
            if (remainder > 0)
            {
                _repeatSprite.SubRect  = new IntRect(src.X, src.Y, remainder, src.Height);
                _repeatSprite.Position = new Vector2(maxX - remainder, y);
                _repeatSprite.Width    = remainder;

                sb.Draw(_repeatSprite);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Draws a <see cref="ISprite"/> tiled on the Y axis.
        /// The <see cref="ISprite"/> is never scaled. If a fraction of a sprite must be drawn (the amount to draw is not
        /// perfectly divisible by the sprite's size) then only a portion of the sprite will be drawn.
        /// </summary>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="minY">The starting Y coordinate to draw at.</param>
        /// <param name="maxY">The ending Y coordinate to draw at.</param>
        /// <param name="x">The X coordinate to draw at.</param>
        /// <param name="s">The <see cref="ISprite"/> to draw.</param>
        /// <param name="color">The color to draw the <see cref="ISprite"/>.</param>
        /// <param name="drawWidth">When a value greater than 0 is given, this will be used as the width of the drawn sprite instead
        /// of the default width for the <paramref name="s"/>. This has no affect on the actual tiling.</param>
        public static void DrawTiledY(this ISpriteBatch sb, int minY, int maxY, int x, ISprite s, Color color, int drawWidth = 0)
        {
            if (!CanDrawSprite(s))
            {
                return;
            }

            if (maxY < minY)
            {
                const string errmsg = "Unable to draw sprite `{0}` since MaxY ({1}) < MinY ({2}).";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, s, maxY, minY);
                }
                return;
            }

            var src         = s.Source;
            var destSize    = maxY - minY;
            var fullSprites = destSize / s.Source.Height;
            var remainder   = destSize % s.Source.Height;

            if (drawWidth <= 0)
            {
                drawWidth = (int)s.Size.X;
            }

            // Set the sprite in general
            _repeatSprite.Color = color;
            _repeatSprite.Image = s.Texture;
            _repeatSprite.Scale = Vector2.One;
            _repeatSprite.Width = drawWidth;

            // Set up the sprite for the full pieces
            if (fullSprites > 0)
            {
                _repeatSprite.SubRect = new IntRect(src.X, src.Y, src.Width, src.Height);

                // Draw all the full pieces
                for (var y = 0; y < fullSprites; y++)
                {
                    _repeatSprite.Position = new Vector2(x, minY + (y * src.Height));
                    sb.Draw(_repeatSprite);
                }
            }

            // Draw the remaining partial piece
            if (remainder > 0)
            {
                _repeatSprite.SubRect  = new IntRect(src.X, src.Y, src.Width, remainder);
                _repeatSprite.Position = new Vector2(x, maxY - remainder);
                _repeatSprite.Height   = remainder;

                sb.Draw(_repeatSprite);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Draw sprites in this frame.
        /// </summary>
        /// <param name="batch">SpriteBatch to draw with</param>
        /// <param name="frame">Frame to draw</param>
        /// <param name="position">World position of frame</param>
        public static void Draw(ISpriteBatch batch, Frame frame, Vector2 position, params Frame[] extraFrames)
        {
            var spriteRefs = new List <SpriteRef>(frame.SpriteRefs);

            foreach (var extraFrame in extraFrames)
            {
                foreach (var sprRef in extraFrame.SpriteRefs)
                {
                    if (sprRef.Z < 0)
                    {
                        spriteRefs.Add(sprRef);
                    }
                    else if (sprRef.Z >= spriteRefs.Count)
                    {
                        spriteRefs.Insert(0, sprRef);
                    }
                    else
                    {
                        spriteRefs.Insert(spriteRefs.Count - sprRef.Z, sprRef);
                    }
                }
            }

            foreach (var spriteRef in spriteRefs)
            {
                Vector2 spritePos = position;
                spritePos.X += spriteRef.X;
                spritePos.Y += spriteRef.Y;

                batch.Draw(spriteRef.Sprite.Texture, spritePos, spriteRef.Sprite.Source, Color.White, spriteRef.Rotation, spriteRef.Sprite.Origin, 1, spriteRef.SpriteEffects, 0);
            }
        }
Esempio n. 4
0
 public void Draw(ISpriteBatch batch)
 {
     foreach (var position in _positions)
     {
         batch.Draw(_texture, new Rectangle((int)position, 0, _texture.Width, _screenHeight), Color.White);
     }
 }
Esempio n. 5
0
        public void Render(ISpriteBatch spriteBatch, V2 cameraPosition)
        {
            spriteBatch.Begin();

            for (int i = 0; i < positionedWorldCells.Length; i++)
            {
                if (positionedWorldCells[i] == null)
                {
                    continue;
                }

                for (int j = 0; j < positionedWorldCells[i].Count; j++)
                {
                    var cell = positionedWorldCells[i][j];

                    if (cell.Tile == null)
                    {
                        continue;
                    }

                    spriteBatch.Draw(cell.Tile.Texture,
                                     new Rect(0, 0, TileWidth, TileHeight),
                                     new Rect((int)cell.Position.X, (int)cell.Position.Y, TileWidth, TileHeight),
                                     0f,
                                     baseDepth - ((i * 100) + j) * HeightRowDepthMod);

                    spriteBatch.DrawString(SysCore.SystemFont, cell.Position.X + ", " + cell.Position.Y, new V2(cell.Position.X, cell.Position.Y), new V4(255), 0f, 1f, 1f);
                }
            }

            spriteBatch.End();
        }
Esempio n. 6
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            _batch.Begin();

            if (RenderGrid)
            {
                DrawGridLines();
            }

            // Draw selection rectangle
            if (SelectionBounds != Rectangle.Empty &&
                ((SelectionBounds.Width > 5 || SelectionBounds.Width < -5) && (SelectionBounds.Height > 5 || SelectionBounds.Height < -5)))
            {
                var selectionBounds = Utils.RenderableRectangle(SelectionBounds);

                _batch.Draw(BlankTexture, selectionBounds, new Color(100, 0, 0, 75));
                Utils.DrawBorder(_batch, BlankTexture, selectionBounds, 1, new Color(150, 0, 0, 175));
            }

            // Render border around selected game objects
            if (SelectedGameObjects != null && SelectedGameObjects.Length > 0)
            {
                foreach (var o in SelectedGameObjects)
                {
                    Vector2 objScreenPos  = _world.ActiveCamera.WorldToScreen(new Vector2(o.BoundsF.X, o.BoundsF.Y));
                    var     objScreenSize = new Vector2(o.BoundsF.Width * _world.ActiveCamera.InvZoom,
                                                        o.BoundsF.Height * _world.ActiveCamera.InvZoom);

                    Utils.DrawBorder(_batch, BlankTexture,
                                     new Rectangle((int)objScreenPos.X, (int)objScreenPos.Y, (int)objScreenSize.X,
                                                   (int)objScreenSize.Y), 2, Color.DarkRed);
                }
            }

            // Render region borders
            if (RenderRegionBorders)
            {
                foreach (var region in _world.ActiveCamera.World.Regions)
                {
                    region.DrawBorders(_batch, BlankTexture, _world.ActiveCamera);
                }
            }

            _batch.End();
        }
Esempio n. 7
0
 public virtual void Draw(ISpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float?depth = null)
 {
     if (Texture == null)
     {
         return;
     }
     //DrawSilhouette(spriteBatch, pos, origin, rotate, scale, spriteEffect, depth);
     spriteBatch.Draw(texture, pos + offset, sourceRect, color, rotation + rotate, origin, scale, spriteEffect, depth ?? this.depth);
 }
Esempio n. 8
0
 public static void Draw(this ISpriteBatch spriteBatch, ISprite sprite)
 {
     if (sprite.Texture == null)
     {
         return;
     }
     spriteBatch.Draw(sprite.Texture, sprite.Position, sprite.SourceRectangle, sprite.Color, sprite.Rotation,
                      sprite.Origin, sprite.Scale, sprite.Effects, sprite.LayerDepth);
 }
Esempio n. 9
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="dest">Destination rectangle.</param>
        /// <param name="color">Color of the rectangle.</param>
        public static void Draw(ISpriteBatch sb, Rectangle dest, Color color)
        {
            var fDest = new FloatRect(dest.Left, dest.Top, dest.Width, dest.Height);

            using (var s = Shape.Rectangle(fDest, color))
            {
                sb.Draw(s);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Draws the current frame of the <see cref="Grh"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to use to draw.</param>
        /// <param name="dest">Top-left corner pixel of the destination.</param>
        public void Draw(ISpriteBatch sb, Vector2 dest)
        {
            if (!CanDrawGrh(sb))
            {
                return;
            }

            sb.Draw(Texture, dest, Source, Color.White);
        }
Esempio n. 11
0
        public void Draw(ISpriteBatch spriteBatch, int spriteIndex, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float?depth = default(float?))
        {
            if (texture == null)
            {
                return;
            }

            spriteBatch.Draw(texture, pos + offset, sourceRects[MathHelper.Clamp(spriteIndex, 0, sourceRects.Length - 1)], color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);
        }
Esempio n. 12
0
        /// <summary>
        /// Draws the <see cref="ISprite"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Position to draw to.</param>
        /// <param name="color"><see cref="Color"/> to draw with.</param>
        public void Draw(ISpriteBatch sb, Vector2 position, Color color)
        {
            if (!CanDraw(sb))
            {
                return;
            }

            sb.Draw(_texture, position, _source, color);
        }
Esempio n. 13
0
        /// <summary>
        /// Draws the Sprite.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to use to draw.</param>
        /// <param name="dest">Destination to draw the sprite.</param>
        public void Draw(ISpriteBatch sb, Rectangle dest)
        {
            if (!CanDraw(sb))
            {
                return;
            }

            sb.Draw(_texture, dest, _source, Color.White);
        }
Esempio n. 14
0
        public override void Draw(ISpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float?depth = default(float?))
        {
            if (texture == null)
            {
                return;
            }

            spriteBatch.Draw(texture, pos + offset, sourceRects[0], color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);
        }
Esempio n. 15
0
        /// <summary>
        /// Draws the current frame of the <see cref="Grh"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Top-left corner pixel of the destination.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        /// <param name="effect">Sprite effect to use (default SpriteEffects.None).</param>
        public void Draw(ISpriteBatch sb, Vector2 dest, Color color, SpriteEffects effect)
        {
            if (!CanDrawGrh(sb))
            {
                return;
            }

            sb.Draw(Texture, dest, Source, color, 0, Vector2.Zero, 1.0f, effect);
        }
Esempio n. 16
0
        /// <summary>
        /// Draws the current frame of the <see cref="Grh"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Destination rectangle to draw to.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        public void Draw(ISpriteBatch sb, Rectangle dest, Color color)
        {
            if (!CanDrawGrh(sb))
            {
                return;
            }

            sb.Draw(Texture, dest, Source, color);
        }
Esempio n. 17
0
        /// <summary>
        /// Draws the current frame of the <see cref="Grh"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Destination rectangle.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        /// <param name="effect">Sprite effect to use (default SpriteEffects.None).</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin (default 0).</param>
        /// <param name="origin">The origin of the sprite to rotate around (default Vector2.Zero).</param>
        public void Draw(ISpriteBatch sb, Rectangle dest, Color color, SpriteEffects effect, float rotation, Vector2 origin)
        {
            if (!CanDrawGrh(sb))
            {
                return;
            }

            sb.Draw(Texture, dest, Source, color, rotation, origin, effect);
        }
Esempio n. 18
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the rectangle.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color)
        {
            var drawRect = _drawRectBorder;

            drawRect.Size = size;
            drawRect.Position = position;
            drawRect.FillColor = color;

            sb.Draw(drawRect);
        }
Esempio n. 19
0
        /// <summary>
        /// Draws the <see cref="ISprite"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Top-left corner pixel of the destination.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        /// <param name="effect">Sprite effect to use (default SpriteEffects.None).</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin (default 0).</param>
        /// <param name="origin">The origin of the sprite to rotate around (default Vector2.Zero).</param>
        /// <param name="scale">Uniform multiply by which to scale the width and height.</param>
        public void Draw(ISpriteBatch sb, Vector2 dest, Color color, SpriteEffects effect, float rotation, Vector2 origin,
                         float scale)
        {
            if (!CanDraw(sb))
            {
                return;
            }

            sb.Draw(Texture, dest, Source, color, rotation, origin, scale, effect);
        }
Esempio n. 20
0
        /// <summary>
        /// Draws the Sprite.
        /// </summary>
        /// <param name="sb">SpriteBatch to draw to.</param>
        /// <param name="position">The location, in screen coordinates, where the sprite will be drawn.</param>
        /// <param name="color">The color channel modulation to use. Use Color.White for full color with no tinting.</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin.</param>
        /// <param name="origin">The origin of the sprite. Specify (0,0) for the upper-left corner.</param>
        /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param>
        /// <param name="effects">Rotations to apply before rendering.</param>
        public void Draw(ISpriteBatch sb, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale,
                         SpriteEffects effects)
        {
            if (!CanDraw(sb))
            {
                return;
            }

            sb.Draw(_texture, position, _source, color, rotation, origin, scale, effects);
        }
Esempio n. 21
0
        public void Draw(ISpriteBatch spriteBatch, Vector offset)
        {
            Rect drawRect = !this.rect.IsEmpty ? this.rect : new Rect();

            drawRect.Displace(offset);

            var solidColorBrush = this.brush as SolidColorBrush;

            spriteBatch.Draw(this.texture, drawRect, solidColorBrush != null ? solidColorBrush.Color : Colors.Magenta);
        }
Esempio n. 22
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the rectangle.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color)
        {
            var drawRect = _drawRectBorder;

            drawRect.Size      = size;
            drawRect.Position  = position;
            drawRect.FillColor = color;

            sb.Draw(drawRect);
        }
Esempio n. 23
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the box.</param>
        /// <param name="borderColor">Color of the border to draw around the rectangle.</param>
        /// <param name="borderThickness">The thickness of the border in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color, Color borderColor, float borderThickness = 1f)
        {
            var drawRect = _drawRectNoBorder;

            drawRect.Size = size;
            drawRect.Position = position;
            drawRect.FillColor = color;
            drawRect.OutlineColor = borderColor;
            drawRect.OutlineThickness = borderThickness;

            sb.Draw(drawRect);
        }
Esempio n. 24
0
 public void Draw(GameTime time, ISpriteBatch batch)
 {
     if (!isVisible)
         return;
     WasDrawn = true;
     if (DrawCallback != null)
         DrawCallback();
     if (batch is SpriteBatchMock)
     {
         batch.Draw(null, new Rectangle((int)XPosition, (int)YPosition, (int)Width, (int)Height), Color);
     }
 }
Esempio n. 25
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Top-left corner position.</param>
        /// <param name="size">The size of the rectangle.</param>
        /// <param name="color">Color of the box.</param>
        /// <param name="borderColor">Color of the border to draw around the rectangle.</param>
        /// <param name="borderThickness">The thickness of the border in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color, Color borderColor, float borderThickness = 1f)
        {
            var drawRect = _drawRectNoBorder;

            drawRect.Size             = size;
            drawRect.Position         = position;
            drawRect.FillColor        = color;
            drawRect.OutlineColor     = borderColor;
            drawRect.OutlineThickness = borderThickness;

            sb.Draw(drawRect);
        }
Esempio n. 26
0
        public void Draw(ISpriteBatch spriteBatch, Vector offset)
        {
            var image = this.imageSource as TextureImage;
            if (image == null)
            {
                throw new NotImplementedException("Currently an ImageSource must be an TextureImage");
            }

            Rect drawRect = !this.rect.IsEmpty ? this.rect : new Rect();
            drawRect.Displace(offset);

            spriteBatch.Draw(image.Texture, drawRect, Colors.White);
        }
Esempio n. 27
0
        public static void DrawBorder(ISpriteBatch spriteBatch, Texture2D blankTexture, Rectangle content, int borderWidth, Color color, bool borderOutsideContent = true)
        {
            int left   = (borderOutsideContent) ? content.Left - borderWidth : content.Left;
            int right  = (borderOutsideContent) ? content.Right : content.Right - borderWidth;
            int top    = (borderOutsideContent) ? content.Top - borderWidth : content.Top;
            int bottom = (borderOutsideContent) ? content.Bottom : content.Bottom - borderWidth;

            int width  = (borderOutsideContent) ? content.Width + borderWidth * 2 : content.Width;
            int height = (borderOutsideContent) ? content.Height + borderWidth * 2 : content.Height;

            // Top border
            spriteBatch.Draw(blankTexture, new Rectangle(left, top, width, borderWidth), color);

            // Bottom border
            spriteBatch.Draw(blankTexture, new Rectangle(left, bottom, width, borderWidth), color);

            // Left border
            spriteBatch.Draw(blankTexture, new Rectangle(left, top, borderWidth, height), color);

            // Right border
            spriteBatch.Draw(blankTexture, new Rectangle(right, top, borderWidth, height), color);
        }
Esempio n. 28
0
        public void Draw(ISpriteBatch spriteBatch, Vector offset)
        {
            var image = this.imageSource as TextureImage;

            if (image == null)
            {
                throw new NotImplementedException("Currently an ImageSource must be an TextureImage");
            }

            Rect drawRect = !this.rect.IsEmpty ? this.rect : new Rect();

            drawRect.Displace(offset);

            spriteBatch.Draw(image.Texture, drawRect, Colors.White);
        }
Esempio n. 29
0
        public void Draw(ISpriteBatch batch, Vector2 position)
        {
            if (!_active)
            {
                return;
            }

            var destRect = new Rectangle(
                (int)position.X - ScaledWidth / 2,
                (int)position.Y - ScaledHeight / 2,
                ScaledWidth,
                ScaledHeight);

            batch.Draw(_spriteStrip, destRect, _sourceRect, _color);
        }
Esempio n. 30
0
        /// <summary>
        /// Draws a line.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="p1">First point of the line.</param>
        /// <param name="p2">Second point of the line.</param>
        /// <param name="color">Color of the line.</param>
        /// <param name="thickness">The thickness of the line in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 p1, Vector2 p2, Color color, float thickness = 1f)
        {
            if (sb == null)
            {
                Debug.Fail("sb is null.");
                return;
            }

            if (sb.IsDisposed)
            {
                Debug.Fail("sb is disposed.");
                return;
            }

            using (var s = Shape.Line(p1, p2, thickness, color))
            {
                sb.Draw(s);
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Draws a line.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="p1">First point of the line.</param>
        /// <param name="p2">Second point of the line.</param>
        /// <param name="color">Color of the line.</param>
        /// <param name="thickness">The thickness of the line in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 p1, Vector2 p2, Color color, float thickness = 1f)
        {
            if (sb == null)
            {
                Debug.Fail("sb is null.");
                return;
            }

            if (sb.IsDisposed)
            {
                Debug.Fail("sb is disposed.");
                return;
            }

            // Common properties set no matter the approach we use below
            _drawLineRect.Position = p1;
            _drawLineRect.FillColor = color;

            // If we have a perfectly vertical or horizontal line, we can avoid using rotation to speed up the calculation, so check for that first.
            // This is purely an optimization - the rotation approach works for all points still.
            if (p1.X == p2.X)
            {
                // Perfectly vertical
                _drawLineRect.Size = new Vector2(thickness, p2.Y - p1.Y);
                _drawLineRect.Rotation = 0;
            }
            else if (p1.Y == p2.Y)
            {
                // Perfectly horizontal
                _drawLineRect.Size = new Vector2(p2.X - p1.X, thickness);
                _drawLineRect.Rotation = 0;
            }
            else
            {
                // Treat as horizontal by setting the X as the distance and Y as the thickness, then rotate
                _drawLineRect.Size = new Vector2(p2.Distance(p1), thickness);
                _drawLineRect.Rotation = MathHelper.ToDegrees((float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X));
            }

            sb.Draw(_drawLineRect);
        }
Esempio n. 32
0
        public void DrawLayer(GameTime gameTime, ISpriteBatch spriteBatch, TileLayer layer, Camera camera)
        {
            Rectangle region = camera.GetTilesRegion();

            for (int y = region.Top; y <= region.Bottom; y++)
            {
                for (int x = region.Left; x <= region.Right; x++)
                {
                    // check that we aren't going outside the map, and that there is a tile at this location
                    if (x >= 0 && x < layer.Tiles.Length && y >= 0 && y < layer.Tiles[x].Length &&
                        layer.Tiles[x][y] != null)
                    {
                        spriteBatch.Draw(
                            // the texture (image) of the tile sheet is mapped by
                            // Tile.SourceID -> TileLayers.TilesetID -> Map.Tileset.Texture
                            Tilesets[SourceTiles[layer.Tiles[x][y].SourceID].TilesetID].Texture,

                            // destination for the tile
                            new Rectangle(x * TileWidth, y * TileHeight, TileWidth, TileHeight),

                            // source of the tile in the tilesheet
                            SourceTiles[layer.Tiles[x][y].SourceID].Source,

                            // layers can have an opacity value, this property is Color.White at the opacity of the layer
                            layer.OpacityColor,

                            // tile rotation value
                            layer.Tiles[x][y].Rotation,

                            // origin of the tile, this is always the center of the tile
                            SourceTiles[layer.Tiles[x][y].SourceID].Origin,

                            // tile horizontal or vertical flipping value
                            layer.Tiles[x][y].Effects,

                            // depth for SpriteSortMode
                            0);
                    }
                }
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Draws a line.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="p1">First point of the line.</param>
        /// <param name="p2">Second point of the line.</param>
        /// <param name="color">Color of the line.</param>
        /// <param name="thickness">The thickness of the line in pixels. Default is 1.</param>
        public static void Draw(ISpriteBatch sb, Vector2 p1, Vector2 p2, Color color, float thickness = 1f)
        {
            if (sb == null)
            {
                Debug.Fail("sb is null.");
                return;
            }

            if (sb.IsDisposed)
            {
                Debug.Fail("sb is disposed.");
                return;
            }

            // Common properties set no matter the approach we use below
            _drawLineRect.Position  = p1;
            _drawLineRect.FillColor = color;

            // If we have a perfectly vertical or horizontal line, we can avoid using rotation to speed up the calculation, so check for that first.
            // This is purely an optimization - the rotation approach works for all points still.
            if (p1.X == p2.X)
            {
                // Perfectly vertical
                _drawLineRect.Size     = new Vector2(thickness, p2.Y - p1.Y);
                _drawLineRect.Rotation = 0;
            }
            else if (p1.Y == p2.Y)
            {
                // Perfectly horizontal
                _drawLineRect.Size     = new Vector2(p2.X - p1.X, thickness);
                _drawLineRect.Rotation = 0;
            }
            else
            {
                // Treat as horizontal by setting the X as the distance and Y as the thickness, then rotate
                _drawLineRect.Size     = new Vector2(p2.Distance(p1), thickness);
                _drawLineRect.Rotation = MathHelper.ToDegrees((float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X));
            }

            sb.Draw(_drawLineRect);
        }
Esempio n. 34
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _spriteBatch.Begin();

            _spriteBatch.Draw(_mainBackground, _mainBackgroundRect, Color.White);
            _background1.Draw(_spriteBatch);
            _background2.Draw(_spriteBatch);

            foreach (var enemy in _enemies)
            {
                enemy.Draw(gameTime);
            }

            _player.Draw(gameTime);

            _spriteBatch.End();

            base.Draw(gameTime);
        }
Esempio n. 35
0
        public void Draw(ISpriteBatch spriteBatch)
        {
            if (Texture != null)
            {
                Vector2       origin  = Origin;
                SpriteEffects effects = SpriteEffects.None;

                if (WorldFlipX)
                {
                    effects |= SpriteEffects.FlipHorizontally;
                    origin.X = Rectangle.Width - origin.X;
                }

                if (WorldFlipY)
                {
                    effects |= SpriteEffects.FlipVertically;
                    origin.Y = Rectangle.Height - origin.Y;
                }

                spriteBatch.Draw(Texture, WorldPosition, Rectangle, Color * WorldOpacity, WorldRotation, origin, new Vector2(WorldScaleX, WorldScaleY), effects, 0.0f);
            }
        }
Esempio n. 36
0
        /// <summary>
        /// Draws the <see cref="ISprite"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="dest"><see cref="Rectangle"/> to draw to.</param>
        /// <param name="color"><see cref="Color"/> to draw with.</param>
        public void Draw(ISpriteBatch sb, Rectangle dest, Color color)
        {
            if (!CanDraw(sb))
                return;

            sb.Draw(_texture, dest, _source, color);
        }
Esempio n. 37
0
        /// <summary>
        /// Draws the <see cref="ISprite"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Destination rectangle.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        /// <param name="effect">Sprite effect to use (default SpriteEffects.None).</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin (default 0).</param>
        /// <param name="origin">The origin of the sprite to rotate around (default Vector2.Zero).</param>
        public void Draw(ISpriteBatch sb, Rectangle dest, Color color, SpriteEffects effect, float rotation, Vector2 origin)
        {
            if (!CanDraw(sb))
                return;

            sb.Draw(Texture, dest, Source, color, rotation, origin, effect);
        }
Esempio n. 38
0
        /// <summary>
        /// Draws the <see cref="ISprite"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Position to draw to.</param>
        /// <param name="color"><see cref="Color"/> to draw with.</param>
        public void Draw(ISpriteBatch sb, Vector2 position, Color color)
        {
            if (!CanDraw(sb))
                return;

            sb.Draw(_texture, position, _source, color);
        }
Esempio n. 39
0
        /// <summary>
        /// Draws the Sprite.
        /// </summary>
        /// <param name="sb">SpriteBatch to draw to.</param>
        /// <param name="position">The location, in screen coordinates, where the sprite will be drawn.</param>
        /// <param name="color">The color channel modulation to use. Use Color.White for full color with no tinting.</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin.</param>
        /// <param name="origin">The origin of the sprite. Specify (0,0) for the upper-left corner.</param>
        /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param>
        /// <param name="effects">Rotations to apply before rendering.</param>
        public void Draw(ISpriteBatch sb, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale,
                         SpriteEffects effects)
        {
            if (!CanDraw(sb))
                return;

            sb.Draw(_texture, position, _source, color, rotation, origin, scale, effects);
        }
Esempio n. 40
0
        /// <summary>
        /// Draws the <see cref="ISprite"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Top-left corner pixel of the destination.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        /// <param name="effect">Sprite effect to use (default SpriteEffects.None).</param>
        public void Draw(ISpriteBatch sb, Vector2 dest, Color color, SpriteEffects effect)
        {
            if (!CanDraw(sb))
                return;

            sb.Draw(Texture, dest, Source, color, 0, Vector2.Zero, 1.0f, effect);
        }
Esempio n. 41
0
 internal void Draw(ISpriteBatch spriteBatch)
 {
     spriteBatch.Draw(myTexture, spritePosition, Color.White);
 }
Esempio n. 42
0
        public void Draw(ISpriteBatch spriteBatch)
        {
            if (Texture != null)
            {
                Vector2 origin = Origin;
                SpriteEffects effects = SpriteEffects.None;

                if (WorldFlipX)
                {
                    effects |= SpriteEffects.FlipHorizontally;
                    origin.X = Rectangle.Width - origin.X;
                }

                if (WorldFlipY)
                {
                    effects |= SpriteEffects.FlipVertically;
                    origin.Y = Rectangle.Height - origin.Y;
                }

                spriteBatch.Draw(Texture, WorldPosition, Rectangle, Color * WorldOpacity, WorldRotation, origin, new Vector2(WorldScaleX, WorldScaleY), effects, 0.0f);
            }
        }
Esempio n. 43
0
        public void Render(ISpriteBatch spriteBatch, V2 cameraPosition)
        {
            spriteBatch.Begin();

            for (int i = 0; i < positionedWorldCells.Length; i++)
            {
                if (positionedWorldCells[i] == null)
                    continue;

                for (int j = 0; j < positionedWorldCells[i].Count; j++)
                {
                    var cell = positionedWorldCells[i][j];

                    if (cell.Tile == null)
                        continue;

                    spriteBatch.Draw(cell.Tile.Texture,
                        new Rect(0, 0, TileWidth, TileHeight),
                        new Rect((int)cell.Position.X, (int)cell.Position.Y, TileWidth, TileHeight),
                        0f,
                        baseDepth - ((i * 100) + j) * HeightRowDepthMod);

                    spriteBatch.DrawString(SysCore.SystemFont, cell.Position.X + ", " + cell.Position.Y, new V2(cell.Position.X, cell.Position.Y), new V4(255), 0f, 1f, 1f);

                }
            }

            spriteBatch.End();
        }
Esempio n. 44
0
File: Grh.cs Progetto: Furt/netgore
        /// <summary>
        /// Draws the current frame of the <see cref="Grh"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Top-left corner pixel of the destination.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        public void Draw(ISpriteBatch sb, Vector2 dest, Color color)
        {
            if (!CanDrawGrh(sb))
                return;

            sb.Draw(Texture, dest, Source, color);
        }
Esempio n. 45
0
File: Grh.cs Progetto: Furt/netgore
        /// <summary>
        /// Draws the current frame of the <see cref="Grh"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
        /// <param name="dest">Top-left corner pixel of the destination.</param>
        /// <param name="color">Color of the sprite (default Color.White).</param>
        /// <param name="effect">Sprite effect to use (default SpriteEffects.None).</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin (default 0).</param>
        /// <param name="origin">The origin of the sprite to rotate around (default Vector2.Zero).</param>
        /// <param name="scale">Vector2 defining the scale.</param>
        public void Draw(ISpriteBatch sb, Vector2 dest, Color color, SpriteEffects effect, float rotation, Vector2 origin,
                         Vector2 scale)
        {
            if (!CanDrawGrh(sb))
                return;

            sb.Draw(Texture, dest, Source, color, rotation, origin, scale, effect);
        }
Esempio n. 46
0
File: Grh.cs Progetto: Furt/netgore
        /// <summary>
        /// Draws the <see cref="ISprite"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to use to draw.</param>
        /// <param name="dest">Destination to draw the sprite.</param>
        public void Draw(ISpriteBatch sb, Rectangle dest)
        {
            if (!CanDrawGrh(sb))
                return;

            sb.Draw(Texture, dest, Source, Color.White);
        }
Esempio n. 47
0
        // Draw one of the squares at a grid coordinate.
        void DrawQuarterCircle(ISpriteBatch spriteBatch, TextureContent content, Rectangle rect, Vector2 gridOrigin, int beat, Color color, float filledness, int depth)
        {
            // we prefer beats to start at upper left, but left to this logic, they start at lower left

            // position of this measure
            Vector2 position = gridOrigin + new Vector2(((beat / 4) % 4) * rect.Width, (beat / 16) * rect.Height);

            Vector2 offset;
            switch (beat % 4)
            {
                case 0: offset = new Vector2(1, 1); break;
                case 1: offset = new Vector2(0, 1); break;
                case 2: offset = new Vector2(0, 0); break;
                case 3: offset = new Vector2(1, 0); break;
                default: offset = Vector2.Zero; break; // NOTREACHED
            }
            position += offset * new Vector2(rect.Width, rect.Height);

            Rectangle destRect = new Rectangle(
                rect.Left + (int)position.X,
                rect.Top + (int)position.Y,
                rect.Width,
                rect.Height);

            Spam.Graphics.WriteLine(new string(' ', depth * 4 + 4) + Label + ": beat " + beat + ", filledness " + filledness + ", destRect " + destRect.ToString());

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            Vector2 origin = new Vector2(0);

            // always draw a hollow quarter circle
            spriteBatch.Draw(
                content.QuarterHollowCircle,
                destRect,
                null,
                color,
                (float)((beat % 4 + 2) * Math.PI / 2),
                origin,
                SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically,
                0);

            // now maybe draw a filled circle
            Vector4 v = color.ToVector4();
            v *= filledness;
            color = new Color(v);

            spriteBatch.Draw(
                content.QuarterFilledCircle,
                destRect,
                null,
                color,
                (float)((beat % 4 + 2) * Math.PI / 2),
                origin,
                SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically,
                0);

            spriteBatch.End();
        }
Esempio n. 48
0
 protected override void DrawComponent(GameTime time, ISpriteBatch batch)
 {
     if (image != null)
         batch.Draw(image, Position, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
 }
Esempio n. 49
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice,
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            bool positionMirrored =
                SecondaryViewOption == SecondaryViewOption.PositionMirrored
                && view == HolofunkView.Secondary;

            Vector2 p0 = m_p0 + parentTransform.Translation;
            Vector2 p1 = m_p1 + parentTransform.Translation;

            if (positionMirrored) {
                p0 = new Vector2(spriteBatch.Viewport.X - p0.X, p0.Y);
                p1 = new Vector2(spriteBatch.Viewport.X - p1.X, p1.Y);
            }

            Vector2 diff = Vector2.Subtract(p1, p0);
            float angleRadians = (float)Math.Atan2(diff.Y, diff.X);
            float length = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y) / 2;

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                content.TinyDot,
                p0,
                null,
                Color,
                angleRadians,
                new Vector2(0f, 1f), // we pivot around the center of the left edge of the 2x2 square
                new Vector2(length, LocalTransform.Scale.Y),
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }
Esempio n. 50
0
        /// <summary>
        /// Draws the control.
        /// </summary>
        /// <param name="spriteBatch"><see cref="ISpriteBatch"/> to draw to.</param>
        protected override void DrawControl(ISpriteBatch spriteBatch)
        {
            // Draw the border
            Border.Draw(spriteBatch, this);

            // Find the sprite based on the state and value
            ISprite sprite;
            if (Value)
            {
                if (_state == CheckBoxState.Pressed)
                    sprite = _tickedPressed;
                else if (_state == CheckBoxState.Over)
                    sprite = _tickedOver;
                else
                    sprite = _ticked;

                if (sprite == null)
                    sprite = _ticked;
            }
            else
            {
                if (_state == CheckBoxState.Pressed)
                    sprite = _untickedPressed;
                else if (_state == CheckBoxState.Over)
                    sprite = _untickedOver;
                else
                    sprite = _unticked;

                if (sprite == null)
                    sprite = _unticked;
            }

            // Validate the sprite
            if (sprite == null)
                return;

            // Find the text offset
            var textOffset = new Vector2(sprite.Source.Width + _textXAdjust, 0);

            // Draw the checkbox
            if (sprite.Texture != null)
                spriteBatch.Draw(sprite.Texture, ScreenPosition, sprite.Source, Color.White);

            // Draw the text
            DrawText(spriteBatch, textOffset);
        }
Esempio n. 51
0
 protected override void DrawComponent(GameTime time, ISpriteBatch batch)
 {
     batch.Draw(spriteSheet, destinationRectangle:destinationRectangle, sourceRectangle: sourceRectangle, color: Color, effects: SpriteEffects);
 }
Esempio n. 52
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            // no texture = no-op
            if (m_texture == null) {
                return;
            }

            int left = -(int)((float)m_texture.Width * m_origin.X);
            int top = -(int)((float)m_texture.Height * m_origin.Y);
            Rectangle rect = new Rectangle(left, top, m_texture.Width, m_texture.Height);

            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            Rectangle transformedRect = rect * combinedTransform;

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform + "; start rect " + rect.FormatToString() + "; transformedRect " + transformedRect.FormatToString());

            Texture2D texture = m_texture;
            SpriteEffects effects = SpriteEffects.None;

            if (view == HolofunkView.Secondary) {
                if ((SecondaryViewOption & SecondaryViewOption.TextureMirrored) != 0) {
                    effects = SpriteEffects.FlipHorizontally;
                }

                if ((SecondaryViewOption & SecondaryViewOption.PositionMirrored) != 0) {
                    // need to flip transformedRect around center of viewport
                    int newLeft = (int)spriteBatch.Viewport.X - transformedRect.Right;

                    transformedRect = new Rectangle(newLeft, transformedRect.Y, transformedRect.Width, transformedRect.Height);
                }

                if ((SecondaryViewOption & SecondaryViewOption.SecondTexture) != 0) {
                    HoloDebug.Assert(m_secondaryTexture != null);
                    texture = m_secondaryTexture;
                }
            }

            Color color = m_color;
            if (view == HolofunkView.Secondary && m_secondaryColor.HasValue) {
                color = m_secondaryColor.Value;
            }

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                texture,
                transformedRect,
                null,
                color,
                0,
                m_origin,
                effects,
                0);

            spriteBatch.End();
        }
Esempio n. 53
0
 public override void Draw(ISpriteBatch spriteBatch, GameTime gameTime)
 {
     spriteBatch.Draw(_texture, Position, Color);
 }