From 2babba33259baea34aec88663ef63672ae3ff79a Mon Sep 17 00:00:00 2001 From: li-kiao Date: Fri, 19 Jan 2024 14:17:21 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ECube=E4=BA=8C=E6=9C=9Fcanvas?= =?UTF-8?q?=E7=9A=84c=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-kiao --- graphic/graphic_2d/native_drawing/BUILD.gn | 2 + .../native_drawing/drawing_canvas.h | 101 ++++++++++++++++++ .../native_drawing/drawing_path_effect.h | 73 +++++++++++++ .../graphic_2d/native_drawing/drawing_point.h | 23 ++++ .../graphic_2d/native_drawing/drawing_types.h | 16 +++ .../native_drawing/libnative_drawing.ndk.json | 10 ++ 6 files changed, 225 insertions(+) create mode 100644 graphic/graphic_2d/native_drawing/drawing_path_effect.h diff --git a/graphic/graphic_2d/native_drawing/BUILD.gn b/graphic/graphic_2d/native_drawing/BUILD.gn index 44f9f3218..6d8e22e3c 100644 --- a/graphic/graphic_2d/native_drawing/BUILD.gn +++ b/graphic/graphic_2d/native_drawing/BUILD.gn @@ -28,6 +28,7 @@ ohos_ndk_headers("native_drawing_header") { "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_mask_filter.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_matrix.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_path.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_path_effect.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_pen.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_point.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_rect.h", @@ -59,6 +60,7 @@ ohos_ndk_library("libnative_drawing_ndk") { "native_drawing/drawing_mask_filter.h", "native_drawing/drawing_matrix.h", "native_drawing/drawing_path.h", + "native_drawing/drawing_path_effect.h", "native_drawing/drawing_pen.h", "native_drawing/drawing_point.h", "native_drawing/drawing_rect.h", diff --git a/graphic/graphic_2d/native_drawing/drawing_canvas.h b/graphic/graphic_2d/native_drawing/drawing_canvas.h index cc3781589..4e85fa736 100644 --- a/graphic/graphic_2d/native_drawing/drawing_canvas.h +++ b/graphic/graphic_2d/native_drawing/drawing_canvas.h @@ -363,6 +363,107 @@ void OH_Drawing_CanvasScale(OH_Drawing_Canvas*, float sx, float sy); */ void OH_Drawing_CanvasClear(OH_Drawing_Canvas*, uint32_t color); +/** + * @brief Get the width of a canvas. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @since 12 + * @version 1.0 + */ +int32_t OH_Drawing_CanvasGetWidth(OH_Drawing_Canvas*); + +/** + * @brief Get the height of a canvas. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @since 12 + * @version 1.0 + */ +int32_t OH_Drawing_CanvasGetHeight(OH_Drawing_Canvas*); + +/** + * @brief Get the bounds of clip of a canvas. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @return The pointer to an OH_Drawing_Rect object, represents the boundar of clip, + * transformed by inverse of matrix. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Rect* OH_Drawing_CanvasGetLocalClipBounds(OH_Drawing_Canvas*); + +/** + * @brief Get a 3x3 matrix of the transform from local coordinates to 'device' + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @return The pointer to an OH_Drawing_Matrix object. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Matrix* OH_Drawing_CanvasGetLocalToDevice(OH_Drawing_Canvas*); + +/** + * @brief Use the passed matrix to transforming the geometry, then use existing matrix. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_Matrix Indicates the pointer to an OH_Drawing_Matrix object, + * represents the matrix which is passed. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_CanvasConcatMatrix(OH_Drawing_Canvas*, OH_Drawing_Matrix*); + +/** + * @brief Enumerates of shadow flags. + * + * @since 12 + * @version 1.0 + */ +typedef enum { + /** + * Use no shadow flags. + */ + SHADOW_FLAGS_NONE, + /** + * The occluding object is transparent. + */ + SHADOW_FLAGS_TRANSPARENT_OCCLUDER, + /** + * No need to analyze shadows. + */ + SHADOW_FLAGS_GEOMETRIC_ONLY, + /** + * Use all shadow falgs. + */ + SHADOW_FLAGS_ALL, +} OH_Drawing_CanvasShadowFlags; + +/** + * @brief Use circular light to draw an offset spot shadow and outlining ambient shadow for the given path. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object. + * @param OH_Drawing_Path Indicates the pointer to an OH_Drawing_Path object, use to generate shadows. + * @param OH_Drawing_Point3 Indicates the pointer to an OH_Drawing_Point3 object. + * represents the value of the function which returns Z offset of the occluder from the canvas based on x and y. + * @param OH_Drawing_Point3 Indicates the pointer to an OH_Drawing_Point3 object. + * represents the position of the light relative to the canvas. + * @param lightRadius The radius of the circular light. + * @param ambientColor Ambient shadow's color. + * @param spotColor Spot shadow's color. + * @param flag Indicates the flag to control opaque occluder, shadow, and light position. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_CanvasDrawShadow(OH_Drawing_Canvas*, OH_Drawing_Path*, OH_Drawing_Point3*, + OH_Drawing_Point3*, float lightRadius, uint32_t ambientColor, uint32_t spotColor, + OH_Drawing_CanvasShadowFlags flag); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_path_effect.h b/graphic/graphic_2d/native_drawing/drawing_path_effect.h new file mode 100644 index 000000000..90aee6f3a --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_path_effect.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_PATH_EFFECT_H +#define C_INCLUDE_DRAWING_PATH_EFFECT_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 12 + * @version 1.0 + */ + +/** + * @file drawing_path_effect.h + * + * @brief Declares functions related to the pathEffect object in the drawing module. + * + * @since 12 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_PathEffect object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param intervals Indicates a array which contain an even number of entries. + * @param count Indicates the number of elements of the intervals array. + * @param phase Indicates the offset into intervals array. + * @return Returns the pointer to the OH_Drawing_PathEffect object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_PathEffect* OH_Drawing_CreateDashPathEffect(float* intervals, int count, float phase); + +/** + * @brief Destroys an OH_Drawing_PathEffect object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_PathEffect Indicates the pointer to an OH_Drawing_PathEffect object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_PathEffectDestroy(OH_Drawing_PathEffect*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_point.h b/graphic/graphic_2d/native_drawing/drawing_point.h index f63faf78d..53c828604 100644 --- a/graphic/graphic_2d/native_drawing/drawing_point.h +++ b/graphic/graphic_2d/native_drawing/drawing_point.h @@ -65,6 +65,29 @@ OH_Drawing_Point* OH_Drawing_PointCreate(float x, float y); */ void OH_Drawing_PointDestroy(OH_Drawing_Point*); +/** + * @brief Creates an OH_Drawing_Point3 object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param x Indicates the x-axis coordinates of the point. + * @param y Indicates the y-axis coordinates of the point. + * @param z Indicates the z-axis coordinates of the point. + * @return Returns the pointer to the OH_Drawing_Point3 object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Point3* OH_Drawing_Point3Create(float x, float y, float z); + +/** + * @brief Destroys an OH_Drawing_Point3 object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Point3 Indicates the pointer to an OH_Drawing_Point3 object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_Point3Destroy(OH_Drawing_Point3*); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index cdf7f35cc..d0ba2e730 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -92,6 +92,22 @@ typedef struct OH_Drawing_Bitmap OH_Drawing_Bitmap; */ typedef struct OH_Drawing_Point OH_Drawing_Point; +/** + * @brief Defines a point of 3x3, which is used to describe the coordinate point. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_Drawing_Point3 OH_Drawing_Point3; + +/** + * @brief Defines a pathEffect, which is used to affects stroked paths. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_Drawing_PathEffect OH_Drawing_PathEffect; + /** * @brief Defines a rect, which is used to describe the rectangle. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index 314e98b41..225b632d6 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -41,6 +41,14 @@ { "name": "OH_Drawing_CanvasTranslate" }, { "name": "OH_Drawing_CanvasScale" }, { "name": "OH_Drawing_CanvasClear" }, + { "name": "OH_Drawing_CanvasGetWidth" }, + { "name": "OH_Drawing_CanvasGetHeight" }, + { "name": "OH_Drawing_CanvasGetLocalClipBounds" }, + { "name": "OH_Drawing_CanvasGetLocalToDevice" }, + { "name": "OH_Drawing_CanvasConcatMatrix" }, + { "name": "OH_Drawing_CanvasDrawShadow" }, + { "name": "OH_Drawing_CreateDashPathEffect" }, + { "name": "OH_Drawing_PathEffectDestroy" }, { "name": "OH_Drawing_ColorFilterCreateBlendMode" }, { "name": "OH_Drawing_ColorFilterCreateCompose" }, { "name": "OH_Drawing_ColorFilterCreateLinearToSrgbGamma" }, @@ -93,6 +101,8 @@ { "name": "OH_Drawing_PenSetShaderEffect" }, { "name": "OH_Drawing_PointCreate" }, { "name": "OH_Drawing_PointDestroy" }, + { "name": "OH_Drawing_Point3Create" }, + { "name": "OH_Drawing_Point3Destroy" }, { "name": "OH_Drawing_ColorSetArgb" }, { "name": "OH_Drawing_CreateFontCollection" }, { "name": "OH_Drawing_DestroyFontCollection" }, -- Gitee