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/rect_modifier.h"
16
17 #include "core/components_ng/base/frame_node.h"
18 #include "core/components_ng/pattern/shape/rect_model_ng.h"
19
20 namespace OHOS::Ace::NG {
21 namespace {
22 constexpr uint32_t VALID_RADIUS_PAIR_FLAG = 1;
23 } // namespace
SetRectRadiusWidth(ArkUINodeHandle node,ArkUI_Float32 radiusWidthValue,ArkUI_Int32 radiusWidthUnit)24 void SetRectRadiusWidth(ArkUINodeHandle node, ArkUI_Float32 radiusWidthValue, ArkUI_Int32 radiusWidthUnit)
25 {
26 auto* frameNode = reinterpret_cast<FrameNode*>(node);
27 CHECK_NULL_VOID(frameNode);
28 RectModelNG::SetRadiusWidth(frameNode, CalcDimension(radiusWidthValue, (DimensionUnit)radiusWidthUnit));
29 }
30
ResetRectRadiusWidth(ArkUINodeHandle node)31 void ResetRectRadiusWidth(ArkUINodeHandle node)
32 {
33 auto* frameNode = reinterpret_cast<FrameNode*>(node);
34 CHECK_NULL_VOID(frameNode);
35 CalcDimension defaultDimension;
36 defaultDimension.Reset();
37 RectModelNG::SetRadiusWidth(frameNode, defaultDimension);
38 return;
39 }
40
SetRectRadiusHeight(ArkUINodeHandle node,ArkUI_Float32 radiusHeightValue,ArkUI_Int32 radiusHeightUnit)41 void SetRectRadiusHeight(ArkUINodeHandle node, ArkUI_Float32 radiusHeightValue, ArkUI_Int32 radiusHeightUnit)
42 {
43 auto* frameNode = reinterpret_cast<FrameNode*>(node);
44 CHECK_NULL_VOID(frameNode);
45 RectModelNG::SetRadiusHeight(frameNode, CalcDimension(radiusHeightValue, (DimensionUnit)radiusHeightUnit));
46 }
47
ResetRectRadiusHeight(ArkUINodeHandle node)48 void ResetRectRadiusHeight(ArkUINodeHandle node)
49 {
50 auto* frameNode = reinterpret_cast<FrameNode*>(node);
51 CHECK_NULL_VOID(frameNode);
52 CalcDimension defaultDimension;
53 defaultDimension.Reset();
54 RectModelNG::SetRadiusHeight(frameNode, defaultDimension);
55 }
56
SetRectRadiusWithArray(ArkUINodeHandle node,ArkUI_Float32 * radiusValues,ArkUI_Int32 * radiusUnits,ArkUI_Uint32 * radiusValidPairs,ArkUI_Uint32 radiusValidPairsSize)57 void SetRectRadiusWithArray(ArkUINodeHandle node, ArkUI_Float32* radiusValues, ArkUI_Int32* radiusUnits,
58 ArkUI_Uint32* radiusValidPairs, ArkUI_Uint32 radiusValidPairsSize)
59 {
60 NG::ResetRectRadiusHeight(node);
61 NG::ResetRectRadiusWidth(node);
62 auto* frameNode = reinterpret_cast<FrameNode*>(node);
63 CHECK_NULL_VOID(frameNode);
64 CHECK_NULL_VOID(radiusValues);
65 CHECK_NULL_VOID(radiusUnits);
66 CHECK_NULL_VOID(radiusValidPairs);
67 for (size_t index = 0; index < radiusValidPairsSize; index++) {
68 if (radiusValidPairs[index] == VALID_RADIUS_PAIR_FLAG) {
69 uint32_t xIndex = index * 2;
70 uint32_t yIndex = xIndex + 1;
71 auto radiusX = CalcDimension(radiusValues[xIndex], (DimensionUnit)radiusUnits[xIndex]);
72 auto radiusY = CalcDimension(radiusValues[yIndex], (DimensionUnit)radiusUnits[yIndex]);
73 RectModelNG::SetRadiusValue(frameNode, radiusX, radiusY, index);
74 }
75 }
76 }
77
SetRectRadiusWithValue(ArkUINodeHandle node,ArkUI_Float32 radiusValue,ArkUI_Int32 radiusUnit)78 void SetRectRadiusWithValue(ArkUINodeHandle node, ArkUI_Float32 radiusValue, ArkUI_Int32 radiusUnit)
79 {
80 auto* frameNode = reinterpret_cast<FrameNode*>(node);
81 CHECK_NULL_VOID(frameNode);
82 NG::ResetRectRadiusWidth(node);
83 NG::ResetRectRadiusHeight(node);
84 RectModelNG::SetRadiusWidth(frameNode, CalcDimension(radiusValue, (DimensionUnit)radiusUnit));
85 RectModelNG::SetRadiusHeight(frameNode, CalcDimension(radiusValue, (DimensionUnit)radiusUnit));
86 }
87
ResetRectRadius(ArkUINodeHandle node)88 void ResetRectRadius(ArkUINodeHandle node)
89 {
90 NG::ResetRectRadiusHeight(node);
91 NG::ResetRectRadiusWidth(node);
92 }
93
94 namespace NodeModifier {
GetRectModifier()95 const ArkUIRectModifier* GetRectModifier()
96 {
97 static const ArkUIRectModifier modifier = { SetRectRadiusWidth, ResetRectRadiusWidth, SetRectRadiusHeight,
98 ResetRectRadiusHeight, SetRectRadiusWithArray, SetRectRadiusWithValue, ResetRectRadius };
99
100 return &modifier;
101 }
102
GetCJUIRectModifier()103 const CJUIRectModifier* GetCJUIRectModifier()
104 {
105 static const CJUIRectModifier modifier = { SetRectRadiusWidth, ResetRectRadiusWidth, SetRectRadiusHeight,
106 ResetRectRadiusHeight, SetRectRadiusWithArray, SetRectRadiusWithValue, ResetRectRadius };
107
108 return &modifier;
109 }
110 }
111 } // namespace OHOS::Ace::NG
112