• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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/image/image_overlay_modifier.h"
17 
18 #include "core/components_ng/render/drawing_prop_convertor.h"
19 
20 namespace OHOS::Ace::NG {
ImageOverlayModifier(const Color & selectedColor)21 ImageOverlayModifier::ImageOverlayModifier(const Color& selectedColor) : selectedColor_(selectedColor)
22 {
23     offset_ = AceType::MakeRefPtr<PropertyOffsetF>(OffsetF());
24     AttachProperty(offset_);
25     isSelected_ = AceType::MakeRefPtr<PropertyBool>(false);
26     AttachProperty(isSelected_);
27     size_ = AceType::MakeRefPtr<PropertySizeF>(SizeF());
28     AttachProperty(size_);
29 }
30 
onDraw(DrawingContext & drawingContext)31 void ImageOverlayModifier::onDraw(DrawingContext& drawingContext)
32 {
33     CHECK_NULL_VOID(isSelected_->Get());
34     auto& canvas = drawingContext.canvas;
35     canvas.Save();
36     RSBrush brush;
37     brush.SetAntiAlias(true);
38     brush.SetColor(selectedColor_.GetValue());
39     canvas.AttachBrush(brush);
40 
41     auto offset = offset_->Get();
42     auto size = size_->Get();
43 
44     canvas.DrawRect(
45         RSRect(offset.GetX(), offset.GetY(), offset.GetX() + size.Width(), offset.GetY() + size.Height()));
46 
47     canvas.DetachBrush();
48     canvas.Restore();
49 }
50 
51 } // namespace OHOS::Ace::NG