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