1 /*
2  * Copyright (c) 2023-2024 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_RECT_H
17 #define C_INCLUDE_DRAWING_RECT_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 11
28  * @version 1.0
29  */
30 
31 /**
32  * @file drawing_rect.h
33  *
34  * @brief Declares functions related to the <b>rect</b> object in the drawing module.
35  *
36  * @kit ArkGraphics2D
37  * @library libnative_drawing.so
38  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
39  * @since 11
40  * @version 1.0
41  */
42 
43 #include "drawing_types.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Creates an <b>OH_Drawing_Rect</b> object.
51  *
52  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
53  * @param left Indicates the left position of the rect.
54  * @param top Indicates the top position of the rect.
55  * @param right Indicates the right position of the rect.
56  * @param bottom Indicates the bottom position of the rect.
57  * @return Returns the pointer to the <b>OH_Drawing_Rect</b> object created.
58  * @since 11
59  * @version 1.0
60  */
61 OH_Drawing_Rect* OH_Drawing_RectCreate(float left, float top, float right, float bottom);
62 
63 /**
64  * @brief If rect intersects other, sets rect to intersection.
65  *
66  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
67  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
68  * @param other Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
69  * @return Returns true if have area in common.
70  * @since 12
71  * @version 1.0
72  */
73 bool OH_Drawing_RectIntersect(OH_Drawing_Rect* rect, const OH_Drawing_Rect* other);
74 
75 /**
76  * @brief Sets rect to the union of rect and other.
77  *
78  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
79  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
80  * @param other Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
81  * @return Returns true if rect and other are not nullptr, and other is not empty;
82  *         false if rect or other is nullptr, or other is empty.
83  * @since 12
84  * @version 1.0
85  */
86 bool OH_Drawing_RectJoin(OH_Drawing_Rect* rect, const OH_Drawing_Rect* other);
87 
88 /**
89  * @brief Set the left position of the rect.
90  *
91  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
92  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
93  * @param left Indicates the left position of the rect.
94  * @since 12
95  * @version 1.0
96  */
97 void OH_Drawing_RectSetLeft(OH_Drawing_Rect* rect, float left);
98 
99 /**
100  * @brief Set the top position of the rect.
101  *
102  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
103  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
104  * @param top Indicates the top position of the rect.
105  * @since 12
106  * @version 1.0
107  */
108 void OH_Drawing_RectSetTop(OH_Drawing_Rect* rect, float top);
109 
110 /**
111  * @brief Set the right position of the rect.
112  *
113  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
114  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
115  * @param right Indicates the right position of the rect.
116  * @since 12
117  * @version 1.0
118  */
119 void OH_Drawing_RectSetRight(OH_Drawing_Rect* rect, float right);
120 
121 /**
122  * @brief Set the bottom position of the rect.
123  *
124  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
125  * @param rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
126  * @param bottom Indicates the bottom position of the rect.
127  * @since 12
128  * @version 1.0
129  */
130 void OH_Drawing_RectSetBottom(OH_Drawing_Rect* rect, float bottom);
131 
132 /**
133  * @brief Get the left position of the rect.
134  *
135  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
136  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
137  * @return Return the left position of the rect.
138  * @since 12
139  * @version 1.0
140  */
141 float OH_Drawing_RectGetLeft(OH_Drawing_Rect*);
142 
143 /**
144  * @brief Get the top position of the rect.
145  *
146  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
147  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
148  * @return Return the top position of the rect.
149  * @since 12
150  * @version 1.0
151  */
152 float OH_Drawing_RectGetTop(OH_Drawing_Rect*);
153 
154 /**
155  * @brief Get the right position of the rect.
156  *
157  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
158  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
159  * @return Return the right position of the rect.
160  * @since 12
161  * @version 1.0
162  */
163 float OH_Drawing_RectGetRight(OH_Drawing_Rect*);
164 
165 /**
166  * @brief Get the bottom position of the rect.
167  *
168  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
169  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
170  * @return Return the bottom position of the rect.
171  * @since 12
172  * @version 1.0
173  */
174 float OH_Drawing_RectGetBottom(OH_Drawing_Rect*);
175 
176 /**
177  * @brief Get the height position of the rect.
178  *
179  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
180  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
181  * @since 12
182  * @version 1.0
183  */
184 float OH_Drawing_RectGetHeight(OH_Drawing_Rect*);
185 
186 /* @brief Get the width position of the rect.
187  *
188  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
189  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
190  * @return Returns the width.
191  * @since 12
192  * @version 1.0
193  */
194 float OH_Drawing_RectGetWidth(OH_Drawing_Rect*);
195 
196 /**
197  * @brief Copy the original rectangular object to the destination rectangular object.
198  *
199  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
200  * @param src Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
201  * @param dst Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
202  * @since 12
203  * @version 1.0
204  */
205 void OH_Drawing_RectCopy(OH_Drawing_Rect* src, OH_Drawing_Rect* dst);
206 
207 /**
208  * @brief Destroys an <b>OH_Drawing_Rect</b> object and reclaims the memory occupied by the object.
209  *
210  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
211  * @param OH_Drawing_Rect Indicates the pointer to an <b>OH_Drawing_Rect</b> object.
212  * @since 11
213  * @version 1.0
214  */
215 void OH_Drawing_RectDestroy(OH_Drawing_Rect*);
216 
217 /**
218  * @brief Creates an <b>OH_Drawing_Array</b> object, which is used to store multiple <b>OH_Drawing_Rect</b> object.
219  *
220  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
221  * @param size Indicates the size of the array object.
222  * @return Returns the pointer to the <b>OH_Drawing_Array</b> object created.
223  *         If nullptr is returned, the creation fails.
224  *         The possible cause of the failure is that the available memory is empty,
225  *         or size is invalid.
226  * @since 14
227  * @version 1.0
228  */
229 OH_Drawing_Array* OH_Drawing_RectCreateArray(size_t size);
230 
231 /**
232  * @brief Gets the size of an <b>OH_Drawing_Array</b> object.
233  *
234  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
235  * @param rectArray Indicates the array object.
236  * @param pSize Indicates the size pointer.
237  * @return Returns the error code.
238  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
239  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if rectArray or pSize is nullptr.
240  * @since 14
241  * @version 1.0
242  */
243 OH_Drawing_ErrorCode OH_Drawing_RectGetArraySize(OH_Drawing_Array* rectArray, size_t* pSize);
244 
245 /**
246  * @brief Gets the specified <b>OH_Drawing_Rect</b> object from <b>OH_Drawing_Array</b> object.
247  *
248  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
249  * @param rectArray Indicates the array object.
250  * @param index Indicates the index of array, caller must make sure the index is valid.
251  * @param rect Pointers to Pointer of <b>OH_Drawing_Rect</b> object, returned to the caller.
252  * @return Returns the error code.
253  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
254  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if rectArray or rect is nullptr,
255  *                 or index is valid.
256  * @since 14
257  * @version 1.0
258  */
259 OH_Drawing_ErrorCode OH_Drawing_RectGetArrayElement(OH_Drawing_Array* rectArray, size_t index,
260     OH_Drawing_Rect** rect);
261 
262 /**
263  * @brief Destroys an array <b>OH_Drawing_Rect</b> object and reclaims the memory occupied by the object.
264  *
265  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
266  * @param rectArray Indicates the pointer to an <b>OH_Drawing_Array</b> object.
267  * @return Returns the error code.
268  *         Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
269  *         Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if rectArray is nullptr.
270  * @since 14
271  * @version 1.0
272  */
273 OH_Drawing_ErrorCode OH_Drawing_RectDestroyArray(OH_Drawing_Array* rectArray);
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 /** @} */
279 #endif
280