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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLL_BAR_OVERLAY_MODIFIER_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLL_BAR_OVERLAY_MODIFIER_H 17 18 #include "base/memory/ace_type.h" 19 #include "core/components/common/properties/color.h" 20 #include "core/components_ng/base/modifier.h" 21 #include "core/components_ng/render/node_paint_method.h" 22 23 namespace OHOS::Ace::NG { 24 enum class OpacityAnimationType { 25 /* 26 * do not run opacity animation. 27 */ 28 NONE = 0, 29 /* 30 * run disappear animation. 31 */ 32 DISAPPEAR, 33 /* 34 * run appear animation. 35 */ 36 APPEAR, 37 }; 38 39 enum class HoverAnimationType { 40 /* 41 * do not run hover animation. 42 */ 43 NONE = 0, 44 /* 45 * run grow animation. 46 */ 47 GROW, 48 /* 49 * run shrink animation. 50 */ 51 SHRINK, 52 }; 53 class ScrollBarOverlayModifier : public OverlayModifier { 54 DECLARE_ACE_TYPE(ScrollBarOverlayModifier, OverlayModifier) 55 56 public: 57 ScrollBarOverlayModifier(const OffsetF& fgOffset = OffsetF(), const OffsetF& bgOffset = OffsetF(), 58 const SizeF& fgSize = SizeF(), const SizeF& bgSize = SizeF()); 59 60 ~ScrollBarOverlayModifier() override = default; 61 62 void onDraw(DrawingContext& drawingContext) override; 63 64 void StartOpacityAnimation(OpacityAnimationType opacityAnimationType); 65 66 void StartHoverAnimation(const SizeF& fgSize, const SizeF& bgSize, const OffsetF& fgOffset, const OffsetF& bgOffset, 67 HoverAnimationType hoverAnimationType); 68 69 void SetOffset(const OffsetF& fgOffset, const OffsetF& bgOffset); 70 71 void SetSize(const SizeF& fgSize, const SizeF& bgSize); 72 73 void SetRect(const Rect& fgRect, const Rect& bgRect); 74 75 void SetFgColor(Color fgColor); 76 77 void SetBgColor(Color bgColor); 78 79 void StopBarOpacityAnimation(); 80 81 void StopBarHoverAnimation(); 82 GetHoverAnimatingType()83 HoverAnimationType GetHoverAnimatingType() const 84 { 85 return hoverAnimatingType_; 86 } 87 SetHoverAnimatingType(HoverAnimationType hoverAnimatingType)88 void SetHoverAnimatingType(HoverAnimationType hoverAnimatingType) 89 { 90 hoverAnimatingType_ = hoverAnimatingType; 91 } 92 GetOpacityAnimatingType()93 OpacityAnimationType GetOpacityAnimatingType() const 94 { 95 return opacityAnimatingType_; 96 } 97 SetOpacityAnimatingType(OpacityAnimationType opacityAnimatingType)98 void SetOpacityAnimatingType(OpacityAnimationType opacityAnimatingType) 99 { 100 opacityAnimatingType_ = opacityAnimatingType; 101 } 102 SetOpacity(uint8_t opacity)103 void SetOpacity(uint8_t opacity) 104 { 105 CHECK_NULL_VOID_NOLOG(opacity_); 106 opacity_->Set(opacity); 107 } 108 GetOpacity()109 uint8_t GetOpacity() const 110 { 111 CHECK_NULL_RETURN_NOLOG(opacity_, 0); 112 return opacity_->Get(); 113 } 114 115 private: 116 // Animatable 117 RefPtr<AnimatablePropertyUint8> opacity_; 118 RefPtr<AnimatablePropertyOffsetF> fgOffset_; 119 RefPtr<AnimatablePropertySizeF> fgSize_; 120 RefPtr<AnimatablePropertyOffsetF> bgOffset_; 121 RefPtr<AnimatablePropertySizeF> bgSize_; 122 123 // no Animatable 124 RefPtr<PropertyColor> fgColor_; 125 RefPtr<PropertyColor> bgColor_; 126 ACE_DISALLOW_COPY_AND_MOVE(ScrollBarOverlayModifier); 127 128 std::shared_ptr<AnimationUtils::Animation> hoverAnimation_; 129 std::shared_ptr<AnimationUtils::Animation> opacityAnimation_; 130 HoverAnimationType hoverAnimatingType_ = HoverAnimationType::NONE; 131 OpacityAnimationType opacityAnimatingType_ = OpacityAnimationType::NONE; 132 }; 133 } // namespace OHOS::Ace::NG 134 135 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLL_BAR_OVERLAY_MODIFIER_H