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