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 "base/memory/referenced.h"
17 #include "bridge/declarative_frontend/jsview/models/line_model_impl.h"
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 #include "core/components/shape/shape_component.h"
20 
21 namespace OHOS::Ace::Framework {
22 
Create()23 void LineModelImpl::Create()
24 {
25     RefPtr<ShapeComponent> lineComponent = AceType::MakeRefPtr<OHOS::Ace::ShapeComponent>(ShapeType::LINE);
26     ViewStackProcessor::GetInstance()->ClaimElementId(lineComponent);
27     lineComponent->SetStroke(Color::BLACK);
28     ViewStackProcessor::GetInstance()->Push(lineComponent);
29 }
30 
StartPoint(const ShapePoint & value)31 void LineModelImpl::StartPoint(const ShapePoint &value)
32 {
33     auto line = AceType::DynamicCast<ShapeComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
34     if (!line) {
35         LOGE("startPointComponent is null.");
36         return;
37     }
38     line->SetStart(value);
39 }
40 
EndPoint(const ShapePoint & value)41 void LineModelImpl::EndPoint(const ShapePoint &value)
42 {
43     auto line = AceType::DynamicCast<ShapeComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
44     if (!line) {
45         LOGE("startPointComponent is null.");
46         return;
47     }
48     line->SetEnd(value);
49 }
50 
51 } // namespace OHOS::Ace::Framework