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_CORE_ANIMATION_MOTION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_MOTION_H 18 19 #include "base/utils/listener.h" 20 #include "core/animation/time_event.h" 21 22 namespace OHOS::Ace { 23 24 class Motion : public TimeEvent, public ValueListenable<double> { 25 DECLARE_ACE_TYPE(Motion, TimeEvent); 26 27 public: 28 virtual double GetCurrentPosition() = 0; 29 virtual double GetCurrentVelocity() = 0; 30 virtual bool IsCompleted() = 0; 31 GetMotionType()32 virtual std::string GetMotionType() const 33 { 34 return "motion"; 35 } 36 37 // Each subclass should override this method to perform motion in each timestamp. 38 virtual void Move(float offsetTime) = 0; 39 40 // Motion do not have duration, normalizedTime always zero OnTimestampChanged(float timestamp,float normalizedTime,bool reverse)41 void OnTimestampChanged(float timestamp, float normalizedTime, bool reverse) final 42 { 43 Move(timestamp); 44 NotifyListener(GetCurrentPosition()); 45 } 46 }; 47 48 } // namespace OHOS::Ace 49 50 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_MOTION_H 51