1 /*
2  * Copyright (c) 2021 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_PROGRESS_RENDER_BUBBLE_PROGRESS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_RENDER_BUBBLE_PROGRESS_H
18 
19 #include <vector>
20 #include <unordered_map>
21 #include <array>
22 
23 #include "core/animation/animator.h"
24 #include "core/animation/flush_event.h"
25 #include "core/animation/picture_animation.h"
26 #include "core/components/progress/bubble_progress_component.h"
27 #include "core/pipeline/base/render_node.h"
28 
29 namespace OHOS::Ace {
30 
31 class RenderBubbleProgress : public RenderNode, public FlushEvent {
32     DECLARE_ACE_TYPE(RenderBubbleProgress, RenderNode, FlushEvent);
33 
34 public:
35     RenderBubbleProgress();
36     ~RenderBubbleProgress() override = default;
37 
38     void OnPostFlush() override;
39 
40     void Update(const RefPtr<Component>& component) override;
41 
SetDiameter(double diameter)42     void SetDiameter(double diameter)
43     {
44         diameter_ = diameter;
45     }
46 
47     void PerformLayout() override;
48 
49     static RefPtr<RenderNode> Create();
50 
51     void OnAppShow() override;
52     void OnAppHide() override;
53 
54 protected:
55     void CalculateCirclePosition();
56     void OnVisibleChanged() override;
57     void OnHiddenChanged(bool hidden) override;
58     void AnimationChanged();
59 
60     double diameter_ = 0.0;
61 
62     using Vertex = Offset;
63     Vertex center_;
64     double radius_ = 0.0;
65     double maxCircleRadius_ = 0.0;
66     std::vector<Vertex> subCircleCenter_;
67 
68     // frame animation
69     int32_t step_ = 0;
70     int32_t progress_ = 0;
71     Color lightToDark_;
72     Color darkToLight_;
73     RefPtr<PictureAnimation<int32_t>> pictureFrames_;
74     RefPtr<Animator> animatorController_;
75 
76     bool simulationPrepared_ = false;
77 };
78 
79 } // namespace OHOS::Ace
80 
81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_RENDER_BUBBLE_PROGRESS_H
82