Revert "License conversion from Flora to Apache 2.0"
[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 Flora License, Version 1.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://floralicense.org/license/
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 #include <dali/dali.h>
21 #include <dali-toolkit/public-api/shader-effects/bouncing-effect.h>
22
23 namespace Dali
24 {
25
26 namespace Toolkit
27 {
28
29 namespace Internal
30 {
31 class Scrollable;
32 class ScrollOvershootEffect;
33 class ScrollOvershootEffectGradient;
34 class ScrollOvershootEffectRipple;
35 typedef IntrusivePtr<ScrollOvershootEffect> ScrollOvershootEffectPtr;
36 typedef IntrusivePtr<ScrollOvershootEffectGradient> ScrollOvershootEffectGradientPtr;
37 typedef IntrusivePtr<ScrollOvershootEffectRipple> ScrollOvershootEffectRipplePtr;
38
39 struct ScrollOvershootIndicator : public Dali::RefObject
40 {
41 public:
42
43   /**
44    * ScrollOvershootIndicator constructor.
45    * @param[in] scrollView reference to ScrollView implementation
46    * or horizontally (false)
47    */
48   ScrollOvershootIndicator( Scrollable& scrollable);
49
50   /**
51    * Virtual destructor
52    */
53   virtual ~ScrollOvershootIndicator();
54
55   /**
56    * Enables and disables the indicator
57    * &param[in] enable true to enable, false to disable
58    */
59   void Enable(bool enable);
60
61   /**
62    * Resets the indicator
63    */
64   void Reset();
65
66   /**
67    * Create an initialized ScrollOvershootIndicator
68    * @param[in] scrollView reference to ScrollView implementation
69    * or horizontally (false)
70    * @return A pointer to the created ScrollOvershootIndicator.
71    */
72   static ScrollOvershootIndicator* New( Scrollable& scrollable);
73
74 private:
75   Scrollable& mScrollable;                                ///< Internal::Scrollable object
76   ScrollOvershootEffectPtr mEffectX;                      ///< effect used for x-axis/horizontal display
77   ScrollOvershootEffectPtr mEffectY;                      ///< effect used for y-axis/vertical display
78 };
79
80 /**
81  * ScrollOvershootEffect is a derivable class, designed to allow the application programmer to create their own
82  * overshoot effect and apply it with minimal implementation required
83  */
84 struct ScrollOvershootEffect : public Dali::RefObject
85 {
86 public:
87   /**
88    * Create a new overshoot effect, passing in whether it is vertical or horizontal
89    *
90    * @param[in] vertical whether this effect is a vertical or horizontal one
91    */
92   ScrollOvershootEffect(bool vertical);
93
94   /**
95    * Virtual destructor
96    */
97   virtual ~ScrollOvershootEffect() {}
98
99   /**
100    * Returns if this is a vertical or horizontal overhoot effect
101    *
102    * @return true or false
103    */
104   inline bool IsVertical() { return mVertical; }
105
106   /**
107    * Applies the indicator effect, all derived effects must implement this function
108    *
109    * @param[in] scrollable the scrollable object to apply this effect to
110    */
111   virtual void Apply(Scrollable& scrollable) = 0;
112
113   /**
114    * Removes the indicator effect, all derived effects must implement this function
115    *
116    * @param[in] scrollable the scrollable object to remove this effect from
117    */
118   virtual void Remove(Scrollable& scrollable) = 0;
119
120   /**
121    * Resets this overshoot effect
122    */
123   virtual void Reset() = 0;
124
125   /**
126    * Updates the constraints used for the overshoot effect
127    *
128    * @param[in] scrollable the container for the overshoot effect
129    */
130   virtual void UpdateConstraints(Actor& scrollable) {}
131
132   /**
133    * Sets up property notifications for overshoot values
134    *
135    * @param[in] scrollable the container for the overshoot effect
136    */
137   virtual void SetPropertyNotifications(Actor& scrollable) {}
138
139 private:
140   bool mVertical;                      ///< whether this is a vertical/horizontal effect
141 };
142
143 /**
144  * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
145  * attempts to scroll past it
146  */
147 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
148 {
149 public:
150   /**
151    * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
152    */
153   ScrollOvershootEffectRipple(bool vertical);
154
155   /**
156    * @copydoc ScrollOvershootEffect::Apply
157    */
158   virtual void Apply(Scrollable& scrollable);
159
160   /**
161    * @copydoc ScrollOvershootEffect::Remove
162    */
163   virtual void Remove(Scrollable& scrollable);
164
165   /**
166    * @copydoc ScrollOvershootEffect::Reset
167    */
168   virtual void Reset();
169
170   /**
171    * @copydoc ScrollOvershootEffect::UpdateConstraints(Actor& scrollable)
172    */
173   virtual void UpdateConstraints(Actor& scrollable);
174
175   /**
176    * @copydoc ScrollOvershootEffect::SetPropertyNotification
177    */
178   virtual void SetPropertyNotifications(Actor& scrollable);
179
180   /**
181    * Constrains the size of the gradient image
182    * @param[in] current current position of the image actor
183    * @param[in] parentSizeProperty size of the scrollable area so we can position image on the edge of it
184    * @param[in] overshootProperty current overshoot amount for this indicator's axis
185    * @return new position of the gradient image actor
186    */
187   Vector3 PositionConstraint(const Vector3& current, const PropertyInput& parentSizeProperty, const PropertyInput& overshootProperty);
188
189   /**
190    * Informs overshoot effect to update image position and to animate effect overshoot value for a
191    * positive overshoot value from scrollview
192    *
193    * @param[in] source the property notification that triggered this callback
194    */
195   void OnPositiveOvershootNotification(PropertyNotification& source);
196
197   /**
198    * Informs overshoot effect to update image position and to animate effect overshoot value for a
199    * negative overshoot value from scrollview
200    *
201    * @param[in] source the property notification that triggered this callback
202    */
203   void OnNegativeOvershootNotification(PropertyNotification& source);
204
205   /**
206    * Function to animate effect overshoot value either to -1.0f/1.0f or 0.0f
207    *
208    * @param[in] overshootAmount the amount to animate overshoot to [-1.0f,0.0f,1.0f]
209    */
210   void AnimateScrollOvershoot(float overshootAmount);
211
212   /**
213    * Connects to the animation finished signal of our overshoot animation
214    *
215    * @param[in] animation the animation instance that has finished
216    */
217   void OnOvershootAnimFinished(Animation& animation);
218
219   /**
220    * Creates a new ScrollOvershootEffectGradient objects and returns a pointer to it
221    * @param[in] vertical whether to create a vertical(true) or horizontal effect
222    * @return a pointer to the new effect
223    */
224   static ScrollOvershootEffectRipplePtr New( bool vertical );
225
226 private:
227
228   float mMaxOvershootImageSize;            ///< maximum size of the image when overshoot value is 1.0f
229   ImageActor mOvershootImage;              ///< the overshoot image...
230   Animation mScrollOvershootAnimation;     ///< animation
231   bool      mAnimatingOvershootOn;         ///< whether we are currently animating overshoot to 1.0f/-1.0f (on) or to 0.0f (off)
232   bool      mAnimateOvershootOff;          ///< whether we are currently animating overshoot to 1.0f/-1.0f (on) or to 0.0f (off)
233   int       mCanScrollPropertyIndex;       ///< property index to a property that informs indicator if it is needed
234   BouncingEffect mRippleEffect;                 // the ripple vertex/fragment shader effect
235   PropertyNotification mOvershootPositiveNotification; // stores the property notification used for positive overshoot values
236   PropertyNotification mOvershootNegativeNotification; // stores the property notification used for negative overshoot values
237   ActiveConstraint    mSizeConstraint;                 // active constraint handle used to store the image width constraint
238   ActiveConstraint    mPositionConstraint;             // active constraint handle used to store the image position constraint
239 };
240
241 } // namespace Internal
242
243 } // namespace Toolkit
244
245 } // namespace Dali
246
247 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__