• 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/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 
28 namespace OHOS::Ace::NG {
29 class LoadingProgressModifier : public ContentModifier {
30     DECLARE_ACE_TYPE(LoadingProgressModifier, ContentModifier);
31 
32 public:
33     explicit LoadingProgressModifier(LoadingProgressOwner loadingProgressOwner = LoadingProgressOwner::SELF);
34     ~LoadingProgressModifier() override = default;
35     void onDraw(DrawingContext& context) override;
36     void DrawOrbit(DrawingContext& canvas, const CometParam& cometParam, float orbitRadius, float date);
37     void DrawRing(DrawingContext& canvas, const RingParam& ringParam);
38     void StartRecycle();
39     void StartRecycleRingAnimation();
40     void StartRecycleCometAnimation();
41     void StartCometTailAnimation();
42     void StartTransToRecycleAnimation();
SetColor(LinearColor color)43     void SetColor(LinearColor color)
44     {
45         if (color_) {
46             color_->Set(color);
47         }
48     }
49 
50     void DrawCustomStyle(DrawingContext& context);
51     void RefreshRecycle(DrawingContext& context, Color& color, float scale);
52     void ChangeRefreshFollowData(float refreshFollowRatio);
53     void ChangeFadeAwayData(float fadeAwayRatio);
54     float CorrectNormalize(float originData);
55 
GetOwner()56     LoadingProgressOwner GetOwner()
57     {
58         return loadingProgressOwner_;
59     }
60 
SetVisible(bool isVisible)61     void SetVisible(bool isVisible)
62     {
63         CHECK_NULL_VOID(isVisible_ != isVisible);
64         isVisible_ = isVisible;
65         LOGD("LoadingModifier SetVisible %d", 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 private:
92     float GetCurentCometOpacity(float baseOpacity, uint32_t index, uint32_t totalNumber);
93     float GetCurentCometAngle(float baseAngle, uint32_t index, uint32_t totalNumber);
94 
95     uint32_t GetCometNumber();
96     // no Animatable
97     RefPtr<PropertyBool> enableLoading_;
98     RefPtr<PropertyOffsetF> offset_;
99     RefPtr<PropertySizeF> contentSize_;
100     // Animatable
101     RefPtr<AnimatablePropertyFloat> date_;
102     RefPtr<AnimatablePropertyColor> color_;
103     RefPtr<AnimatablePropertyFloat> centerDeviation_;
104     RefPtr<AnimatablePropertyFloat> cometOpacity_;
105     RefPtr<AnimatablePropertyFloat> cometSizeScale_;
106     RefPtr<AnimatablePropertyFloat> cometTailLen_;
107     RefPtr<AnimatablePropertyFloat> sizeScale_;
108 
109     LoadingProgressOwner loadingProgressOwner_;
110     bool isLoading_ = false;
111     bool isVisible_ = true;
112     ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressModifier);
113 };
114 } // namespace OHOS::Ace::NG
115 
116 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_MODIFIER_H
117 
118