Example #1
0
        protected override void AfterDraw(RendererBatch batch)
        {
            BlendState        = null;
            DepthStencilState = new DepthStencilState()
            {
                DepthBufferEnable = false,
                StencilEnable     = true,
                StencilFunction   = Reverse
                    ? CompareFunction.Equal
                    : CompareFunction.NotEqual,
                StencilPass      = StencilOperation.Keep,
                ReferenceStencil = 0
            };
            Effect = null;

            batch.Configure(BlendState, DepthStencilState, Effect, Matrix);
            batch.Begin();
            batch.DrawPrimitives(primitive =>
            {
                primitive.FillRectangle(
                    View.Location.ToVector2(),
                    View.Size.ToVector2(),
                    ClearColor);
            });
            batch.End();
        }
Example #2
0
        protected override void Draw(RendererBatch batch)
        {
            for (int i = 0; i < _mapSize.X * _mapSize.Y; i++)
            {
                var x      = i % _mapSize.X;
                var y      = i / _mapSize.X;
                var origin = Origin - new Vector2(
                    x * Texture.Width,
                    y * Texture.Height);

                var width = x < _mapSize.X - 1 || _remaining.X == 0
                    ? Texture.Width
                    : _remaining.X;
                var height = y < _mapSize.Y - 1 || _remaining.Y == 0
                    ? Texture.Height
                    : _remaining.Y;

                var bounds = new Rectangle(
                    Texture.Bounds.X,
                    Texture.Bounds.Y,
                    width,
                    height);

                Texture.Draw(
                    batch,
                    DrawPosition,
                    bounds,
                    origin,
                    Scale,
                    Angle,
                    Color * Opacity.Clamp(0f, 1f),
                    SpriteEffects);
            }
        }
Example #3
0
 public void Draw(
     RendererBatch batch,
     string text,
     Point position,
     Point size,
     Vector2?origin             = null,
     Vector2?scale              = null,
     float angle                = 0f,
     Color?color                = null,
     SpriteEffects effects      = SpriteEffects.None,
     HorizontalAlignment xAlign = HorizontalAlignment.Left,
     VerticalAlignment yAlign   = VerticalAlignment.Top,
     bool wordWrap              = false)
 {
     Draw(
         batch,
         text,
         position.ToVector2(),
         size.ToVector2(),
         origin,
         scale,
         angle,
         color,
         effects,
         xAlign,
         yAlign,
         wordWrap);
 }
Example #4
0
        public void Draw(RendererBatch batch, Color treeColor, Color leafColor)
        {
            var treeNodes = new Stack <Node>();

            treeNodes.Push(_root);

            while (treeNodes.Count > 0)
            {
                var treeNode = treeNodes.Pop();

                if (treeNode != null && !treeNode.IsLeaf)
                {
                    batch.DrawPrimitives(p =>
                    {
                        var aabb = treeNode.AABB;
                        p.DrawRectangle(aabb.Min, aabb.Size, treeColor);
                    });

                    treeNodes.Push(treeNode.Left);
                    treeNodes.Push(treeNode.Right);
                }
            }

            foreach (var leafNode in _nodes.Values)
            {
                batch.DrawPrimitives(p =>
                {
                    var aabb = leafNode.AABB;
                    p.DrawRectangle(aabb.Min, aabb.Size, leafColor);
                });
            }
        }
Example #5
0
        protected virtual void DrawTileShape(
            RendererBatch batch,
            Color color,
            Point position)
        {
            var shape = GetTileShape(position);

            shape?.Draw(batch, color);
        }
Example #6
0
        public sealed override void Draw(RendererBatch batch, Color color)
        {
            for (int i = 0; i < DrawRegion.Width * DrawRegion.Height; i++)
            {
                var x = DrawRegion.Left + (i % DrawRegion.Width);
                var y = DrawRegion.Top + (i / DrawRegion.Width);

                DrawTileShape(batch, color, new Point(x, y));
            }
        }
Example #7
0
 protected override void Draw(RendererBatch batch)
 {
     Texture.Draw(
         batch,
         DrawPosition,
         Origin,
         Scale,
         Angle,
         Color * Opacity.Clamp(0f, 1f),
         SpriteEffects);
 }
Example #8
0
        public void Draw(RendererBatch batch, Color color, Color fill, int segments)
        {
            batch.DrawPrimitives(p =>
            {
                if (fill != default)
                {
                    p.FillCircle(Center, Radius, fill, segments);
                }

                p.DrawCircle(Center, Radius, color, segments);
            });
        }
Example #9
0
        public override void Draw(RendererBatch batch, Color color, Color fill)
        {
            batch.DrawPrimitives(p =>
            {
                if (fill != default)
                {
                    p.FillPolygon(Vertices, fill);
                }

                p.DrawPolygon(Vertices, color);
            });
        }
Example #10
0
        public override void Draw(RendererBatch batch, Color color, Color fill)
        {
            batch.DrawPrimitives(p =>
            {
                if (fill != default)
                {
                    p.FillRectangle(Position, Size, fill);
                }

                p.DrawRectangle(Position, Size, color);
            });
        }
Example #11
0
        protected override void DrawTileShape(RendererBatch batch, Color color, Point position)
        {
            var index = Map[position];

            if (index != Map.Empty)
            {
                Tile tile;

                if (Tiles.TryGetValue(index, out tile) && tile.Color.HasValue)
                {
                    color = tile.Color.Value;
                }
            }

            base.DrawTileShape(batch, color, position);
        }
Example #12
0
        protected override void AfterDraw(RendererBatch batch)
        {
            BlendState        = null;
            DepthStencilState = new DepthStencilState()
            {
                DepthBufferEnable = false,
                StencilEnable     = true,
                StencilFunction   = Reverse
                    ? CompareFunction.Equal
                    : CompareFunction.NotEqual,
                StencilPass      = StencilOperation.Keep,
                ReferenceStencil = 0
            };

            base.AfterDraw(batch);
        }
Example #13
0
        protected sealed override void Draw(RendererBatch batch)
        {
            for (int i = 0; i < DrawRegion.Width * DrawRegion.Height; i++)
            {
                var x        = DrawRegion.Left + (i % DrawRegion.Width);
                var y        = DrawRegion.Top + (i / DrawRegion.Width);
                var position = DrawPosition.Floor() + new Vector2(x * TileWidth, y * TileHeight);

                GetTile(x, y)?.Draw(
                    batch,
                    position,
                    Vector2.Zero,
                    Vector2.One,
                    0f,
                    Color * Opacity.Clamp(0f, 1f),
                    SpriteEffects);
            }
        }
Example #14
0
        internal virtual void Draw(RendererBatch batch)
        {
            State = ManagerState.ThrowError;

            C child;

            for (int i = 0; i < Children.Count; i++)
            {
                child = Children[i];

                if (child.IsVisible)
                {
                    child.DrawInternally(batch);
                }
            }

            State = ManagerState.Opened;
        }
Example #15
0
        internal DisplayAdapter(GameAdapter game, Point size, int scale, bool fullscreen)
        {
            _game = game;
            _game.Graphics.DeviceCreated   += OnDeviceChanged;
            _game.Window.ClientSizeChanged += OnDeviceChanged;
            _size = size;

            if (fullscreen)
            {
                ToFullscreen();
            }
            else
            {
                ToFixedScale(scale);
            }

            _game.ApplyChanges();
            _batch = new RendererBatch(_game.GraphicsDevice);
        }
Example #16
0
        protected override void Draw(RendererBatch batch)
        {
            if (IsDirty)
            {
                Refresh();
            }

            for (int i = 0; i < Characters.Count; i++)
            {
                var origin = Origin - Characters[i].Offset;
                Characters[i].Source.Texture.Draw(
                    batch,
                    DrawPosition,
                    origin,
                    Scale,
                    Angle,
                    Color * MathHelper.Clamp(Opacity, 0f, 1f),
                    SpriteEffects);
            }
        }
Example #17
0
        protected override void DrawTileShape(RendererBatch batch, Color color, Point position)
        {
            var index = Map[position];

            if (typeof(T).IsEnum)
            {
                var isFlag = typeof(T).IsDefined(typeof(FlagsAttribute), false);

                if (isFlag)
                {
                    var first = true;

                    foreach (var pair in Colors)
                    {
                        var tile       = (Enum)Enum.ToObject(typeof(T), index);
                        var tileToFind = (Enum)Enum.ToObject(typeof(T), pair.Key);

                        if (tile.HasFlag(tileToFind))
                        {
                            color = !first
                                ? Color.Lerp(color, pair.Value, .5f)
                                : pair.Value;

                            first = false;
                        }
                    }
                }
                else
                {
                    var originalColor = color;
                    var tile          = (T)Enum.ToObject(typeof(T), index);

                    if (!Colors.TryGetValue(tile, out color))
                    {
                        color = originalColor;
                    }
                }
            }

            base.DrawTileShape(batch, color, position);
        }
Example #18
0
        protected sealed override void Draw(RendererBatch batch)
        {
            if (Scene?.Entities == null)
            {
                return;
            }

            Scene.Entities.State = ManagerState.ThrowError;
            batch.Configure(BlendState, DepthStencilState, Effect, Matrix);
            batch.Begin();

            foreach (var entity in Scene.Entities.OnLayer(this))
            {
                if (entity.IsVisible)
                {
                    entity.DrawInternally(batch);
                }
            }

            batch.End();
            Scene.Entities.State = ManagerState.Opened;
        }
Example #19
0
 public void Draw(
     RendererBatch batch,
     Vector2 position,
     Vector2 origin,
     Vector2 scale,
     float angle,
     Color color,
     SpriteEffects effects)
 {
     batch.DrawSprites((sprite) =>
     {
         sprite.Draw(
             _xnaTexture,
             position,
             Bounds,
             color,
             angle,
             origin,
             scale,
             effects,
             0f);
     });
 }
Example #20
0
 protected override void Draw(RendererBatch batch)
 {
     Texture = Animation?.GetFrame(Textures) ?? Textures[0];
     base.Draw(batch);
 }
Example #21
0
 public override void Draw(RendererBatch batch, Color color, Color fill)
 {
     Draw(batch, color, fill, 16);
 }
Example #22
0
        public void Draw(
            RendererBatch batch,
            string text,
            Vector2 position,
            Vector2 size,
            Vector2?origin             = null,
            Vector2?scale              = null,
            float angle                = 0f,
            Color?color                = null,
            SpriteEffects effects      = SpriteEffects.None,
            HorizontalAlignment xAlign = HorizontalAlignment.Left,
            VerticalAlignment yAlign   = VerticalAlignment.Top,
            bool wordWrap              = false)
        {
            if (text.IsNullOrEmpty())
            {
                return;
            }
            if (wordWrap)
            {
                text = WordWrap(text, (int)size.X);
            }

            var offset = MeasureVerticalOffset(yAlign, text, (int)size.Y).ToUnitYF();
            var lines  = text.Split('\n');

            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                offset.X = MeasureHorizontalOffset(xAlign, line, (int)size.X);

                for (int j = 0; j < line.Length; j++)
                {
                    BitmapCharacter character;

                    if (Characters.TryGetValue(line[j], out character))
                    {
                        var kerning = 0;
                        if (j < line.Length - 1)
                        {
                            character.Kernings.TryGetValue(line[j + 1], out kerning);
                        }
                        var charOrigin = (origin ?? Vector2.Zero)
                                         - (offset + character.Offset.ToVector2());

                        character.Texture.Draw(
                            batch,
                            position,
                            charOrigin,
                            scale ?? Vector2.One,
                            angle,
                            color ?? Color.White,
                            effects);

                        offset.X += kerning + character.Spacing + Spacing;
                    }
                }

                offset.Y += DefaultLineHeight + LineHeight;
            }
        }
Example #23
0
 protected override void BeforeDraw(RendererBatch batch)
 {
     BlendState        = _nonColorWriteBlend;
     DepthStencilState = _alwaysStencil;
     Effect            = _alphaTestEffect;
 }
Example #24
0
        public void Draw(
            RendererBatch batch,
            Vector2 position,
            Vector2 origin,
            Vector2 scale,
            float angle,
            Color color,
            SpriteEffects effects)
        {
            var offset      = Origin;
            var origEffects = effects;

            if (IsRotated)
            {
                offset = offset.Rotate(true) - Texture.Width * Vector2.UnitX;
                origin = origin.Rotate(true);
                angle -= MathHelper.PiOver2;

                switch (effects)
                {
                case SpriteEffects.FlipHorizontally:
                    effects = SpriteEffects.FlipVertically;
                    break;

                case SpriteEffects.FlipVertically:
                    effects = SpriteEffects.FlipHorizontally;
                    break;
                }
            }

            if (origEffects.HasFlag(SpriteEffects.FlipHorizontally))
            {
                if (IsRotated)
                {
                    offset.Y = (Width - RealWidth) - offset.Y;
                }
                else
                {
                    offset.X = (Width - RealWidth) - offset.X;
                }
            }

            if (origEffects.HasFlag(SpriteEffects.FlipVertically))
            {
                if (IsRotated)
                {
                    offset.X = (Height - RealHeight) - (Height + offset.X)
                               * 2f + offset.X;
                }
                else
                {
                    offset.Y = (Height - RealHeight) - offset.Y;
                }
            }

            Texture.Draw(
                batch,
                position,
                origin - offset,
                scale,
                angle,
                color,
                effects);
        }
Example #25
0
 public abstract void Draw(RendererBatch batch, Color color);
Example #26
0
 public void Draw(RendererBatch batch, Color color)
 {
     Draw(batch, color, default);
 }
Example #27
0
 protected virtual void AfterDraw(RendererBatch batch)
 {
 }
Example #28
0
 protected virtual void BeforeDraw(RendererBatch batch)
 {
 }
Example #29
0
        internal void Draw(
            DisplayAdapter display,
            RendererBatch batch,
            out RenderTarget2D renderTarget)
        {
            renderTarget = _renderTarget;

            var projection   = new Rectangle(Point.Zero, display.Size);
            var clearOptions = ClearOptions.Target
                               | ClearOptions.Stencil
                               | ClearOptions.DepthBuffer;

            display.GraphicsDevice.SetRenderTarget(renderTarget);
            display.GraphicsDevice.Viewport = new Viewport(projection);
            display.GraphicsDevice.Clear(clearOptions, ClearColor, 0, 0);

            BeforeDraw(batch);

            Entities.State = ManagerState.ThrowError;
            batch.Configure(transformMatrix: Camera.Matrix);
            batch.Begin();

            foreach (var entity in Entities.OnLayer(null))
            {
                if (entity.IsVisible)
                {
                    entity.DrawInternally(batch);
                }
            }

            batch.End();
            Entities.State = ManagerState.Opened;

            Layers.State = ManagerState.ThrowError;

            foreach (var layer in Layers)
            {
                display.GraphicsDevice.SetRenderTarget(layer.RenderTarget);
                display.GraphicsDevice.Clear(clearOptions, Color.Transparent, 0, 0);

                if (!layer.RenderBeforeMerge)
                {
                    batch.Sprite.Begin(samplerState: SamplerState.PointClamp);
                    batch.Sprite.Draw(renderTarget, Vector2.Zero, Color.White);
                    batch.Sprite.End();
                }

                if (layer.IsVisible)
                {
                    layer.DrawInternally(batch);
                }

                display.GraphicsDevice.SetRenderTarget(_backupRenderTarget);
                display.GraphicsDevice.Clear(clearOptions, Color.Transparent, 0, 0);

                if (layer.RenderBeforeMerge)
                {
                    batch.Sprite.Begin(samplerState: SamplerState.PointClamp);
                    batch.Sprite.Draw(renderTarget, Vector2.Zero, Color.White);
                    batch.Sprite.End();
                }

                batch.Sprite.Begin(
                    samplerState: SamplerState.PointClamp,
                    effect: layer.Effect);
                batch.Sprite.Draw(layer.RenderTarget, Vector2.Zero, layer.Color);
                batch.Sprite.End();

                display.GraphicsDevice.SetRenderTarget(layer.RenderTarget);
                display.GraphicsDevice.Clear(clearOptions, Color.Transparent, 0, 0);

                batch.Sprite.Begin(samplerState: SamplerState.PointClamp);
                batch.Sprite.Draw(_backupRenderTarget, Vector2.Zero, Color.White);
                batch.Sprite.End();

                renderTarget = layer.RenderTarget;
            }

            Layers.State = ManagerState.Opened;

            AfterDraw(batch);
        }
Example #30
0
 internal virtual void DrawInternally(RendererBatch batch)
 {
     BeforeDraw(batch);
     Draw(batch);
     AfterDraw(batch);
 }