Example #1
0
        public override void Render(Batcher batcher)
        {
            Core.GraphicsDevice.SetRenderTarget(null);
            batcher.Begin(BlendState.NonPremultiplied, Core.DefaultSamplerState, DepthStencilState.None, null);

            // we only render the previousSceneRender while fading to _color. It will be null after that.
            if (!_isNewSceneLoaded)
            {
                batcher.Draw(PreviousSceneRender, _destinationRect, Color.White);
            }

            batcher.Draw(_overlayTexture, new Rectangle(0, 0, Screen.Width, Screen.Height), _color);

            batcher.End();
        }
Example #2
0
 /// <summary>
 /// do all of your rendering here.static This is a base implementation. Any special rendering should override
 /// this method.
 /// </summary>
 /// <param name="batcher">Batcher.</param>
 public virtual void Render(Batcher batcher)
 {
     Core.GraphicsDevice.SetRenderTarget(null);
     batcher.Begin(BlendState.Opaque, Core.DefaultSamplerState, DepthStencilState.None, null);
     batcher.Draw(PreviousSceneRender, Vector2.Zero, Color.White);
     batcher.End();
 }
Example #3
0
        public override void Render(Batcher batcher)
        {
            Core.GraphicsDevice.SetRenderTarget(null);

            // if we are scaling out we dont need to render the previous scene anymore since we want the new scene to be visible
            if (!_isNewSceneLoaded)
            {
                batcher.Begin(BlendState.Opaque, Core.DefaultSamplerState, DepthStencilState.None, null);
                batcher.Draw(PreviousSceneRender, Vector2.Zero, Color.White);
                batcher.End();
            }

            batcher.Begin(_blendState, Core.DefaultSamplerState, DepthStencilState.None, null);
            batcher.Draw(_maskRenderTarget, Vector2.Zero, Color.White);
            batcher.End();
        }
Example #4
0
 public override void Render(Batcher batcher)
 {
     Core.GraphicsDevice.SetRenderTarget(null);
     batcher.Begin(BlendState.NonPremultiplied, Core.DefaultSamplerState, DepthStencilState.None, null);
     batcher.Draw(PreviousSceneRender, Vector2.Zero, _color);
     batcher.End();
 }
Example #5
0
 public override void Render(Batcher batcher)
 {
     Core.GraphicsDevice.SetRenderTarget(null);
     batcher.Begin(BlendState.NonPremultiplied, Core.DefaultSamplerState, DepthStencilState.None, null);
     batcher.Draw(PreviousSceneRender, _destinationRect, Color.White);
     batcher.End();
 }
Example #6
0
 public static void DrawRect(this Batcher batcher, float x, float y, float width, float height, Color color)
 {
     _tempRect.X      = (int)x;
     _tempRect.Y      = (int)y;
     _tempRect.Width  = (int)width;
     _tempRect.Height = (int)height;
     batcher.Draw(Graphics.Instance.PixelTexture, _tempRect, Graphics.Instance.PixelTexture.SourceRect, color);
 }
Example #7
0
 public override void PreRender(Batcher batcher)
 {
     Core.GraphicsDevice.SetRenderTarget(_maskRenderTarget);
     batcher.Begin(BlendState.AlphaBlend, Core.DefaultSamplerState, DepthStencilState.None, null);
     batcher.Draw(_maskTexture, _maskPosition, null, Color.White, _renderRotation, _maskOrigin,
                  _renderScale, SpriteEffects.None, 0);
     batcher.End();
     Core.GraphicsDevice.SetRenderTarget(null);
 }
Example #8
0
        public override void Render(Batcher batcher, Camera camera)
        {
            var pos      = (Entity.Transform.Position - (Origin * Entity.Transform.Scale) + LocalOffset);
            var size     = new Point((int)(_width * Entity.Transform.Scale.X), (int)(_height * Entity.Transform.Scale.Y));
            var destRect = new Rectangle((int)pos.X, (int)pos.Y, size.X, size.Y);

            batcher.Draw(_sprite, destRect, _sprite.SourceRect, Color, Entity.Transform.Rotation,
                         SpriteEffects.None, LayerDepth, SkewTopX, SkewBottomX, SkewLeftY, SkewRightY);
        }
Example #9
0
        void DrawLine(Batcher batcher, Vector2 start, Vector2 end, Color color, float thickness = 2f)
        {
            var delta = end - start;
            var angle = (float)Math.Atan2(delta.Y, delta.X);

            batcher.Draw(Graphics.Instance.PixelTexture, start + Entity.Transform.Position + LocalOffset,
                         Graphics.Instance.PixelTexture.SourceRect, color, angle, new Vector2(0, 0.5f),
                         new Vector2(delta.Length(), thickness), SpriteEffects.None, LayerDepth);
        }
Example #10
0
        public static void DrawPixel(this Batcher batcher, Vector2 position, Color color, int size = 1)
        {
            var destRect = new Rectangle((int)position.X, (int)position.Y, size, size);

            if (size != 1)
            {
                destRect.X -= (int)(size * 0.5f);
                destRect.Y -= (int)(size * 0.5f);
            }

            batcher.Draw(Graphics.Instance.PixelTexture, destRect, Graphics.Instance.PixelTexture.SourceRect, color);
        }
Example #11
0
        public void Render(Batcher batcher, Vector2 offset)
        {
            var origin = new Vector2(0, _image.Height / 2f);

            batcher.Draw(_image, offset + Position, null, _color, 0, origin, _scale, SpriteEffects.None, 0);
        }
Example #12
0
        public void DrawInto(Batcher batcher, ref FontCharacterSource text, Vector2 position, Color color,
                             float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth)
        {
            var flipAdjustment = Vector2.Zero;

            var flippedVert = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically;
            var flippedHorz = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally;

            if (flippedVert || flippedHorz)
            {
                Vector2 size;
                MeasureString(ref text, out size);

                if (flippedHorz)
                {
                    origin.X        *= -1;
                    flipAdjustment.X = -size.X;
                }

                if (flippedVert)
                {
                    origin.Y        *= -1;
                    flipAdjustment.Y = _font.LineSpacing - size.Y;
                }
            }

            // TODO: This looks excessive... i suspect we could do most of this with simple vector math and avoid this much matrix work.
            var requiresTransformation = flippedHorz || flippedVert || rotation != 0f || scale != Vector2.One;

            if (requiresTransformation)
            {
                Matrix2D temp;
                Matrix2D.CreateTranslation(-origin.X, -origin.Y, out _transformationMatrix);
                Matrix2D.CreateScale((flippedHorz ? -scale.X : scale.X), (flippedVert ? -scale.Y : scale.Y), out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
                Matrix2D.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, out temp);
                Matrix2D.Multiply(ref temp, ref _transformationMatrix, out _transformationMatrix);
                Matrix2D.CreateRotation(rotation, out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
                Matrix2D.CreateTranslation(position.X, position.Y, out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
            }

            // Get the default glyph here once.
            SpriteFont.Glyph?defaultGlyph = null;
            if (_font.DefaultCharacter.HasValue)
            {
                defaultGlyph = _glyphs[_font.DefaultCharacter.Value];
            }

            var currentGlyph     = SpriteFont.Glyph.Empty;
            var offset           = requiresTransformation ? Vector2.Zero : position - origin;
            var firstGlyphOfLine = true;

            for (var i = 0; i < text.Length; ++i)
            {
                var c = text[i];

                if (c == '\r')
                {
                    continue;
                }

                if (c == '\n')
                {
                    offset.X         = requiresTransformation ? 0f : position.X - origin.X;
                    offset.Y        += _font.LineSpacing;
                    firstGlyphOfLine = true;
                    continue;
                }

                if (!_glyphs.TryGetValue(c, out currentGlyph))
                {
                    if (!defaultGlyph.HasValue)
                    {
                        throw new ArgumentException("Errors.TextContainsUnresolvableCharacters", "text");
                    }

                    currentGlyph = defaultGlyph.Value;
                }

                // The first character on a line might have a negative left side bearing.
                // In this scenario, SpriteBatch/SpriteFont normally offset the text to the right,
                // so that text does not hang off the left side of its rectangle.
                if (firstGlyphOfLine)
                {
                    offset.X        += Math.Max(currentGlyph.LeftSideBearing, 0);
                    firstGlyphOfLine = false;
                }
                else
                {
                    offset.X += _font.Spacing + currentGlyph.LeftSideBearing;
                }

                var p = offset;

                if (flippedHorz)
                {
                    p.X += currentGlyph.BoundsInTexture.Width;
                }
                p.X += currentGlyph.Cropping.X;

                if (flippedVert)
                {
                    p.Y += currentGlyph.BoundsInTexture.Height - _font.LineSpacing;
                }
                p.Y += currentGlyph.Cropping.Y;

                // transform our point if we need to
                if (requiresTransformation)
                {
                    Vector2Ext.Transform(ref p, ref _transformationMatrix, out p);
                }

                var destRect = RectangleExt.FromFloats(p.X, p.Y,
                                                       currentGlyph.BoundsInTexture.Width * scale.X,
                                                       currentGlyph.BoundsInTexture.Height * scale.Y);

                batcher.Draw(_font.Texture, destRect, currentGlyph.BoundsInTexture, color, rotation, Vector2.Zero,
                             effect, depth);

                offset.X += currentGlyph.Width + currentGlyph.RightSideBearing;
            }
        }
Example #13
0
 public static void DrawRect(this Batcher batcher, Rectangle rect, Color color)
 {
     batcher.Draw(Graphics.Instance.PixelTexture, rect, Graphics.Instance.PixelTexture.SourceRect, color);
 }
Example #14
0
 public static void DrawLineAngle(this Batcher batcher, Vector2 start, float radians, float length, Color color,
                                  float thickness)
 {
     batcher.Draw(Graphics.Instance.PixelTexture, start, Graphics.Instance.PixelTexture.SourceRect, color,
                  radians, new Vector2(0f, 0.5f), new Vector2(length, thickness), SpriteEffects.None, 0);
 }