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(); }
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); } }
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); }
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); }); } }
protected virtual void DrawTileShape( RendererBatch batch, Color color, Point position) { var shape = GetTileShape(position); shape?.Draw(batch, color); }
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)); } }
protected override void Draw(RendererBatch batch) { Texture.Draw( batch, DrawPosition, Origin, Scale, Angle, Color * Opacity.Clamp(0f, 1f), SpriteEffects); }
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); }); }
public override void Draw(RendererBatch batch, Color color, Color fill) { batch.DrawPrimitives(p => { if (fill != default) { p.FillPolygon(Vertices, fill); } p.DrawPolygon(Vertices, color); }); }
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); }); }
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); }
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); }
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); } }
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; }
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); }
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); } }
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); }
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; }
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); }); }
protected override void Draw(RendererBatch batch) { Texture = Animation?.GetFrame(Textures) ?? Textures[0]; base.Draw(batch); }
public override void Draw(RendererBatch batch, Color color, Color fill) { Draw(batch, color, fill, 16); }
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; } }
protected override void BeforeDraw(RendererBatch batch) { BlendState = _nonColorWriteBlend; DepthStencilState = _alwaysStencil; Effect = _alphaTestEffect; }
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); }
public abstract void Draw(RendererBatch batch, Color color);
public void Draw(RendererBatch batch, Color color) { Draw(batch, color, default); }
protected virtual void AfterDraw(RendererBatch batch) { }
protected virtual void BeforeDraw(RendererBatch batch) { }
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); }
internal virtual void DrawInternally(RendererBatch batch) { BeforeDraw(batch); Draw(batch); AfterDraw(batch); }