License conversion from Flora to Apache 2.0
[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) { mMaxSwingAngle = maxSwingAngle; }
103
104   /**
105    * @copydoc Toolkit::ScrollViewEffect::SetSwingDropOff
106    */
107   void SetSwingDropOff(const Vector2& dropOff, const Vector2& distance, AlphaFunction function = NULL);
108
109 public:
110
111   /**
112    * @copydoc ScrollViewEffect::OnAttach
113    */
114   virtual void OnAttach(Toolkit::ScrollView& scrollView);
115
116   /**
117    * @copydoc ScrollViewEffect::OnDetach
118    */
119   virtual void OnDetach(Toolkit::ScrollView& scrollView);
120
121 protected:
122
123   /**
124    * A reference counted object may only be deleted by calling Unreference()
125    */
126   virtual ~ScrollViewTwistEffect();
127
128 private:
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 is moving
139    *
140    * @param[in] position The current scroll positionApply
141    */
142   void OnScrollUpdate( const Vector3& position );
143
144   /**
145    * Signal handler, called when the ScrollView has completed movement
146    *
147    * @param[in] position The current scroll position
148    */
149   void OnScrollComplete( const Vector3& position );
150
151   void OnScrollSnap( const Toolkit::ScrollView::SnapEvent& event );
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   void OnActivateAnimationFinished( Animation& animation );
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   ushort mFlags;
187   Animation mAnimation;                         ///< Animation Timer to drive the twist effect constraint.
188   Animation mActivateAnimation;
189   Property::Index mPropertyTime;                ///< Time property used by twist effect constraint to calculate timePassed.
190   bool mEnableEffect;                           ///< flag that decide whether enable or disable the twist effect.
191   bool mAdditionalEffects;                      ///< whether we want to apply extra effects
192   Property::Index mPropertyReference;           ///< Reference point in scroll-contents, this point has no delay.
193   Property::Index mPropertyActivate;                                              ///::< The further out from this point, the further the delay.
194   Property::Index mPropertyDepth;               ///< Depth property used by twist effect constraint to shrink Actors.
195   float mMinimumDistanceForShrink;              ///< Scrolling animation must last for longer than this amount to do shrink effect.s
196   Vector2 mMaxSwingAngle;                       ///< Maximum swing angle to be applied to x and y axes
197   Vector2 mDropOff;                             ///< Amount to drop off the angle on each axis of drop off distance
198   Vector2 mDropOffDistance;                     ///< Distance to apply the full drop off over
199   AlphaFunction mDropOffFunction;                      ///< Function to adjust how drop off is aplied over the distance, NULL for linear
200   float mScaleFactor;                           ///< Amount to scale by during translation
201   float mDelayMin;
202   float mDelayMax;
203 };
204
205 } // namespace Internal
206
207 // Helpers for public-api forwarding methods
208
209 inline Internal::ScrollViewTwistEffect& GetImpl(Dali::Toolkit::ScrollViewTwistEffect& obj)
210 {
211   DALI_ASSERT_ALWAYS(obj);
212
213   Dali::RefObject& handle = obj.GetBaseObject();
214
215   return static_cast<Internal::ScrollViewTwistEffect&>(handle);
216 }
217
218 inline const Internal::ScrollViewTwistEffect& GetImpl(const Dali::Toolkit::ScrollViewTwistEffect& obj)
219 {
220   DALI_ASSERT_ALWAYS(obj);
221
222   const Dali::RefObject& handle = obj.GetBaseObject();
223
224   return static_cast<const Internal::ScrollViewTwistEffect&>(handle);
225 }
226
227 } // namespace Toolkit
228
229 } // namespace Dali
230
231 #endif // __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_TWIST_EFFECT_H__