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>
32 class ScrollOvershootEffect;
33 class ScrollOvershootEffectGradient;
34 class ScrollOvershootEffectRipple;
35 typedef IntrusivePtr<ScrollOvershootEffect> ScrollOvershootEffectPtr;
36 typedef IntrusivePtr<ScrollOvershootEffectGradient> ScrollOvershootEffectGradientPtr;
37 typedef IntrusivePtr<ScrollOvershootEffectRipple> ScrollOvershootEffectRipplePtr;
39 struct ScrollOvershootIndicator : public Dali::RefObject
44 * ScrollOvershootIndicator constructor.
46 ScrollOvershootIndicator();
51 virtual ~ScrollOvershootIndicator();
54 * Attaches the scroll indicator to a scrollable actor
56 * ¶m[in] scrollable The scrollable actor to attach to
58 void AttachToScrollable(Scrollable& scrollable);
61 * Detaches the scroll indicator from a scrollable actor
63 * ¶m[in] scrollable The scrollable actor to detach from
65 void DetachFromScrollable(Scrollable& scrollable);
68 * Resets the indicator
73 * Clears the overshoot
75 void ClearOvershoot();
78 * Create an initialized ScrollOvershootIndicator
80 * @return A pointer to the created ScrollOvershootIndicator.
82 static ScrollOvershootIndicator* New();
85 * Set the color of the overshoot effect.
86 * @parm[in] color The color of the overshoot effect
88 void SetOvershootEffectColor( const Vector4& color );
91 ScrollOvershootEffectPtr mEffectX; ///< effect used for x-axis/horizontal display
92 ScrollOvershootEffectPtr mEffectY; ///< effect used for y-axis/vertical display
96 * ScrollOvershootEffect is a derivable class, designed to allow the application programmer to create their own
97 * overshoot effect and apply it with minimal implementation required
99 struct ScrollOvershootEffect : public Dali::RefObject
103 * Create a new overshoot effect, passing in whether it is vertical or horizontal
105 * @param[in] vertical whether this effect is a vertical or horizontal one
107 ScrollOvershootEffect( bool vertical );
112 virtual ~ScrollOvershootEffect() {}
115 * Returns if this is a vertical or horizontal overhoot effect
117 * @return true or false
119 bool IsVertical() const;
122 * Applies the indicator effect, all derived effects must implement this function
124 * @param[in] scrollable the scrollable object to apply this effect to
126 virtual void Apply() = 0;
129 * Removes the indicator effect, all derived effects must implement this function
131 * @param[in] scrollable the scrollable object to remove this effect from
133 virtual void Remove( Scrollable& scrollable ) = 0;
136 * Resets this overshoot effect
138 virtual void Reset() = 0;
141 * Sets up property notifications for overshoot values
143 virtual void UpdatePropertyNotifications() {}
146 * @copydoc ScrollOvershootIndicator::SetOvershootEffectColor()
148 virtual void SetOvershootEffectColor( const Vector4& color ) = 0;
151 * Sets shader overshoot value, either immediately of by animating over time
153 * @param[in] amount The amount to set overshoot to [-1.0f,1.0f]
154 * @param[in] animate Whether to animate or set immediately
156 virtual void SetOvershoot(float amount, bool animate = true) = 0;
159 bool mVertical; ///< whether this is a vertical/horizontal effect
163 * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
164 * attempts to scroll past it
166 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
170 AnimatingIn = 0x01, ///< animating overshoot to 0
171 AnimatingOut = 0x02, ///< animating overshoot to negative (overshoot image displays in +ve area of screen)
172 AnimateBack = 0x04, ///< indicates that we need to animate overshoot back to zero immediately after it has finished animating in
178 * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
180 * @param[in] vertical Whether this indicator is vertical or horizontal
182 ScrollOvershootEffectRipple( bool vertical, Scrollable& scrollable );
185 * @copydoc ScrollOvershootEffect::Apply
187 virtual void Apply();
190 * @copydoc ScrollOvershootEffect::Remove
192 virtual void Remove( Scrollable& scrollable );
195 * @copydoc ScrollOvershootEffect::Reset
197 virtual void Reset();
200 * @copydoc ScrollOvershootEffect::UpdatePropertyNotifications
202 void UpdatePropertyNotifications();
205 * @copydoc ScrollOvershootEffect::SetOvershootEffectColor()
207 void SetOvershootEffectColor( const Vector4& color );
210 * Updates the vibility of the overshoot image as well as updating its size, position and rotation
211 * This function is called when animation starts and finishes
213 * @param[in] visible Whether to set the image visible or not
215 void UpdateVisibility( bool visible );
218 * Informs overshoot effect to update image position and to animate effect overshoot value for a
219 * positive overshoot value from scrollview
221 * @param[in] source the property notification that triggered this callback
223 void OnOvershootNotification(PropertyNotification& source);
226 * @copydoc ScrollOvershootEffect::SetOvershoot()
228 void SetOvershoot(float amount, bool animate = true);
231 * Connects to the animation finished signal of our overshoot animation
233 * @param[in] animation the animation instance that has finished
235 void OnOvershootAnimFinished(Animation& animation);
238 * Creates a new ScrollOvershootEffectGradient objects and returns a pointer to it
240 * @param[in] vertical whether to create a vertical(true) or horizontal effect
241 * @return a pointer to the new effect
243 static ScrollOvershootEffectRipplePtr New( bool vertical, Scrollable& scrollable );
246 Actor mOvershootOverlay; ///< the actor which displays the overshoot effect
247 Scrollable& mAttachedScrollView; ///< the actor that this indicator has been attached to
248 Animation mScrollOvershootAnimation; ///< overshoot animation
249 PropertyNotification mOvershootIncreaseNotification;///< notification used to inform as overshoot increases
250 PropertyNotification mOvershootDecreaseNotification;///< notification used to inform as overshoot decreases
251 Property::Index mCanScrollPropertyIndex; ///< property index to a property that informs indicator if it is needed
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 mMaxOvershootImageSize; ///< maximum height of the image when overshoot value is 1.0f
255 float mOvershootAnimationDuration; ///< time taken for overshoot to go from fully offscreen to fully onscreen and vice versa
256 float mOvershoot; ///< last overshoot value as detected by notifications
257 unsigned short mAnimationStateFlags; ///< contains flags indicating the current state of the overshoot animation
260 } // namespace Internal
262 } // namespace Toolkit
266 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__