• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_PATH_H
17 #define C_INCLUDE_DRAWING_PATH_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_path.h
33  *
34  * @brief Declares functions related to the <b>path</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 Direction for adding closed contours.
48  *
49  * @since 12
50  * @version 1.0
51  */
52 typedef enum {
53     /** clockwise direction for adding closed contours */
54     PATH_DIRECTION_CW,
55     /** counter-clockwise direction for adding closed contours */
56     PATH_DIRECTION_CCW,
57 } OH_Drawing_PathDirection;
58 
59 /**
60  * @brief FillType of path
61  *
62  * @since 12
63  * @version 1.0
64  */
65 typedef enum {
66     /** Specifies that "inside" is computed by a non-zero sum of signed edge crossings */
67     PATH_FILL_TYPE_WINDING,
68     /** Specifies that "inside" is computed by an odd number of edge crossings */
69     PATH_FILL_TYPE_EVEN_ODD,
70     /** Same as Winding, but draws outside of the path, rather than inside */
71     PATH_FILL_TYPE_INVERSE_WINDING,
72     /** Same as EvenOdd, but draws outside of the path, rather than inside */
73     PATH_FILL_TYPE_INVERSE_EVEN_ODD,
74 } OH_Drawing_PathFillType;
75 
76 /**
77  * @brief Creates an <b>OH_Drawing_Path</b> object.
78  *
79  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
80  * @return Returns the pointer to the <b>OH_Drawing_Path</b> object created.
81  * @since 8
82  * @version 1.0
83  */
84 OH_Drawing_Path* OH_Drawing_PathCreate(void);
85 
86 /**
87  * @brief Creates an <b>OH_Drawing_Path</b> copy object.
88  *
89  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
90  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
91  * @return Returns the pointer to the <b>OH_Drawing_Path</b> object created.
92  * @since 12
93  * @version 1.0
94  */
95 OH_Drawing_Path* OH_Drawing_PathCopy(OH_Drawing_Path*);
96 
97 /**
98  * @brief Destroys an <b>OH_Drawing_Path</b> object and reclaims the memory occupied by the object.
99  *
100  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
101  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
102  * @since 8
103  * @version 1.0
104  */
105 void OH_Drawing_PathDestroy(OH_Drawing_Path*);
106 
107 /**
108  * @brief Sets the start point of a path.
109  *
110  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
111  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
112  * @param x Indicates the x coordinate of the start point.
113  * @param y Indicates the y coordinate of the start point.
114  * @since 8
115  * @version 1.0
116  */
117 void OH_Drawing_PathMoveTo(OH_Drawing_Path*, float x, float y);
118 
119 /**
120  * @brief Draws a line segment from the last point of a path to the target point.
121  *
122  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
123  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
124  * @param x Indicates the x coordinate of the target point.
125  * @param y Indicates the y coordinate of the target point.
126  * @since 8
127  * @version 1.0
128  */
129 void OH_Drawing_PathLineTo(OH_Drawing_Path*, float x, float y);
130 
131 /**
132  * @brief Draws an arc to a path.
133  *
134  * This is done by using angle arc mode. In this mode, a rectangle that encloses an ellipse is specified first,
135  * and then a start angle and a sweep angle are specified.
136  * The arc is a portion of the ellipse defined by the start angle and the sweep angle.
137  * By default, a line segment from the last point of the path to the start point of the arc is also added.
138  *
139  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
140  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
141  * @param x1 Indicates the x coordinate of the upper left corner of the rectangle.
142  * @param y1 Indicates the y coordinate of the upper left corner of the rectangle.
143  * @param x2 Indicates the x coordinate of the lower right corner of the rectangle.
144  * @param y2 Indicates the y coordinate of the lower right corner of the rectangle.
145  * @param startDeg Indicates the start angle, in degrees.
146  * @param sweepDeg Indicates the angle to sweep, in degrees.
147  * @since 8
148  * @version 1.0
149  */
150 void OH_Drawing_PathArcTo(OH_Drawing_Path*, float x1, float y1, float x2, float y2, float startDeg, float sweepDeg);
151 
152 /**
153  * @brief Draws a quadratic Bezier curve from the last point of a path to the target point.
154  *
155  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
156  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
157  * @param ctrlX Indicates the x coordinate of the control point.
158  * @param ctrlY Indicates the y coordinate of the control point.
159  * @param endX Indicates the x coordinate of the target point.
160  * @param endY Indicates the y coordinate of the target point.
161  * @since 8
162  * @version 1.0
163  */
164 void OH_Drawing_PathQuadTo(OH_Drawing_Path*, float ctrlX, float ctrlY, float endX, float endY);
165 
166 /**
167  * @brief Draws a cubic Bezier curve from the last point of a path to the target point.
168  *
169  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
170  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
171  * @param ctrlX1 Indicates the x coordinate of the first control point.
172  * @param ctrlY1 Indicates the y coordinate of the first control point.
173  * @param ctrlX2 Indicates the x coordinate of the second control point.
174  * @param ctrlY2 Indicates the y coordinate of the second control point.
175  * @param endX Indicates the x coordinate of the target point.
176  * @param endY Indicates the y coordinate of the target point.
177  * @since 8
178  * @version 1.0
179  */
180 void OH_Drawing_PathCubicTo(
181     OH_Drawing_Path*, float ctrlX1, float ctrlY1, float ctrlX2, float ctrlY2, float endX, float endY);
182 
183 /**
184  * @brief Adds a new contour to the path, defined by the rect, and wound in the specified direction.
185  *
186  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
187  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
188  * @param left Indicates the left coordinate of the upper left corner of the rectangle.
189  * @param top Indicates the top coordinate of the upper top corner of the rectangle.
190  * @param right Indicates the right coordinate of the lower right corner of the rectangle.
191  * @param bottom Indicates the bottom coordinate of the lower bottom corner of the rectangle.
192  * @param OH_Drawing_PathDirection Indicates the path direction.
193  * @since 12
194  * @version 1.0
195  */
196 void OH_Drawing_PathAddRect(OH_Drawing_Path*, float left, float top, float right, float bottom,
197     OH_Drawing_PathDirection);
198 
199 /**
200  * @brief Adds a new contour to the path, defined by the round rect, and wound in the specified direction.
201  *
202  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
203  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
204  * @param OH_Drawing_RoundRect Indicates the pointer to an <b>OH_Drawing_RoundRect</b> object.
205  * @param OH_Drawing_PathDirection Indicates the path direction.
206  * @since 12
207  * @version 1.0
208  */
209 void OH_Drawing_PathAddRoundRect(OH_Drawing_Path*, const OH_Drawing_RoundRect* roundRect, OH_Drawing_PathDirection);
210 
211 /**
212  * @brief Appends arc to path, as the start of new contour.Arc added is part of ellipse bounded by oval,
213  * from startAngle through sweepAngle. Both startAngle and sweepAngle are measured in degrees, where zero degrees
214  * is aligned with the positive x-axis, and positive sweeps extends arc clockwise.If sweepAngle <= -360, or
215  * sweepAngle >= 360; and startAngle modulo 90 is nearly zero, append oval instead of arc. Otherwise, sweepAngle
216  * values are treated modulo 360, and arc may or may not draw depending on numeric rounding.
217  *
218  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
219  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
220  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
221  * @param startAngle Indicates the starting angle of arc in degrees.
222  * @param sweepAngle Indicates the sweep, in degrees. Positive is clockwise.
223  * @since 12
224  * @version 1.0
225  */
226 void OH_Drawing_PathAddArc(OH_Drawing_Path*, const OH_Drawing_Rect*, float startAngle, float sweepAngle);
227 
228 /**
229  * @brief Appends src path to path, transformed by matrix. Transformed curves may have different verbs,
230  * point, and conic weights.
231  *
232  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
233  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
234  * @param src Indicates the pointer to an <b>OH_Drawing_Path</b> object.
235  * @param OH_Drawing_Matrix Indicates the length of the <b>OH_Drawing_Matrix</b> object.
236  * @since 12
237  * @version 1.0
238  */
239 void OH_Drawing_PathAddPath(OH_Drawing_Path*, const OH_Drawing_Path* src, const OH_Drawing_Matrix*);
240 
241 /**
242  * @brief Return the status that point (x, y) is contained by path.
243  *
244  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
245  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
246  * @param x Indicates the x-axis value of containment test.
247  * @param y Indicates the y-axis value of containment test.
248  * @return Returns true if the point (x, y) is contained by path.
249  * @since 12
250  * @version 1.0
251  */
252 bool OH_Drawing_PathContains(OH_Drawing_Path*, float x, float y);
253 
254 /**
255  * @brief Transforms verb array, point array, and weight by matrix. transform may change verbs
256  * and increase their number. path is replaced by transformed data.
257  *
258  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
259  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
260  * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object.
261  * @since 12
262  * @version 1.0
263  */
264 void OH_Drawing_PathTransform(OH_Drawing_Path*, const OH_Drawing_Matrix*);
265 
266 /**
267  * @brief Sets FillType, the rule used to fill path.
268  *
269  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
270  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
271  * @param OH_Drawing_PathFillType Indicates the add path's fill type.
272  * @since 12
273  * @version 1.0
274  */
275 void OH_Drawing_SetFillStyle(OH_Drawing_Path*, OH_Drawing_PathFillType);
276 
277 /**
278  * @brief Closes a path. A line segment from the start point to the last point of the path is added.
279  *
280  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
281  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
282  * @since 8
283  * @version 1.0
284  */
285 void OH_Drawing_PathClose(OH_Drawing_Path*);
286 
287 /**
288  * @brief Resets path data.
289  *
290  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
291  * @param OH_Drawing_Path Indicates the pointer to an <b>OH_Drawing_Path</b> object.
292  * @since 8
293  * @version 1.0
294  */
295 void OH_Drawing_PathReset(OH_Drawing_Path*);
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 /** @} */
301 #endif
302