11import { Canvas } from "./canvas" ;
22
3+ /**
4+ * Provides a rendering context, partly compatible with the official `CanvasRenderingContext2D`, for drawing shapes on a `Canvas`.
5+ */
36export interface CanvasContext {
7+ /**
8+ * Gets the canvas for which the context was created.
9+ */
410 readonly canvas : Canvas ;
11+ /**
12+ * Specifies the fill color that is used when the fill method is called. Allowed values are:
13+ * - 32 bit integers on the format 0xRRGGBBAA
14+ * - strings on the format `"#RGB"`
15+ * - strings on the format `"#RGBA"`
16+ * - strings on the format `"#RRGGBB"`
17+ * - strings on the format `"#RRGGBBAA"`
18+ * - strings on the format `"rgb(255, 255, 255)"`
19+ * - strings on the format `"rgb(255, 255, 255, 0.5)"`
20+ * - strings on the format `"rgb(255, 255, 255, 50%)"`
21+ * - strings on the format `"rgba(255, 255, 255, 0.5)"`
22+ * - strings on the format `"rgba(255, 255, 255, 50%)"`
23+ * - strings on the format `"hsl(134, 50%, 50%)"`
24+ * - strings on the format `"hsl(134, 50%, 50%, 0.5)"`
25+ * - strings on the format `"hsl(134, 50%, 50%, 50%)"`
26+ * - strings on the format `"hsla(134, 50%, 50%, 0.5)"`
27+ * - strings on the format `"hsla(134, 50%, 50%, 50%)"`
28+ * - strings on the format `"hwb(134, 50%, 50%)"`
29+ * - strings on the format `"hwb(134, 50%, 50%, 0.5)"`
30+ * - strings on the format `"hwb(134, 50%, 50%, 50%)"`
31+ */
532 fillStyle : number | string ;
33+ /**
34+ * Saves the current drawing state to a stack. The state can later be restored by calling `CanvasContext.restore()`.
35+ *
36+ * The following state is included when being saved to the stack:
37+ * - Current transformation matrix
38+ * - Current fill style
39+ */
640 save ( ) : void ;
41+ /**
42+ * Restores the last drawing state that was saved with `CanvasContext.save()`, and then removes it from the state stack.
43+ */
744 restore ( ) : void ;
45+ /**
46+ * Restores the current transformation to the identity matrix.
47+ */
848 resetTransform ( ) : void ;
49+ /**
50+ * Multiplies the current transformation matrix with the specified values.
51+ */
952 transform (
1053 a : number ,
1154 b : number ,
@@ -14,6 +57,9 @@ export interface CanvasContext {
1457 e : number ,
1558 f : number
1659 ) : void ;
60+ /**
61+ * Sets the transformation matrix to the specified matrix.
62+ */
1763 setTransform (
1864 a : number ,
1965 b : number ,
@@ -22,13 +68,52 @@ export interface CanvasContext {
2268 e : number ,
2369 f : number
2470 ) : void ;
71+ /**
72+ * Applies a translation transformation on top of the current transform.
73+ * @param x Distance to move in the horizontal direction in pixels.
74+ * @param y Distance to move in the vertical direction in pixels.
75+ */
2576 translate ( x : number , y : number ) : void ;
77+ /**
78+ * Applies a scale transformation on top of the current transform.
79+ * @param x Scale in the horizontal direction. `1` means no horizontal scaling.
80+ * @param y Scale in the vertical direction. `1` means no vertical scaling.
81+ */
2682 scale ( x : number , y : number ) : void ;
83+ /**
84+ * Applies a rotation transformation on top of the current transform around the current canvas origo.
85+ * @param angle Angle in radians measured clockwise from the positive x axis.
86+ */
2787 rotate ( angle : number ) : void ;
88+ /**
89+ * Removes all existing subpaths and begins a new path.
90+ */
2891 beginPath ( ) : void ;
92+ /**
93+ * Starts a new subpath that begins in the same point as the start and end point of the previous one.
94+ */
2995 closePath ( ) : void ;
96+ /**
97+ * Begins a new subpath by moving the cursor to the specified position.
98+ * @param x X coordinate.
99+ * @param y Y coordinate.
100+ */
30101 moveTo ( x : number , y : number ) : void ;
102+ /**
103+ * Inserts an edge between the last and specified position.
104+ * @param x Target X coordinate.
105+ * @param y Target Y coordinate.
106+ */
31107 lineTo ( x : number , y : number ) : void ;
108+ /**
109+ * Adds an arc to the current path.
110+ * @param x X coordinate of the center of the arc.
111+ * @param y Y coordinate of the center of the arc.
112+ * @param radius Radius of the arc.
113+ * @param startAngle The angle in radians at which the arc starts, measured clockwise from the positive x axis.
114+ * @param endAngle The angle in radians at which the arc end, measured clockwise from the positive x axis.
115+ * @param anticlockwise Specifies whether the arc will be drawn counter clockwise. Default is clockwise.
116+ */
32117 arc (
33118 x : number ,
34119 y : number ,
@@ -37,7 +122,26 @@ export interface CanvasContext {
37122 endAngle : number ,
38123 anticlockwise ?: boolean
39124 ) : void ;
125+ /**
126+ * Fills a specified rectangle with fully transparent black without blending with the background or affecting the current paths.
127+ * @param x X coordinate of the left side of the rectangle.
128+ * @param y Y coordinate of the top of the rectangle.
129+ * @param width Width of the rectangle.
130+ * @param height Height of the rectangle.
131+ */
40132 clearRect ( x : number , y : number , width : number , height : number ) : void ;
133+ /**
134+ * Fills a specified rectangle without affecting the current paths.
135+ * @param x X coordinate of the left side of the rectangle.
136+ * @param y Y coordinate of the top of the rectangle.
137+ * @param width Width of the rectangle.
138+ * @param height Height of the rectangle.
139+ */
41140 fillRect ( x : number , y : number , width : number , height : number ) : void ;
141+ /**
142+ * Fills the defined paths.
143+ * @param windingRule The winding rule to be used for determining
144+ * which areas are covered by the current path. Default is `"nonzero"`.
145+ */
42146 fill ( windingRule ?: "nonzero" | "evenodd" ) : void ;
43147}
0 commit comments