• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef C_INCLUDE_DRAWING_H
17 #define C_INCLUDE_DRAWING_H
18 
19 /**
20  * @addtogroup Drawing
21  * @{
22  *
23  * @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
24  *
25  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
26  *
27  * @since 8
28  * @version 1.0
29  */
30 
31 /**
32  * @file drawing_canvas.h
33  *
34  * @brief Declares functions related to the <b>canvas</b> object in the drawing module.
35  *
36  * @since 8
37  * @version 1.0
38  */
39 
40 #include "drawing_types.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Creates an <b>OH_Drawing_Canvas</b> object.
48  *
49  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
50  * @return Returns the pointer to the <b>OH_Drawing_Canvas</b> object created.
51  * @since 8
52  * @version 1.0
53  */
54 OH_Drawing_Canvas* OH_Drawing_CanvasCreate(void);
55 
56 /**
57  * @brief Destroys an <b>OH_Drawing_Canvas</b> object and reclaims the memory occupied by the object.
58  *
59  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
60  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
61  * @since 8
62  * @version 1.0
63  */
64 void OH_Drawing_CanvasDestroy(OH_Drawing_Canvas*);
65 
66 /**
67  * @brief Binds a bitmap to a canvas so that the content drawn on the canvas
68  * is output to the bitmap (this process is called CPU rendering).
69  *
70  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
71  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
72  * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object.
73  * @since 8
74  * @version 1.0
75  */
76 void OH_Drawing_CanvasBind(OH_Drawing_Canvas*, OH_Drawing_Bitmap*);
77 
78 /**
79  * @brief Attaches a pen to a canvas so that the canvas will use the style and color of the pen to outline a shape.
80  *
81  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
82  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
83  * @param OH_Drawing_Pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object.
84  * @since 8
85  * @version 1.0
86  */
87 void OH_Drawing_CanvasAttachPen(OH_Drawing_Canvas*, const OH_Drawing_Pen*);
88 
89 /**
90  * @brief Detaches the pen from a canvas so that the canvas will not use the style
91  * and color of the pen to outline a shape.
92  *
93  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
94  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
95  * @since 8
96  * @version 1.0
97  */
98 void OH_Drawing_CanvasDetachPen(OH_Drawing_Canvas*);
99 
100 /**
101  * @brief Attaches a brush to a canvas so that the canvas will use the style and color of the brush to fill in a shape.
102  *
103  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
104  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
105  * @param OH_Drawing_Brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object.
106  * @since 8
107  * @version 1.0
108  */
109 void OH_Drawing_CanvasAttachBrush(OH_Drawing_Canvas*, const OH_Drawing_Brush*);
110 
111 /**
112  * @brief Detaches the brush from a canvas so that the canvas will not use the style
113  * and color of the brush to fill in a shape.
114  *
115  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
116  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
117  * @since 8
118  * @version 1.0
119  */
120 void OH_Drawing_CanvasDetachBrush(OH_Drawing_Canvas*);
121 
122 /**
123  * @brief Saves the current canvas status (canvas matrix) to the top of the stack.
124  *
125  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
126  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
127  * @since 8
128  * @version 1.0
129  */
130 void OH_Drawing_CanvasSave(OH_Drawing_Canvas*);
131 
132 /**
133  * @brief Restores the canvas status (canvas matrix) saved on the top of the stack.
134  *
135  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
136  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
137  * @since 8
138  * @version 1.0
139  */
140 void OH_Drawing_CanvasRestore(OH_Drawing_Canvas*);
141 
142 /**
143  * @brief Gets the number of the canvas status (canvas matrix) saved in the stack.
144  *
145  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
146  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
147  * @return Returns a 32-bit variable that describes the number of canvas status.
148  * @since 11
149  * @version 1.0
150  */
151 uint32_t OH_Drawing_CanvasGetSaveCount(OH_Drawing_Canvas*);
152 
153 /**
154  * @brief Restores the specific number of the canvas status (canvas matrix) saved in the stack.
155  *
156  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
157  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
158  * @param saveCount Indicates the specific number of canvas status.
159  * @since 11
160  * @version 1.0
161  */
162 void OH_Drawing_CanvasRestoreToCount(OH_Drawing_Canvas*, uint32_t saveCount);
163 
164 /**
165  * @brief Draws a line segment.
166  *
167  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
168  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
169  * @param x1 Indicates the x coordinate of the start point of the line segment.
170  * @param y1 Indicates the y coordinate of the start point of the line segment.
171  * @param x2 Indicates the x coordinate of the end point of the line segment.
172  * @param y2 Indicates the y coordinate of the end point of the line segment.
173  * @since 8
174  * @version 1.0
175  */
176 void OH_Drawing_CanvasDrawLine(OH_Drawing_Canvas*, float x1, float y1, float x2, float y2);
177 
178 /**
179  * @brief Draws a path.
180  *
181  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
182  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
183  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
184  * @since 8
185  * @version 1.0
186  */
187 void OH_Drawing_CanvasDrawPath(OH_Drawing_Canvas*, const OH_Drawing_Path*);
188 
189 /**
190  * @brief Draws a bitmap.
191  *
192  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
193  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
194  * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object.
195  * @param left Indicates the left position of the <b>OH_Drawing_Bitmap</b>.
196  * @param top Indicates the top position of the <b>OH_Drawing_Bitmap</b>.
197  * @since 11
198  * @version 1.0
199  */
200 void OH_Drawing_CanvasDrawBitmap(OH_Drawing_Canvas*, const OH_Drawing_Bitmap*, float left, float top);
201 
202 /**
203  * @brief Draws a rect.
204  *
205  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
206  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
207  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
208  * @since 11
209  * @version 1.0
210  */
211 void OH_Drawing_CanvasDrawRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*);
212 
213 /**
214  * @brief Draws a circle.
215  *
216  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
217  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
218  * @param OH_Drawing_Point Indicates the pointer to an <b>OH_Drawing_Point</b> object.
219  * @param radius Indicates the radius of the circle.
220  * @since 11
221  * @version 1.0
222  */
223 void OH_Drawing_CanvasDrawCircle(OH_Drawing_Canvas*, const OH_Drawing_Point*, float radius);
224 
225 /**
226  * @brief Draws an oval.
227  *
228  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
229  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
230  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
231  * @since 11
232  * @version 1.0
233  */
234 void OH_Drawing_CanvasDrawOval(OH_Drawing_Canvas*, const OH_Drawing_Rect*);
235 
236 /**
237  * @brief Draws an arc.
238  *
239  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
240  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
241  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
242  * @param startAngle Indicates the startAngle of the arc.
243  * @param sweepAngle Indicates the sweepAngle of the arc.
244  * @since 11
245  * @version 1.0
246  */
247 void OH_Drawing_CanvasDrawArc(OH_Drawing_Canvas*, const OH_Drawing_Rect*, float startAngle, float sweepAngle);
248 
249 /**
250  * @brief Draws a roundrect.
251  *
252  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
253  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
254  * @param OH_Drawing_RoundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object.
255  * @since 11
256  * @version 1.0
257  */
258 void OH_Drawing_CanvasDrawRoundRect(OH_Drawing_Canvas*, const OH_Drawing_RoundRect*);
259 
260 /**
261  * @brief Draws a textblob.
262  *
263  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
264  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
265  * @param OH_Drawing_TextBlob Indicates the pointer to an <b>OH_Drawing_TextBlob</b> object.
266  * @param x Indicates the horizontal offset applied to blob.
267  * @param y Indicates the vertical offset applied to blob.
268  * @since 11
269  * @version 1.0
270  */
271 void OH_Drawing_CanvasDrawTextBlob(OH_Drawing_Canvas*, const OH_Drawing_TextBlob*, float x, float y);
272 
273 /**
274  * @brief Enumerates clip op.
275  *
276  * @since 11
277  * @version 1.0
278  */
279 typedef enum {
280     /**
281      * Clip with difference.
282      */
283     DIFFERENCE,
284     /**
285      * Clip with intersection.
286      */
287     INTERSECT,
288 } OH_Drawing_CanvasClipOp;
289 
290 /**
291  * @brief Clip a rect.
292  *
293  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
294  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
295  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
296  * @param clipOp Indicates the operation to apply to clip.
297  * @param doAntiAlias Indicates whether clip operation requires anti-aliased.
298  * @since 11
299  * @version 1.0
300  */
301 void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*,
302     OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
303 
304 /**
305  * @brief Clip a path.
306  *
307  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
308  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
309  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
310  * @param clipOp Indicates the operation to apply to clip.
311  * @param doAntiAlias Indicates whether clip operation requires anti-aliased.
312  * @since 11
313  * @version 1.0
314  */
315 void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas*, const OH_Drawing_Path*,
316     OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
317 
318 /**
319  * @brief Rotates by degrees. Positive degrees rotates clockwise.
320  *
321  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
322  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
323  * @param degrees Indicates the amount to rotate, in degrees.
324  * @param px Indicates the x-axis value of the point to rotate about.
325  * @param py Indicates the y-axis value of the point to rotate about.
326  * @since 11
327  * @version 1.0
328  */
329 void OH_Drawing_CanvasRotate(OH_Drawing_Canvas*, float degrees, float px, float py);
330 
331 /**
332  * @brief Translates by dx along the x-axis and dy along the y-axis.
333  *
334  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
335  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
336  * @param dx Indicates the distance to translate on x-axis.
337  * @param dy Indicates the distance to translate on y-axis.
338  * @since 11
339  * @version 1.0
340  */
341 void OH_Drawing_CanvasTranslate(OH_Drawing_Canvas*, float dx, float dy);
342 
343 /**
344  * @brief Scales by sx on the x-axis and sy on the y-axis.
345  *
346  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
347  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
348  * @param sx Indicates the amount to scale on x-axis.
349  * @param sy Indicates the amount to scale on y-axis.
350  * @since 11
351  * @version 1.0
352  */
353 void OH_Drawing_CanvasScale(OH_Drawing_Canvas*, float sx, float sy);
354 
355 /**
356  * @brief Clears a canvas by using a specified color.
357  *
358  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
359  * @param OH_Drawing_Canvas Indicates the pointer to an <b>OH_Drawing_Canvas</b> object.
360  * @param color Indicates the color, which is a 32-bit (ARGB) variable.
361  * @since 8
362  * @version 1.0
363  */
364 void OH_Drawing_CanvasClear(OH_Drawing_Canvas*, uint32_t color);
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 /** @} */
370 #endif
371