public static void DrawString(this Batcher batcher, NezSpriteFont spriteFont, string text, Vector2 position, Color color) { batcher.DrawString(spriteFont, text, position, color, 0.0f, Vector2.Zero, new Vector2(1.0f), SpriteEffects.None, 0.0f); }
public static void DrawLine(this Batcher batcher, float x1, float y1, float x2, float y2, Color color) { DrawLine(batcher, new Vector2(x1, y1), new Vector2(x2, y2), color); }
/// <summary> /// called before the Scene is rendered. This allows a transition to render to a RenderTarget if needed and avoids issues with MonoGame /// clearing the framebuffer when a RenderTarget is used. /// </summary> public virtual void PreRender(Batcher batcher) { }
public static void DrawHollowRect(this Batcher batcher, RectangleF rect, Color color, float thickness = 1) { DrawHollowRect(batcher, rect.X, rect.Y, rect.Width, rect.Height, color, thickness); }
public static void DrawPixel(this Batcher batcher, float x, float y, Color color, int size = 1) { DrawPixel(batcher, new Vector2(x, y), color, size); }
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; } }
public override void Render(Batcher batcher, Camera camera) { _sprite.DrawOutline(batcher, camera, OutlineColor, OutlineWidth); _sprite.Render(batcher, camera); }
public static void DrawRect(this Batcher batcher, Vector2 position, float width, float height, Color color) { DrawRect(batcher, position.X, position.Y, width, height, color); }
public static void DrawRect(this Batcher batcher, Rectangle rect, Color color) { batcher.Draw(Graphics.Instance.PixelTexture, rect, Graphics.Instance.PixelTexture.SourceRect, color); }
public static void DrawLineAngle(this Batcher batcher, float startX, float startY, float radians, float length, Color color) { DrawLineAngle(batcher, new Vector2(startX, startY), radians, length, color); }
public static void DrawCircle(this Batcher batcher, float x, float y, float radius, Color color, int thickness = 1, int resolution = 12) { DrawCircle(batcher, new Vector2(x, y), radius, color, thickness, resolution); }
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); }
/// <summary> /// Submit a text string of sprites for drawing in the current batch. /// </summary> /// <param name="batcher">Batcher.</param> /// <param name="font">Font.</param> /// <param name="text">Text.</param> /// <param name="position">Position.</param> /// <param name="color">Color.</param> /// <param name="rotation">Rotation.</param> /// <param name="origin">Origin.</param> /// <param name="scale">Scale.</param> /// <param name="effects">Effects.</param> /// <param name="layerDepth">Layer depth.</param> public static void DrawString(this Batcher batcher, IFont font, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { batcher.DrawString(font, text, position, color, rotation, origin, new Vector2(scale), effects, layerDepth); }
/// <summary> /// Submit a text string of sprites for drawing in the current batch. /// </summary> /// <param name="batcher">Batcher.</param> /// <param name="font">Font.</param> /// <param name="text">Text.</param> /// <param name="position">Position.</param> /// <param name="color">Color.</param> public static void DrawString(this Batcher batcher, IFont font, StringBuilder text, Vector2 position, Color color) { batcher.DrawString(font, text, position, color, 0.0f, Vector2.Zero, new Vector2(1.0f), SpriteEffects.None, 0.0f); }
protected override void DebugDraw(GiaScene context, Batcher batcher, Entity entity, ref AABB bounds) { Gia.Debug.DeferWorldHollowRect(bounds.Bounds, Color.Orange); Gia.Debug.DeferWorldPixel(bounds.Bounds.Location, Color.Orange, 4); }
public static void DrawLine(this Batcher batcher, Vector2 start, Vector2 end, Color color, float thickness) { DrawLineAngle(batcher, start, Mathf.AngleBetweenVectors(start, end), Vector2.Distance(start, end), color, thickness); }
protected override void Draw(GiaScene context, Batcher batcher, Entity entity, ref AABB bounds) { ref var text = ref entity.Get <Text>();
public static void DrawHollowRect(this Batcher batcher, Vector2 position, float width, float height, Color color, float thickness = 1) { DrawHollowRect(batcher, position.X, position.Y, width, height, color, thickness); }
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); }
public override void Render(Batcher batcher, Camera camera) { // TODO: make culling smarter and only render the lines that are actually on the screen rather than all or nothing var width = _points.GetLength(0); var height = _points.GetLength(1); for (var y = 1; y < height; y++) { for (var x = 1; x < width; x++) { var left = new Vector2(); var up = new Vector2(); var p = ProjectToVector2(_points[x, y].Position); if (x > 1) { float thickness; Color gridColor; if (y % GridMajorPeriodY == 1) { thickness = GridMajorThickness; gridColor = GridMajorColor; } else { thickness = GridMinorThickness; gridColor = GridMinorColor; } // use Catmull-Rom interpolation to help smooth bends in the grid left = ProjectToVector2(_points[x - 1, y].Position); var clampedX = Math.Min(x + 1, width - 1); var mid = Vector2.CatmullRom(ProjectToVector2(_points[x - 2, y].Position), left, p, ProjectToVector2(_points[clampedX, y].Position), 0.5f); // If the grid is very straight here, draw a single straight line. Otherwise, draw lines to our new interpolated midpoint if (Vector2.DistanceSquared(mid, (left + p) / 2) > 1) { DrawLine(batcher, left, mid, gridColor, thickness); DrawLine(batcher, mid, p, gridColor, thickness); } else { DrawLine(batcher, left, p, gridColor, thickness); } } if (y > 1) { float thickness; Color gridColor; if (x % GridMajorPeriodX == 1) { thickness = GridMajorThickness; gridColor = GridMajorColor; } else { thickness = GridMinorThickness; gridColor = GridMinorColor; } up = ProjectToVector2(_points[x, y - 1].Position); var clampedY = Math.Min(y + 1, height - 1); var mid = Vector2.CatmullRom(ProjectToVector2(_points[x, y - 2].Position), up, p, ProjectToVector2(_points[x, clampedY].Position), 0.5f); if (Vector2.DistanceSquared(mid, (up + p) / 2) > 1) { DrawLine(batcher, up, mid, gridColor, thickness); DrawLine(batcher, mid, p, gridColor, thickness); } else { DrawLine(batcher, up, p, gridColor, thickness); } } // Add interpolated lines halfway between our point masses. This makes the grid look // denser without the cost of simulating more springs and point masses. if (x > 1 && y > 1) { var upLeft = ProjectToVector2(_points[x - 1, y - 1].Position); DrawLine(batcher, 0.5f * (upLeft + up), 0.5f * (left + p), GridMinorColor, GridMinorThickness); // vertical line DrawLine(batcher, 0.5f * (upLeft + left), 0.5f * (up + p), GridMinorColor, GridMinorThickness); // horizontal line } } } }