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/polyline_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 {
24 
SetPoints(ArkUINodeHandle node,const ArkUI_Float32 * pointX,const ArkUI_Float32 * pointY,int32_t length)25 void SetPoints(ArkUINodeHandle node, const ArkUI_Float32* pointX, const ArkUI_Float32* pointY, int32_t length)
26 {
27     auto* frameNode = reinterpret_cast<FrameNode*>(node);
28     CHECK_NULL_VOID(frameNode);
29     ShapePoint shapePoint;
30     ShapePoints shapePoints;
31     for (int32_t i = 0; i < length; i++) {
32         auto xVal = pointX[i];
33         auto yVal = pointY[i];
34         shapePoint.first = Dimension(xVal, DimensionUnit::VP);
35         shapePoint.second = Dimension(yVal, DimensionUnit::VP);
36         shapePoints.push_back(shapePoint);
37     }
38 
39     PolygonModelNG::SetPoints(frameNode, shapePoints);
40 }
41 
ResetPoints(ArkUINodeHandle node)42 void ResetPoints(ArkUINodeHandle node)
43 {
44     ShapePoints points;
45     auto* frameNode = reinterpret_cast<FrameNode*>(node);
46     CHECK_NULL_VOID(frameNode);
47     PolygonModelNG::SetPoints(frameNode, points);
48 }
49 
50 namespace NodeModifier {
GetPolylineModifier()51 const ArkUIPolylineModifier* GetPolylineModifier()
52 {
53     static const ArkUIPolylineModifier modifier = {SetPoints, ResetPoints};
54 
55     return &modifier;
56 }
57 
GetCJUIPolylineModifier()58 const CJUIPolylineModifier* GetCJUIPolylineModifier()
59 {
60     static const CJUIPolylineModifier modifier = {SetPoints, ResetPoints};
61 
62     return &modifier;
63 }
64 }
65 }