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.
21 #include <dali/dali.h>
22 #include <dali-toolkit/public-api/shader-effects/bouncing-effect.h>
33 class ScrollOvershootEffect;
34 class ScrollOvershootEffectGradient;
35 class ScrollOvershootEffectRipple;
36 typedef IntrusivePtr<ScrollOvershootEffect> ScrollOvershootEffectPtr;
37 typedef IntrusivePtr<ScrollOvershootEffectGradient> ScrollOvershootEffectGradientPtr;
38 typedef IntrusivePtr<ScrollOvershootEffectRipple> ScrollOvershootEffectRipplePtr;
40 struct ScrollOvershootIndicator : public Dali::RefObject
45 * ScrollOvershootIndicator constructor.
47 ScrollOvershootIndicator();
52 virtual ~ScrollOvershootIndicator();
55 * Attaches the scroll indicator to a scrollable actor
57 * ¶m[in] scrollable The scrollable actor to attach to
59 void AttachToScrollable(Scrollable& scrollable);
62 * Detaches the scroll indicator from a scrollable actor
64 * ¶m[in] scrollable The scrollable actor to detach from
66 void DetachFromScrollable(Scrollable& scrollable);
69 * Resets the indicator
74 * Create an initialized ScrollOvershootIndicator
76 * @return A pointer to the created ScrollOvershootIndicator.
78 static ScrollOvershootIndicator* New();
81 ScrollOvershootEffectPtr mEffectX; ///< effect used for x-axis/horizontal display
82 ScrollOvershootEffectPtr mEffectY; ///< effect used for y-axis/vertical display
86 * ScrollOvershootEffect is a derivable class, designed to allow the application programmer to create their own
87 * overshoot effect and apply it with minimal implementation required
89 struct ScrollOvershootEffect : public Dali::RefObject
93 * Create a new overshoot effect, passing in whether it is vertical or horizontal
95 * @param[in] vertical whether this effect is a vertical or horizontal one
97 ScrollOvershootEffect( bool vertical );
102 virtual ~ScrollOvershootEffect() {}
105 * Returns if this is a vertical or horizontal overhoot effect
107 * @return true or false
109 bool IsVertical() const;
112 * Applies the indicator effect, all derived effects must implement this function
114 * @param[in] scrollable the scrollable object to apply this effect to
116 virtual void Apply() = 0;
119 * Removes the indicator effect, all derived effects must implement this function
121 * @param[in] scrollable the scrollable object to remove this effect from
123 virtual void Remove( Scrollable& scrollable ) = 0;
126 * Resets this overshoot effect
128 virtual void Reset() = 0;
131 * Sets up property notifications for overshoot values
133 virtual void UpdatePropertyNotifications() {}
136 bool mVertical; ///< whether this is a vertical/horizontal effect
140 * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
141 * attempts to scroll past it
143 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
147 AnimatingIn = 0x01, ///< animating overshoot to 0
148 AnimatingOut = 0x02, ///< animating overshoot to negative (overshoot image displays in +ve area of screen)
149 AnimateBack = 0x04, ///< indicates that we need to animate overshoot back to zero immediately after it has finished animating in
155 * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
157 * @param[in] vertical Whether this indicator is vertical or horizontal
159 ScrollOvershootEffectRipple( bool vertical, Scrollable& scrollable );
162 * @copydoc ScrollOvershootEffect::Apply
164 virtual void Apply();
167 * @copydoc ScrollOvershootEffect::Remove
169 virtual void Remove( Scrollable& scrollable );
172 * @copydoc ScrollOvershootEffect::Reset
174 virtual void Reset();
177 * @copydoc ScrollOvershootEffect::UpdatePropertyNotifications
179 void UpdatePropertyNotifications();
182 * Updates the vibility of the overshoot image as well as updating its size, position and rotation
183 * This function is called when animation starts and finishes
185 * @param[in] visible Whether to set the image visible or not
187 void UpdateVisibility( bool visible );
190 * Informs overshoot effect to update image position and to animate effect overshoot value for a
191 * positive overshoot value from scrollview
193 * @param[in] source the property notification that triggered this callback
195 void OnOvershootNotification(PropertyNotification& source);
198 * Sets shader overshoot value, either immediately of by animating over time
200 * @param[in] amount The amount to set overshoot to [-1.0f,1.0f]
201 * @param[in] animate Whether to animate or set immediately
203 void SetOvershoot(float amount, bool animate = true);
206 * Connects to the animation finished signal of our overshoot animation
208 * @param[in] animation the animation instance that has finished
210 void OnOvershootAnimFinished(Animation& animation);
213 * Creates a new ScrollOvershootEffectGradient objects and returns a pointer to it
215 * @param[in] vertical whether to create a vertical(true) or horizontal effect
216 * @return a pointer to the new effect
218 static ScrollOvershootEffectRipplePtr New( bool vertical, Scrollable& scrollable );
221 ImageActor mOvershootImage; ///< the overshoot image...
222 Scrollable& mAttachedScrollView; ///< the actor that this indicator has been attached to
223 BouncingEffect mRippleEffect; ///< the ripple vertex/fragment shader effect
224 Animation mScrollOvershootAnimation; ///< overshoot animation
225 PropertyNotification mOvershootIncreaseNotification;///< notification used to inform as overshoot increases
226 PropertyNotification mOvershootDecreaseNotification;///< notification used to inform as overshoot decreases
227 Property::Index mCanScrollPropertyIndex; ///< property index to a property that informs indicator if it is needed
228 Property::Index mOvershootProperty; ///< index of the overshoot property in the scrollable actor
229 Property::Index mEffectOvershootProperty; ///< index of the effect's overshoot property
230 float mMaxOvershootImageSize; ///< maximum height of the image when overshoot value is 1.0f
231 float mOvershootAnimationDuration; ///< time taken for overshoot to go from fully offscreen to fully onscreen and vice versa
232 float mOvershoot; ///< last overshoot value as detected by notifications
233 unsigned short mAnimationStateFlags; ///< contains flags indicating the current state of the overshoot animation
236 } // namespace Internal
238 } // namespace Toolkit
242 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__