• 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/shape_abstract_model_impl.h"
17 
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 #include "core/components/shape/shape_component.h"
20 
21 namespace OHOS::Ace::Framework {
22 
SetStroke(const Color & color)23 void ShapeAbstractModelImpl::SetStroke(const Color& color)
24 {
25     auto stack = ViewStackProcessor::GetInstance();
26     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
27     if (component) {
28         AnimationOption option = stack->GetImplicitAnimationOption();
29         component->SetStroke(color, option);
30     }
31 }
32 
SetFill(const Color & color)33 void ShapeAbstractModelImpl::SetFill(const Color& color)
34 {
35     auto stack = ViewStackProcessor::GetInstance();
36     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
37     if (!component) {
38         LOGE("component is null");
39         return;
40     }
41     AnimationOption option = stack->GetImplicitAnimationOption();
42     component->SetFill(color, option);
43 }
44 
SetForegroundColor(const Color & color)45 void ShapeAbstractModelImpl::SetForegroundColor(const Color& color)
46 {
47     SetFill(color);
48 }
49 
SetStrokeDashOffset(const Ace::Dimension & dashOffset)50 void ShapeAbstractModelImpl::SetStrokeDashOffset(const Ace::Dimension& dashOffset)
51 {
52     auto stack = ViewStackProcessor::GetInstance();
53     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
54     if (component) {
55         AnimationOption option = stack->GetImplicitAnimationOption();
56         component->SetStrokeDashOffset(dashOffset, option);
57     }
58 }
59 
SetStrokeLineCap(int lineCapStyle)60 void ShapeAbstractModelImpl::SetStrokeLineCap(int lineCapStyle)
61 {
62     auto stack = ViewStackProcessor::GetInstance();
63     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
64     if (!component) {
65         LOGE("ShapeComponent is null");
66         return;
67     }
68     if (static_cast<int>(LineCapStyle::SQUARE) == lineCapStyle) {
69         component->SetStrokeLineCap(LineCapStyle::SQUARE);
70     } else if (static_cast<int>(LineCapStyle::ROUND) == lineCapStyle) {
71         component->SetStrokeLineCap(LineCapStyle::ROUND);
72     } else {
73         component->SetStrokeLineCap(LineCapStyle::BUTT);
74     }
75 }
76 
SetStrokeLineJoin(int lineJoinStyle)77 void ShapeAbstractModelImpl::SetStrokeLineJoin(int lineJoinStyle)
78 {
79     auto stack = ViewStackProcessor::GetInstance();
80     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
81     if (!component) {
82         LOGE("ShapeComponent is null");
83         return;
84     }
85     if (static_cast<int>(LineJoinStyle::BEVEL) == lineJoinStyle) {
86         component->SetStrokeLineJoin(LineJoinStyle::BEVEL);
87     } else if (static_cast<int>(LineJoinStyle::ROUND) == lineJoinStyle) {
88         component->SetStrokeLineJoin(LineJoinStyle::ROUND);
89     } else {
90         component->SetStrokeLineJoin(LineJoinStyle::MITER);
91     }
92 }
93 
SetStrokeMiterLimit(double miterLimit)94 void ShapeAbstractModelImpl::SetStrokeMiterLimit(double miterLimit)
95 {
96     auto stack = ViewStackProcessor::GetInstance();
97     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
98     if (!component) {
99         LOGE("ShapeComponent is null");
100         return;
101     }
102     component->SetStrokeMiterLimit(miterLimit);
103 }
104 
SetStrokeOpacity(double opacity)105 void ShapeAbstractModelImpl::SetStrokeOpacity(double opacity)
106 {
107     auto stack = ViewStackProcessor::GetInstance();
108     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
109     if (component) {
110         AnimationOption option = stack->GetImplicitAnimationOption();
111         component->SetStrokeOpacity(opacity, option);
112     }
113 }
114 
SetFillOpacity(double opacity)115 void ShapeAbstractModelImpl::SetFillOpacity(double opacity)
116 {
117     auto stack = ViewStackProcessor::GetInstance();
118     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
119     if (component) {
120         AnimationOption option = stack->GetImplicitAnimationOption();
121         component->SetFillOpacity(opacity, option);
122     }
123 }
124 
SetStrokeWidth(const Ace::Dimension & lineWidth)125 void ShapeAbstractModelImpl::SetStrokeWidth(const Ace::Dimension& lineWidth)
126 {
127     auto stack = ViewStackProcessor::GetInstance();
128     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
129     if (!component) {
130         LOGE("ShapeComponent is null");
131         return;
132     }
133     AnimationOption option = stack->GetImplicitAnimationOption();
134     component->SetStrokeWidth(lineWidth, option);
135 }
136 
SetStrokeDashArray(const std::vector<Ace::Dimension> & dashArray)137 void ShapeAbstractModelImpl::SetStrokeDashArray(const std::vector<Ace::Dimension>& dashArray)
138 {
139     auto stack = ViewStackProcessor::GetInstance();
140     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
141     if (!component) {
142         LOGE("component is null");
143         return;
144     }
145     component->SetStrokeDashArray(dashArray);
146 }
SetAntiAlias(bool antiAlias)147 void ShapeAbstractModelImpl::SetAntiAlias(bool antiAlias)
148 {
149     auto stack = ViewStackProcessor::GetInstance();
150     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
151     if (component) {
152         component->SetAntiAlias(antiAlias);
153     }
154 }
155 
SetWidth(Dimension & width)156 void ShapeAbstractModelImpl::SetWidth(Dimension& width)
157 {
158     auto stack = ViewStackProcessor::GetInstance();
159     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
160     if (!component) {
161         LOGE("ShapeComponent is null");
162         return;
163     }
164     AnimationOption option = stack->GetImplicitAnimationOption();
165     component->SetWidth(width, option);
166 }
167 
SetHeight(Dimension & height)168 void ShapeAbstractModelImpl::SetHeight(Dimension& height)
169 {
170     auto stack = ViewStackProcessor::GetInstance();
171     auto component = AceType::DynamicCast<OHOS::Ace::ShapeComponent>(stack->GetMainComponent());
172     if (!component) {
173         LOGE("ShapeComponent is null");
174         return;
175     }
176     AnimationOption option = stack->GetImplicitAnimationOption();
177     component->SetHeight(height, option);
178 }
179 
180 } // namespace OHOS::Ace::Framework