1 /*
2 * Copyright (c) 2023 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 "core/components_ng/pattern/divider/divider_modifier.h"
17
18 #include "base/utils/utils.h"
19 #include "core/components_ng/base/modifier.h"
20 #include "core/components_ng/render/drawing.h"
21 #include "core/components_ng/render/drawing_prop_convertor.h"
22 #include "core/components_ng/render/divider_painter.h"
23
24 namespace OHOS::Ace::NG {
DividerModifier()25 DividerModifier::DividerModifier()
26 {
27 color_ = AceType::MakeRefPtr<AnimatablePropertyColor>(LinearColor::BLUE);
28 strokeWidth_ = AceType::MakeRefPtr<AnimatablePropertyFloat>(0.0);
29 dividerLength_ = AceType::MakeRefPtr<PropertyFloat>(0.0);
30 lineCap_ = AceType::MakeRefPtr<PropertyInt>(0);
31 vertical_ = AceType::MakeRefPtr<PropertyBool>(false);
32 offset_ = AceType::MakeRefPtr<PropertyOffsetF>(OffsetF());
33
34 AttachProperty(color_);
35 AttachProperty(strokeWidth_);
36 AttachProperty(dividerLength_);
37 AttachProperty(lineCap_);
38 AttachProperty(vertical_);
39 AttachProperty(offset_);
40 }
41
onDraw(DrawingContext & context)42 void DividerModifier::onDraw(DrawingContext& context)
43 {
44 LineCap lineCap = LineCap(lineCap_->Get());
45 lineCap = lineCap == LineCap::BUTT ? LineCap::SQUARE : lineCap;
46 DividerPainter dividerPainter(
47 strokeWidth_->Get(), dividerLength_->Get(), vertical_->Get(), color_->Get().ToColor(), lineCap);
48 dividerPainter.DrawLine(context.canvas, offset_->Get());
49 }
50 } // namespace OHOS::Ace::NG
51