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_ANIMATION_SIMPLE_SPRING_ADAPTER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SIMPLE_SPRING_ADAPTER_H
18 
19 #include <unordered_map>
20 
21 #include "core/animation/simple_spring_node.h"
22 #include "core/animation/spring_adapter.h"
23 
24 namespace OHOS::Ace {
25 
26 class SimpleSpringAdapter : public SpringAdapter {
27     DECLARE_ACE_TYPE(SimpleSpringAdapter, SpringAdapter);
28 
29 public:
30     void AddNode(RefPtr<SpringNode> node);
31 
32     RefPtr<SpringNode> GetNext(const RefPtr<SpringNode>& node) override;
33 
GetSize()34     int32_t GetSize() const override
35     {
36         return nodes_.size();
37     }
38 
GetControlNode()39     RefPtr<SpringNode> GetControlNode() const override
40     {
41         return GetNode(GetControlIndex());
42     }
43 
44     RefPtr<SpringNode> GetNode(int32_t index) const override;
45 
GetControlIndex()46     int32_t GetControlIndex() const override
47     {
48         return 0;
49     }
50 
51     std::string DumpNodes();
52 
53     void FlushAnimation() override;
54 
SetDeltaValue(double delta)55     virtual void SetDeltaValue(double delta)
56     {
57         for (int32_t index = 0; index < GetSize(); index++) {
58             auto node = GetNode(index);
59             if (node) {
60                 node->SetDeltaValue(delta);
61             }
62         }
63     }
64 
65 protected:
66     std::unordered_map<int32_t, RefPtr<SpringNode>> nodes_;
67 };
68 
69 } // namespace OHOS::Ace
70 
71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SIMPLE_SPRING_ADAPTER_H
72