// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Drawing.Processing { /// /// Convenience shape helpers that forward to the core primitives. /// public abstract partial class DrawingCanvas { /// /// Saves the current drawing state and begins an isolated compositing layer over the whole canvas. /// /// The save count after the layer state has been pushed. public int SaveLayer() => this.SaveLayer(new GraphicsOptions(), this.Bounds); /// /// Saves the current drawing state and begins an isolated compositing layer over the whole canvas. /// /// Graphics options controlling how the layer is composited on restore. /// The save count after the layer state has been pushed. public int SaveLayer(GraphicsOptions layerOptions) => this.SaveLayer(layerOptions, this.Bounds); /// /// Fills the whole canvas using the given brush. /// /// Brush used to shade destination pixels. public void Fill(Brush brush) { Rectangle bounds = this.Bounds; this.Fill(brush, new RectanglePolygon(bounds)); } /// /// Fills a local region using the given brush. /// /// Brush used to shade destination pixels. /// Region to fill in local coordinates. public void Fill(Brush brush, Rectangle region) => this.Fill(brush, new RectanglePolygon(region)); /// /// Clears the whole canvas using the given brush and clear-style composition options. /// /// Brush used to shade destination pixels during clear. public void Clear(Brush brush) { Rectangle bounds = this.Bounds; this.Clear(brush, new RectanglePolygon(bounds)); } /// /// Clears a local region using the given brush and clear-style composition options. /// /// Brush used to shade destination pixels during clear. /// Region to clear in local coordinates. public void Clear(Brush brush, Rectangle region) => this.Clear(brush, new RectanglePolygon(region)); /// /// Fills all paths in a collection using the given brush. /// /// Brush used to shade covered pixels. /// Path collection to fill. public void Fill(Brush brush, IPathCollection paths) { Guard.NotNull(paths, nameof(paths)); foreach (IPath path in paths) { this.Fill(brush, path); } } /// /// Fills a path built by the provided builder using the given brush. /// /// Brush used to shade covered pixels. /// The path builder describing the fill region. public void Fill(Brush brush, PathBuilder pathBuilder) { Guard.NotNull(pathBuilder, nameof(pathBuilder)); this.Fill(brush, pathBuilder.Build()); } /// /// Fills an ellipse using the provided brush. /// /// Brush used to shade covered pixels. /// Ellipse center point in local coordinates. /// Ellipse width and height in local coordinates. public void FillEllipse(Brush brush, PointF center, SizeF size) => this.Fill(brush, new EllipsePolygon(center, size)); /// /// Fills the closed arc shape produced by joining the arc endpoints with a straight line. /// /// Brush used to shade covered pixels. /// Arc center point in local coordinates. /// Arc radii in local coordinates. /// Ellipse rotation in degrees. /// Arc start angle in degrees. /// Arc sweep angle in degrees. public void FillArc(Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) => this.Fill(brush, new Path(new ArcLineSegment(center, radius, rotation, startAngle, sweepAngle))); /// /// Fills a pie sector using the provided brush. /// /// Brush used to shade covered pixels. /// The center point of the pie sector in local coordinates. /// The x and y radii of the pie sector in local coordinates. /// Ellipse rotation in degrees. /// The start angle of the pie sector in degrees. /// The sweep angle of the pie sector in degrees. public void FillPie(Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) => this.Fill(brush, new PiePolygon(center, radius, rotation, startAngle, sweepAngle)); /// /// Fills a pie sector using the provided brush. /// /// Brush used to shade covered pixels. /// The center point of the pie sector in local coordinates. /// The x and y radii of the pie sector in local coordinates. /// The start angle of the pie sector in degrees. /// The sweep angle of the pie sector in degrees. public void FillPie(Brush brush, PointF center, SizeF radius, float startAngle, float sweepAngle) => this.Fill(brush, new PiePolygon(center, radius, startAngle, sweepAngle)); /// /// Draws an arc outline using the provided pen. /// /// Pen used to generate the arc outline. /// Arc center point in local coordinates. /// Arc radii in local coordinates. /// Ellipse rotation in degrees. /// Arc start angle in degrees. /// Arc sweep angle in degrees. public void DrawArc(Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) => this.Draw(pen, new Path(new ArcLineSegment(center, radius, rotation, startAngle, sweepAngle))); /// /// Draws a cubic bezier outline using the provided pen. /// /// Pen used to generate the bezier outline. /// Bezier control points. public void DrawBezier(Pen pen, params PointF[] points) { Guard.NotNull(points, nameof(points)); this.Draw(pen, new Path(new CubicBezierLineSegment(points))); } /// /// Draws an ellipse outline using the provided pen. /// /// Pen used to generate the ellipse outline. /// Ellipse center point in local coordinates. /// Ellipse width and height in local coordinates. public void DrawEllipse(Pen pen, PointF center, SizeF size) => this.Draw(pen, new EllipsePolygon(center, size)); /// /// Draws a pie sector outline using the provided pen. /// /// Pen used to generate the pie outline. /// The center point of the pie sector in local coordinates. /// The x and y radii of the pie sector in local coordinates. /// Ellipse rotation in degrees. /// The start angle of the pie sector in degrees. /// The sweep angle of the pie sector in degrees. public void DrawPie(Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) => this.Draw(pen, new PiePolygon(center, radius, rotation, startAngle, sweepAngle)); /// /// Draws a pie sector outline using the provided pen. /// /// Pen used to generate the pie outline. /// The center point of the pie sector in local coordinates. /// The x and y radii of the pie sector in local coordinates. /// The start angle of the pie sector in degrees. /// The sweep angle of the pie sector in degrees. public void DrawPie(Pen pen, PointF center, SizeF radius, float startAngle, float sweepAngle) => this.Draw(pen, new PiePolygon(center, radius, startAngle, sweepAngle)); /// /// Draws a rectangular outline using the provided pen. /// /// Pen used to generate the rectangle outline. /// Rectangle region to stroke. public void Draw(Pen pen, Rectangle region) => this.Draw(pen, new RectanglePolygon(region)); /// /// Draws all paths in a collection using the provided pen. /// /// Pen used to generate outlines. /// Path collection to stroke. public void Draw(Pen pen, IPathCollection paths) { Guard.NotNull(paths, nameof(paths)); foreach (IPath path in paths) { this.Draw(pen, path); } } /// /// Draws a path outline built by the provided builder using the given pen. /// /// Pen used to generate the outline fill path. /// The path builder describing the path to stroke. public void Draw(Pen pen, PathBuilder pathBuilder) { Guard.NotNull(pathBuilder, nameof(pathBuilder)); this.Draw(pen, pathBuilder.Build()); } } }