Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-overshoot-indicator-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 #include <dali/dali.h>
22 #include <dali-toolkit/public-api/shader-effects/bouncing-effect.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32 class Scrollable;
33 class ScrollOvershootEffect;
34 class ScrollOvershootEffectGradient;
35 class ScrollOvershootEffectRipple;
36 typedef IntrusivePtr<ScrollOvershootEffect> ScrollOvershootEffectPtr;
37 typedef IntrusivePtr<ScrollOvershootEffectGradient> ScrollOvershootEffectGradientPtr;
38 typedef IntrusivePtr<ScrollOvershootEffectRipple> ScrollOvershootEffectRipplePtr;
39
40 struct ScrollOvershootIndicator : public Dali::RefObject
41 {
42 public:
43
44   /**
45    * ScrollOvershootIndicator constructor.
46    * @param[in] scrollView reference to ScrollView implementation
47    * or horizontally (false)
48    */
49   ScrollOvershootIndicator( Scrollable& scrollable);
50
51   /**
52    * Virtual destructor
53    */
54   virtual ~ScrollOvershootIndicator();
55
56   /**
57    * Enables and disables the indicator
58    * &param[in] enable true to enable, false to disable
59    */
60   void Enable(bool enable);
61
62   /**
63    * Resets the indicator
64    */
65   void Reset();
66
67   /**
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.
72    */
73   static ScrollOvershootIndicator* New( Scrollable& scrollable);
74
75 private:
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
79 };
80
81 /**
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
84  */
85 struct ScrollOvershootEffect : public Dali::RefObject
86 {
87 public:
88   /**
89    * Create a new overshoot effect, passing in whether it is vertical or horizontal
90    *
91    * @param[in] vertical whether this effect is a vertical or horizontal one
92    */
93   ScrollOvershootEffect(bool vertical);
94
95   /**
96    * Virtual destructor
97    */
98   virtual ~ScrollOvershootEffect() {}
99
100   /**
101    * Returns if this is a vertical or horizontal overhoot effect
102    *
103    * @return true or false
104    */
105   inline bool IsVertical() { return mVertical; }
106
107   /**
108    * Applies the indicator effect, all derived effects must implement this function
109    *
110    * @param[in] scrollable the scrollable object to apply this effect to
111    */
112   virtual void Apply(Scrollable& scrollable) = 0;
113
114   /**
115    * Removes the indicator effect, all derived effects must implement this function
116    *
117    * @param[in] scrollable the scrollable object to remove this effect from
118    */
119   virtual void Remove(Scrollable& scrollable) = 0;
120
121   /**
122    * Resets this overshoot effect
123    */
124   virtual void Reset() = 0;
125
126   /**
127    * Updates the constraints used for the overshoot effect
128    *
129    * @param[in] scrollable the container for the overshoot effect
130    */
131   virtual void UpdateConstraints(Actor& scrollable) {}
132
133   /**
134    * Sets up property notifications for overshoot values
135    *
136    * @param[in] scrollable the container for the overshoot effect
137    */
138   virtual void SetPropertyNotifications(Actor& scrollable) {}
139
140 private:
141   bool mVertical;                      ///< whether this is a vertical/horizontal effect
142 };
143
144 /**
145  * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
146  * attempts to scroll past it
147  */
148 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
149 {
150 public:
151   /**
152    * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
153    */
154   ScrollOvershootEffectRipple(bool vertical);
155
156   /**
157    * @copydoc ScrollOvershootEffect::Apply
158    */
159   virtual void Apply(Scrollable& scrollable);
160
161   /**
162    * @copydoc ScrollOvershootEffect::Remove
163    */
164   virtual void Remove(Scrollable& scrollable);
165
166   /**
167    * @copydoc ScrollOvershootEffect::Reset
168    */
169   virtual void Reset();
170
171   /**
172    * @copydoc ScrollOvershootEffect::UpdateConstraints(Actor& scrollable)
173    */
174   virtual void UpdateConstraints(Actor& scrollable);
175
176   /**
177    * @copydoc ScrollOvershootEffect::SetPropertyNotification
178    */
179   virtual void SetPropertyNotifications(Actor& scrollable);
180
181   /**
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
187    */
188   Vector3 PositionConstraint(const Vector3& current, const PropertyInput& parentSizeProperty, const PropertyInput& overshootProperty);
189
190   /**
191    * Informs overshoot effect to update image position and to animate effect overshoot value for a
192    * positive overshoot value from scrollview
193    *
194    * @param[in] source the property notification that triggered this callback
195    */
196   void OnPositiveOvershootNotification(PropertyNotification& source);
197
198   /**
199    * Informs overshoot effect to update image position and to animate effect overshoot value for a
200    * negative overshoot value from scrollview
201    *
202    * @param[in] source the property notification that triggered this callback
203    */
204   void OnNegativeOvershootNotification(PropertyNotification& source);
205
206   /**
207    * Function to animate effect overshoot value either to -1.0f/1.0f or 0.0f
208    *
209    * @param[in] overshootAmount the amount to animate overshoot to [-1.0f,0.0f,1.0f]
210    */
211   void AnimateScrollOvershoot(float overshootAmount);
212
213   /**
214    * Connects to the animation finished signal of our overshoot animation
215    *
216    * @param[in] animation the animation instance that has finished
217    */
218   void OnOvershootAnimFinished(Animation& animation);
219
220   /**
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
224    */
225   static ScrollOvershootEffectRipplePtr New( bool vertical );
226
227 private:
228
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
240 };
241
242 } // namespace Internal
243
244 } // namespace Toolkit
245
246 } // namespace Dali
247
248 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__