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/polygon_modifier.h"
16 
17 #include "core/pipeline/base/element_register.h"
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components/common/layout/constants.h"
20 #include "core/components_ng/pattern/shape/polygon_model_ng.h"
21 #include "base/geometry/shape.h"
22 
23 namespace OHOS::Ace::NG {
SetPolygonPoints(ArkUINodeHandle node,const ArkUI_Float32 * pointX,const ArkUI_Float32 * pointY,int32_t length)24 void SetPolygonPoints(ArkUINodeHandle node, const ArkUI_Float32* pointX, const ArkUI_Float32* pointY, int32_t length)
25 {
26     auto* frameNode = reinterpret_cast<FrameNode*>(node);
27     CHECK_NULL_VOID(frameNode);
28     ShapePoint shapePoint;
29     ShapePoints shapePoints;
30     for (int32_t i = 0; i < length; i++) {
31         auto xVal = pointX[i];
32         auto yVal = pointY[i];
33         shapePoint.first = Dimension(xVal, DimensionUnit::VP);
34         shapePoint.second = Dimension(yVal, DimensionUnit::VP);
35         shapePoints.push_back(shapePoint);
36     }
37 
38     PolygonModelNG::SetPoints(frameNode, shapePoints);
39 }
40 
ResetPolygonPoints(ArkUINodeHandle node)41 void ResetPolygonPoints(ArkUINodeHandle node)
42 {
43     ShapePoints points;
44     auto* frameNode = reinterpret_cast<FrameNode*>(node);
45     CHECK_NULL_VOID(frameNode);
46     PolygonModelNG::SetPoints(frameNode, points);
47 }
48 
49 namespace NodeModifier {
GetPolygonModifier()50 const ArkUIPolygonModifier* GetPolygonModifier()
51 {
52     static const ArkUIPolygonModifier modifier = {SetPolygonPoints, ResetPolygonPoints};
53 
54     return &modifier;
55 }
56 
GetCJUIPolygonModifier()57 const CJUIPolygonModifier* GetCJUIPolygonModifier()
58 {
59     static const CJUIPolygonModifier modifier = {SetPolygonPoints, ResetPolygonPoints};
60 
61     return &modifier;
62 }
63 }
64 }
65