• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_PAINT_METHOD_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/memory/referenced.h"
21 #include "base/utils/macros.h"
22 #include "base/utils/noncopyable.h"
23 #include "core/components_ng/pattern/image/image_content_modifier.h"
24 #include "core/components_ng/pattern/image/image_dfx.h"
25 #include "core/components_ng/pattern/image/image_overlay_modifier.h"
26 #include "core/components_ng/pattern/image/image_render_property.h"
27 #include "core/components_ng/render/canvas_image.h"
28 #include "core/components_ng/render/node_paint_method.h"
29 #include "core/components_ng/render/paint_wrapper.h"
30 
31 namespace OHOS::Ace::NG {
32 struct ImagePaintMethodConfig {
33     bool sensitive = false;
34     bool selected = false;
35     RefPtr<ImageOverlayModifier> imageOverlayModifier;
36     RefPtr<ImageContentModifier> imageContentModifier;
37     ImageInterpolation interpolation = ImageInterpolation::NONE;
38 };
39 
40 class ACE_EXPORT ImagePaintMethod : public NodePaintMethod {
41     DECLARE_ACE_TYPE(ImagePaintMethod, NodePaintMethod);
42 public:
43     explicit ImagePaintMethod(
44         const RefPtr<CanvasImage>& canvasImage, const ImagePaintMethodConfig& imagePainterMethodConfig = {})
45         : selected_(imagePainterMethodConfig.selected), sensitive_(imagePainterMethodConfig.sensitive),
46           canvasImage_(canvasImage), interpolationDefault_(imagePainterMethodConfig.interpolation),
47           imageOverlayModifier_(imagePainterMethodConfig.imageOverlayModifier),
48           imageContentModifier_(imagePainterMethodConfig.imageContentModifier)
49     {}
50     ~ImagePaintMethod() override = default;
51 
52     RefPtr<Modifier> GetOverlayModifier(PaintWrapper* paintWrapper) override;
53     void UpdateOverlayModifier(PaintWrapper* paintWrapper) override;
54 
55     RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override;
56     void UpdateContentModifier(PaintWrapper* paintWrapper) override;
57     void UpdatePaintMethod(
58         const RefPtr<CanvasImage>& canvasImage, const ImagePaintMethodConfig& imagePainterMethodConfig = {});
59 
60 private:
61     void UpdatePaintConfig(PaintWrapper* paintWrapper);
62     void UpdateBorderRadius(PaintWrapper* paintWrapper, ImageDfxConfig& imageDfxConfig);
63 
64     bool selected_ = false;
65     bool sensitive_ = false;
66 
67     RefPtr<CanvasImage> canvasImage_;
68     ImageInterpolation interpolationDefault_ = ImageInterpolation::NONE;
69 
70     RefPtr<ImageOverlayModifier> imageOverlayModifier_;
71     RefPtr<ImageContentModifier> imageContentModifier_;
72 
73     ACE_DISALLOW_COPY_AND_MOVE(ImagePaintMethod);
74 };
75 
76 } // namespace OHOS::Ace::NG
77 
78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_PAINT_METHOD_H
79