• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PROPERTIES_ANIMATION_OPTION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATION_OPTION_H
18 
19 #include <functional>
20 #include <string>
21 #include <unordered_map>
22 
23 #include "core/animation/animation_pub.h"
24 #include "core/animation/curve.h"
25 
26 namespace OHOS::Ace {
27 
28 class AnimationOption final {
29 public:
30     AnimationOption() = default;
AnimationOption(const RefPtr<Curve> & curve,int32_t duration)31     AnimationOption(const RefPtr<Curve>& curve, int32_t duration) : duration_(duration), curve_(curve) {}
32     ~AnimationOption() = default;
33 
SetDuration(int32_t duration)34     void SetDuration(int32_t duration)
35     {
36         duration_ = duration;
37     }
38 
GetDuration()39     int32_t GetDuration() const
40     {
41         return duration_;
42     }
43 
SetDelay(int32_t delay)44     void SetDelay(int32_t delay)
45     {
46         delay_ = delay;
47     }
48 
GetDelay()49     int32_t GetDelay() const
50     {
51         return delay_;
52     }
53 
SetCurve(const RefPtr<Curve> & curve)54     void SetCurve(const RefPtr<Curve>& curve)
55     {
56         if (!curve) {
57             LOGE("set curve failed. curve is null.");
58             return;
59         }
60         curve_ = curve;
61     }
62 
SetIteration(int32_t iteration)63     void SetIteration(int32_t iteration)
64     {
65         if (iteration < 0 && iteration != ANIMATION_REPEAT_INFINITE) {
66             return;
67         }
68         iteration_ = iteration;
69     }
70 
GetIteration()71     int32_t GetIteration() const
72     {
73         return iteration_;
74     }
75 
SetTempo(float tempo)76     void SetTempo(float tempo)
77     {
78         if (tempo < 0.0f) {
79             return;
80         }
81         tempo_ = tempo;
82     }
83 
GetTempo()84     float GetTempo() const
85     {
86         return tempo_;
87     }
88 
SetAnimationDirection(AnimationDirection direction)89     void SetAnimationDirection(AnimationDirection direction)
90     {
91         direction_ = direction;
92     }
93 
GetAnimationDirection()94     AnimationDirection GetAnimationDirection() const
95     {
96         return direction_;
97     }
98 
GetCurve()99     const RefPtr<Curve>& GetCurve() const
100     {
101         return curve_;
102     }
103 
SetFillMode(const FillMode & fillMode)104     void SetFillMode(const FillMode& fillMode)
105     {
106         fillMode_ = fillMode;
107     }
108 
GetFillMode()109     FillMode GetFillMode() const
110     {
111         return fillMode_;
112     }
113 
SetOnFinishEvent(const std::function<void ()> & onFinishEvent)114     void SetOnFinishEvent(const std::function<void()>& onFinishEvent)
115     {
116         onFinishEvent_ = onFinishEvent;
117     }
118 
GetOnFinishEvent()119     const std::function<void()>& GetOnFinishEvent() const
120     {
121         return onFinishEvent_;
122     }
123 
IsValid()124     bool IsValid() const
125     {
126         return (GetDuration() > 0 || GetAllowRunningAsynchronously());
127     }
128 
SetAllowRunningAsynchronously(bool runAsync)129     void SetAllowRunningAsynchronously(bool runAsync)
130     {
131         allowRunningAsynchronously_ = runAsync;
132     }
133 
GetAllowRunningAsynchronously()134     bool GetAllowRunningAsynchronously() const
135     {
136         return allowRunningAsynchronously_;
137     }
138 
139 private:
140     int32_t duration_ = 0;
141     int32_t delay_ = 0;
142     int32_t iteration_ = 1;
143     float tempo_ = 1.0f;
144     FillMode fillMode_ = FillMode::FORWARDS;
145     bool allowRunningAsynchronously_ = false;
146     RefPtr<Curve> curve_;
147     std::function<void()> onFinishEvent_;
148     AnimationDirection direction_ = AnimationDirection::NORMAL;
149 };
150 
151 } // namespace OHOS::Ace
152 
153 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATION_OPTION_H
154