5aca6a0cc13199e9c60a7e1ce085b44270c66afb
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-twist-effect-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_TWIST_EFFECT_H__
2 #define __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_TWIST_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-twist-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 /**
46  * @copydoc Toolkit::ScrollViewTwistEffect
47  */
48 class ScrollViewTwistEffect : public ScrollViewEffect
49 {
50
51 public:
52   enum Flag
53   {
54     FlagTwist = 0x01,
55     FlagScale = 0x02,
56     FlagDropOff = 0x04,
57     FlagDefaultDropOff = 0x08,
58     DefaultFlags = FlagTwist | FlagDropOff | FlagDefaultDropOff
59   };
60
61   /**
62    * Constructor
63    */
64   ScrollViewTwistEffect();
65
66 public:
67
68   /**
69    * @copydoc ScrollViewEffect::GetMinimumDistanceForShrink
70    */
71   float GetMinimumDistanceForShrink() const;
72
73   /**
74    * @copydoc ScrollViewEffect::SetMinimumDistanceForShrink
75    */
76   void SetMinimumDistanceForShrink(float distance);
77
78   /**
79    * enable or disable this effect
80    * @param[in] enable when enableFlag is true, disable when enableFlag is false.
81    */
82   void EnableEffect(bool enableFlag);
83
84   /**
85    * @copydoc ScrollViewEffect::ApplyToActor
86    */
87   void ApplyToActor( Actor child,
88                      bool additionalEffects,
89                      const Vector2& angleSwing,
90                      float scaleAmount,
91                      float delayMin,
92                      float delayMax );
93
94   /**
95    * @copydoc Toolkit::ScrollViewEffect::Apply
96    */
97   void Apply(Actor child);
98
99   /**
100    * @copydoc Toolkit::ScrollViewEffect::SetMaxSwingAngle
101    */
102   void SetMaxSwingAngle(const Vector2& maxSwingAngle);
103
104   /**
105    * @copydoc Toolkit::ScrollViewEffect::GetMaxSwingAngle
106    */
107   Vector2 GetMaxSwingAngle() const;
108
109   /**
110    * @copydoc Toolkit::ScrollViewEffect::SetSwingDropOff
111    */
112   void SetSwingDropOff(const Vector2& dropOff, const Vector2& distance, AlphaFunction function = NULL);
113
114   /**
115    * @copydoc Toolkit::ScrollViewEffect::GetSwingDropOff
116    */
117   void GetSwingDropOff( Vector2& dropOff, Vector2& distance, AlphaFunction& function ) const;
118
119 public:
120
121   /**
122    * @copydoc ScrollViewEffect::OnAttach
123    */
124   virtual void OnAttach(Toolkit::ScrollView& scrollView);
125
126   /**
127    * @copydoc ScrollViewEffect::OnDetach
128    */
129   virtual void OnDetach(Toolkit::ScrollView& scrollView);
130
131 protected:
132
133   /**
134    * A reference counted object may only be deleted by calling Unreference()
135    */
136   virtual ~ScrollViewTwistEffect();
137
138 private:
139
140   /**
141    * Signal handler, called when the ScrollView starts to move
142    *
143    * @param[in] position The current scroll position
144    */
145   void OnScrollStart( const Vector3& position );
146
147   /**
148    * Signal handler, called when the ScrollView is moving
149    *
150    * @param[in] position The current scroll positionApply
151    */
152   void OnScrollUpdate( const Vector3& position );
153
154   /**
155    * Signal handler, called when the ScrollView has completed movement
156    *
157    * @param[in] position The current scroll position
158    */
159   void OnScrollComplete( const Vector3& position );
160
161   void OnScrollSnap( const Toolkit::ScrollView::SnapEvent& event );
162
163   /**
164    * Signal handler, called when the Wobble Effect animation has completed.
165    *
166    * @param[in] animation The animation.
167    */
168   void OnAnimationFinished( Animation& animation );
169
170   void OnActivateAnimationFinished( Animation& animation );
171   /**
172    * Attaches effect to Scroll Actor (ScrollView)
173    *
174    * Applies the same wobble effect to each Scroll Actor.
175    *
176    * @param[in] actor The attached Actor
177    */
178   void AttachActor(Actor actor);
179
180   /**
181    * Detaches effect from Scroll Actor (ScrollView)
182    *
183    * @param[in] actor The attached Actor
184    */
185   void DetachActor(Actor actor);
186
187   /**
188    * Continues Animation to time reaches endTime
189    *
190    * @param[in] endTime the target time to reach.
191    */
192   void ContinueAnimation(float endTime);
193
194 private:
195
196   ushort mFlags;
197   Animation mAnimation;                         ///< Animation Timer to drive the twist effect constraint.
198   float     mActivationTime;                    ///< Time taken for overshoot to reach zero, which is the time we need to allow effect to be active
199   Animation mActivateAnimation;
200   Property::Index mPropertyTime;                ///< Time property used by twist effect constraint to calculate timePassed.
201   bool mEnableEffect;                           ///< flag that decide whether enable or disable the twist effect.
202   bool mAdditionalEffects;                      ///< whether we want to apply extra effects
203   Property::Index mPropertyReference;           ///< Reference point in scroll-contents, this point has no delay.
204   Property::Index mPropertyActivate;                                              ///::< The further out from this point, the further the delay.
205   Property::Index mPropertyDepth;               ///< Depth property used by twist effect constraint to shrink Actors.
206   float mMinimumDistanceForShrink;              ///< Scrolling animation must last for longer than this amount to do shrink effect.s
207   Vector2 mMaxSwingAngle;                       ///< Maximum swing angle to be applied to x and y axes
208   Vector2 mDropOff;                             ///< Amount to drop off the angle on each axis of drop off distance
209   Vector2 mDropOffDistance;                     ///< Distance to apply the full drop off over
210   AlphaFunction mDropOffFunction;                      ///< Function to adjust how drop off is aplied over the distance, NULL for linear
211   float mScaleFactor;                           ///< Amount to scale by during translation
212   float mDelayMin;
213   float mDelayMax;
214 };
215
216 } // namespace Internal
217
218 // Helpers for public-api forwarding methods
219
220 inline Internal::ScrollViewTwistEffect& GetImpl(Dali::Toolkit::ScrollViewTwistEffect& obj)
221 {
222   DALI_ASSERT_ALWAYS(obj);
223
224   Dali::RefObject& handle = obj.GetBaseObject();
225
226   return static_cast<Internal::ScrollViewTwistEffect&>(handle);
227 }
228
229 inline const Internal::ScrollViewTwistEffect& GetImpl(const Dali::Toolkit::ScrollViewTwistEffect& obj)
230 {
231   DALI_ASSERT_ALWAYS(obj);
232
233   const Dali::RefObject& handle = obj.GetBaseObject();
234
235   return static_cast<const Internal::ScrollViewTwistEffect&>(handle);
236 }
237
238 } // namespace Toolkit
239
240 } // namespace Dali
241
242 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_TWIST_EFFECT_H__