1 /*
2  * Copyright (c) 2024 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 META_INTERFACE_INTF_ANIMATION_CONTROLLER_H
17 #define META_INTERFACE_INTF_ANIMATION_CONTROLLER_H
18 
19 #include <base/containers/vector.h>
20 #include <base/math/vector.h>
21 #include <base/util/uid.h>
22 #include <core/plugin/intf_interface.h>
23 
24 #include <meta/base/interface_macros.h>
25 #include <meta/base/namespace.h>
26 #include <meta/base/shared_ptr.h>
27 #include <meta/base/types.h>
28 #include <meta/interface/interface_macros.h>
29 #include <meta/interface/intf_clock.h>
30 #include <meta/interface/intf_meta_object_lib.h>
31 #include <meta/interface/intf_object_registry.h>
32 #include <meta/interface/property/intf_property.h>
33 
34 META_BEGIN_NAMESPACE()
35 
36 META_REGISTER_INTERFACE(IAnimationController, "e1c2d8bf-fc1f-45e5-b43d-f290531939ec")
37 
38 class IAnimation;
39 class IClock;
40 
41 /**
42  * @brief IAnimationController defines an interface for a class which can act as
43  *        a controller for animations.
44  */
45 class IAnimationController : public CORE_NS::IInterface {
46     META_INTERFACE(CORE_NS::IInterface, IAnimationController, META_NS::InterfaceId::IAnimationController)
47 public:
48     /**
49      * @brief The StepInfo struct contains information about a Step
50      *        operation.
51      */
52     struct StepInfo {
53         /** Number of animations that were stepped. */
54         uint32_t stepped_;
55         /** Number of animations still running after step. */
56         uint32_t running_;
57     };
58     /**
59      * @brief The number of animations handled by this controller.
60      */
61     META_READONLY_PROPERTY(uint32_t, Count)
62 
63     /**
64      * @brief The number of animations running currently.
65      */
66     META_READONLY_PROPERTY(uint32_t, RunningCount)
67 
68     /**
69      * @brief Returns weak references to all animations in this controller.
70      */
71     virtual BASE_NS::vector<BASE_NS::weak_ptr<IAnimation>> GetAnimations() const = 0;
72     /**
73      * @brief Returns weak references to all active animations in this controller.
74      */
75     virtual BASE_NS::vector<BASE_NS::weak_ptr<IAnimation>> GetRunning() const = 0;
76     /**
77      * @brief AddAnimation adds an animation for this controller to handle.
78      * @param animation The animation to add.
79      * @return True if the animation is handled by the controller after the function returns, false otherwise.
80      */
81     virtual bool AddAnimation(const BASE_NS::shared_ptr<IAnimation>& animation) = 0;
82     /**
83      * @brief Removes an animation from this controller.
84      * @param animation The animation to remove.
85      * @return True if the animation was removed from the controller, false otherwise.
86      */
87     virtual bool RemoveAnimation(const BASE_NS::shared_ptr<IAnimation>& animation) = 0;
88     /**
89      * @brief Removes all animations from the controller.
90      */
91     virtual void Clear() = 0;
92     /**
93      * @brief Steps all animations controller by this controller using the
94      *        current time. To manually specify the timestamp, use
95      *        Step(int64_t time).
96      * @note The time used for stepping the animations can be retrieved
97      *       from the returned StepInfo object.
98      * @return Information about the step operation.
99      */
100     virtual StepInfo Step(const IClock::ConstPtr& clock) = 0;
101 };
102 
103 META_END_NAMESPACE()
104 
META_TYPE(META_NS::IAnimationController::WeakPtr)105 META_TYPE(META_NS::IAnimationController::WeakPtr)
106 META_TYPE(META_NS::IAnimationController::Ptr)
107 
108 META_BEGIN_NAMESPACE()
109 
110 /**
111  * @brief Get global animation controller.
112  */
113 inline META_NS::IAnimationController::Ptr GetAnimationController()
114 {
115     return GetMetaObjectLib().GetAnimationController();
116 }
117 
118 META_END_NAMESPACE()
119 
120 #endif
121