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 #include "loop.h"
16 
17 #include <algorithm>
18 #include <limits>
19 
20 #include <meta/api/make_callback.h>
21 #include <meta/api/util.h>
22 #include <meta/interface/builtin_objects.h>
23 
24 META_BEGIN_NAMESPACE()
25 
26 namespace AnimationModifiers {
27 
Build(const IMetadata::Ptr & data)28 bool Loop::Build(const IMetadata::Ptr& data)
29 {
30     LoopCount()->OnChanged()->AddHandler(META_ACCESS_EVENT(OnChanged));
31     return true;
32 }
33 
ProcessOnGetDuration(DurationData & duration) const34 bool Loop::ProcessOnGetDuration(DurationData& duration) const
35 {
36     const auto loopCount = META_ACCESS_PROPERTY_VALUE(LoopCount);
37     if (loopCount == 0) {
38         // Invalid
39         return false;
40     }
41     if (loopCount > 0) {
42         duration.loopCount = duration.loopCount < 0 ? duration.loopCount : duration.loopCount + loopCount - 1;
43     } else {
44         duration.loopCount = -1;
45     }
46     return true;
47 }
48 
ProcessOnStep(StepData & step) const49 bool Loop::ProcessOnStep(StepData& step) const
50 {
51     return true;
52 }
53 
54 } // namespace AnimationModifiers
55 
56 META_END_NAMESPACE()
57