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