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) vertical_(vertical)28 : vertical_(vertical), isReverse_(isReverse), isVerticalReverse_(isVerticalReverse) 29 {} 30 ~ScrollablePaintMethod() override = default; 31 SetOverlayRenderContext(const RefPtr<RenderContext> & overlayRenderContext)32 void SetOverlayRenderContext(const RefPtr<RenderContext>& overlayRenderContext) 33 { 34 overlayRenderContext_ = overlayRenderContext; 35 } 36 37 void SetFadingInfo(bool isFadingTop, bool isFadingBottom, float percentFading = 0.0f, 38 float startPercent = 0.0f, float endPercent = 1.0f) 39 { 40 isFadingTop_ = isFadingTop; 41 isFadingBottom_ = isFadingBottom; 42 percentFading_ = percentFading; 43 startPercent_ = startPercent; 44 endPercent_ = endPercent; 45 } 46 SetHasFadingEdge(bool hasFadingEdge)47 void SetHasFadingEdge(bool hasFadingEdge) 48 { 49 hasFadingEdge_ = hasFadingEdge; 50 } 51 SetNeedUpdateFadingEdge(bool needUpdate)52 void SetNeedUpdateFadingEdge(bool needUpdate) 53 { 54 needUpdateFadingEdge_ = needUpdate; 55 } 56 57 protected: 58 void UpdateFadingGradient(const RefPtr<RenderContext>& renderContext); 59 60 /** 61 * @brief Try to set content clip to render context. 62 * 63 * @return true if content clip is set up 64 */ 65 bool TryContentClip(PaintWrapper* wrapper); 66 67 bool vertical_ = false; 68 bool isReverse_ = false; 69 bool isVerticalReverse_ = false; 70 71 private: 72 RefPtr<RenderContext> overlayRenderContext_; 73 bool isFadingTop_ = false; 74 bool isFadingBottom_ = false; 75 bool needUpdateFadingEdge_ = false; 76 bool hasFadingEdge_ = false; 77 float percentFading_ = 0.0f; 78 float startPercent_ = 0.0f; 79 float endPercent_ = 1.0f; 80 }; 81 } // namespace OHOS::Ace::NG 82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_PAINT_METHOD_H 83