• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(NodeHandle node,double * dimValues,int32_t * dimUnits)24 void SetShapeViewPort(NodeHandle node, double* dimValues, int32_t* 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(NodeHandle node)35 void ResetShapeViewPort(NodeHandle 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(NodeHandle node,const double * mesh,size_t arrayItemCount,int32_t column,int32_t row)46 void SetShapeMesh(NodeHandle node, const double* mesh, size_t arrayItemCount, int32_t column, int32_t row)
47 {
48     auto* frameNode = reinterpret_cast<FrameNode*>(node);
49     CHECK_NULL_VOID(frameNode);
50     std::vector<double> meshVaules(mesh, mesh + arrayItemCount);
51     ShapeModelNG::SetBitmapMesh(frameNode, meshVaules, column, row);
52 }
53 
ResetShapeMesh(NodeHandle node)54 void ResetShapeMesh(NodeHandle node)
55 {
56     auto* frameNode = reinterpret_cast<FrameNode*>(node);
57     CHECK_NULL_VOID(frameNode);
58     std::vector<double> meshVaules;
59     int32_t column = 0;
60     int32_t row = 0;
61     ShapeModelNG::SetBitmapMesh(frameNode, meshVaules, column, row);
62 }
63 
GetShapeModifier()64 ArkUIShapeModifierAPI GetShapeModifier()
65 {
66     static const ArkUIShapeModifierAPI modifier = { SetShapeViewPort, ResetShapeViewPort, SetShapeMesh,
67         ResetShapeMesh };
68     return modifier;
69 }
70 } // namespace OHOS::Ace::NG
71