Revert "[Tizen] Ensure cached values of properties animated using AnimateTo are updated"
[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) 2017 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/object-impl.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 Object
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::Object::Observer::SceneObjectAdded()
62    */
63   virtual void SceneObjectAdded(Object& object){}
64
65   /**
66    * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
67    */
68   virtual void SceneObjectRemoved(Object& object){}
69
70   /**
71    * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
72    */
73   virtual void ObjectDestroyed(Object& object){}
74
75   /**
76    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
77    */
78   virtual unsigned int GetDefaultPropertyCount() const;
79
80   /**
81    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
82    */
83   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
84
85   /**
86    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
87    */
88   virtual const char* GetDefaultPropertyName(Property::Index index) const;
89
90   /**
91    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
92    */
93   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
94
95   /**
96    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
97    */
98   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
99
100   /**
101    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
102    */
103   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
104
105   /**
106    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
107    */
108   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
109
110   /**
111    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
112    */
113   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
114
115   /**
116    * @copydoc Dali::Internal::Object::SetDefaultProperty()
117    */
118   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
119
120    /**
121    * @copydoc Dali::Internal::Object::GetDefaultProperty()
122    */
123   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
124
125   /**
126    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
127    */
128   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
129
130   /**
131    * @copydoc Dali::Internal::Object::GetSceneObject()
132    */
133   virtual const SceneGraph::PropertyOwner* GetSceneObject() const{ return NULL; }
134
135   /**
136    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
137    */
138   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const{ return NULL; }
139
140   /**
141    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
142    */
143   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const{ return NULL; }
144
145 public:
146
147   /**
148    * Returns a clone to the given path
149    */
150   static Path* Clone(const Path& path);
151
152   /**
153    * @copydoc Dali::Path::AddPoint
154    */
155   void AddPoint(const Vector3& point );
156
157   /**
158    * @copydoc Dali::Path::AddControlPoint
159    */
160   void AddControlPoint(const Vector3& point );
161
162   /**
163    * @copydoc Dali::Path::GenerateControlPoints
164    */
165   void GenerateControlPoints( float curvature );
166
167   /**
168    * @copydoc Dali::Path::Sample
169    */
170   void Sample( float t, Vector3& position, Vector3& tangent ) const;
171
172   /**
173    * @brief Sample path at a given progress. Calculates position and tangent at that point of the curve
174    *
175    * @param[in]  progress  A floating point value between 0.0 and 1.0.
176    * @param[out] position The interpolated position at that progress.
177    * @param[out] tangent The interpolated tangent at that progress.
178    * @return true if Sample could be calculated
179    */
180   bool SampleAt( float t, Vector3& position, Vector3& tangent ) const;
181
182   /**
183    * Sample position at point t.
184    *
185    * @param[in] progress  A floating point value between 0.0 and 1.0.
186    * @param[out] position The interpolated position at that progress.
187    * @return true if sample could be calculated
188    */
189   bool SamplePosition( float t, Vector3& position ) const;
190
191   /**
192    * @brief Sample tangent at point t.
193    *
194    * @param[in] progress  A floating point value between 0.0 and 1.0.
195    * @param[out] tangent The interpolated tangent at that progress.
196    * @return true if sample could be calculated
197    */
198   bool SampleTangent( float t, Vector3& tangent ) const;
199
200   /**
201    * @copydoc Dali::Path::GetPoint
202    */
203   Vector3& GetPoint( size_t index );
204
205   /**
206    * @copydoc Dali::Path::GetControlPoint
207    */
208   Vector3& GetControlPoint( size_t index );
209
210   /**
211    * @copydoc Dali::Path::GetPointCount
212    */
213   size_t GetPointCount() const;
214
215   /**
216    * Clears the points of the path
217    */
218   void ClearPoints();
219
220   /**
221    * Clears the control points of the path
222    */
223   void ClearControlPoints();
224
225   /**
226    * @brief Get mPoint property
227    *
228    * @return A const reference to mPoint vector
229    */
230   const Dali::Vector<Vector3>& GetPoints() const{ return mPoint; }
231
232   /*
233    * @brief Set mPoint
234    *
235    * @param[in] p New value for mPoint property
236    */
237   void SetPoints( const Dali::Vector<Vector3>& p ){ mPoint = p; }
238
239   /**
240    * @brief Get mCotrolPoint property
241    *
242    * @return A const reference to mControlPoint vector
243    */
244   const Dali::Vector<Vector3>& GetControlPoints() const{ return mControlPoint; }
245
246   /*
247    * @brief Set mControlPoint property
248    *
249    * @param[in] p New value for mControlPoint property
250    */
251   void SetControlPoints( const Dali::Vector<Vector3>& p ){ mControlPoint = p; }
252
253 private:
254
255   /**
256    * Undefined
257    */
258   Path(const Path& p);
259
260   /**
261    * Undefined
262    */
263   Path& operator=(const Path& rhs);
264
265   /**
266    * Helper function to calculate the segment and local progress in that segment
267    * given a progress
268    *
269    * @param[in] t Progress
270    * @param[out] segment Segment for t
271    * @param[out] tLocal Local progress in the segment
272    *
273    */
274   void FindSegmentAndProgress( float t, unsigned int& segment, float& tLocal ) const;
275
276   /**
277    * Helper function to calculate to number of segments in the path
278    */
279   unsigned int GetNumberOfSegments() const;
280
281   Dali::Vector<Vector3> mPoint;            ///< Interpolation points
282   Dali::Vector<Vector3> mControlPoint;     ///< Control points
283 };
284
285 } // Internal
286
287 // Get impl of handle
288 inline Internal::Path& GetImplementation(Dali::Path& path)
289 {
290   DALI_ASSERT_ALWAYS( path && "Path handle is empty" );
291   Dali::RefObject& object = path.GetBaseObject();
292   return static_cast<Internal::Path&>(object);
293 }
294
295 inline const Internal::Path& GetImplementation(const Dali::Path& path)
296 {
297   DALI_ASSERT_ALWAYS( path && "Path handle is empty" );
298   const Dali::RefObject& object = path.GetBaseObject();
299   return static_cast<const Internal::Path&>(object);
300 }
301
302
303 } // Dali
304
305 #endif //__DALI_INTERNAL_KEY_FRAMES_H__