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