1 /*
2  * Copyright (c) 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 #include "core/interfaces/native/node/shape_modifier.h"
16 
17 #include "core/components/common/layout/constants.h"
18 #include "core/components/common/properties/color.h"
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components_ng/pattern/shape/shape_model_ng.h"
21 #include "core/pipeline/base/element_register.h"
22 
23 namespace OHOS::Ace::NG {
SetShapeViewPort(ArkUINodeHandle node,const ArkUI_Float32 * dimValues,const ArkUI_Int32 * dimUnits)24 void SetShapeViewPort(ArkUINodeHandle node, const ArkUI_Float32* dimValues, const ArkUI_Int32* dimUnits)
25 {
26     auto* frameNode = reinterpret_cast<FrameNode*>(node);
27     CHECK_NULL_VOID(frameNode);
28     CalcDimension dimLeft = CalcDimension(dimValues[0], (DimensionUnit)dimUnits[0]);
29     CalcDimension dimTop = CalcDimension(dimValues[1], (DimensionUnit)dimUnits[1]);
30     CalcDimension dimWidth = CalcDimension(dimValues[2], (DimensionUnit)dimUnits[2]);
31     CalcDimension dimHeight = CalcDimension(dimValues[3], (DimensionUnit)dimUnits[3]);
32     ShapeModelNG::SetViewPort(frameNode, dimLeft, dimTop, dimWidth, dimHeight);
33 }
34 
ResetShapeViewPort(ArkUINodeHandle node)35 void ResetShapeViewPort(ArkUINodeHandle node)
36 {
37     auto* frameNode = reinterpret_cast<FrameNode*>(node);
38     CHECK_NULL_VOID(frameNode);
39     CalcDimension dimLeft = CalcDimension(0.0, DimensionUnit::PX);
40     CalcDimension dimTop = CalcDimension(0.0, DimensionUnit::PX);
41     CalcDimension dimWidth = CalcDimension(0.0, DimensionUnit::PX);
42     CalcDimension dimHeight = CalcDimension(0.0, DimensionUnit::PX);
43     ShapeModelNG::SetViewPort(frameNode, dimLeft, dimTop, dimWidth, dimHeight);
44 }
45 
SetShapeMesh(ArkUINodeHandle node,const ArkUI_Float32 * mesh,ArkUI_Uint32 arrayItemCount,ArkUI_Int32 column,ArkUI_Int32 row)46 void SetShapeMesh(ArkUINodeHandle node, const ArkUI_Float32* mesh, ArkUI_Uint32 arrayItemCount,
47     ArkUI_Int32 column, ArkUI_Int32 row)
48 {
49     auto* frameNode = reinterpret_cast<FrameNode*>(node);
50     CHECK_NULL_VOID(frameNode);
51     std::vector<double> meshValues(mesh, mesh + arrayItemCount);
52     ShapeModelNG::SetBitmapMesh(frameNode, meshValues, column, row);
53 }
54 
ResetShapeMesh(ArkUINodeHandle node)55 void ResetShapeMesh(ArkUINodeHandle node)
56 {
57     auto* frameNode = reinterpret_cast<FrameNode*>(node);
58     CHECK_NULL_VOID(frameNode);
59     std::vector<double> meshValues;
60     int32_t column = 0;
61     int32_t row = 0;
62     ShapeModelNG::SetBitmapMesh(frameNode, meshValues, column, row);
63 }
64 
65 namespace NodeModifier {
GetShapeModifier()66 const ArkUIShapeModifier* GetShapeModifier()
67 {
68     static const ArkUIShapeModifier modifier = { SetShapeViewPort, ResetShapeViewPort, SetShapeMesh, ResetShapeMesh };
69     return &modifier;
70 }
71 
GetCJUIShapeModifier()72 const CJUIShapeModifier* GetCJUIShapeModifier()
73 {
74     static const CJUIShapeModifier modifier = { SetShapeViewPort, ResetShapeViewPort, SetShapeMesh, ResetShapeMesh };
75     return &modifier;
76 }
77 }
78 } // namespace OHOS::Ace::NG
79