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 
16 #ifndef META_API_ANIMATION_MODIFIERS_LOOP_H
17 #define META_API_ANIMATION_MODIFIERS_LOOP_H
18 
19 #include <meta/api/internal/animation_modifier_api.h>
20 #include <meta/base/namespace.h>
21 #include <meta/interface/animation/builtin_animations.h>
22 #include <meta/interface/animation/modifiers/intf_loop.h>
23 
META_BEGIN_NAMESPACE()24 META_BEGIN_NAMESPACE()
25 
26 namespace AnimationModifiers {
27 
28 /**
29  * @brief Modifier for animations to create looping
30  * Example:
31  *     auto loop = AnimationModifiers::Loop().LoopCount(2);
32  *     animation.Attach(loop);
33  *   will run the original animation twice.
34  * Default value for looping is 1 (i.e. not altering behaviour).
35  */
36 class Loop final : public Internal::AnimationModifierInterfaceAPI<Loop, META_NS::ClassId::LoopAnimationModifier> {
37     META_API(Loop)
38     META_API_OBJECT_CONVERTIBLE(META_NS::AnimationModifiers::ILoop)
39     META_API_CACHE_INTERFACE(META_NS::AnimationModifiers::ILoop, Loop)
40 public:
41     /**
42      * @brief Set how many times the animation should loop, negative value means keep looping indefinitely.
43      */
44     META_API_INTERFACE_PROPERTY_CACHED(Loop, LoopCount, int32_t)
45     /**
46      * @brief Make the animation to keep looping until explicitly stopped.
47      */
48     Loop& LoopIndefinitely()
49     {
50         META_NS::SetValue(META_API_CACHED_INTERFACE(Loop)->LoopCount(), -1);
51         return *this;
52     }
53 };
54 
55 } // namespace AnimationModifiers
56 
57 META_END_NAMESPACE()
58 
59 #endif // META_API_ANIMATION_MODIFIERS_LOOP_H
60