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.
46 * @param[in] scrollView reference to ScrollView implementation
47 * or horizontally (false)
49 ScrollOvershootIndicator( Scrollable& scrollable);
54 virtual ~ScrollOvershootIndicator();
57 * Enables and disables the indicator
58 * ¶m[in] enable true to enable, false to disable
60 void Enable(bool enable);
63 * Resets the indicator
68 * Create an initialized ScrollOvershootIndicator
69 * @param[in] scrollView reference to ScrollView implementation
70 * or horizontally (false)
71 * @return A pointer to the created ScrollOvershootIndicator.
73 static ScrollOvershootIndicator* New( Scrollable& scrollable);
76 Scrollable& mScrollable; ///< Internal::Scrollable object
77 ScrollOvershootEffectPtr mEffectX; ///< effect used for x-axis/horizontal display
78 ScrollOvershootEffectPtr mEffectY; ///< effect used for y-axis/vertical display
82 * ScrollOvershootEffect is a derivable class, designed to allow the application programmer to create their own
83 * overshoot effect and apply it with minimal implementation required
85 struct ScrollOvershootEffect : public Dali::RefObject
89 * Create a new overshoot effect, passing in whether it is vertical or horizontal
91 * @param[in] vertical whether this effect is a vertical or horizontal one
93 ScrollOvershootEffect(bool vertical);
98 virtual ~ScrollOvershootEffect() {}
101 * Returns if this is a vertical or horizontal overhoot effect
103 * @return true or false
105 inline bool IsVertical() { return mVertical; }
108 * Applies the indicator effect, all derived effects must implement this function
110 * @param[in] scrollable the scrollable object to apply this effect to
112 virtual void Apply(Scrollable& scrollable) = 0;
115 * Removes the indicator effect, all derived effects must implement this function
117 * @param[in] scrollable the scrollable object to remove this effect from
119 virtual void Remove(Scrollable& scrollable) = 0;
122 * Resets this overshoot effect
124 virtual void Reset() = 0;
127 * Updates the constraints used for the overshoot effect
129 * @param[in] scrollable the container for the overshoot effect
131 virtual void UpdateConstraints(Actor& scrollable) {}
134 * Sets up property notifications for overshoot values
136 * @param[in] scrollable the container for the overshoot effect
138 virtual void SetPropertyNotifications(Actor& scrollable) {}
141 bool mVertical; ///< whether this is a vertical/horizontal effect
145 * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
146 * attempts to scroll past it
148 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
152 * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
154 ScrollOvershootEffectRipple(bool vertical);
157 * @copydoc ScrollOvershootEffect::Apply
159 virtual void Apply(Scrollable& scrollable);
162 * @copydoc ScrollOvershootEffect::Remove
164 virtual void Remove(Scrollable& scrollable);
167 * @copydoc ScrollOvershootEffect::Reset
169 virtual void Reset();
172 * @copydoc ScrollOvershootEffect::UpdateConstraints(Actor& scrollable)
174 virtual void UpdateConstraints(Actor& scrollable);
177 * @copydoc ScrollOvershootEffect::SetPropertyNotification
179 virtual void SetPropertyNotifications(Actor& scrollable);
182 * Constrains the size of the gradient image
183 * @param[in] current current position of the image actor
184 * @param[in] parentSizeProperty size of the scrollable area so we can position image on the edge of it
185 * @param[in] overshootProperty current overshoot amount for this indicator's axis
186 * @return new position of the gradient image actor
188 Vector3 PositionConstraint(const Vector3& current, const PropertyInput& parentSizeProperty, const PropertyInput& overshootProperty);
191 * Informs overshoot effect to update image position and to animate effect overshoot value for a
192 * positive overshoot value from scrollview
194 * @param[in] source the property notification that triggered this callback
196 void OnPositiveOvershootNotification(PropertyNotification& source);
199 * Informs overshoot effect to update image position and to animate effect overshoot value for a
200 * negative overshoot value from scrollview
202 * @param[in] source the property notification that triggered this callback
204 void OnNegativeOvershootNotification(PropertyNotification& source);
207 * Function to animate effect overshoot value either to -1.0f/1.0f or 0.0f
209 * @param[in] overshootAmount the amount to animate overshoot to [-1.0f,0.0f,1.0f]
211 void AnimateScrollOvershoot(float overshootAmount);
214 * Connects to the animation finished signal of our overshoot animation
216 * @param[in] animation the animation instance that has finished
218 void OnOvershootAnimFinished(Animation& animation);
221 * Creates a new ScrollOvershootEffectGradient objects and returns a pointer to it
222 * @param[in] vertical whether to create a vertical(true) or horizontal effect
223 * @return a pointer to the new effect
225 static ScrollOvershootEffectRipplePtr New( bool vertical );
229 float mMaxOvershootImageSize; ///< maximum size of the image when overshoot value is 1.0f
230 ImageActor mOvershootImage; ///< the overshoot image...
231 Animation mScrollOvershootAnimation; ///< animation
232 bool mAnimatingOvershootOn; ///< whether we are currently animating overshoot to 1.0f/-1.0f (on) or to 0.0f (off)
233 bool mAnimateOvershootOff; ///< whether we are currently animating overshoot to 1.0f/-1.0f (on) or to 0.0f (off)
234 int mCanScrollPropertyIndex; ///< property index to a property that informs indicator if it is needed
235 BouncingEffect mRippleEffect; // the ripple vertex/fragment shader effect
236 PropertyNotification mOvershootPositiveNotification; // stores the property notification used for positive overshoot values
237 PropertyNotification mOvershootNegativeNotification; // stores the property notification used for negative overshoot values
238 ActiveConstraint mSizeConstraint; // active constraint handle used to store the image width constraint
239 ActiveConstraint mPositionConstraint; // active constraint handle used to store the image position constraint
242 } // namespace Internal
244 } // namespace Toolkit
248 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__