From 24315b44eb1e94de91abbbc6ea7b06bba6c88f49 Mon Sep 17 00:00:00 2001 From: l00844999 Date: Fri, 3 May 2024 20:44:08 +0800 Subject: [PATCH] [Drawing NDK]add some interfaces Signed-off-by: l00844999 --- .../graphic_2d/native_drawing/drawing_path.h | 107 ++++++++++++++++++ .../native_drawing/drawing_region.h | 72 ++++++++++++ .../native_drawing/libnative_drawing.ndk.json | 28 +++++ 3 files changed, 207 insertions(+) diff --git a/graphic/graphic_2d/native_drawing/drawing_path.h b/graphic/graphic_2d/native_drawing/drawing_path.h index d82a70df8..fac5a2066 100644 --- a/graphic/graphic_2d/native_drawing/drawing_path.h +++ b/graphic/graphic_2d/native_drawing/drawing_path.h @@ -86,6 +86,56 @@ typedef enum { PATH_ADD_MODE_EXTEND, } OH_Drawing_PathAddMode; +/** + * @brief Operations when two paths are combined. + * + * @since 12 + * @version 1.0 + */ +typedef enum { + /** + * Difference operation. + */ + PATH_OP_MODE_DIFFERENCE, + /** + * Intersect operation. + */ + PATH_OP_MODE_INTERSECT, + /** + * Union operation. + */ + PATH_OP_MODE_UNION, + /** + * Xor operation. + */ + PATH_OP_MODE_XOR, + /** + * Reverse difference operation. + */ + PATH_OP_MODE_REVERSE_DIFFERENCE, +} OH_Drawing_PathOpMode; + +/** + * @brief What should be returned in the matrix. + * + * @since 12 + * @version 1.0 + */ +typedef enum { + /** + * Gets position. + */ + GET_POSITION_MATRIX, + /** + * Gets tangent. + */ + GET_TANGENT_MATRIX, + /** + * Gets both position and tangent. + */ + GET_POS_AND_TAN_MATRIX, +} OH_Drawing_PathMeasureMatrixFlags; + /** * @brief Creates an OH_Drawing_Path object. * @@ -516,6 +566,63 @@ void OH_Drawing_PathOffset(OH_Drawing_Path* path, OH_Drawing_Path* dst, float dx */ void OH_Drawing_PathReset(OH_Drawing_Path*); +/** + * @brief Determines whether the path current contour is closed. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param path Indicates the pointer to an OH_Drawing_Path object. + * @param forceClosed Whether to close the Path. + * @return Returns true if the path current contour is closed. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_PathIsClosed(OH_Drawing_Path* path, bool forceClosed); + +/** + * @brief Gets the position and tangent of the distance from the starting position of the Path. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param path Indicates the pointer to an OH_Drawing_Path object. + * @param distance The distance from the start of the Path. + * @param position Sets to the position of distance from the starting position of the Path. + * @param tangent Sets to the tangent of distance from the starting position of the Path. + * @param forceClosed Whether to close the Path. + * @return Returns true if succeeded, otherwise false. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_PathGetPosTan(OH_Drawing_Path* path, bool forceClosed, + float distance, OH_Drawing_Point2D* position, OH_Drawing_Point2D* tangent); + +/** + * @brief Combines two paths. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param path Indicates the pointer to an OH_Drawing_Path object. + * @param srcPath Indicates the pointer to an OH_Drawing_Path object. + * @param op Indicates the operation to apply to combine. + * @return Returns true if constructed path is not empty. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_PathOp(OH_Drawing_Path* path, const OH_Drawing_Path* srcPath, OH_Drawing_PathOpMode op); + +/** + * @brief Computes the corresponding matrix at the specified distance. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param path Indicates the pointer to an OH_Drawing_Path object. + * @param forceClosed Whether to close the Path. + * @param distance The distance from the start of the Path. + * @param matrix Indicates the pointer to an OH_Drawing_Matrix object. + * @param flag Indicates what should be returned in the matrix. + * @return Returns false if path is nullptr or zero-length, otherwise true. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_PathGetMatrix(OH_Drawing_Path* path, bool forceClosed, + float distance, OH_Drawing_Matrix* matrix, OH_Drawing_PathMeasureMatrixFlags flag); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_region.h b/graphic/graphic_2d/native_drawing/drawing_region.h index b145f999e..f40cc9471 100644 --- a/graphic/graphic_2d/native_drawing/drawing_region.h +++ b/graphic/graphic_2d/native_drawing/drawing_region.h @@ -43,6 +43,39 @@ extern "C" { #endif +/** + * @brief Operations when two regions are combined. + * + * @since 12 + * @version 1.0 + */ +typedef enum { + /** + * Difference operation. + */ + REGION_OP_MODE_DIFFERENCE, + /** + * Intersect operation. + */ + REGION_OP_MODE_INTERSECT, + /** + * Union operation. + */ + REGION_OP_MODE_UNION, + /** + * Xor operation. + */ + REGION_OP_MODE_XOR, + /** + * Reverse difference operation. + */ + REGION_OP_MODE_REVERSE_DIFFERENCE, + /** + * Replace operation. + */ + REGION_OP_MODE_REPLACE, +} OH_Drawing_RegionOpMode; + /** * @brief Creates an OH_Drawing_Region object. * @@ -53,6 +86,32 @@ extern "C" { */ OH_Drawing_Region* OH_Drawing_RegionCreate(void); +/** + * @brief Determines whether the region contains the specified coordinates. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param region Indicates the pointer to an OH_Drawing_Region object. + * @param int32_t x-coordinate. + * @param int32_t y-coordinate. + * @return Return true if (x, y) is inside region. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_RegionContains(OH_Drawing_Region* region, int32_t x, int32_t y); + +/** + * @brief Combines two regions. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param region Indicates the pointer to an OH_Drawing_Region object. + * @param dst Indicates the pointer to an OH_Drawing_Region object. + * @param op Indicates the operation to apply to combine. + * @return Return true if constructed Region is not empty. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_RegionOp(OH_Drawing_Region* region, const OH_Drawing_Region* dst, OH_Drawing_RegionOpMode op); + /** * @brief Destroys an OH_Drawing_Region object and reclaims the memory occupied by the object. * @@ -65,6 +124,19 @@ OH_Drawing_Region* OH_Drawing_RegionCreate(void); */ bool OH_Drawing_RegionSetRect(OH_Drawing_Region* region, const OH_Drawing_Rect* rect); +/** + * @brief Constructs region that matchs outline of path within clip. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param region Indicates the pointer to an OH_Drawing_Region object. + * @param path Indicates the pointer to an OH_Drawing_Path object. + * @param clip Indicates the pointer to an OH_Drawing_Region object. + * @return Return true if constructed Region is not empty. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_RegionSetPath(OH_Drawing_Region* region, const OH_Drawing_Path* path, const OH_Drawing_Region* clip); + /** * @brief Destroys an OH_Drawing_Region object and reclaims the memory occupied by the object. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index e41daf797..80a44c280 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -363,6 +363,22 @@ "name": "OH_Drawing_PathOffset" }, { "name": "OH_Drawing_PathReset" }, + { + "first_introduced": "12", + "name": "OH_Drawing_PathIsClosed" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_PathGetPosTan" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_PathOp" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_PathGetMatrix" + }, { "name": "OH_Drawing_PenCreate" }, { "name": "OH_Drawing_PenDestroy" }, { "name": "OH_Drawing_PenGetAlpha" }, @@ -926,6 +942,18 @@ "first_introduced": "12", "name": "OH_Drawing_RegionCreate" }, + { + "first_introduced": "12", + "name": "OH_Drawing_RegionContains" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_RegionOp" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_RegionSetPath" + }, { "first_introduced": "12", "name": "OH_Drawing_RegionDestroy" -- Gitee