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