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