840bdd580681f1e63be271ee3e91160d3a85bf70
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-slide-effect-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_SLIDE_EFFECT_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_SLIDE_EFFECT_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 // INTERNAL INCLUDES
21 #include <dali/public-api/animation/animation.h>
22 #include <dali/public-api/animation/alpha-functions.h>
23 #include <dali/public-api/animation/time-period.h>
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
26 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-effect.h>
27 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-slide-effect.h>
28
29 namespace Dali
30 {
31
32 class Animation;
33
34 namespace Toolkit
35 {
36
37 class ScrollView;
38
39 namespace Internal
40 {
41
42 class ScrollViewEffect;
43
44 class ScrollSlideInfo;
45
46 typedef IntrusivePtr<ScrollSlideInfo> ScrollSlideInfoPtr;
47
48 /**
49  * @copydoc Toolkit::ScrollViewSlideEffect
50  */
51 class ScrollViewSlideEffect : public ScrollViewEffect
52 {
53 public:
54
55   /**
56    * Constructor
57    */
58   ScrollViewSlideEffect();
59
60 public:
61
62   /**
63    * @copydoc ScrollViewEffect::GetSlideDirection
64    */
65   bool GetSlideDirection() const;
66
67   /**
68    * @copydoc ScrollViewEffect::SetSlideDirection
69    */
70   void SetSlideDirection(bool vertical);
71
72   /**
73    * @copydoc ScrollViewEffect::GetDelayReferenceOffset
74    */
75   const Vector3& GetDelayReferenceOffset() const;
76
77   /**
78    * @copydoc ScrollViewEffect::SetDelayReferenceOffset
79    */
80   void SetDelayReferenceOffset(const Vector3& offset);
81
82   /**
83    * @copydoc ScrollViewEffect::GetMaxDelayDuration
84    */
85   float GetMaxDelayDuration() const;
86
87   /**
88    * @copydoc ScrollViewEffect::SetMaxDelayDuration
89    */
90   void SetMaxDelayDuration(float duration);
91
92   /**
93    * @copydoc ScrollViewEffect::ApplyToActor
94    */
95   void ApplyToActor( Actor child,
96                      float delayMin,
97                      float delayMax );
98 public:
99
100   /**
101    * @copydoc ScrollViewEffect::OnAttach
102    */
103   virtual void OnAttach(Toolkit::ScrollView& scrollView);
104
105   /**
106    * @copydoc ScrollViewEffect::OnDetach
107    */
108   virtual void OnDetach(Toolkit::ScrollView& scrollView);
109
110 protected:
111
112   /**
113    * A reference counted object may only be deleted by calling Unreference()
114    */
115   virtual ~ScrollViewSlideEffect();
116
117 private:
118
119   /**
120    * Invoked when user touches the scroll-view
121    * We keep track of the touch as this is used to determine
122    * the reference point which is used to determine the delay
123    * factor for the Actors' movements.
124    * @param[in] actor The actor touched
125    * @param[in] event The touch Event
126    * @return Whether to consume the even or not.
127    */
128   bool OnScrollTouched(Actor actor, const TouchEvent& event);
129
130   /**
131    * Signal handler, called when the ScrollView starts to move
132    *
133    * @param[in] position The current scroll position
134    */
135   void OnScrollStart( const Vector3& position );
136
137   /**
138    * Signal handler, called when the ScrollView starts to snap
139    * @param[in] event The snap event.
140    */
141   void OnScrollSnapStarted(const Toolkit::ScrollView::SnapEvent& event);
142
143   /**
144    * Signal handler, called some time after the ScrollView has completed
145    * movement. There is a delay as when the ScrollView has completed
146    * movement, there are Actors that have a delay, and take time to arrive
147    * at their final destination.
148    *
149    * @param[in] animation The animation delegate for this delay
150    */
151   void OnAnimationSnapFinished( Animation& animation );
152
153   /**
154    * Signal handler, called when the Wobble Effect animation has completed.
155    *
156    * @param[in] animation The animation.
157    */
158   void OnAnimationFinished( Animation& animation );
159
160   /**
161    * Attaches effect to Scroll Actor (ScrollView)
162    *
163    * Applies the same wobble effect to each Scroll Actor.
164    *
165    * @param[in] actor The attached Actor
166    */
167   void AttachActor(Actor actor);
168
169   /**
170    * Detaches effect from Scroll Actor (ScrollView)
171    *
172    * @param[in] actor The attached Actor
173    */
174   void DetachActor(Actor actor);
175
176   /**
177    * Continues Animation to time reaches endTime
178    *
179    * @param[in] endTime the target time to reach.
180    */
181   void ContinueAnimation(float endTime);
182
183 private:
184
185   ScrollSlideInfoPtr mScrollSlideInfo;                  ///< Info structure to keep track of common properties amongst many constraints.
186   ActiveConstraint mInfoUpdateConstraint;               ///< Constraint applied to scroll-view to update Info structure.
187   Animation mAnimation;                                 ///< Animation Timer to drive the twist effect constraint.
188   Animation mAnimationSnap;                             ///< Animation Snap (this animates from from 1.0 to 0.0 when contents snap)
189   Property::Index mPropertyTime;                        ///< Time property used by twist effect constraint to calculate timePassed.
190   Property::Index mPropertyReference;                   ///< Reference point in scroll-contents, this point has no delay.
191                                                         ///< The further out from this point, the further the delay.
192   Property::Index mPropertyActive;                      ///< Property indicates the progress of the scrolling from 1.0f (scrolling) to 0.0f (fully snapped)
193   Vector3 mDelayReferenceOffset;                        ///< Where to offset the delay reference point when dragging.
194   float mMaxDelayDuration;                              ///< Maximum duration of effect after scroll-view completes.
195 };
196
197 } // namespace Internal
198
199 // Helpers for public-api forwarding methods
200
201 inline Internal::ScrollViewSlideEffect& GetImpl(Dali::Toolkit::ScrollViewSlideEffect& obj)
202 {
203   DALI_ASSERT_ALWAYS(obj);
204
205   Dali::RefObject& handle = obj.GetBaseObject();
206
207   return static_cast<Internal::ScrollViewSlideEffect&>(handle);
208 }
209
210 inline const Internal::ScrollViewSlideEffect& GetImpl(const Dali::Toolkit::ScrollViewSlideEffect& obj)
211 {
212   DALI_ASSERT_ALWAYS(obj);
213
214   const Dali::RefObject& handle = obj.GetBaseObject();
215
216   return static_cast<const Internal::ScrollViewSlideEffect&>(handle);
217 }
218
219 } // namespace Toolkit
220
221 } // namespace Dali
222
223 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_SLIDE_EFFECT_H__