ce0b8d563f044e2ea56e0e66a69a2e13de3dd516
[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    */
47   ScrollOvershootIndicator();
48
49   /**
50    * Virtual destructor
51    */
52   virtual ~ScrollOvershootIndicator();
53
54   /**
55    * Attaches the scroll indicator to a scrollable actor
56    *
57    * &param[in] scrollable The scrollable actor to attach to
58    */
59   void AttachToScrollable(Scrollable& scrollable);
60
61   /**
62    * Detaches the scroll indicator from a scrollable actor
63    *
64    * &param[in] scrollable The scrollable actor to detach from
65    */
66   void DetachFromScrollable(Scrollable& scrollable);
67
68   /**
69    * Resets the indicator
70    */
71   void Reset();
72
73   /**
74    * Create an initialized ScrollOvershootIndicator
75    *
76    * @return A pointer to the created ScrollOvershootIndicator.
77    */
78   static ScrollOvershootIndicator* New();
79
80 private:
81   ScrollOvershootEffectPtr mEffectX;                      ///< effect used for x-axis/horizontal display
82   ScrollOvershootEffectPtr mEffectY;                      ///< effect used for y-axis/vertical display
83 };
84
85 /**
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
88  */
89 struct ScrollOvershootEffect : public Dali::RefObject
90 {
91 public:
92   /**
93    * Create a new overshoot effect, passing in whether it is vertical or horizontal
94    *
95    * @param[in] vertical whether this effect is a vertical or horizontal one
96    */
97   ScrollOvershootEffect( bool vertical );
98
99   /**
100    * Virtual destructor
101    */
102   virtual ~ScrollOvershootEffect() {}
103
104   /**
105    * Returns if this is a vertical or horizontal overhoot effect
106    *
107    * @return true or false
108    */
109   bool IsVertical() const;
110
111   /**
112    * Applies the indicator effect, all derived effects must implement this function
113    *
114    * @param[in] scrollable the scrollable object to apply this effect to
115    */
116   virtual void Apply() = 0;
117
118   /**
119    * Removes the indicator effect, all derived effects must implement this function
120    *
121    * @param[in] scrollable the scrollable object to remove this effect from
122    */
123   virtual void Remove( Scrollable& scrollable ) = 0;
124
125   /**
126    * Resets this overshoot effect
127    */
128   virtual void Reset() = 0;
129
130   /**
131    * Sets up property notifications for overshoot values
132    */
133   virtual void UpdatePropertyNotifications() {}
134
135 private:
136   bool mVertical;                      ///< whether this is a vertical/horizontal effect
137 };
138
139 /**
140  * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
141  * attempts to scroll past it
142  */
143 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
144 {
145   enum AnimationState
146   {
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
150   };
151
152 public:
153
154   /**
155    * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
156    *
157    * @param[in] vertical Whether this indicator is vertical or horizontal
158    */
159   ScrollOvershootEffectRipple( bool vertical, Scrollable& scrollable );
160
161   /**
162    * @copydoc ScrollOvershootEffect::Apply
163    */
164   virtual void Apply();
165
166   /**
167    * @copydoc ScrollOvershootEffect::Remove
168    */
169   virtual void Remove( Scrollable& scrollable );
170
171   /**
172    * @copydoc ScrollOvershootEffect::Reset
173    */
174   virtual void Reset();
175
176   /**
177    * @copydoc ScrollOvershootEffect::UpdatePropertyNotifications
178    */
179   void UpdatePropertyNotifications();
180
181   /**
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
184    *
185    * @param[in] visible Whether to set the image visible or not
186    */
187   void UpdateVisibility( bool visible );
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 OnOvershootNotification(PropertyNotification& source);
196
197   /**
198    * Sets shader overshoot value, either immediately of by animating over time
199    *
200    * @param[in] amount The amount to set overshoot to [-1.0f,1.0f]
201    * @param[in] animate Whether to animate or set immediately
202    */
203   void SetOvershoot(float amount, bool animate = true);
204
205   /**
206    * Connects to the animation finished signal of our overshoot animation
207    *
208    * @param[in] animation the animation instance that has finished
209    */
210   void OnOvershootAnimFinished(Animation& animation);
211
212   /**
213    * Creates a new ScrollOvershootEffectGradient objects and returns a pointer to it
214    *
215    * @param[in] vertical whether to create a vertical(true) or horizontal effect
216    * @return a pointer to the new effect
217    */
218   static ScrollOvershootEffectRipplePtr New( bool vertical, Scrollable& scrollable );
219
220 private:
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
234 };
235
236 } // namespace Internal
237
238 } // namespace Toolkit
239
240 } // namespace Dali
241
242 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H__