-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ICanvas.cs
360 lines (314 loc) · 15.4 KB
/
ICanvas.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
using System.Numerics;
using Microsoft.Maui.Graphics.Text;
namespace Microsoft.Maui.Graphics
{
/// <summary>
/// Represents a platform-agnostic canvas on which 2D graphics can be drawn using types from the <see cref="Microsoft.Maui.Graphics"/> namespace.
/// </summary>
public interface ICanvas
{
/// <summary>
/// Gets or sets a value that represents the scaling factor to scale the UI by.
/// </summary>
public float DisplayScale { get; set; }
/// <summary>
/// Sets the width of the stroke used to draw an object's outline.
/// </summary>
public float StrokeSize { set; }
/// <summary>
/// Sets the limit of the miter length of line joins in an object.
/// </summary>
public float MiterLimit { set; }
/// <summary>
/// Sets the <see cref="Color"/> used to paint an object's outline.
/// </summary>
public Color StrokeColor { set; }
/// <summary>
/// Sets the shape at the start and end of a line.
/// </summary>
public LineCap StrokeLineCap { set; }
/// <summary>
/// Sets the type of join used at the vertices of a shape.
/// </summary>
public LineJoin StrokeLineJoin { set; }
/// <summary>
/// Sets the pattern of dashes and gaps that are used to outline an object.
/// </summary>
public float[] StrokeDashPattern { set; }
/// <summary>
/// Sets the distance within the dash pattern where a dash begins.
/// </summary>
public float StrokeDashOffset { set; }
/// <summary>
/// Sets the color used to paint an object's interior.
/// </summary>
public Color FillColor { set; }
/// <summary>
/// Sets the font color when drawing text.
/// </summary>
public Color FontColor { set; }
/// <summary>
/// Sets the font used when drawing text.
/// </summary>
public IFont Font { set; }
/// <summary>
/// Sets the size of the font used when drawing text.
/// </summary>
public float FontSize { set; }
/// <summary>
/// Sets the opacity of am object.
/// </summary>
public float Alpha { set; }
/// <summary>
/// Sets a value that indicates whether to use anti-aliasing is enabled.
/// </summary>
public bool Antialias { set; }
/// <summary>
/// Sets the blend mode, which determines what happens when an object is rendered on top of an existing object.
/// </summary>
public BlendMode BlendMode { set; }
/// <summary>
/// Draws the specified <paramref name="path"/> onto the canvas.
/// </summary>
/// <param name="path">The path to be drawn.</param>
public void DrawPath(PathF path);
/// <summary>
/// Draws and fills the specified <paramref name="path"/> onto the canvas.
/// </summary>
/// <param name="path">The path to be drawn.</param>
/// <param name="windingMode">The fill algorithm to be used.</param>
public void FillPath(PathF path, WindingMode windingMode);
/// <summary>
/// Clips an object so that only the area outside the of a rectangle will be visible.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate of the rectangle.</param>
/// <param name="y">Starting <c>y</c> coordinate of the rectangle.</param>
/// <param name="width">Width of the rectangle.</param>
/// <param name="height">Height of the rectangle.</param>
public void SubtractFromClip(float x, float y, float width, float height);
/// <summary>
/// Clips an object so that only the area outside of a <see cref="PathF"/> object will be visible.
/// </summary>
/// <param name="path">The path used to clip the object</param>
/// <param name="windingMode">Fill algorithm used for the path. Default is <see cref="WindingMode.NonZero"/>.</param>
public void ClipPath(PathF path, WindingMode windingMode = WindingMode.NonZero);
/// <summary>
/// Clips an object so that only the area that's within the region of the rectangle will be visible.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate of the rectangle.</param>
/// <param name="y">Starting <c>y</c> coordinate of the rectangle.</param>
/// <param name="width">Width of the rectangle.</param>
/// <param name="height">Height of the rectangle.</param>
public void ClipRectangle(float x, float y, float width, float height);
/// <summary>
/// Draws a line between two points onto the canvas.
/// </summary>
/// <param name="x1">Starting <c>x</c> coordinate.</param>
/// <param name="y1">Starting <c>y</c> coordinate.</param>
/// <param name="x2">Ending <c>x</c> coordinate.</param>
/// <param name="y2">Ending <c>x</c> coordinate.</param>
public void DrawLine(float x1, float y1, float x2, float y2);
/// <summary>
/// Draws an arc onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the arc.</param>
/// <param name="height">Height of the arc.</param>
/// <param name="startAngle">The angle from the x-axis to the start point of the arc.</param>
/// <param name="endAngle">The angle from the x-axis to the end point of the arc.</param>
/// <param name="clockwise"><see langword="true"/> to draw the arc in a clockwise direction; <see langword="false"/> to draw the arc counterclockwise.</param>
/// <param name="closed"><see langword="true"/> to specify whether the end point of the arc will be connected to the start point; <see langword="false"/> otherwise.</param>
public void DrawArc(float x, float y, float width, float height, float startAngle, float endAngle, bool clockwise, bool closed);
/// <summary>
/// Draws a filled arc onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the arc.</param>
/// <param name="height">Height of the arc.</param>
/// <param name="startAngle">The angle from the x-axis to the start point of the arc.</param>
/// <param name="endAngle">The angle from the x-axis to the end point of the arc.</param>
/// <param name="clockwise"><see langword="true"/> to draw the arc in a clockwise direction; <see langword="false"/> to draw the arc counterclockwise.</param>
public void FillArc(float x, float y, float width, float height, float startAngle, float endAngle, bool clockwise);
/// <summary>
/// Draws a rectangle onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the rectangle.</param>
/// <param name="height">Height of the rectangle.</param>
public void DrawRectangle(float x, float y, float width, float height);
/// <summary>
/// Draws a filled rectangle onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the rectangle.</param>
/// <param name="height">Height of the rectangle.</param>
public void FillRectangle(float x, float y, float width, float height);
/// <summary>
/// Draws a rectangle with rounded corners onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the rectangle.</param>
/// <param name="height">Height of the rectangle.</param>
/// <param name="cornerRadius">The radius used to round the corners of the rectangle.</param>
public void DrawRoundedRectangle(float x, float y, float width, float height, float cornerRadius);
/// <summary>
/// Draws a filled rectangle with rounded corners onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the rectangle.</param>
/// <param name="height">Height of the rectangle.</param>
/// <param name="cornerRadius">The radius used to round the corners of the rectangle.</param>
public void FillRoundedRectangle(float x, float y, float width, float height, float cornerRadius);
/// <summary>
/// Draws an ellipse onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the ellipse.</param>
/// <param name="height">Height of the ellipse.</param>
public void DrawEllipse(float x, float y, float width, float height);
/// <summary>
/// Draws a filled ellipse onto the canvas.
/// </summary>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="width">Width of the ellipse.</param>
/// <param name="height">Height of the ellipse.</param>
public void FillEllipse(float x, float y, float width, float height);
/// <summary>
/// Draws a text string onto the canvas.
/// </summary>
/// <remarks>To draw attributed text, use <see cref="DrawText(IAttributedText, float, float, float, float)"/> instead.</remarks>
/// <param name="value">Text to be displayed.</param>
/// <param name="x">Starting <c>x</c> coordinate.</param>
/// <param name="y">Starting <c>y</c> coordinate.</param>
/// <param name="horizontalAlignment">Horizontal alignment options to align the string.</param>
public void DrawString(string value, float x, float y, HorizontalAlignment horizontalAlignment);
/// <summary>
/// Draws a text string within a bounding box onto the canvas.
/// </summary>
/// <param name="value">Text to be displayed.</param>
/// <param name="x">Starting <c>x</c> coordinate of the bounding box.</param>
/// <param name="y">Starting <c>y</c> coordinate of the bounding box.</param>
/// <param name="width">Width of the bounding box.</param>
/// <param name="height">Height of the bounding box.</param>
/// <param name="horizontalAlignment">Horizontal alignment options to align the string within the bounding box.</param>
/// <param name="verticalAlignment">Vertical alignment options to align the string within the bounding box.</param>
/// <param name="textFlow">Specifies whether text will be clipped in case it overflows the bounding box. Default is <see cref="TextFlow.ClipBounds"/>.</param>
/// <param name="lineSpacingAdjustment">Spacing adjustment between lines. Default is 0.</param>
public void DrawString(
string value,
float x,
float y,
float width,
float height,
HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment,
TextFlow textFlow = TextFlow.ClipBounds,
float lineSpacingAdjustment = 0);
/// <summary>
/// Draws attributed text within a bounding box onto the canvas.
/// </summary>
/// <param name="value">Attributed text to be displayed.</param>
/// <param name="x">Starting <c>x</c> coordinate of the bounding box.</param>
/// <param name="y">Starting <c>y</c> coordinate of the bounding box.</param>
/// <param name="width">Width of the bounding box.</param>
/// <param name="height">Height of the bounding box.</param>
public void DrawText(
IAttributedText value,
float x,
float y,
float width,
float height);
/// <summary>
/// Rotates a graphical object around a point.
/// </summary>
/// <remarks>Rotation is clockwise for increasing angles. Negative angles and angles greater than 360 are allowed.</remarks>
/// <param name="degrees">Rotation angle.</param>
/// <param name="x"><c>x</c> coordinate of the rotation point.</param>
/// <param name="y"><c>y</c> coordinate of the rotation point.</param>
public void Rotate(float degrees, float x, float y);
/// <summary>
/// Rotates a graphical object around the upper-left corner of the canvas (0,0).
/// </summary>
/// <remarks>Rotation is clockwise for increasing angles. Negative angles and angles greater than 360 are allowed.</remarks>
public void Rotate(float degrees);
/// <summary>
/// Changes the size of a graphical object by scaling it.
/// </summary>
/// <remarks>Can cause starting coordinates to move when an object is made larger.</remarks>
/// <param name="sx">Value for horizontal scaling.</param>
/// <param name="sy">Value for vertical scaling.</param>
public void Scale(float sx, float sy);
/// <summary>
/// Shifts a graphical object in horizontal and vertical directions.
/// </summary>
/// <param name="tx">Horizontal shift. Negative values move the object to the left, while positive values move it to the right.</param>
/// <param name="ty">Vertical shift. Negative values move the object down, while positive values move it up.</param>
public void Translate(float tx, float ty);
/// <summary>
/// Applies transformation specified by <paramref name="transform"/> to a graphical object.
/// </summary>
/// <param name="transform">Affine transformation matrix.</param>
public void ConcatenateTransform(Matrix3x2 transform);
/// <summary>
/// Saves the current graphics state.
/// </summary>
public void SaveState();
/// <summary>
/// Restores the graphics state to the most recently saved state.
/// </summary>
/// <returns><see langword="true"/> if the restore was succesful, <see langword="false"/> otherwise.</returns>
public bool RestoreState();
/// <summary>
/// Resets the graphics state to its default values.
/// </summary>
public void ResetState();
/// <summary>
/// Adds a shadow to a graphical object.
/// </summary>
/// <param name="offset">Represents the position of a light source that creates the shadow.</param>
/// <param name="blur">Amount of blur to apply to the shadow.</param>
/// <param name="color">Color of the shadow.</param>
public void SetShadow(SizeF offset, float blur, Color color);
/// <summary>
/// Sets <paramref name="paint"/> as the fill of a graphical object.
/// </summary>
/// <param name="paint">Paint to set as fill</param>
/// <param name="rectangle">Rectangle to apply a gradient on if the <paramref name="paint"/> supports it.</param>
public void SetFillPaint(Paint paint, RectF rectangle);
/// <summary>
/// Draws an image onto the canvas.
/// </summary>
/// <param name="image">Image to display</param>
/// <param name="x">Top left corner <c>x</c> coordinate.</param>
/// <param name="y">Top left corner <c>y</c> coordinate.</param>
/// <param name="width">Width of the image.</param>
/// <param name="height">Height of the image.</param>
public void DrawImage(IImage image, float x, float y, float width, float height);
/// <summary>
/// Calculates the area a string would occupy if drawn on the canvas.
/// </summary>
/// <param name="value">String to calculate the size on.</param>
/// <param name="font">The string's font type.</param>
/// <param name="fontSize">The string's font size.</param>
/// <returns>The area the string would occupy on the canvas.</returns>
public SizeF GetStringSize(string value, IFont font, float fontSize);
/// <summary>
/// Calculates the area a string would occupy if drawn on the canvas.
/// </summary>
/// <param name="value">String to calculate the size on.</param>
/// <param name="font">The string's font type.</param>
/// <param name="fontSize">The string's font size.</param>
/// <param name="horizontalAlignment">Horizontal alignment options for the string.</param>
/// <param name="verticalAlignment">Vertical alignment options for the string.</param>
/// <returns>The area the string would occupy on the canvas.</returns>
public SizeF GetStringSize(string value, IFont font, float fontSize, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment);
}
}