Refactor SceneGraphProperty handling code in event side to make RegisterProperty...
[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) 2018 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   /**
62    * @copydoc Dali::Internal::Object::SetDefaultProperty()
63    */
64   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
65
66    /**
67    * @copydoc Dali::Internal::Object::GetDefaultProperty()
68    */
69   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
70
71 public:
72
73   /**
74    * Returns a clone to the given path
75    */
76   static Path* Clone(const Path& path);
77
78   /**
79    * @copydoc Dali::Path::AddPoint
80    */
81   void AddPoint(const Vector3& point );
82
83   /**
84    * @copydoc Dali::Path::AddControlPoint
85    */
86   void AddControlPoint(const Vector3& point );
87
88   /**
89    * @copydoc Dali::Path::GenerateControlPoints
90    */
91   void GenerateControlPoints( float curvature );
92
93   /**
94    * @copydoc Dali::Path::Sample
95    */
96   void Sample( float t, Vector3& position, Vector3& tangent ) const;
97
98   /**
99    * @brief Sample path at a given progress. Calculates position and tangent at that point of the curve
100    *
101    * @param[in]  progress  A floating point value between 0.0 and 1.0.
102    * @param[out] position The interpolated position at that progress.
103    * @param[out] tangent The interpolated tangent at that progress.
104    * @return true if Sample could be calculated
105    */
106   bool SampleAt( float t, Vector3& position, Vector3& tangent ) const;
107
108   /**
109    * Sample position at point t.
110    *
111    * @param[in] progress  A floating point value between 0.0 and 1.0.
112    * @param[out] position The interpolated position at that progress.
113    * @return true if sample could be calculated
114    */
115   bool SamplePosition( float t, Vector3& position ) const;
116
117   /**
118    * @brief Sample tangent at point t.
119    *
120    * @param[in] progress  A floating point value between 0.0 and 1.0.
121    * @param[out] tangent The interpolated tangent at that progress.
122    * @return true if sample could be calculated
123    */
124   bool SampleTangent( float t, Vector3& tangent ) const;
125
126   /**
127    * @copydoc Dali::Path::GetPoint
128    */
129   Vector3& GetPoint( uint32_t index );
130
131   /**
132    * @copydoc Dali::Path::GetControlPoint
133    */
134   Vector3& GetControlPoint( uint32_t index );
135
136   /**
137    * @copydoc Dali::Path::GetPointCount
138    */
139   uint32_t GetPointCount() const;
140
141   /**
142    * Clears the points of the path
143    */
144   void ClearPoints();
145
146   /**
147    * Clears the control points of the path
148    */
149   void ClearControlPoints();
150
151   /**
152    * @brief Get mPoint property
153    *
154    * @return A const reference to mPoint vector
155    */
156   const Dali::Vector<Vector3>& GetPoints() const{ return mPoint; }
157
158   /*
159    * @brief Set mPoint
160    *
161    * @param[in] p New value for mPoint property
162    */
163   void SetPoints( const Dali::Vector<Vector3>& p ){ mPoint = p; }
164
165   /**
166    * @brief Get mCotrolPoint property
167    *
168    * @return A const reference to mControlPoint vector
169    */
170   const Dali::Vector<Vector3>& GetControlPoints() const{ return mControlPoint; }
171
172   /*
173    * @brief Set mControlPoint property
174    *
175    * @param[in] p New value for mControlPoint property
176    */
177   void SetControlPoints( const Dali::Vector<Vector3>& p ){ mControlPoint = p; }
178
179 private:
180
181   /**
182    * Undefined
183    */
184   Path(const Path& p);
185
186   /**
187    * Undefined
188    */
189   Path& operator=(const Path& rhs);
190
191   /**
192    * Helper function to calculate the segment and local progress in that segment
193    * given a progress
194    *
195    * @param[in] t Progress
196    * @param[out] segment Segment for t
197    * @param[out] tLocal Local progress in the segment
198    *
199    */
200   void FindSegmentAndProgress( float t, uint32_t& segment, float& tLocal ) const;
201
202   /**
203    * Helper function to calculate to number of segments in the path
204    */
205   uint32_t GetNumberOfSegments() const;
206
207   Dali::Vector<Vector3> mPoint;            ///< Interpolation points
208   Dali::Vector<Vector3> mControlPoint;     ///< Control points
209 };
210
211 } // Internal
212
213 // Get impl of handle
214 inline Internal::Path& GetImplementation(Dali::Path& path)
215 {
216   DALI_ASSERT_ALWAYS( path && "Path handle is empty" );
217   Dali::RefObject& object = path.GetBaseObject();
218   return static_cast<Internal::Path&>(object);
219 }
220
221 inline const Internal::Path& GetImplementation(const Dali::Path& path)
222 {
223   DALI_ASSERT_ALWAYS( path && "Path handle is empty" );
224   const Dali::RefObject& object = path.GetBaseObject();
225   return static_cast<const Internal::Path&>(object);
226 }
227
228
229 } // Dali
230
231 #endif //__DALI_INTERNAL_KEY_FRAMES_H__