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_SRC_ANIMATION_INTERNAL_H 17 #define META_SRC_ANIMATION_INTERNAL_H 18 19 #include <meta/interface/animation/intf_animation.h> 20 21 META_BEGIN_NAMESPACE() 22 23 META_REGISTER_INTERFACE(IAnimationInternal, "ab8878c9-9784-4949-84a4-2a7988ec1b80") 24 25 /** 26 * @brief The IAnimationInternal interface defins the internal interface used between 27 * AnimationState and Animation implementations. 28 */ 29 class IAnimationInternal : public CORE_NS::IInterface { 30 META_INTERFACE(CORE_NS::IInterface, IAnimationInternal) 31 public: 32 enum class AnimationTargetState : uint32_t { 33 /** Undefined state */ 34 UNDEFINED = 0, 35 /** The animation is running. Progress property is between [0,1[. */ 36 RUNNING = 1, 37 /** The animation is stopped. 38 If the animation has not been started, its Progress is 0. 39 If the animation has finished running, its Progress is 1. */ 40 STOPPED = 2, 41 /** Finish the animation. */ 42 FINISHED = 3, 43 /** A previously RUNNING animation has been paused. Its progress is between [0,1[. */ 44 PAUSED = 5 45 }; 46 /** 47 * @brief The AnimationStateChangedInfo structure defines the parameters for an event which is invoked when 48 * animation state was changed. 49 */ 50 struct AnimationStateChangedInfo { 51 /** The animation whose state changed. */ 52 BASE_NS::weak_ptr<const IAnimation> source; 53 /** The new state. */ 54 AnimationTargetState state; 55 /** Previous state. */ 56 AnimationTargetState previous; 57 }; 58 /** 59 * @brief Resets the animation clock to initial state. 60 */ 61 virtual void ResetClock() = 0; 62 /** Parameters for move operation */ 63 struct MoveParams { 64 /** Step information */ 65 IAnimationModifier::StepData step; 66 /** Target state. If AnimationState::UNDEFINED, a suitable state shall be 67 decided automatically by the Move() operation. */ 68 AnimationTargetState state { AnimationTargetState::UNDEFINED }; 69 /** Returns a MoveParams object with given progress */ FromProgressMoveParams70 constexpr static MoveParams FromProgress(float progress) noexcept 71 { 72 MoveParams params; 73 params.step = IAnimationModifier::StepData(progress); 74 return params; 75 } 76 /** Returns a MoveParams object with given progress and target state */ FromProgressMoveParams77 constexpr static MoveParams FromProgress(float progress, AnimationTargetState state) noexcept 78 { 79 MoveParams params; 80 params.step = IAnimationModifier::StepData(progress); 81 params.state = state; 82 return params; 83 } 84 }; 85 /** 86 * @brief Move the animation to given status.. 87 * @param move Move operation parameters. 88 * @return True if the state of the animation changed in some way as a result of the operation. False otherwise. 89 */ 90 virtual bool Move(const MoveParams& move) = 0; 91 /** 92 * @brief Invoked by AnimationState when animation state has changed. 93 */ 94 virtual void OnAnimationStateChanged(const AnimationStateChangedInfo& info) = 0; 95 /** 96 * @brief Invoked by AnimationState when owning animation should re-evaluate itself. 97 */ 98 virtual void OnEvaluationNeeded() = 0; 99 }; 100 101 META_END_NAMESPACE() 102 103 #endif // META_INTF_ANIMATION_INTERNAL_H 104