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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RENDER_HODE_RENDER_NODE_MODIFIER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RENDER_HODE_RENDER_NODE_MODIFIER_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/memory/referenced.h"
21 #include "core/common/container.h"
22 #include "core/components_ng/base/modifier.h"
23 #include "core/components_ng/property/property.h"
24 #include "core/components_ng/render/canvas_image.h"
25 #include "core/components_ng/render/drawing_forward.h"
26 #include "core/components_ng/render/paint_wrapper.h"
27 
28 namespace OHOS::Ace::NG {
29 class RenderNodeModifier : public ContentModifier {
30     DECLARE_ACE_TYPE(RenderNodeModifier, ContentModifier);
31 
32 public:
RenderNodeModifier(const std::function<void (DrawingContext & context)> & drawCallback)33     explicit RenderNodeModifier(const std::function<void(DrawingContext& context)>& drawCallback)
34         : drawCallback_(drawCallback)
35     {
36         renderNodeFlag_ = AceType::MakeRefPtr<PropertyInt>(0);
37         AttachProperty(renderNodeFlag_);
38     };
39 
40     ~RenderNodeModifier() override = default;
41 
onDraw(DrawingContext & context)42     void onDraw(DrawingContext& context) override
43     {
44         if (drawCallback_) {
45             drawCallback_(context);
46         }
47     }
48 
SetRenderNodeFlag(int32_t renderNodeFlag)49     void SetRenderNodeFlag(int32_t renderNodeFlag)
50     {
51         renderNodeFlag_->Set(renderNodeFlag);
52     }
53 
Modify()54     void Modify()
55     {
56         renderNodeFlag_->Set(renderNodeFlag_->Get() + 1);
57     }
58 
59 private:
60     std::function<void(DrawingContext& context)> drawCallback_;
61     RefPtr<PropertyInt> renderNodeFlag_;
62 };
63 } // namespace OHOS::Ace::NG
64 
65 #endif
66