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 DrawRingBackground(DrawingContext& canvas, const RingParam& ringParam, LinearColor& ringColor); 40 void StartRecycle(); 41 void StartRecycleRingAnimation(); 42 void StartRecycleCometAnimation(); 43 void StartCometTailAnimation(); 44 void StartTransToRecycleAnimation(); SetColor(LinearColor color)45 void SetColor(LinearColor color) 46 { 47 if (color_) { 48 color_->Set(color); 49 } 50 } 51 52 void DrawCustomStyle(DrawingContext& context); 53 void RefreshRecycle(DrawingContext& context, Color& color, float scale); 54 void ChangeRefreshFollowData(float refreshFollowRatio); 55 void ChangeSizeScaleData(float fadeAwayRatio); 56 float CorrectNormalize(float originData); 57 GetOwner()58 LoadingProgressOwner GetOwner() 59 { 60 return loadingProgressOwner_; 61 } 62 SetVisible(bool isVisible)63 void SetVisible(bool isVisible) 64 { 65 CHECK_NULL_VOID(isVisible_ != isVisible); 66 isVisible_ = isVisible; 67 isLoading_ = false; 68 } 69 GetVisible()70 bool GetVisible() const 71 { 72 return isVisible_; 73 } 74 SetEnableLoading(bool enable)75 void SetEnableLoading(bool enable) 76 { 77 CHECK_NULL_VOID(enableLoading_); 78 enableLoading_->Set(enable); 79 } 80 SetContentOffset(const OffsetF & offset)81 void SetContentOffset(const OffsetF& offset) 82 { 83 CHECK_NULL_VOID(offset_); 84 offset_->Set(offset); 85 } 86 SetContentSize(const SizeF & contentSize)87 void SetContentSize(const SizeF& contentSize) 88 { 89 CHECK_NULL_VOID(contentSize_); 90 contentSize_->Set(contentSize); 91 } 92 void CloseAnimation(float date, float cometLen, float cometOpacity, float cometScale); 93 SetUseContentModifier(bool useContentModifier)94 void SetUseContentModifier(bool useContentModifier) 95 { 96 CHECK_NULL_VOID(useContentModifier_); 97 useContentModifier_->Set(useContentModifier); 98 } 99 100 private: 101 void AdjustMatrix(RSCamera3D& camera, RSMatrix& matrix); 102 float GetCurentCometOpacity(float baseOpacity, uint32_t index, uint32_t totalNumber); 103 float GetCurentCometAngle(float baseAngle, uint32_t index, uint32_t totalNumber); 104 uint32_t GetCometNumber(); 105 // no Animatable 106 RefPtr<PropertyBool> enableLoading_; 107 RefPtr<PropertyOffsetF> offset_; 108 RefPtr<PropertySizeF> contentSize_; 109 // Animatable 110 RefPtr<AnimatablePropertyFloat> date_; 111 RefPtr<AnimatablePropertyColor> color_; 112 RefPtr<AnimatablePropertyFloat> centerDeviation_; 113 RefPtr<AnimatablePropertyFloat> cometOpacity_; 114 RefPtr<AnimatablePropertyFloat> cometSizeScale_; 115 RefPtr<AnimatablePropertyFloat> cometTailLen_; 116 RefPtr<AnimatablePropertyFloat> sizeScale_; 117 RefPtr<PropertyBool> useContentModifier_; 118 119 LoadingProgressOwner loadingProgressOwner_; 120 bool isLoading_ = false; 121 bool isVisible_ = false; 122 float recycleSizeScale_ = 1.0f; 123 ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressModifier); 124 }; 125 } // namespace OHOS::Ace::NG 126 127 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_MODIFIER_H 128 129