1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/common/intrusive-ptr.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/object/property-notification.h>
27 #include <dali/public-api/object/ref-object.h>
38 class ScrollOvershootEffect;
39 class ScrollOvershootEffectGradient;
40 class ScrollOvershootEffectRipple;
41 typedef IntrusivePtr<ScrollOvershootEffect> ScrollOvershootEffectPtr;
42 typedef IntrusivePtr<ScrollOvershootEffectGradient> ScrollOvershootEffectGradientPtr;
43 typedef IntrusivePtr<ScrollOvershootEffectRipple> ScrollOvershootEffectRipplePtr;
45 struct ScrollOvershootIndicator : public Dali::RefObject
50 * ScrollOvershootIndicator constructor.
52 ScrollOvershootIndicator();
57 virtual ~ScrollOvershootIndicator();
60 * Attaches the scroll indicator to a scrollable actor
62 * ¶m[in] scrollable The scrollable actor to attach to
64 void AttachToScrollable(Scrollable& scrollable);
67 * Detaches the scroll indicator from a scrollable actor
69 * ¶m[in] scrollable The scrollable actor to detach from
71 void DetachFromScrollable(Scrollable& scrollable);
74 * Resets the indicator
79 * Create an initialized ScrollOvershootIndicator
81 * @return A pointer to the created ScrollOvershootIndicator.
83 static ScrollOvershootIndicator* New();
86 * Set the color of the overshoot effect.
87 * @parm[in] color The color of the overshoot effect
89 void SetOvershootEffectColor( const Vector4& color );
92 ScrollOvershootEffectPtr mEffectX; ///< effect used for x-axis/horizontal display
93 ScrollOvershootEffectPtr mEffectY; ///< effect used for y-axis/vertical display
97 * ScrollOvershootEffect is a derivable class, designed to allow the application programmer to create their own
98 * overshoot effect and apply it with minimal implementation required
100 struct ScrollOvershootEffect : public Dali::RefObject
104 * Create a new overshoot effect, passing in whether it is vertical or horizontal
106 * @param[in] vertical whether this effect is a vertical or horizontal one
108 ScrollOvershootEffect( bool vertical );
113 virtual ~ScrollOvershootEffect() {}
116 * Returns if this is a vertical or horizontal overhoot effect
118 * @return true or false
120 bool IsVertical() const;
123 * Applies the indicator effect, all derived effects must implement this function
125 * @param[in] scrollable the scrollable object to apply this effect to
127 virtual void Apply() = 0;
130 * Removes the indicator effect, all derived effects must implement this function
132 * @param[in] scrollable the scrollable object to remove this effect from
134 virtual void Remove( Scrollable& scrollable ) = 0;
137 * Resets this overshoot effect
139 virtual void Reset() = 0;
142 * Sets up property notifications for overshoot values
144 virtual void UpdatePropertyNotifications() {}
147 * @copydoc ScrollOvershootIndicator::SetOvershootEffectColor()
149 virtual void SetOvershootEffectColor( const Vector4& color ) = 0;
152 * Sets shader overshoot value, either immediately of by animating over time
154 * @param[in] amount The amount to set overshoot to [-1.0f,1.0f]
155 * @param[in] animate Whether to animate or set immediately
157 virtual void SetOvershoot(float amount, bool animate = true) = 0;
160 bool mVertical; ///< whether this is a vertical/horizontal effect
164 * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
165 * attempts to scroll past it
167 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
171 AnimatingIn = 0x01, ///< animating overshoot to 0
172 AnimatingOut = 0x02, ///< animating overshoot to negative (overshoot image displays in +ve area of screen)
173 AnimateBack = 0x04, ///< indicates that we need to animate overshoot back to zero immediately after it has finished animating in
179 * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
181 * @param[in] vertical Whether this indicator is vertical or horizontal
183 ScrollOvershootEffectRipple( bool vertical, Scrollable& scrollable );
186 * @copydoc ScrollOvershootEffect::Apply
188 virtual void Apply();
191 * @copydoc ScrollOvershootEffect::Remove
193 virtual void Remove( Scrollable& scrollable );
196 * @copydoc ScrollOvershootEffect::Reset
198 virtual void Reset();
201 * @copydoc ScrollOvershootEffect::UpdatePropertyNotifications
203 void UpdatePropertyNotifications();
206 * @copydoc ScrollOvershootEffect::SetOvershootEffectColor()
208 void SetOvershootEffectColor( const Vector4& color );
211 * Updates the vibility of the overshoot image as well as updating its size, position and rotation
212 * This function is called when animation starts and finishes
214 * @param[in] visible Whether to set the image visible or not
216 void UpdateVisibility( bool visible );
219 * Informs overshoot effect to update image position and to animate effect overshoot value for a
220 * positive overshoot value from scrollview
222 * @param[in] source the property notification that triggered this callback
224 void OnOvershootNotification(PropertyNotification& source);
227 * @copydoc ScrollOvershootEffect::SetOvershoot()
229 void SetOvershoot(float amount, bool animate = true);
232 * Connects to the animation finished signal of our overshoot animation
234 * @param[in] animation the animation instance that has finished
236 void OnOvershootAnimFinished(Animation& animation);
239 * Creates a new ScrollOvershootEffectGradient objects and returns a pointer to it
241 * @param[in] vertical whether to create a vertical(true) or horizontal effect
242 * @return a pointer to the new effect
244 static ScrollOvershootEffectRipplePtr New( bool vertical, Scrollable& scrollable );
247 Actor mOvershootOverlay; ///< the actor which displays the overshoot effect
248 Scrollable& mAttachedScrollView; ///< the actor that this indicator has been attached to
249 Animation mScrollOvershootAnimation; ///< overshoot animation
250 PropertyNotification mOvershootIncreaseNotification;///< notification used to inform as overshoot increases
251 PropertyNotification mOvershootDecreaseNotification;///< notification used to inform as overshoot decreases
252 Property::Index mOvershootProperty; ///< index of the overshoot property in the scrollable actor
253 Property::Index mEffectOvershootProperty; ///< index of the effect's overshoot property
254 float mOvershoot; ///< last overshoot value as detected by notifications
255 Vector2 mOvershootSize; ///< The size of the overshoot effect
256 unsigned short mAnimationStateFlags; ///< contains flags indicating the current state of the overshoot animation
259 } // namespace Internal
261 } // namespace Toolkit
265 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__