Merge branch 'devel/master' into tizen
[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) 2021 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 namespace Internal
28 {
29 typedef Dali::Vector<Object*> ObjectContainer;
30 using ObjectIter = ObjectContainer::Iterator;
31
32 /**
33  * An abstract base class for constrainers.
34  * Constrainer base class is responsible or observing constrained objects and remove all the constraints created
35  * when it is destroyed
36  */
37 class Constrainer : public Object, public Object::Observer
38 {
39 public:
40   /**
41    * Constructor.
42    */
43   Constrainer();
44
45   /**
46    * Virtual destructor.
47    */
48   ~Constrainer() override;
49
50 public: // Object::Observer methods
51   /**
52    * @copydoc Object::Observer::SceneObjectAdded()
53    */
54   void SceneObjectAdded(Object& object) override
55   {
56   }
57
58   /**
59    * @copydoc Object::Observer::SceneObjectRemoved()
60    */
61   void SceneObjectRemoved(Object& object) override
62   {
63   }
64
65   /**
66    * @copydoc Object::Observer::ObjectDestroyed()
67    */
68   void ObjectDestroyed(Object& object) override;
69
70 public:
71   /**
72    * @brief Applies the constraint to the target property
73
74    * @param[in] target Property to be constrained
75    * @param[in] source Property used as parameter for the path
76    * @param[in] range The range of values in the source property which will be mapped to [0,1]
77    * @param[in] wrap Wrapping domain. Source property will be wrapped in the domain [wrap.x,wrap.y] before mapping to [0,1]
78    */
79   virtual void Apply(Property target, Property source, const Vector2& range, const Vector2& wrap) = 0;
80
81   /**
82    * @brief Removes the constraint in the target object
83    *
84    * @param[in] target A handle to an object constrained by the Constrainer
85    */
86   void Remove(Dali::Handle& target);
87
88 protected:
89   /**
90    * @brief Adds an object to the list of observed objects
91    *
92    * @param[in] handle A handle to the object to be observed
93    */
94   void Observe(Dali::Handle& handle);
95
96 private:
97   ObjectContainer mObservedObjects; ///< The list of object which have been constrained by the Constrainer
98 };
99
100 } // namespace Internal
101
102 } // namespace Dali
103
104 #endif // DALI_INTERNAL_CONSTRAINER_H