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