|
3 | 3 |
|
4 | 4 | namespace SixLabors.ImageSharp.Drawing.Processing; |
5 | 5 |
|
6 | | -/// <summary> |
7 | | -/// Convenience canvas helpers that forward to the core <see cref="DrawingCanvas"/> primitives. |
8 | | -/// </summary> |
9 | | -public static class DrawingCanvasShapeExtensions |
| 6 | +/// <content> |
| 7 | +/// Convenience shape helpers that forward to the core <see cref="DrawingCanvas"/> primitives. |
| 8 | +/// </content> |
| 9 | +public abstract partial class DrawingCanvas |
10 | 10 | { |
11 | 11 | /// <summary> |
12 | 12 | /// Saves the current drawing state and begins an isolated compositing layer over the whole canvas. |
13 | 13 | /// </summary> |
14 | | - /// <param name="canvas">The destination canvas.</param> |
15 | 14 | /// <returns>The save count after the layer state has been pushed.</returns> |
16 | | - public static int SaveLayer(this DrawingCanvas canvas) |
17 | | - => canvas.SaveLayer(new GraphicsOptions(), canvas.Bounds); |
| 15 | + public int SaveLayer() |
| 16 | + => this.SaveLayer(new GraphicsOptions(), this.Bounds); |
18 | 17 |
|
19 | 18 | /// <summary> |
20 | 19 | /// Saves the current drawing state and begins an isolated compositing layer over the whole canvas. |
21 | 20 | /// </summary> |
22 | | - /// <param name="canvas">The destination canvas.</param> |
23 | 21 | /// <param name="layerOptions">Graphics options controlling how the layer is composited on restore.</param> |
24 | 22 | /// <returns>The save count after the layer state has been pushed.</returns> |
25 | | - public static int SaveLayer(this DrawingCanvas canvas, GraphicsOptions layerOptions) |
26 | | - => canvas.SaveLayer(layerOptions, canvas.Bounds); |
| 23 | + public int SaveLayer(GraphicsOptions layerOptions) |
| 24 | + => this.SaveLayer(layerOptions, this.Bounds); |
27 | 25 |
|
28 | 26 | /// <summary> |
29 | 27 | /// Fills the whole canvas using the given brush. |
30 | 28 | /// </summary> |
31 | | - /// <param name="canvas">The destination canvas.</param> |
32 | 29 | /// <param name="brush">Brush used to shade destination pixels.</param> |
33 | | - public static void Fill(this DrawingCanvas canvas, Brush brush) |
| 30 | + public void Fill(Brush brush) |
34 | 31 | { |
35 | | - Rectangle bounds = canvas.Bounds; |
36 | | - canvas.Fill(brush, new RectangularPolygon(bounds)); |
| 32 | + Rectangle bounds = this.Bounds; |
| 33 | + |
| 34 | + this.Fill(brush, new RectangularPolygon(bounds)); |
37 | 35 | } |
38 | 36 |
|
39 | 37 | /// <summary> |
40 | 38 | /// Fills a local region using the given brush. |
41 | 39 | /// </summary> |
42 | | - /// <param name="canvas">The destination canvas.</param> |
43 | 40 | /// <param name="brush">Brush used to shade destination pixels.</param> |
44 | 41 | /// <param name="region">Region to fill in local coordinates.</param> |
45 | | - public static void Fill(this DrawingCanvas canvas, Brush brush, Rectangle region) |
46 | | - => canvas.Fill(brush, new RectangularPolygon(region)); |
| 42 | + public void Fill(Brush brush, Rectangle region) |
| 43 | + => this.Fill(brush, new RectangularPolygon(region)); |
47 | 44 |
|
48 | 45 | /// <summary> |
49 | 46 | /// Clears the whole canvas using the given brush and clear-style composition options. |
50 | 47 | /// </summary> |
51 | | - /// <param name="canvas">The destination canvas.</param> |
52 | 48 | /// <param name="brush">Brush used to shade destination pixels during clear.</param> |
53 | | - public static void Clear(this DrawingCanvas canvas, Brush brush) |
| 49 | + public void Clear(Brush brush) |
54 | 50 | { |
55 | | - Rectangle bounds = canvas.Bounds; |
56 | | - canvas.Clear(brush, new RectangularPolygon(bounds)); |
| 51 | + Rectangle bounds = this.Bounds; |
| 52 | + |
| 53 | + this.Clear(brush, new RectangularPolygon(bounds)); |
57 | 54 | } |
58 | 55 |
|
59 | 56 | /// <summary> |
60 | 57 | /// Clears a local region using the given brush and clear-style composition options. |
61 | 58 | /// </summary> |
62 | | - /// <param name="canvas">The destination canvas.</param> |
63 | 59 | /// <param name="brush">Brush used to shade destination pixels during clear.</param> |
64 | 60 | /// <param name="region">Region to clear in local coordinates.</param> |
65 | | - public static void Clear(this DrawingCanvas canvas, Brush brush, Rectangle region) |
66 | | - => canvas.Clear(brush, new RectangularPolygon(region)); |
| 61 | + public void Clear(Brush brush, Rectangle region) |
| 62 | + => this.Clear(brush, new RectangularPolygon(region)); |
67 | 63 |
|
68 | 64 | /// <summary> |
69 | 65 | /// Fills all paths in a collection using the given brush. |
70 | 66 | /// </summary> |
71 | | - /// <param name="canvas">The destination canvas.</param> |
72 | 67 | /// <param name="brush">Brush used to shade covered pixels.</param> |
73 | 68 | /// <param name="paths">Path collection to fill.</param> |
74 | | - public static void Fill(this DrawingCanvas canvas, Brush brush, IPathCollection paths) |
| 69 | + public void Fill(Brush brush, IPathCollection paths) |
75 | 70 | { |
76 | 71 | Guard.NotNull(paths, nameof(paths)); |
77 | 72 |
|
78 | 73 | foreach (IPath path in paths) |
79 | 74 | { |
80 | | - canvas.Fill(brush, path); |
| 75 | + this.Fill(brush, path); |
81 | 76 | } |
82 | 77 | } |
83 | 78 |
|
84 | 79 | /// <summary> |
85 | 80 | /// Fills a path built by the provided builder using the given brush. |
86 | 81 | /// </summary> |
87 | | - /// <param name="canvas">The destination canvas.</param> |
88 | 82 | /// <param name="brush">Brush used to shade covered pixels.</param> |
89 | 83 | /// <param name="pathBuilder">The path builder describing the fill region.</param> |
90 | | - public static void Fill(this DrawingCanvas canvas, Brush brush, PathBuilder pathBuilder) |
| 84 | + public void Fill(Brush brush, PathBuilder pathBuilder) |
91 | 85 | { |
92 | 86 | Guard.NotNull(pathBuilder, nameof(pathBuilder)); |
93 | | - canvas.Fill(brush, pathBuilder.Build()); |
| 87 | + |
| 88 | + this.Fill(brush, pathBuilder.Build()); |
94 | 89 | } |
95 | 90 |
|
96 | 91 | /// <summary> |
97 | 92 | /// Fills an ellipse using the provided brush. |
98 | 93 | /// </summary> |
99 | | - /// <param name="canvas">The destination canvas.</param> |
100 | 94 | /// <param name="brush">Brush used to shade covered pixels.</param> |
101 | 95 | /// <param name="center">Ellipse center point in local coordinates.</param> |
102 | 96 | /// <param name="size">Ellipse width and height in local coordinates.</param> |
103 | | - public static void FillEllipse(this DrawingCanvas canvas, Brush brush, PointF center, SizeF size) |
104 | | - => canvas.Fill(brush, new EllipsePolygon(center, size)); |
| 97 | + public void FillEllipse(Brush brush, PointF center, SizeF size) |
| 98 | + => this.Fill(brush, new EllipsePolygon(center, size)); |
105 | 99 |
|
106 | 100 | /// <summary> |
107 | 101 | /// Fills the closed arc shape produced by joining the arc endpoints with a straight line. |
108 | 102 | /// </summary> |
109 | | - /// <param name="canvas">The destination canvas.</param> |
110 | 103 | /// <param name="brush">Brush used to shade covered pixels.</param> |
111 | 104 | /// <param name="center">Arc center point in local coordinates.</param> |
112 | 105 | /// <param name="radius">Arc radii in local coordinates.</param> |
113 | 106 | /// <param name="rotation">Ellipse rotation in degrees.</param> |
114 | 107 | /// <param name="startAngle">Arc start angle in degrees.</param> |
115 | 108 | /// <param name="sweepAngle">Arc sweep angle in degrees.</param> |
116 | | - public static void FillArc(this DrawingCanvas canvas, Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
117 | | - => canvas.Fill(brush, new Path(new ArcLineSegment(center, radius, rotation, startAngle, sweepAngle))); |
| 109 | + public void FillArc(Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
| 110 | + => this.Fill(brush, new Path(new ArcLineSegment(center, radius, rotation, startAngle, sweepAngle))); |
118 | 111 |
|
119 | 112 | /// <summary> |
120 | 113 | /// Fills a pie sector using the provided brush. |
121 | 114 | /// </summary> |
122 | | - /// <param name="canvas">The destination canvas.</param> |
123 | 115 | /// <param name="brush">Brush used to shade covered pixels.</param> |
124 | 116 | /// <param name="center">Pie center point in local coordinates.</param> |
125 | 117 | /// <param name="radius">Pie radii in local coordinates.</param> |
126 | 118 | /// <param name="rotation">Ellipse rotation in degrees.</param> |
127 | 119 | /// <param name="startAngle">Pie start angle in degrees.</param> |
128 | 120 | /// <param name="sweepAngle">Pie sweep angle in degrees.</param> |
129 | | - public static void FillPie(this DrawingCanvas canvas, Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
130 | | - => canvas.Fill(brush, new Pie(center, radius, rotation, startAngle, sweepAngle)); |
| 121 | + public void FillPie(Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
| 122 | + => this.Fill(brush, new Pie(center, radius, rotation, startAngle, sweepAngle)); |
131 | 123 |
|
132 | 124 | /// <summary> |
133 | 125 | /// Fills a pie sector using the provided brush. |
134 | 126 | /// </summary> |
135 | | - /// <param name="canvas">The destination canvas.</param> |
136 | 127 | /// <param name="brush">Brush used to shade covered pixels.</param> |
137 | 128 | /// <param name="center">Pie center point in local coordinates.</param> |
138 | 129 | /// <param name="radius">Pie radii in local coordinates.</param> |
139 | 130 | /// <param name="startAngle">Pie start angle in degrees.</param> |
140 | 131 | /// <param name="sweepAngle">Pie sweep angle in degrees.</param> |
141 | | - public static void FillPie(this DrawingCanvas canvas, Brush brush, PointF center, SizeF radius, float startAngle, float sweepAngle) |
142 | | - => canvas.Fill(brush, new Pie(center, radius, startAngle, sweepAngle)); |
| 132 | + public void FillPie(Brush brush, PointF center, SizeF radius, float startAngle, float sweepAngle) |
| 133 | + => this.Fill(brush, new Pie(center, radius, startAngle, sweepAngle)); |
143 | 134 |
|
144 | 135 | /// <summary> |
145 | 136 | /// Draws an arc outline using the provided pen. |
146 | 137 | /// </summary> |
147 | | - /// <param name="canvas">The destination canvas.</param> |
148 | 138 | /// <param name="pen">Pen used to generate the arc outline.</param> |
149 | 139 | /// <param name="center">Arc center point in local coordinates.</param> |
150 | 140 | /// <param name="radius">Arc radii in local coordinates.</param> |
151 | 141 | /// <param name="rotation">Ellipse rotation in degrees.</param> |
152 | 142 | /// <param name="startAngle">Arc start angle in degrees.</param> |
153 | 143 | /// <param name="sweepAngle">Arc sweep angle in degrees.</param> |
154 | | - public static void DrawArc(this DrawingCanvas canvas, Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
155 | | - => canvas.Draw(pen, new Path(new ArcLineSegment(center, radius, rotation, startAngle, sweepAngle))); |
| 144 | + public void DrawArc(Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
| 145 | + => this.Draw(pen, new Path(new ArcLineSegment(center, radius, rotation, startAngle, sweepAngle))); |
156 | 146 |
|
157 | 147 | /// <summary> |
158 | 148 | /// Draws a cubic bezier outline using the provided pen. |
159 | 149 | /// </summary> |
160 | | - /// <param name="canvas">The destination canvas.</param> |
161 | 150 | /// <param name="pen">Pen used to generate the bezier outline.</param> |
162 | 151 | /// <param name="points">Bezier control points.</param> |
163 | | - public static void DrawBezier(this DrawingCanvas canvas, Pen pen, params PointF[] points) |
| 152 | + public void DrawBezier(Pen pen, params PointF[] points) |
164 | 153 | { |
165 | 154 | Guard.NotNull(points, nameof(points)); |
166 | | - canvas.Draw(pen, new Path(new CubicBezierLineSegment(points))); |
| 155 | + |
| 156 | + this.Draw(pen, new Path(new CubicBezierLineSegment(points))); |
167 | 157 | } |
168 | 158 |
|
169 | 159 | /// <summary> |
170 | 160 | /// Draws an ellipse outline using the provided pen. |
171 | 161 | /// </summary> |
172 | | - /// <param name="canvas">The destination canvas.</param> |
173 | 162 | /// <param name="pen">Pen used to generate the ellipse outline.</param> |
174 | 163 | /// <param name="center">Ellipse center point in local coordinates.</param> |
175 | 164 | /// <param name="size">Ellipse width and height in local coordinates.</param> |
176 | | - public static void DrawEllipse(this DrawingCanvas canvas, Pen pen, PointF center, SizeF size) |
177 | | - => canvas.Draw(pen, new EllipsePolygon(center, size)); |
| 165 | + public void DrawEllipse(Pen pen, PointF center, SizeF size) |
| 166 | + => this.Draw(pen, new EllipsePolygon(center, size)); |
178 | 167 |
|
179 | 168 | /// <summary> |
180 | 169 | /// Draws a pie sector outline using the provided pen. |
181 | 170 | /// </summary> |
182 | | - /// <param name="canvas">The destination canvas.</param> |
183 | 171 | /// <param name="pen">Pen used to generate the pie outline.</param> |
184 | 172 | /// <param name="center">Pie center point in local coordinates.</param> |
185 | 173 | /// <param name="radius">Pie radii in local coordinates.</param> |
186 | 174 | /// <param name="rotation">Ellipse rotation in degrees.</param> |
187 | 175 | /// <param name="startAngle">Pie start angle in degrees.</param> |
188 | 176 | /// <param name="sweepAngle">Pie sweep angle in degrees.</param> |
189 | | - public static void DrawPie(this DrawingCanvas canvas, Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
190 | | - => canvas.Draw(pen, new Pie(center, radius, rotation, startAngle, sweepAngle)); |
| 177 | + public void DrawPie(Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) |
| 178 | + => this.Draw(pen, new Pie(center, radius, rotation, startAngle, sweepAngle)); |
191 | 179 |
|
192 | 180 | /// <summary> |
193 | 181 | /// Draws a pie sector outline using the provided pen. |
194 | 182 | /// </summary> |
195 | | - /// <param name="canvas">The destination canvas.</param> |
196 | 183 | /// <param name="pen">Pen used to generate the pie outline.</param> |
197 | 184 | /// <param name="center">Pie center point in local coordinates.</param> |
198 | 185 | /// <param name="radius">Pie radii in local coordinates.</param> |
199 | 186 | /// <param name="startAngle">Pie start angle in degrees.</param> |
200 | 187 | /// <param name="sweepAngle">Pie sweep angle in degrees.</param> |
201 | | - public static void DrawPie(this DrawingCanvas canvas, Pen pen, PointF center, SizeF radius, float startAngle, float sweepAngle) |
202 | | - => canvas.Draw(pen, new Pie(center, radius, startAngle, sweepAngle)); |
| 188 | + public void DrawPie(Pen pen, PointF center, SizeF radius, float startAngle, float sweepAngle) |
| 189 | + => this.Draw(pen, new Pie(center, radius, startAngle, sweepAngle)); |
203 | 190 |
|
204 | 191 | /// <summary> |
205 | 192 | /// Draws a rectangular outline using the provided pen. |
206 | 193 | /// </summary> |
207 | | - /// <param name="canvas">The destination canvas.</param> |
208 | 194 | /// <param name="pen">Pen used to generate the rectangle outline.</param> |
209 | 195 | /// <param name="region">Rectangle region to stroke.</param> |
210 | | - public static void Draw(this DrawingCanvas canvas, Pen pen, Rectangle region) |
211 | | - => canvas.Draw(pen, new RectangularPolygon(region)); |
| 196 | + public void Draw(Pen pen, Rectangle region) |
| 197 | + => this.Draw(pen, new RectangularPolygon(region)); |
212 | 198 |
|
213 | 199 | /// <summary> |
214 | 200 | /// Draws all paths in a collection using the provided pen. |
215 | 201 | /// </summary> |
216 | | - /// <param name="canvas">The destination canvas.</param> |
217 | 202 | /// <param name="pen">Pen used to generate outlines.</param> |
218 | 203 | /// <param name="paths">Path collection to stroke.</param> |
219 | | - public static void Draw(this DrawingCanvas canvas, Pen pen, IPathCollection paths) |
| 204 | + public void Draw(Pen pen, IPathCollection paths) |
220 | 205 | { |
221 | 206 | Guard.NotNull(paths, nameof(paths)); |
222 | 207 |
|
223 | 208 | foreach (IPath path in paths) |
224 | 209 | { |
225 | | - canvas.Draw(pen, path); |
| 210 | + this.Draw(pen, path); |
226 | 211 | } |
227 | 212 | } |
228 | 213 |
|
229 | 214 | /// <summary> |
230 | 215 | /// Draws a path outline built by the provided builder using the given pen. |
231 | 216 | /// </summary> |
232 | | - /// <param name="canvas">The destination canvas.</param> |
233 | 217 | /// <param name="pen">Pen used to generate the outline fill path.</param> |
234 | 218 | /// <param name="pathBuilder">The path builder describing the path to stroke.</param> |
235 | | - public static void Draw(this DrawingCanvas canvas, Pen pen, PathBuilder pathBuilder) |
| 219 | + public void Draw(Pen pen, PathBuilder pathBuilder) |
236 | 220 | { |
237 | 221 | Guard.NotNull(pathBuilder, nameof(pathBuilder)); |
238 | | - canvas.Draw(pen, pathBuilder.Build()); |
| 222 | + |
| 223 | + this.Draw(pen, pathBuilder.Build()); |
239 | 224 | } |
240 | 225 | } |
0 commit comments