1 /* 2 * Copyright (c) 2021-2022 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_CORE_ANIMATOR_INFO_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATOR_INFO_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/animation/animator.h" 21 #include "core/animation/curve.h" 22 23 namespace OHOS::Ace::Framework { 24 25 enum class AnimationStatus { 26 INITIAL, 27 RUNNING, 28 PAUSED, 29 STOPPED, 30 }; 31 32 enum class EventOperation { 33 NONE, 34 START, 35 PAUSE, 36 REPEAT, 37 CANCEL, 38 FINISH, 39 }; 40 41 using AnimatorEventFunc = std::function<void(const float&)>; 42 43 class AnimatorInfo : public AceType { 44 public: 45 AnimatorInfo() = default; 46 ~AnimatorInfo() override = default; 47 SetAnimator(const RefPtr<Animator> & animator)48 void SetAnimator(const RefPtr<Animator>& animator) 49 { 50 if (!animator) { 51 LOGE("set animator failed. animator is null."); 52 return; 53 } 54 animator_ = animator; 55 } 56 GetAnimator()57 RefPtr<Animator> GetAnimator() const 58 { 59 return animator_; 60 } 61 SetCurve(const RefPtr<Curve> & curve)62 void SetCurve(const RefPtr<Curve>& curve) 63 { 64 if (!curve) { 65 LOGE("set curve failed. curve is null."); 66 return; 67 } 68 curve_ = curve; 69 } 70 GetCurve()71 const RefPtr<Curve>& GetCurve() const 72 { 73 return curve_; 74 } 75 SetDelay(int32_t delay)76 void SetDelay(int32_t delay) 77 { 78 delay_ = delay; 79 } 80 GetDelay()81 int32_t GetDelay() const 82 { 83 return delay_; 84 } 85 SetIteration(int32_t iteration)86 void SetIteration(int32_t iteration) 87 { 88 iteration_ = iteration; 89 } 90 GetIteration()91 int32_t GetIteration() const 92 { 93 return iteration_; 94 } 95 SetFillMode(FillMode fillMode)96 void SetFillMode(FillMode fillMode) 97 { 98 fillMode_ = fillMode; 99 } 100 GetFillMode()101 FillMode GetFillMode() const 102 { 103 return fillMode_; 104 } 105 SetPlayMode(AnimationDirection playMode)106 void SetPlayMode(AnimationDirection playMode) 107 { 108 playMode_ = playMode; 109 } 110 GetPlayMode()111 AnimationDirection GetPlayMode() const 112 { 113 return playMode_; 114 } 115 SetAnimatorMotion(const RefPtr<Motion> & motion)116 void SetAnimatorMotion(const RefPtr<Motion>& motion) 117 { 118 motion_ = motion; 119 } 120 GetAnimatorMotion()121 const RefPtr<Motion>& GetAnimatorMotion() const 122 { 123 return motion_; 124 } 125 SetDuration(int32_t duration)126 void SetDuration(int32_t duration) 127 { 128 duration_ = duration; 129 } 130 131 // Duration in millisecond. GetDuration()132 int32_t GetDuration() const 133 { 134 return duration_; 135 } 136 SetFrameEvent(const AnimatorEventFunc & frameEvent)137 void SetFrameEvent(const AnimatorEventFunc& frameEvent) 138 { 139 frameEvent_ = frameEvent; 140 } 141 GetFrameEvent()142 const AnimatorEventFunc& GetFrameEvent() const 143 { 144 return frameEvent_; 145 } 146 OnJsEngineDestroy()147 void OnJsEngineDestroy() 148 { 149 frameEvent_ = nullptr; 150 } 151 152 private: 153 RefPtr<Animator> animator_; 154 RefPtr<Curve> curve_; 155 FillMode fillMode_ = FillMode::FORWARDS; 156 AnimationDirection playMode_ = AnimationDirection::NORMAL; 157 RefPtr<Motion> motion_; 158 AnimatorEventFunc frameEvent_; 159 int32_t duration_ = 0; 160 int32_t delay_ = 0; 161 int32_t iteration_ = 1; 162 }; 163 164 } // namespace OHOS::Ace::Framework 165 166 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATOR_INFO_H