1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_ANIMATABLE_MATRIX4_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_ANIMATABLE_MATRIX4_H 18 19 #include "base/geometry/matrix4.h" 20 #include "core/animation/animator.h" 21 #include "core/animation/curve_animation.h" 22 #include "core/components/common/properties/animation_option.h" 23 24 namespace OHOS::Ace { 25 26 using RenderNodeAnimationCallback = std::function<void()>; 27 28 class ACE_EXPORT AnimatableMatrix4 : public Matrix4 { 29 public: 30 AnimatableMatrix4() = default; 31 ~AnimatableMatrix4() = default; 32 33 explicit AnimatableMatrix4(Matrix4 matrix4, const AnimationOption& option = AnimationOption()) 34 : Matrix4(matrix4), animationOption_(option) 35 {} 36 SetContextAndCallback(const WeakPtr<PipelineBase> & context,const RenderNodeAnimationCallback & callback)37 void SetContextAndCallback(const WeakPtr<PipelineBase>& context, const RenderNodeAnimationCallback& callback) 38 { 39 context_ = context; 40 animationCallback_ = callback; 41 } 42 GetAnimationOption()43 const AnimationOption& GetAnimationOption() const 44 { 45 return animationOption_; 46 } 47 SetAnimationOption(const AnimationOption & option)48 void SetAnimationOption(const AnimationOption& option) 49 { 50 animationOption_ = option; 51 } 52 SetAnimationStopCallback(const RenderNodeAnimationCallback & callback)53 void SetAnimationStopCallback(const RenderNodeAnimationCallback& callback) 54 { 55 stopCallback_ = callback; 56 } 57 GetAnimationStatus()58 Animator::Status GetAnimationStatus() const 59 { 60 if (!animationController_) { 61 return Animator::Status::IDLE; 62 } 63 return animationController_->GetStatus(); 64 } 65 66 AnimatableMatrix4& operator=(const Matrix4& matrix4); 67 68 AnimatableMatrix4& operator=(const AnimatableMatrix4& newMatrix4); 69 70 void MoveTo(const Matrix4& target); 71 SetEvaluator(const RefPtr<Evaluator<TransformOperation>> & evaluator)72 void SetEvaluator(const RefPtr<Evaluator<TransformOperation>>& evaluator) 73 { 74 evaluator_ = evaluator; 75 } 76 77 private: 78 void AnimateTo(const Matrix4& endValue); 79 void ResetController(); 80 void OnAnimationCallback(const TransformOperation& value); 81 void ResetAnimatableMatrix(); 82 83 private: 84 bool isFirstAssign_ = true; 85 AnimationOption animationOption_; 86 RefPtr<Animator> animationController_; 87 WeakPtr<PipelineBase> context_; 88 RenderNodeAnimationCallback animationCallback_; 89 RenderNodeAnimationCallback stopCallback_; 90 91 RefPtr<Evaluator<TransformOperation>> evaluator_; 92 }; 93 94 } // namespace OHOS::Ace 95 96 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_ANIMATABLE_MATRIX4_H 97