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