[Adaptation Layer] Added rive-tizen adaptation layer class.
[platform/core/uifw/rive-tizen.git] / submodule / include / animation / state_transition.hpp
1 #ifndef _RIVE_STATE_TRANSITION_HPP_
2 #define _RIVE_STATE_TRANSITION_HPP_
3 #include "animation/state_transition_flags.hpp"
4 #include "generated/animation/state_transition_base.hpp"
5 #include <stdio.h>
6 #include <vector>
7
8 namespace rive
9 {
10         class LayerState;
11         class StateMachineLayerImporter;
12         class StateTransitionImporter;
13         class TransitionCondition;
14         class StateInstance;
15         class SMIInput;
16         class LinearAnimation;
17         class LinearAnimationInstance;
18
19         enum class AllowTransition : unsigned char
20         {
21                 no,
22                 waitingForExit,
23                 yes
24         };
25
26         class StateTransition : public StateTransitionBase
27         {
28                 friend class StateMachineLayerImporter;
29                 friend class StateTransitionImporter;
30
31         private:
32                 StateTransitionFlags transitionFlags() const
33                 {
34                         return static_cast<StateTransitionFlags>(flags());
35                 }
36                 LayerState* m_StateTo = nullptr;
37
38                 std::vector<TransitionCondition*> m_Conditions;
39                 void addCondition(TransitionCondition* condition);
40
41         public:
42                 ~StateTransition();
43                 const LayerState* stateTo() const { return m_StateTo; }
44
45                 StatusCode onAddedDirty(CoreContext* context) override;
46                 StatusCode onAddedClean(CoreContext* context) override;
47
48                 /// Whether the transition is marked disabled (usually done in the
49                 /// editor).
50                 bool isDisabled() const
51                 {
52                         return (transitionFlags() & StateTransitionFlags::Disabled) ==
53                                StateTransitionFlags::Disabled;
54                 }
55
56                 /// Returns AllowTransition::yes when this transition can be taken from
57                 /// stateFrom with the given inputs.
58                 AllowTransition allowed(StateInstance* stateFrom,
59                                         SMIInput** inputs,
60                                         bool ignoreTriggers) const;
61
62                 /// Whether the animation is held at exit or if it keeps advancing
63                 /// during mixing.
64                 bool pauseOnExit() const
65                 {
66                         return (transitionFlags() & StateTransitionFlags::PauseOnExit) ==
67                                StateTransitionFlags::PauseOnExit;
68                 }
69
70                 /// Whether exit time is enabled. All other conditions still apply, the
71                 /// exit time is effectively an AND with the rest of the conditions.
72                 bool enableExitTime() const
73                 {
74                         return (transitionFlags() & StateTransitionFlags::EnableExitTime) ==
75                                StateTransitionFlags::EnableExitTime;
76                 }
77
78                 StatusCode import(ImportStack& importStack) override;
79
80                 size_t conditionCount() const { return m_Conditions.size(); }
81                 TransitionCondition* condition(size_t index) const
82                 {
83                         if (index < m_Conditions.size())
84                         {
85                                 return m_Conditions[index];
86                         }
87                         return nullptr;
88                 }
89
90                 /// The amount of time to mix the outgoing animation onto the incoming
91                 /// one when changing state. Only applies when going out from an
92                 /// AnimationState.
93                 float mixTime(const LayerState* stateFrom) const;
94
95                 /// Computes the exit time in seconds of the stateFrom. Set absolute to
96                 /// true if you want the returned time to be relative to the entire
97                 /// animation. Set absolute to false if you want it relative to the work
98                 /// area.
99                 float exitTimeSeconds(const LayerState* stateFrom,
100                                       bool absolute = false) const;
101
102                 /// Provide the animation instance to use for computing percentage
103                 /// durations for exit time.
104                 virtual const LinearAnimationInstance*
105                 exitTimeAnimationInstance(const StateInstance* from) const;
106
107                 /// Provide the animation to use for computing percentage durations for
108                 /// exit time.
109                 virtual const LinearAnimation*
110                 exitTimeAnimation(const LayerState* from) const;
111
112                 /// Retruns true when we need to hold the exit time, also applies the
113                 /// correct time to the animation instance in the stateFrom, when
114                 /// applicable (when it's an AnimationState).
115                 bool applyExitCondition(StateInstance* stateFrom) const;
116         };
117 } // namespace rive
118
119 #endif