Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / 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) 2021 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/common/intrusive-ptr.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/object/property-notification.h>
27 #include <dali/public-api/object/ref-object.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35 class Scrollable;
36 class ScrollOvershootEffect;
37 class ScrollOvershootEffectGradient;
38 class ScrollOvershootEffectRipple;
39 typedef IntrusivePtr<ScrollOvershootEffect>         ScrollOvershootEffectPtr;
40 typedef IntrusivePtr<ScrollOvershootEffectGradient> ScrollOvershootEffectGradientPtr;
41 typedef IntrusivePtr<ScrollOvershootEffectRipple>   ScrollOvershootEffectRipplePtr;
42
43 struct ScrollOvershootIndicator : public Dali::RefObject
44 {
45 public:
46   /**
47    * ScrollOvershootIndicator constructor.
48    */
49   ScrollOvershootIndicator();
50
51   /**
52    * Virtual destructor
53    */
54   virtual ~ScrollOvershootIndicator();
55
56   /**
57    * Attaches the scroll indicator to a scrollable actor
58    *
59    * &param[in] scrollable The scrollable actor to attach to
60    */
61   void AttachToScrollable(Scrollable& scrollable);
62
63   /**
64    * Detaches the scroll indicator from a scrollable actor
65    *
66    * &param[in] scrollable The scrollable actor to detach from
67    */
68   void DetachFromScrollable(Scrollable& scrollable);
69
70   /**
71    * Resets the indicator
72    */
73   void Reset();
74
75   /**
76    * Create an initialized ScrollOvershootIndicator
77    *
78    * @return A pointer to the created ScrollOvershootIndicator.
79    */
80   static ScrollOvershootIndicator* New();
81
82   /**
83    * Set the color of the overshoot effect.
84    * @parm[in] color The color of the overshoot effect
85    */
86   void SetOvershootEffectColor(const Vector4& color);
87
88 private:
89   ScrollOvershootEffectPtr mEffectX; ///< effect used for x-axis/horizontal display
90   ScrollOvershootEffectPtr mEffectY; ///< effect used for y-axis/vertical display
91 };
92
93 /**
94  * ScrollOvershootEffect is a derivable class, designed to allow the application programmer to create their own
95  * overshoot effect and apply it with minimal implementation required
96  */
97 struct ScrollOvershootEffect : public Dali::RefObject
98 {
99 public:
100   /**
101    * Create a new overshoot effect, passing in whether it is vertical or horizontal
102    *
103    * @param[in] vertical whether this effect is a vertical or horizontal one
104    */
105   ScrollOvershootEffect(bool vertical);
106
107   /**
108    * Virtual destructor
109    */
110   virtual ~ScrollOvershootEffect()
111   {
112   }
113
114   /**
115    * Returns if this is a vertical or horizontal overhoot effect
116    *
117    * @return true or false
118    */
119   bool IsVertical() const;
120
121   /**
122    * Applies the indicator effect, all derived effects must implement this function
123    *
124    * @param[in] scrollable the scrollable object to apply this effect to
125    */
126   virtual void Apply() = 0;
127
128   /**
129    * Removes the indicator effect, all derived effects must implement this function
130    *
131    * @param[in] scrollable the scrollable object to remove this effect from
132    */
133   virtual void Remove(Scrollable& scrollable) = 0;
134
135   /**
136    * Resets this overshoot effect
137    */
138   virtual void Reset() = 0;
139
140   /**
141    * Sets up property notifications for overshoot values
142    */
143   virtual void UpdatePropertyNotifications()
144   {
145   }
146
147   /**
148    * @copydoc ScrollOvershootIndicator::SetOvershootEffectColor()
149    */
150   virtual void SetOvershootEffectColor(const Vector4& color) = 0;
151
152   /**
153    * Sets shader overshoot value, either immediately of by animating over time
154    *
155    * @param[in] amount The amount to set overshoot to [-1.0f,1.0f]
156    * @param[in] animate Whether to animate or set immediately
157    */
158   virtual void SetOvershoot(float amount, bool animate = true) = 0;
159
160 private:
161   bool mVertical; ///< whether this is a vertical/horizontal effect
162 };
163
164 /**
165  * ScrollOvershootEffectRipple creates an animated bounce effect at the end of the scrollable area if the user
166  * attempts to scroll past it
167  */
168 struct ScrollOvershootEffectRipple : public ScrollOvershootEffect, public ConnectionTracker
169 {
170   enum AnimationState
171   {
172     AnimatingIn  = 0x01, ///< animating overshoot to 0
173     AnimatingOut = 0x02, ///< animating overshoot to negative (overshoot image displays in +ve area of screen)
174     AnimateBack  = 0x04, ///< indicates that we need to animate overshoot back to zero immediately after it has finished animating in
175   };
176
177 public:
178   /**
179    * Create a new gradient overshoot effect, passing in whether it is vertical or horizontal
180    *
181    * @param[in] vertical Whether this indicator is vertical or horizontal
182    */
183   ScrollOvershootEffectRipple(bool vertical, Scrollable& scrollable);
184
185   /**
186    * @copydoc ScrollOvershootEffect::Apply
187    */
188   void Apply() override;
189
190   /**
191    * @copydoc ScrollOvershootEffect::Remove
192    */
193   void Remove(Scrollable& scrollable) override;
194
195   /**
196    * @copydoc ScrollOvershootEffect::Reset
197    */
198   void Reset() override;
199
200   /**
201    * @copydoc ScrollOvershootEffect::UpdatePropertyNotifications
202    */
203   void UpdatePropertyNotifications();
204
205   /**
206    * @copydoc ScrollOvershootEffect::SetOvershootEffectColor()
207    */
208   void SetOvershootEffectColor(const Vector4& color);
209
210   /**
211    * Updates the vibility of the overshoot image as well as updating its size, position and rotation
212    * This function is called when animation starts and finishes
213    *
214    * @param[in] visible Whether to set the image visible or not
215    */
216   void UpdateVisibility(bool visible);
217
218   /**
219    * Informs overshoot effect to update image position and to animate effect overshoot value for a
220    * positive overshoot value from scrollview
221    *
222    * @param[in] source the property notification that triggered this callback
223    */
224   void OnOvershootNotification(PropertyNotification& source);
225
226   /**
227    * @copydoc ScrollOvershootEffect::SetOvershoot()
228    */
229   void SetOvershoot(float amount, bool animate = true);
230
231   /**
232    * Connects to the animation finished signal of our overshoot animation
233    *
234    * @param[in] animation the animation instance that has finished
235    */
236   void OnOvershootAnimFinished(Animation& animation);
237
238   /**
239    * Creates a new ScrollOvershootEffectGradient objects and returns a pointer to it
240    *
241    * @param[in] vertical whether to create a vertical(true) or horizontal effect
242    * @return a pointer to the new effect
243    */
244   static ScrollOvershootEffectRipplePtr New(bool vertical, Scrollable& scrollable);
245
246 private:
247   Actor                mOvershootOverlay;              ///< the actor which displays the overshoot effect
248   Scrollable&          mAttachedScrollView;            ///< the actor that this indicator has been attached to
249   Animation            mScrollOvershootAnimation;      ///< overshoot animation
250   PropertyNotification mOvershootIncreaseNotification; ///< notification used to inform as overshoot increases
251   PropertyNotification mOvershootDecreaseNotification; ///< notification used to inform as overshoot decreases
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                mOvershoot;                     ///< last overshoot value as detected by notifications
255   Vector2              mOvershootSize;                 ///< The size of the overshoot effect
256   unsigned short       mAnimationStateFlags;           ///< contains flags indicating the current state of the overshoot animation
257 };
258
259 } // namespace Internal
260
261 } // namespace Toolkit
262
263 } // namespace Dali
264
265 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_OVERSHOOT_INDICATOR_H