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 45 public: 46 AnimatorInfo() = default; 47 ~AnimatorInfo() override = default; 48 SetAnimator(const RefPtr<Animator> & animator)49 void SetAnimator(const RefPtr<Animator>& animator) 50 { 51 if (!animator) { 52 LOGE("set animator failed. animator is null."); 53 return; 54 } 55 animator_ = animator; 56 } 57 GetAnimator()58 RefPtr<Animator> GetAnimator() const 59 { 60 return animator_; 61 } 62 SetCurve(const RefPtr<Curve> & curve)63 void SetCurve(const RefPtr<Curve>& curve) 64 { 65 if (!curve) { 66 LOGE("set curve failed. curve is null."); 67 return; 68 } 69 curve_ = curve; 70 } 71 GetCurve()72 const RefPtr<Curve>& GetCurve() const 73 { 74 return curve_; 75 } 76 SetDelay(int32_t delay)77 void SetDelay(int32_t delay) 78 { 79 delay_ = delay; 80 } 81 GetDelay()82 int32_t GetDelay() const 83 { 84 return delay_; 85 } 86 SetIteration(int32_t iteration)87 void SetIteration(int32_t iteration) 88 { 89 iteration_ = iteration; 90 } 91 GetIteration()92 int32_t GetIteration() const 93 { 94 return iteration_; 95 } 96 SetFillMode(FillMode fillMode)97 void SetFillMode(FillMode fillMode) 98 { 99 fillMode_ = fillMode; 100 } 101 GetFillMode()102 FillMode GetFillMode() const 103 { 104 return fillMode_; 105 } 106 SetPlayMode(AnimationDirection playMode)107 void SetPlayMode(AnimationDirection playMode) 108 { 109 playMode_ = playMode; 110 } 111 GetPlayMode()112 AnimationDirection GetPlayMode() const 113 { 114 return playMode_; 115 } 116 SetAnimatorMotion(const RefPtr<Motion> & motion)117 void SetAnimatorMotion(const RefPtr<Motion>& motion) 118 { 119 motion_ = motion; 120 } 121 GetAnimatorMotion()122 const RefPtr<Motion>& GetAnimatorMotion() const 123 { 124 return motion_; 125 } 126 SetDuration(int32_t duration)127 void SetDuration(int32_t duration) 128 { 129 duration_ = duration; 130 } 131 132 // Duration in millisecond. GetDuration()133 int32_t GetDuration() const 134 { 135 return duration_; 136 } 137 SetFrameEvent(const AnimatorEventFunc & frameEvent)138 void SetFrameEvent(const AnimatorEventFunc& frameEvent) 139 { 140 frameEvent_ = frameEvent; 141 } 142 GetFrameEvent()143 const AnimatorEventFunc& GetFrameEvent() const 144 { 145 return frameEvent_; 146 } 147 OnJsEngineDestroy()148 void OnJsEngineDestroy() 149 { 150 frameEvent_ = nullptr; 151 } 152 153 private: 154 RefPtr<Animator> animator_; 155 RefPtr<Curve> curve_; 156 FillMode fillMode_ = FillMode::FORWARDS; 157 AnimationDirection playMode_ = AnimationDirection::NORMAL; 158 RefPtr<Motion> motion_; 159 AnimatorEventFunc frameEvent_; 160 int32_t duration_ = 0; 161 int32_t delay_ = 0; 162 int32_t iteration_ = 1; 163 }; 164 165 } // namespace OHOS::Ace::Framework 166 167 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATOR_INFO_H