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_MODIFIER_H
17 #define META_INTERFACE_INTF_ANIMATION_MODIFIER_H
18 
19 #include <meta/base/interface_macros.h>
20 #include <meta/base/namespace.h>
21 #include <meta/base/types.h>
22 #include <meta/interface/intf_clock.h>
23 #include <meta/interface/property/property.h>
24 
25 META_BEGIN_NAMESPACE()
26 
27 META_REGISTER_INTERFACE(IAnimationModifier, "9da441d6-e0db-464a-80d4-a5657918c601")
28 
29 /**
30  * @brief Interface for animation modifiers.
31  *
32  * Animation modifiers are used to modify existing animations by attaching them with the IAttach mechanism.
33  */
34 class IAnimationModifier : public CORE_NS::IInterface {
35     META_INTERFACE(CORE_NS::IInterface, IAnimationModifier, META_NS::InterfaceId::IAnimationModifier)
36 public:
37     /**
38      * @brief Struct used for modifying animation length by an animation modifier.
39      */
40     struct DurationData {
41         constexpr DurationData() noexcept = default;
DurationDataDurationData42         explicit constexpr DurationData(TimeSpan duration) noexcept : duration(duration) {}
43         /** Duration of one loop of the animation */
44         TimeSpan duration { TimeSpan::Zero() };
45         /** Loop count */
46         int32_t loopCount { 1 };
47     };
48     /**
49      * @brief Called by an animation during initialization, allowing the modifier to change the
50      *        duration of the animation.
51      * @param duration Duration info.
52      * @return True if the modifier can be applied on the input data, false otherwise.
53      */
54     virtual bool ProcessOnGetDuration(DurationData& duration) const = 0;
55     /**
56      * @brief Struct used for modifying animation step by an animation modifier.
57      */
58     struct StepData {
59         constexpr StepData() noexcept = default;
StepDataStepData60         explicit constexpr StepData(float progress) noexcept : progress(progress) {}
61         /** Current progress. */
62         float progress {};
63         /** Is the animation reversing */
64         bool reverse {};
65     };
66     /**
67      * @brief Called by an animation during Step phase, allowing the modifier to change the
68      *        current progress.
69      * @param step Step info.
70      * @return True if the modifier can be applied on the input data, false otherwise.
71      */
72     virtual bool ProcessOnStep(StepData& step) const = 0;
73 };
74 
75 META_END_NAMESPACE()
76 
77 #endif // META_INTERFACE_INTF_ANIMATION_MODIFIER_H
78