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