1 /*
2  * Copyright (c) 2024 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 
16 #include "bridge/cj_frontend/cppview/shape_abstract.h"
17 
18 #include <cinttypes>
19 
20 namespace OHOS::Ace::Framework {
21 
NativeShapeAbstract()22 NativeShapeAbstract::NativeShapeAbstract() : FFIData()
23 {
24     LOGI("Native ShapeAbstract constructed: %{public}" PRId64, GetID());
25 }
26 
~NativeShapeAbstract()27 NativeShapeAbstract::~NativeShapeAbstract()
28 {
29     LOGI("Native ShapeAbstract Destroyed: %{public}" PRId64, GetID());
30 }
31 
SetWidth(const Dimension & value)32 void NativeShapeAbstract::SetWidth(const Dimension& value)
33 {
34     if (basicShape_) {
35         basicShape_->SetWidth(value);
36     } else {
37         LOGE("basicShape is not exist");
38     }
39 }
40 
SetHeight(const Dimension & value)41 void NativeShapeAbstract::SetHeight(const Dimension& value)
42 {
43     if (basicShape_) {
44         basicShape_->SetHeight(value);
45     } else {
46         LOGE("basicShape is not exist");
47     }
48 }
49 
SetSize(const Dimension & width,const Dimension & height)50 void NativeShapeAbstract::SetSize(const Dimension& width, const Dimension& height)
51 {
52     SetWidth(width);
53     SetHeight(height);
54 }
55 
SetOffset(const Dimension & x,const Dimension & y)56 void NativeShapeAbstract::SetOffset(const Dimension& x, const Dimension& y)
57 {
58     if (basicShape_) {
59         basicShape_->SetOffset(DimensionOffset(x, y));
60     } else {
61         LOGE("basicShape is not exist");
62     }
63 }
64 
SetFill(const Color & color)65 void NativeShapeAbstract::SetFill(const Color& color)
66 {
67     if (basicShape_) {
68         basicShape_->SetColor(color);
69     } else {
70         LOGE("basicShape is not exist");
71     }
72 }
73 
NativeCircle(const Dimension & width,const Dimension & height)74 NativeCircle::NativeCircle(const Dimension& width, const Dimension& height) : NativeShapeAbstract()
75 {
76     auto circle = AceType::MakeRefPtr<Circle>();
77     circle->SetWidth(width);
78     circle->SetHeight(height);
79     SetBasicShape(circle);
80     LOGI("NativeCircle constructed: %{public}" PRId64, GetID());
81 }
82 
~NativeCircle()83 NativeCircle::~NativeCircle()
84 {
85     LOGI("NativeCircle Destroyed: %{public}" PRId64, GetID());
86 }
87 
NativeEllipse(const Dimension & width,const Dimension & height)88 NativeEllipse::NativeEllipse(const Dimension& width, const Dimension& height) : NativeShapeAbstract()
89 {
90     auto ellipse = AceType::MakeRefPtr<Ellipse>();
91     ellipse->SetWidth(width);
92     ellipse->SetHeight(height);
93     SetBasicShape(ellipse);
94     LOGI("NativeEllipse constructed: %{public}" PRId64, GetID());
95 }
96 
~NativeEllipse()97 NativeEllipse::~NativeEllipse()
98 {
99     LOGI("NativeEllipse Destroyed: %{public}" PRId64, GetID());
100 }
101 
NativeRect(const Dimension & width,const Dimension & height)102 NativeRect::NativeRect(const Dimension& width, const Dimension& height) : NativeShapeAbstract()
103 {
104     auto rect = AceType::MakeRefPtr<ShapeRect>();
105     rect->SetWidth(width);
106     rect->SetHeight(height);
107     SetBasicShape(rect);
108     LOGI("NativeRect constructed: %{public}" PRId64, GetID());
109 }
110 
~NativeRect()111 NativeRect::~NativeRect()
112 {
113     LOGI("NativeRect Destroyed: %{public}" PRId64, GetID());
114 }
115 
SetRadius(const OHOS::Ace::Dimension & value)116 void NativeRect::SetRadius(const OHOS::Ace::Dimension& value)
117 {
118     SetRadiusWidth(value);
119     SetRadiusHeight(value);
120 }
121 
SetRadiusWidth(const OHOS::Ace::Dimension & value)122 void NativeRect::SetRadiusWidth(const OHOS::Ace::Dimension& value)
123 {
124     if (basicShape_) {
125         auto rect = AceType::DynamicCast<ShapeRect>(basicShape_);
126         rect->SetRadiusWidth(value);
127     } else {
128         LOGE("basicShape is not exist");
129     }
130 }
131 
SetRadiusHeight(const OHOS::Ace::Dimension & value)132 void NativeRect::SetRadiusHeight(const OHOS::Ace::Dimension& value)
133 {
134     if (basicShape_) {
135         auto rect = AceType::DynamicCast<ShapeRect>(basicShape_);
136         rect->SetRadiusHeight(value);
137     } else {
138         LOGE("basicShape is not exist");
139     }
140 }
141 
NativePath(const std::string & pathCmd)142 NativePath::NativePath(const std::string& pathCmd) : NativeShapeAbstract()
143 {
144     auto path = AceType::MakeRefPtr<Path>();
145     path->SetValue(pathCmd);
146     SetBasicShape(path);
147     LOGI("NativePath constructed: %{public}" PRId64, GetID());
148 }
149 
~NativePath()150 NativePath::~NativePath()
151 {
152     LOGI("NativePath Destroyed: %{public}" PRId64, GetID());
153 }
154 } // namespace OHOS::Ace::Framework
155