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/line_modifier.h"
16
17 #include "core/pipeline/base/element_register.h"
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/pattern/shape/line_model_ng.h"
20 #include "core/components/common/layout/constants.h"
21 #include "base/geometry/shape.h"
22
23 namespace OHOS::Ace::NG {
SetStartPoint(ArkUINodeHandle node,const ArkUI_Float32 * pointValues,const ArkUI_Int32 * pointUnits,const char * pointStr[])24 void SetStartPoint(ArkUINodeHandle node, const ArkUI_Float32* pointValues, const ArkUI_Int32* pointUnits,
25 const char* pointStr[])
26 {
27 ShapePoint point;
28 auto* frameNode = reinterpret_cast<FrameNode*>(node);
29 CHECK_NULL_VOID(frameNode);
30 point.first = Dimension(pointValues[0], static_cast<OHOS::Ace::DimensionUnit>(pointUnits[0]));
31 point.second = Dimension(pointValues[1], static_cast<OHOS::Ace::DimensionUnit>(pointUnits[1]));
32 LineModelNG::StartPoint(frameNode, point);
33 }
34
ResetStartPoint(ArkUINodeHandle node)35 void ResetStartPoint(ArkUINodeHandle node)
36 {
37 ShapePoint point;
38 point.first = 0.0_vp;
39 point.second = 0.0_vp;
40 auto* frameNode = reinterpret_cast<FrameNode*>(node);
41 CHECK_NULL_VOID(frameNode);
42 LineModelNG::StartPoint(frameNode, point);
43 }
44
SetEndPoint(ArkUINodeHandle node,const ArkUI_Float32 * pointValues,const ArkUI_Int32 * pointUnits,const char * pointStr[])45 void SetEndPoint(ArkUINodeHandle node, const ArkUI_Float32* pointValues, const ArkUI_Int32* pointUnits,
46 const char* pointStr[])
47 {
48 ShapePoint point;
49 auto* frameNode = reinterpret_cast<FrameNode*>(node);
50 CHECK_NULL_VOID(frameNode);
51 point.first = Dimension(pointValues[0], static_cast<OHOS::Ace::DimensionUnit>(pointUnits[0]));
52 point.second = Dimension(pointValues[1], static_cast<OHOS::Ace::DimensionUnit>(pointUnits[1]));
53 LineModelNG::EndPoint(frameNode, point);
54 }
55
ResetEndPoint(ArkUINodeHandle node)56 void ResetEndPoint(ArkUINodeHandle node)
57 {
58 ShapePoint point;
59 point.first = 0.0_vp;
60 point.second = 0.0_vp;
61 auto* frameNode = reinterpret_cast<FrameNode*>(node);
62 CHECK_NULL_VOID(frameNode);
63 LineModelNG::EndPoint(frameNode, point);
64 }
65
66 namespace NodeModifier {
GetLineModifier()67 const ArkUILineModifier* GetLineModifier()
68 {
69 static const ArkUILineModifier modifier = {SetStartPoint, ResetStartPoint, SetEndPoint, ResetEndPoint};
70 return &modifier;
71 }
72
GetCJUILineModifier()73 const CJUILineModifier* GetCJUILineModifier()
74 {
75 static const CJUILineModifier modifier = {SetStartPoint, ResetStartPoint, SetEndPoint, ResetEndPoint};
76 return &modifier;
77 }
78 }
79 }