bc575703994a711e0cd5ee0ca85fb2121792354d
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / path-impl.h
1 #ifndef __DALI_INTERNAL_PATH_H__
2 #define __DALI_INTERNAL_PATH_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/path.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/math/matrix.h>
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/internal/event/common/proxy-object.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33 typedef IntrusivePtr<Path> PathPtr;
34
35 /**
36  * A 3D path
37  */
38 class Path : public ProxyObject
39 {
40 public:
41
42   /**
43    * Construct a new path
44    */
45   static Path* New();
46
47   /**
48    * Constructor
49    */
50   Path();
51
52
53 protected:
54   /**
55    * virtual destructor
56    */
57   virtual ~Path();
58
59 private:
60   /**
61    * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
62    */
63   virtual void SceneObjectAdded(ProxyObject& proxy){}
64
65   /**
66    * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
67    */
68   virtual void SceneObjectRemoved(ProxyObject& proxy){}
69
70   /**
71    * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed()
72    */
73   virtual void ProxyDestroyed(ProxyObject& proxy){}
74
75   /**
76    * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
77    */
78   virtual bool IsSceneObjectRemovable() const{ return false;}
79
80   /**
81    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
82    */
83   virtual unsigned int GetDefaultPropertyCount() const;
84
85   /**
86    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
87    */
88   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
89
90   /**
91    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
92    */
93   virtual const char* GetDefaultPropertyName(Property::Index index) const;
94
95   /**
96    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
97    */
98   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
99
100   /**
101    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
102    */
103   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
104
105   /**
106    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
107    */
108   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
109
110   /**
111    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
112    */
113   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
114
115   /**
116    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
117    */
118   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
119
120   /**
121    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
122    */
123   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
124
125    /**
126    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
127    */
128   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
129
130   /**
131    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
132    */
133   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ){}
134
135   /**
136    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
137    */
138   virtual const SceneGraph::PropertyOwner* GetSceneObject() const{ return NULL; }
139
140   /**
141    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
142    */
143   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const{ return NULL; }
144
145   /**
146    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
147    */
148   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const{ return NULL; }
149
150 public:
151
152   /**
153    * Returns a clone to the given path
154    */
155   static Path* Clone(const Path& path);
156
157   /**
158    * @copydoc Dali::Path::AddPoint
159    */
160   void AddPoint(const Vector3& point );
161
162   /**
163    * @copydoc Dali::Path::AddControlPoint
164    */
165   void AddControlPoint(const Vector3& point );
166
167   /**
168    * @copydoc Dali::Path::GenerateControlPoints
169    */
170   void GenerateControlPoints( float curvature );
171
172   /**
173    * @copydoc Dali::Path::Sample
174    */
175   void Sample( float t, Vector3& position, Vector3& tangent ) const;
176
177   /**
178    * Sample position at point t.
179    *
180    * @param[in] progress  A floating point value between 0.0 and 1.0.
181    * @param[out] position The interpolated position at that progress.
182    */
183   Vector3 SamplePosition( float t ) const;
184
185   /**
186    * @brief Sample tangent at point t.
187    *
188    * @param[in] progress  A floating point value between 0.0 and 1.0.
189    * @param[out] tangent The interpolated tangent at that progress.
190    */
191   Vector3 SampleTangent( float t ) const;
192
193   /**
194    * @copydoc Dali::Path::GetPoint
195    */
196   Vector3& GetPoint( size_t index );
197
198   /**
199    * @copydoc Dali::Path::GetControlPoint
200    */
201   Vector3& GetControlPoint( size_t index );
202
203   /**
204    * @copydoc Dali::Path::GetPointCount
205    */
206   size_t GetPointCount() const;
207
208   /**
209    * @brief Get mPoint property
210    *
211    * @return A const reference to mPoint vector
212    */
213   const Dali::Vector<Vector3>& GetPoints() const{ return mPoint; }
214
215   /*
216    * @brief Set mPoint
217    *
218    * @param[in] p New value for mPoint property
219    */
220   void SetPoints( const Dali::Vector<Vector3>& p ){ mPoint = p; }
221
222   /**
223    * @brief Get mCotrolPoint property
224    *
225    * @return A const reference to mControlPoint vector
226    */
227   const Dali::Vector<Vector3>& GetControlPoints() const{ return mControlPoint; }
228
229   /*
230    * @brief Set mControlPoint property
231    *
232    * @param[in] p New value for mControlPoint property
233    */
234   void SetControlPoints( const Dali::Vector<Vector3>& p ){ mControlPoint = p; }
235
236 private:
237
238   /**
239    * Undefined
240    */
241   Path(const Path& p);
242
243   /**
244    * Undefined
245    */
246   Path& operator=(const Path& rhs);
247
248   /**
249    * Helper function to calculate the segment and local progress in that segment
250    * given a progress
251    *
252    * @param[in] t Progress
253    * @param[out] segment Segment for t
254    * @param[out] tLocal Local progress in the segment
255    *
256    */
257   void FindSegmentAndProgress( float t, unsigned int& segment, float& tLocal ) const;
258
259   /**
260    * Helper function to calculate to number of segments in the path
261    */
262   unsigned int GetNumberOfSegments() const;
263
264   Dali::Vector<Vector3> mPoint;            ///< Interpolation points
265   Dali::Vector<Vector3> mControlPoint;     ///< Control points
266 };
267
268 } // Internal
269
270 // Get impl of handle
271 inline Internal::Path& GetImplementation(Dali::Path& path)
272 {
273   DALI_ASSERT_ALWAYS( path && "Path handle is empty" );
274   Dali::RefObject& object = path.GetBaseObject();
275   return static_cast<Internal::Path&>(object);
276 }
277
278 inline const Internal::Path& GetImplementation(const Dali::Path& path)
279 {
280   DALI_ASSERT_ALWAYS( path && "Path handle is empty" );
281   const Dali::RefObject& object = path.GetBaseObject();
282   return static_cast<const Internal::Path&>(object);
283 }
284
285
286 } // Dali
287
288 #endif //__DALI_INTERNAL_KEY_FRAMES_H__