soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SAnimationSet.h
1#ifndef __SANIMATIONSET__H__
2#define __SANIMATIONSET__H__
3
4#include <animation/SAnimation.h>
5#include <souicoll.h>
6
7/**
8 * @brief Represents a group of Animations that should be played together.
9 *
10 * The transformation of each individual animation are composed together into a single transform.
11 * If AnimationSet sets any properties that its children also set (for example, duration or fillBefore),
12 * the values of AnimationSet override the child values.
13 *
14 * <p>The way that AnimationSet inherits behavior from Animation is important to understand.
15 * Some of the Animation attributes applied to AnimationSet affect the AnimationSet itself,
16 * some are pushed down to the children, and some are ignored, as follows:
17 * <ul>
18 * <li>duration, repeatMode, fillBefore, fillAfter: These properties, when set on an AnimationSet object,
19 * will be pushed down to all child animations.</li>
20 * <li>repeatCount, fillEnabled: These properties are ignored for AnimationSet.</li>
21 * <li>startOffset, shareInterpolator: These properties apply to the AnimationSet itself.</li>
22 * </ul>
23 * Starting with {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, the behavior of these properties
24 * is the same in XML resources and at runtime (prior to that release, the values set in XML were ignored
25 * for AnimationSet). That is, calling <code>setDuration(500)</code> on an AnimationSet has the same effect
26 * as declaring <code>android:duration="500"</code> in an XML resource for an AnimationSet object.</p>
27 */
28
29SNSBEGIN
30
31class SOUI_EXP SAnimationSet : public SAnimation {
32 DEF_SOBJECT(SAnimation, L"set")
33
34 enum
35 {
36 PROPERTY_FILL_AFTER_MASK = 0x1,
37 PROPERTY_FILL_BEFORE_MASK = 0x2,
38 PROPERTY_DURATION_MASK = 0x04,
39 PROPERTY_SHARE_INTERPOLATOR_MASK = 0x08,
40 };
41
42 private:
43 int mFlags; ///< Flags to manage properties like fillAfter, fillBefore, duration, and shareInterpolator.
44 bool mDirty; ///< Indicates if the animation set needs to be reinitialized.
45 bool mHasAlpha; ///< Indicates if any child animation affects the alpha property.
46 SArray<SAutoRefPtr<IAnimation>> mAnimations; ///< Array of child animations.
47 bool mChildStarted; ///< Indicates if any child animation has started.
48 long mLastEnd; ///< The end time of the last child animation.
49
50 public:
51 /**
52 * @brief Constructor to use when building an AnimationSet from code.
53 * @param shareInterpolator Pass true if all of the animations in this set should use the interpolator
54 * associated with this AnimationSet. Pass false if each animation should use its own interpolator.
55 */
56 SAnimationSet(bool shareInterpolator = true);
57
58 /**
59 * @brief Add a child animation to this animation set.
60 * The transforms of the child animations are applied in the order that they were added.
61 * @param a Pointer to the animation to add.
62 */
63 void addAnimation(IAnimation *a);
64
65 /**
66 * @brief Checks if any child animation affects the alpha property.
67 * @return TRUE if any child animation affects the alpha property, FALSE otherwise.
68 */
69 bool hasAlpha();
70
71 private:
72 /**
73 * @brief Sets a specific flag.
74 * @param mask The flag mask to set.
75 * @param value The value to set for the flag.
76 */
77 void setFlag(int mask, bool value);
78
79 /**
80 * @brief Initializes the animation set.
81 */
82 void init();
83
84 public:
85 /**
86 * @brief Sets whether the animation transformation should be applied after the animation ends.
87 * @param bFill Boolean indicating whether to fill after.
88 */
89 STDMETHOD_(void, setFillAfter)(THIS_ BOOL bFill) OVERRIDE;
90
91 /**
92 * @brief Sets whether the animation transformation should be applied before the animation starts.
93 * @param bFill Boolean indicating whether to fill before.
94 */
95 STDMETHOD_(void, setFillBefore)(THIS_ BOOL bFill) OVERRIDE;
96
97 /**
98 * @brief Sets the duration of every child animation.
99 * @param durationMillis The duration of the animation, in milliseconds, for every child in this set.
100 */
101 STDMETHOD_(void, setDuration)(THIS_ long durationMillis) OVERRIDE;
102
103 /**
104 * @brief Gets the duration of the AnimationSet.
105 * The duration of an AnimationSet is defined to be the duration of the longest child animation.
106 * @return The duration in milliseconds.
107 */
108 STDMETHOD_(long, getDuration)(THIS) SCONST OVERRIDE;
109
110 /**
111 * @brief Gets the transformation at a specific time.
112 * The transformation of an animation set is the concatenation of all of its component animations.
113 * @param currentTime Current time in milliseconds.
114 * @param outTransformation Pointer to the transformation to apply.
115 * @return TRUE if the transformation is valid, FALSE otherwise.
116 */
117 STDMETHOD_(BOOL, getTransformation)
118 (THIS_ uint64_t currentTime, ITransformation *outTransformation) OVERRIDE;
119
120 /**
121 * @brief Scales the current duration of the animation.
122 * @param scale Scale factor.
123 */
124 STDMETHOD_(void, scaleCurrentDuration)(THIS_ float scale) OVERRIDE;
125
126 /**
127 * @brief Initializes the animation with the dimensions of the object and its parent.
128 * @param width Width of the object being animated.
129 * @param height Height of the object being animated.
130 * @param parentWidth Width of the parent of the object being animated.
131 * @param parentHeight Height of the parent of the object being animated.
132 * @param nScale Scale factor.
133 */
134 STDMETHOD_(void, initialize)
135 (THIS_ int width, int height, int parentWidth, int parentHeight, int nScale) OVERRIDE;
136
137 /**
138 * @brief Copies the properties of another animation to this animation.
139 * @param src Pointer to the source animation to copy from.
140 */
141 STDMETHOD_(void, copy)(THIS_ const IAnimation *src) OVERRIDE;
142
143 /**
144 * @brief Pauses the animation.
145 */
146 STDMETHOD_(void, pause)(THIS) OVERRIDE;
147
148 /**
149 * @brief Resumes the animation.
150 */
151 STDMETHOD_(void, resume)(THIS) OVERRIDE;
152
153 protected:
154 /**
155 * @brief Initializes the animation set from an XML node.
156 * @param pNode Pointer to the XML node.
157 * @return HRESULT indicating success or failure.
158 */
159 STDMETHOD_(BOOL, InitFromXml)(THIS_ IXmlNode *pNode) OVERRIDE;
160
161 /**
162 * @brief Custom attribute handler for duration.
163 * @param value The duration value as a string.
164 * @param bLoading Boolean indicating if the attribute is being loaded.
165 * @return HRESULT indicating success or failure.
166 */
167 HRESULT OnAttrDuration(const SStringW &value, BOOL bLoading);
168
169 /**
170 * @brief Custom attribute handler for fillBefore.
171 * @param value The fillBefore value as a string.
172 * @param bLoading Boolean indicating if the attribute is being loaded.
173 * @return HRESULT indicating success or failure.
174 */
175 HRESULT OnAttrFillBefore(const SStringW &value, BOOL bLoading);
176
177 /**
178 * @brief Custom attribute handler for fillAfter.
179 * @param value The fillAfter value as a string.
180 * @param bLoading Boolean indicating if the attribute is being loaded.
181 * @return HRESULT indicating success or failure.
182 */
183 HRESULT OnAttrFillAfter(const SStringW &value, BOOL bLoading);
184
185 /**
186 * @brief Custom attribute handler for startOffset.
187 * @param value The startOffset value as a string.
188 * @param bLoading Boolean indicating if the attribute is being loaded.
189 * @return HRESULT indicating success or failure.
190 */
191 HRESULT OnAttrStartOffset(const SStringW &value, BOOL bLoading);
192
193 /**
194 * @brief Attributes for SAnimationSet
195 */
196 SOUI_ATTRS_BEGIN()
197 ATTR_BIT(L"shareInterpolator", mFlags, PROPERTY_SHARE_INTERPOLATOR_MASK, FALSE) ///< Whether to share the interpolator with child animations.
198 ATTR_CUSTOM(L"duration", OnAttrDuration) ///< Duration of the animation in milliseconds.
199 ATTR_CUSTOM(L"fillBefore", OnAttrFillBefore) ///< Whether the animation transformation should be applied before the animation starts.
200 ATTR_CUSTOM(L"fillAfter", OnAttrFillAfter) ///< Whether the animation transformation should be applied after the animation ends.
201 ATTR_CUSTOM(L"startOffset", OnAttrStartOffset) ///< Delay before the animation starts in milliseconds.
202 SOUI_ATTRS_END()
203};
204
205SNSEND
206
207#endif // __SANIMATIONSET__H__
BOOL hasAlpha() SCONST OVERRIDE
Checks whether the animation affects the alpha property.
SAnimation()
Default constructor for SAnimation.
void setFillBefore(BOOL bFill) OVERRIDE
Sets whether the animation transformation should be applied before the animation starts.
long getDuration() SCONST OVERRIDE
Gets the duration of the AnimationSet. The duration of an AnimationSet is defined to be the duration ...
void setFillAfter(BOOL bFill) OVERRIDE
Sets whether the animation transformation should be applied after the animation ends.
void pause() OVERRIDE
Pauses the animation.
HRESULT OnAttrDuration(const SStringW &value, BOOL bLoading)
Custom attribute handler for duration.
void addAnimation(IAnimation *a)
Add a child animation to this animation set. The transforms of the child animations are applied in th...
void initialize(int width, int height, int parentWidth, int parentHeight, int nScale) OVERRIDE
Initializes the animation with the dimensions of the object and its parent.
void resume() OVERRIDE
Resumes the animation.
SAnimationSet(bool shareInterpolator=true)
Constructor to use when building an AnimationSet from code.
HRESULT OnAttrFillBefore(const SStringW &value, BOOL bLoading)
Custom attribute handler for fillBefore.
void setDuration(long durationMillis) OVERRIDE
Sets the duration of every child animation.
void scaleCurrentDuration(float scale) OVERRIDE
Scales the current duration of the animation.
BOOL getTransformation(uint64_t currentTime, ITransformation *outTransformation) OVERRIDE
Gets the transformation at a specific time. The transformation of an animation set is the concatenati...
HRESULT OnAttrFillAfter(const SStringW &value, BOOL bLoading)
Custom attribute handler for fillAfter.
HRESULT OnAttrStartOffset(const SStringW &value, BOOL bLoading)
Custom attribute handler for startOffset.
void copy(const IAnimation *src) OVERRIDE
Copies the properties of another animation to this animation.
BOOL InitFromXml(IXmlNode *pNode) OVERRIDE
Initializes the animation set from an XML node.
A class representing an ASCII string.
Definition sstringw.h:96
Interface for XML nodes.
Definition sxml-i.h:128