1 /*
2 * Copyright (c) 2022 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/declarative_frontend/jsview/models/rect_model_impl.h"
17
18 #include "base/memory/referenced.h"
19 #include "bridge/declarative_frontend/view_stack_processor.h"
20 #include "core/components/shape/shape_component.h"
21
22 namespace OHOS::Ace::Framework {
23
Create()24 void RectModelImpl::Create()
25 {
26 RefPtr<ShapeComponent> rectComponent = AceType::MakeRefPtr<OHOS::Ace::ShapeComponent>(ShapeType::RECT);
27 ViewStackProcessor::GetInstance()->ClaimElementId(rectComponent);
28 ViewStackProcessor::GetInstance()->Push(rectComponent);
29 }
30
SetRadiusWidth(const Dimension & value)31 void RectModelImpl::SetRadiusWidth(const Dimension& value)
32 {
33 auto stack = ViewStackProcessor::GetInstance();
34 auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
35 if (!component) {
36 LOGE("shapeComponent is null");
37 return;
38 }
39 AnimationOption option = stack->GetImplicitAnimationOption();
40 component->SetRadiusWidth(value, option);
41 }
42
SetRadiusHeight(const Dimension & value)43 void RectModelImpl::SetRadiusHeight(const Dimension& value)
44 {
45 auto stack = ViewStackProcessor::GetInstance();
46 auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
47 if (!component) {
48 LOGE("shapeComponent is null");
49 return;
50 }
51 AnimationOption option = stack->GetImplicitAnimationOption();
52 component->SetRadiusHeight(value, option);
53 }
54
SetRadiusValue(const Dimension & radiusX,const Dimension & radiusY,int32_t index)55 void RectModelImpl::SetRadiusValue(const Dimension& radiusX, const Dimension& radiusY, int32_t index)
56 {
57 auto stack = ViewStackProcessor::GetInstance();
58 auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
59 AnimationOption option = ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
60 Radius newRadius = Radius(AnimatableDimension(radiusX, option), AnimatableDimension(radiusY, option));
61 switch (index) {
62 case TOP_LEFT_RADIUS:
63 component->SetTopLeftRadius(newRadius);
64 break;
65 case TOP_RIGHT_RADIUS:
66 component->SetTopRightRadius(newRadius);
67 break;
68 case BOTTOM_RIGHT_RADIUS:
69 component->SetBottomRightRadius(newRadius);
70 break;
71 case BOTTOM_LEFT_RADIUS:
72 component->SetBottomLeftRadius(newRadius);
73 break;
74 default:
75 break;
76 }
77 }
78
79 } // namespace OHOS::Ace::Framework