Added animation and constraint support for UNSIGNED_INTEGER property type
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / path-constraint-impl.h
1 #ifndef __DALI_INTERNAL_PATH_CONSTRAINT_H__
2 #define __DALI_INTERNAL_PATH_CONSTRAINT_H__
3
4 /*
5  * Copyright (c) 2015 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/internal/event/animation/path-impl.h>
23 #include <dali/internal/event/common/object-impl.h>
24 #include <dali/public-api/animation/path-constraint.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 typedef IntrusivePtr<PathConstraint>  PathConstraintPtr;
33 typedef Dali::Vector<Object*>         ObjectContainer;
34 typedef ObjectContainer::Iterator     ObjectIter;
35
36 /**
37  * @brief Constraint functor to constraint properties to paths.
38  *
39  * Vector3 properties will be constrained to the position of the path and
40  * Rotation properties will be constrained to follow the tangent of the path
41  * given a forward vector in object's local space.
42  */
43 struct PathConstraintFunctor
44 {
45   /**
46    * @brief Constructor.
47    *
48    * @param[in] path The path used in the constraint
49    * @param[in] range The range of values in the input property which will be mapped to 0..1
50    */
51
52   PathConstraintFunctor(PathPtr path, const Vector2& range ):mPath(path),mRange(range){}
53
54   /**
55    * @brief Constructor.
56    *
57    * @param[in] path The path used in the constraint
58    * @param[in] range The range of values in the input property which will be mapped to 0..1
59    * @param[in] forward Vector in object space which will be aligned with the tangent of the path
60    */
61   PathConstraintFunctor(PathPtr path, const Vector2& range,const Vector3& forward ):mPath(path),mForward(forward),mRange(range){}
62
63   /**
64    * @brief Functor operator for Vector3 properties
65    *
66    * @param[in,out] position Current value of the property
67    * @param[in]     inputs Contains the input property used as the parameter for the path
68    *
69    * @return The position of the path at the given parameter.
70    */
71   void operator()( Vector3& position,
72                    const PropertyInputContainer& inputs)
73   {
74     float t = ( inputs[0]->GetFloat() - mRange.x ) / ( mRange.y-mRange.x );
75     Vector3 tangent;
76     mPath->Sample( t, position, tangent );
77   }
78
79   /**
80    * @brief Functor operator for Quaternion properties
81    *
82    * @param[in,out] current Current value of the property
83    * @param[in]     inputs Contains the input property used as the parameter for the path
84    *
85    * @return The rotation which will align the forward vector and the tangent of the path at the given parameter.
86    */
87   void operator()( Quaternion& current,
88                    const PropertyInputContainer& inputs)
89   {
90     float t = ( inputs[0]->GetFloat() - mRange.x ) / (mRange.y-mRange.x);
91     Vector3 position, tangent;
92     mPath->Sample( t, position, tangent );
93     current = Quaternion( mForward, tangent );
94   }
95
96   PathPtr     mPath;      ///< The path used
97   Vector3     mForward;   ///< Vector in object space which will be aligned with the tangent of the path
98   Vector2     mRange;     ///< The range of values in the input property which will be mapped to 0..1
99 };
100
101 /**
102  * @brief A PathConstraint used to constraint properties to a path
103  */
104 class PathConstraint : public Object, public Object::Observer
105 {
106 public:
107
108   /**
109    * Create a new PathConstraint
110    * @param[in] path The path used in the constraint
111    * @param[in] range The range of values in the input property which will be mapped to 0..1
112    * @return A smart-pointer to the newly allocated PathConstraint.
113    */
114   static PathConstraint* New( Path& path, const Vector2& range );
115
116
117
118 protected:
119   /**
120    * virtual destructor
121    */
122   virtual ~PathConstraint();
123
124 private:
125   /**
126    * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
127    */
128   virtual void SceneObjectAdded(Object& object){}
129
130   /**
131    * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
132    */
133   virtual void SceneObjectRemoved(Object& object){}
134
135   /**
136    * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
137    */
138   virtual void ObjectDestroyed(Object& object);
139
140   /**
141    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
142    */
143   virtual unsigned int GetDefaultPropertyCount() const;
144
145   /**
146    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
147    */
148   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
149
150   /**
151    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
152    */
153   virtual const char* GetDefaultPropertyName(Property::Index index) const;
154
155   /**
156    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
157    */
158   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
159
160   /**
161    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
162    */
163   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
164
165   /**
166    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
167    */
168   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
169
170   /**
171    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
172    */
173   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
174
175   /**
176    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
177    */
178   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
179
180   /**
181    * @copydoc Dali::Internal::Object::SetDefaultProperty()
182    */
183   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
184
185    /**
186    * @copydoc Dali::Internal::Object::GetDefaultProperty()
187    */
188   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
189
190   /**
191    * @copydoc Dali::Internal::Object::GetSceneObject()
192    */
193   virtual const SceneGraph::PropertyOwner* GetSceneObject() const{ return NULL; }
194
195   /**
196    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
197    */
198   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const{ return NULL; }
199
200   /**
201    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
202    */
203   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const{ return NULL; }
204
205 public:
206
207   /**
208    * @copydoc Dali::PathConstraint::Apply
209    */
210   void Apply( Property source, Property target, const Vector3& forward );
211
212   /**
213    * @copydoc Dali::PathConstraint::Remove
214    */
215   void Remove( Dali::Handle& target );
216
217
218 private:
219   /**
220    * Constructor
221    * @param[in] path The path used in the constraint
222    * @param[in] range The range of values in the input property which will be mapped to 0..1
223    */
224   PathConstraint( Path& path, const Vector2& range );
225
226   // Undefined
227   PathConstraint();
228
229   // Undefined
230   PathConstraint(const PathConstraint&);
231
232   // Undefined
233   PathConstraint& operator=(const PathConstraint& rhs);
234
235   PathPtr           mPath;              ///< The path used to constrain objects
236   ObjectContainer   mObservedObjects;   ///< The list of object which have been constrained by the PathConstraint
237   Vector2           mRange;             ///< The range of values in the input property which will be mapped to 0..1
238 };
239
240 } // Internal
241
242 // Get impl of handle
243 inline Internal::PathConstraint& GetImplementation(Dali::PathConstraint& pathConstraint)
244 {
245   DALI_ASSERT_ALWAYS( pathConstraint && "PathConstraint handle is empty" );
246   Dali::RefObject& object = pathConstraint.GetBaseObject();
247   return static_cast<Internal::PathConstraint&>(object);
248 }
249
250 inline const Internal::PathConstraint& GetImplementation(const Dali::PathConstraint& pathConstraint)
251 {
252   DALI_ASSERT_ALWAYS( pathConstraint && "PathConstraint handle is empty" );
253   const Dali::RefObject& object = pathConstraint.GetBaseObject();
254   return static_cast<const Internal::PathConstraint&>(object);
255 }
256
257 } // Dali
258
259 #endif //__DALI_INTERNAL_KEY_FRAMES_H__