[dali_1.2.42] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animator-connector-base.h
1 #ifndef __DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_H__
2 #define __DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_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/animation/alpha-function.h>
24 #include <dali/public-api/animation/time-period.h>
25 #include <dali/public-api/common/dali-common.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 class Animation;
34
35 /**
36  * An abstract base class for animator connectors.
37  *
38  * The scene-graph objects are created by a Object e.g. Actor is a proxy for SceneGraph::Node.
39  * AnimatorConnectorBase observes the proxy object, in order to detect when a scene-graph object is created.
40  */
41 class AnimatorConnectorBase: public Object::Observer
42 {
43 public:
44
45   /**
46    * Constructor.
47    */
48   AnimatorConnectorBase(
49       Object& object,
50       Property::Index propertyIndex,
51       int componentIndex,
52       AlphaFunction alpha,
53       const TimePeriod& period)
54   : mParent( NULL ),
55     mObject( &object ),
56     mAlphaFunction(alpha),
57     mTimePeriod(period),
58     mPropertyIndex( propertyIndex ),
59     mComponentIndex( componentIndex )
60   {
61     object.AddObserver( *this );
62   }
63
64   /**
65    * Virtual destructor.
66    */
67   virtual ~AnimatorConnectorBase()
68   {
69   }
70
71   /**
72    * Set the parent of the AnimatorConnector.
73    * @pre The connector does not already have a parent.
74    * @param [in] parent The parent object.
75    */
76   virtual void SetParent(Animation& parent) = 0;
77
78   /**
79    * Retrieve the parent of the AnimatorConnector.
80    * @return The parent object, or NULL.
81    */
82   Animation* GetParent() const
83   {
84     return mParent;
85   }
86
87   Object* GetObject() const
88   {
89     return mObject;
90   }
91
92   Property::Index GetPropertyIndex() const
93   {
94     return mPropertyIndex;
95   }
96
97   int GetComponentIndex() const
98   {
99     return mComponentIndex;
100   }
101
102 private:
103
104   /**
105    * From Object::Observer
106    */
107   virtual void SceneObjectAdded( Object& object )
108   {
109   }
110
111   /**
112    * From Object::Observer
113    */
114   virtual void SceneObjectRemoved( Object& object )
115   {
116   }
117
118   /**
119    * From Object::Observer
120    */
121   virtual void ObjectDestroyed( Object& object )
122   {
123     mObject = NULL;
124   }
125
126 protected:
127
128   Animation* mParent; ///< The parent owns the connector.
129   Object* mObject; ///< Not owned by the animator connector. Valid until ObjectDestroyed() is called.
130
131   AlphaFunction mAlphaFunction;
132   TimePeriod mTimePeriod;
133
134   Property::Index mPropertyIndex;
135   int mComponentIndex;
136
137 };
138
139 } // namespace Internal
140
141 } // namespace Dali
142
143 #endif // __DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_H__