Synchronous Set/Get behaviour for default properties
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / constrainer.h
1 #ifndef __DALI_INTERNAL_CONSTRAINER_H__
2 #define __DALI_INTERNAL_CONSTRAINER_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/internal/event/common/object-impl.h>
23 #include <dali/public-api/common/dali-vector.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 typedef Dali::Vector<Object*>         ObjectContainer;
32 typedef ObjectContainer::Iterator     ObjectIter;
33
34 /**
35  * An abstract base class for constrainers.
36  * Constrainer base class is responsible or observing constrained objects and remove all the constraints created
37  * when it is destroyed
38  */
39 class Constrainer : public Object, public Object::Observer
40 {
41 public:
42
43   /**
44    * Constructor.
45    */
46   Constrainer();
47
48   /**
49    * Virtual destructor.
50    */
51   virtual ~Constrainer();
52
53 public: // Object methods
54
55   /**
56    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
57    */
58   virtual unsigned int GetDefaultPropertyCount() const{return 0;}
59
60   /**
61    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
62    */
63   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const{}
64
65   /**
66    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
67    */
68   virtual const char* GetDefaultPropertyName( Property::Index index ) const{return 0;}
69
70   /**
71    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
72    */
73   virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const{return  Property::INVALID_INDEX;}
74
75   /**
76    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
77    */
78   virtual bool IsDefaultPropertyWritable( Property::Index index ) const{return false;}
79
80   /**
81    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
82    */
83   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const{return false;}
84
85   /**
86    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
87    */
88   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const{return false;}
89
90   /**
91    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
92    */
93   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const{return Property::NONE;}
94
95   /**
96    * @copydoc Dali::Internal::Object::SetDefaultProperty()
97    */
98   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ){}
99
100   /**
101    * @copydoc Dali::Internal::Object::GetDefaultProperty()
102    */
103   virtual Property::Value GetDefaultProperty( Property::Index index ) const{return Property::Value();}
104
105   /**
106    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
107    */
108   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const{return Property::Value();}
109
110   /**
111    * @copydoc Dali::Internal::Object::GetSceneObject()
112    */
113   virtual const SceneGraph::PropertyOwner* GetSceneObject() const{return 0;}
114
115   /**
116    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
117    */
118   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const{return 0;}
119
120   /**
121    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
122    */
123   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const{return 0;}
124
125 public: // Object::Observer methods
126
127   /**
128    * @copydoc Object::Observer::SceneObjectAdded()
129    */
130   virtual void SceneObjectAdded( Object& object ){}
131
132   /**
133    * @copydoc Object::Observer::SceneObjectRemoved()
134    */
135   virtual void SceneObjectRemoved( Object& object ){}
136
137   /**
138    * @copydoc Object::Observer::ObjectDestroyed()
139    */
140   virtual void ObjectDestroyed( Object& object );
141
142 public:
143
144   /**
145    * @brief Applies the constraint to the target property
146
147    * @param[in] target Property to be constrained
148    * @param[in] source Property used as parameter for the path
149    * @param[in] range The range of values in the source property which will be mapped to [0,1]
150    * @param[in] wrap Wrapping domain. Source property will be wrapped in the domain [wrap.x,wrap.y] before mapping to [0,1]
151    */
152   virtual void Apply( Property target, Property source, const Vector2& range, const Vector2& wrap) = 0;
153
154   /**
155    * @brief Removes the constraint in the target object
156    *
157    * @param[in] target A handle to an object constrained by the Constrainer
158    */
159   void Remove( Dali::Handle& target );
160
161 protected:
162
163   /**
164    * @brief Adds an object to the list of observed objects
165    *
166    * @param[in] handle A handle to the object to be observed
167    */
168   void Observe( Dali::Handle& handle );
169
170 private:
171
172   ObjectContainer   mObservedObjects;   ///< The list of object which have been constrained by the Constrainer
173 };
174
175 } // namespace Internal
176
177 } // namespace Dali
178
179 #endif // __DALI_INTERNAL_CONSTRAINER_H__