• 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_BORDER_IMAGE_MODIFIER_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_BORDER_IMAGE_MODIFIER_H
17 
18 #include <functional>
19 #include <memory>
20 
21 #include "core/components_ng/property/gradient_property.h"
22 #include "core/components_ng/render/adapter/rosen_modifier_adapter.h"
23 
24 namespace OHOS::Ace::NG {
25 class BorderImageModifier : public RSForegroundStyleModifier {
26 public:
27     BorderImageModifier() = default;
28     ~BorderImageModifier() override = default;
29 
Draw(RSDrawingContext & context)30     void Draw(RSDrawingContext& context) const override
31     {
32         CHECK_NULL_VOID(context.canvas);
33         CHECK_NULL_VOID(paintTask_);
34         paintTask_(*context.canvas);
35     }
36 
SetPaintTask(std::function<void (RSCanvas &)> && paintTask)37     void SetPaintTask(std::function<void(RSCanvas&)>&& paintTask)
38     {
39         paintTask_ = paintTask;
40     }
41 
Modify()42     void Modify()
43     {
44         if (!flag_) {
45             flag_ = std::make_shared<Rosen::RSProperty<bool>>(0);
46             AttachProperty(flag_);
47         } else {
48             flag_->Set(!flag_->Get());
49         }
50     }
51 
52 private:
53     std::shared_ptr<Rosen::RSProperty<bool>> flag_;
54     std::function<void(RSCanvas&)> paintTask_;
55 };
56 
57 } // namespace OHOS::Ace::NG
58 
59 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_BORDER_IMAGE_MODIFIER_H
60