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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_MODIFIER_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components_ng/base/modifier.h" 22 #include "core/components_ng/pattern/loading_progress/loading_progress_base.h" 23 #include "core/components_ng/pattern/loading_progress/loading_progress_owner.h" 24 #include "core/components_ng/pattern/refresh/refresh_animation_state.h" 25 #include "core/components_ng/property/property.h" 26 #include "core/components_ng/render/animation_utils.h" 27 #include "core/components_ng/render/drawing.h" 28 29 namespace OHOS::Ace::NG { 30 class LoadingProgressModifier : public ContentModifier { 31 DECLARE_ACE_TYPE(LoadingProgressModifier, ContentModifier); 32 33 public: 34 explicit LoadingProgressModifier(LoadingProgressOwner loadingProgressOwner = LoadingProgressOwner::SELF); 35 ~LoadingProgressModifier() override = default; 36 void onDraw(DrawingContext& context) override; 37 void DrawOrbit(DrawingContext& canvas, const CometParam& cometParam, float orbitRadius, float date); 38 void DrawRing(DrawingContext& canvas, const RingParam& ringParam); 39 void StartRecycle(); 40 void StartRecycleRingAnimation(); 41 void StartRecycleCometAnimation(); 42 void StartCometTailAnimation(); 43 void StartTransToRecycleAnimation(); SetColor(LinearColor color)44 void SetColor(LinearColor color) 45 { 46 if (color_) { 47 color_->Set(color); 48 } 49 } 50 51 void DrawCustomStyle(DrawingContext& context); 52 void RefreshRecycle(DrawingContext& context, Color& color, float scale); 53 void ChangeRefreshFollowData(float refreshFollowRatio); 54 void ChangeSizeScaleData(float fadeAwayRatio); 55 float CorrectNormalize(float originData); 56 GetOwner()57 LoadingProgressOwner GetOwner() 58 { 59 return loadingProgressOwner_; 60 } 61 SetVisible(bool isVisible)62 void SetVisible(bool isVisible) 63 { 64 CHECK_NULL_VOID(isVisible_ != isVisible); 65 isVisible_ = isVisible; 66 isLoading_ = false; 67 } 68 GetVisible()69 bool GetVisible() const 70 { 71 return isVisible_; 72 } 73 SetEnableLoading(bool enable)74 void SetEnableLoading(bool enable) 75 { 76 CHECK_NULL_VOID(enableLoading_); 77 enableLoading_->Set(enable); 78 } 79 SetContentOffset(const OffsetF & offset)80 void SetContentOffset(const OffsetF& offset) 81 { 82 CHECK_NULL_VOID(offset_); 83 offset_->Set(offset); 84 } 85 SetContentSize(const SizeF & contentSize)86 void SetContentSize(const SizeF& contentSize) 87 { 88 CHECK_NULL_VOID(contentSize_); 89 contentSize_->Set(contentSize); 90 } 91 void CloseAnimation(float date, float cometLen, float cometOpacity, float cometScale); 92 93 private: 94 void AdjustMatrix(RSCamera3D& camera, RSMatrix& matrix); 95 float GetCurentCometOpacity(float baseOpacity, uint32_t index, uint32_t totalNumber); 96 float GetCurentCometAngle(float baseAngle, uint32_t index, uint32_t totalNumber); 97 uint32_t GetCometNumber(); 98 // no Animatable 99 RefPtr<PropertyBool> enableLoading_; 100 RefPtr<PropertyOffsetF> offset_; 101 RefPtr<PropertySizeF> contentSize_; 102 // Animatable 103 RefPtr<AnimatablePropertyFloat> date_; 104 RefPtr<AnimatablePropertyColor> color_; 105 RefPtr<AnimatablePropertyFloat> centerDeviation_; 106 RefPtr<AnimatablePropertyFloat> cometOpacity_; 107 RefPtr<AnimatablePropertyFloat> cometSizeScale_; 108 RefPtr<AnimatablePropertyFloat> cometTailLen_; 109 RefPtr<AnimatablePropertyFloat> sizeScale_; 110 111 LoadingProgressOwner loadingProgressOwner_; 112 bool isLoading_ = false; 113 bool isVisible_ = false; 114 float recycleSizeScale_ = 1.0f; 115 ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressModifier); 116 }; 117 } // namespace OHOS::Ace::NG 118 119 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_MODIFIER_H 120 121