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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_PAINT_METHOD_H
18 
19 #include "core/components_ng/pattern/scrollable/scrollable_paint_property.h"
20 #include "core/components_ng/render/node_paint_method.h"
21 
22 namespace OHOS::Ace::NG {
23 class ACE_EXPORT ScrollablePaintMethod : public NodePaintMethod {
24     DECLARE_ACE_TYPE(ScrollablePaintMethod, NodePaintMethod)
25 public:
26     ScrollablePaintMethod() = default;
27     ScrollablePaintMethod(bool vertical, bool isReverse, bool isVerticalReverse = false)
28         : vertical_(vertical), isReverse_(isReverse), isVerticalReverse_(isVerticalReverse)
29     {}
30     ~ScrollablePaintMethod() override = default;
31 
32 
SetOverlayRenderContext(const RefPtr<RenderContext> & overlayRenderContext)33     void SetOverlayRenderContext(const RefPtr<RenderContext>& overlayRenderContext)
34     {
35         overlayRenderContext_ = overlayRenderContext;
36     }
37 
38     void SetFadingInfo(bool isFadingTop, bool isFadingBottom, bool hasFadingEdge, float percentFading = 0.0f,
39         float startPercent = 0.0f, float endPercent = 1.0f)
40     {
41         isFadingTop_ = isFadingTop;
42         isFadingBottom_ = isFadingBottom;
43         hasFadingEdge_ = hasFadingEdge;
44         percentFading_ = percentFading;
45         startPercent_ = startPercent;
46         endPercent_ = endPercent;
47     }
48 
49 protected:
50     void UpdateFadingGradient(const RefPtr<RenderContext>& renderContext);
51 
52     /**
53      * @brief Try to set content clip to render context.
54      *
55      * @return true if content clip is set up
56      */
57     bool TryContentClip(PaintWrapper* wrapper);
58 
59     bool vertical_ = false;
60     bool isReverse_ = false;
61     bool isVerticalReverse_ = false;
62 
63 private:
64     RefPtr<RenderContext> overlayRenderContext_;
65     bool isFadingTop_ = false;
66     bool isFadingBottom_ = false;
67     bool hasFadingEdge_ = false;
68     float percentFading_ = 0.0f;
69     float startPercent_ = 0.0f;
70     float endPercent_ = 1.0f;
71 
72 };
73 } // namespace OHOS::Ace::NG
74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_PAINT_METHOD_H