1 #ifndef DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_H
2 #define DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/animation/alpha-function.h>
23 #include <dali/public-api/animation/time-period.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/internal/event/common/object-impl.h>
26 #include <dali/internal/update/common/property-resetter.h>
27 #include <dali/internal/update/manager/update-manager.h>
39 * An abstract base class to create animator connectors and property re-setters for them when needed.
41 * The scene-graph objects are created by a Object e.g. Actor is a proxy for SceneGraph::Node.
42 * AnimatorConnectorBase observes the proxy object, in order to detect when a scene-graph object is created
43 * to avoid having unnecessary animations on the scene-graph and allow apps to create animations in initialisation
45 class AnimatorConnectorBase: public Object::Observer
52 AnimatorConnectorBase(Object& object,
53 Property::Index propertyIndex,
54 int32_t componentIndex,
56 const TimePeriod& period)
58 mAlphaFunction(alpha),
60 mPropertyIndex(propertyIndex),
61 mComponentIndex(componentIndex)
63 object.AddObserver( *this );
69 ~AnimatorConnectorBase() override
73 mObject->RemoveObserver( *this );
78 * Helper function to create a Scenegraph::Animator and PropertyResetter and add it to its correspondent
79 * SceneGraph::Animation.
81 * @note This function will only be called the first time the object is added to the scene or at creation time if
82 * the object was already in the scene
86 DALI_ASSERT_DEBUG( mAnimator == nullptr );
87 DALI_ASSERT_DEBUG( mParent != nullptr );
89 //Get the PropertyOwner the animator is going to animate
90 const SceneGraph::PropertyOwner& propertyOwner = mObject->GetSceneObject();
92 // Get SceneGraph::BaseProperty
93 const SceneGraph::PropertyBase* baseProperty = mObject->GetSceneObjectAnimatableProperty( mPropertyIndex );
94 DALI_ASSERT_ALWAYS( baseProperty && "Property is not animatable" );
96 // Check if property is a component of another property
97 const int32_t componentIndex = mObject->GetPropertyComponentIndex( mPropertyIndex );
98 if( componentIndex != Property::INVALID_COMPONENT_INDEX )
100 mComponentIndex = componentIndex;
103 // call the type specific method to create the concrete animator
104 bool resetterRequired = DoCreateAnimator( propertyOwner, *baseProperty );
106 DALI_ASSERT_DEBUG( mAnimator != nullptr );
108 // Add the new SceneGraph::Animator to its correspondent SceneGraph::Animation via message
109 const SceneGraph::Animation* animation = mParent->GetSceneObject();
110 DALI_ASSERT_DEBUG( nullptr != animation );
111 AddAnimatorMessage( mParent->GetEventThreadServices(), *animation, *mAnimator );
113 // Add the new SceneGraph::PropertyResetter to the update manager via message
114 if( resetterRequired )
116 OwnerPointer<SceneGraph::PropertyResetterBase> resetter = SceneGraph::AnimatorResetter::New( propertyOwner, *baseProperty, *mAnimator );
117 AddResetterMessage( mParent->GetEventThreadServices().GetUpdateManager(), resetter );
122 * Type specific extension of animator creation
124 virtual bool DoCreateAnimator( const SceneGraph::PropertyOwner& propertyOwner, const SceneGraph::PropertyBase& baseProperty ) = 0;
127 * Set the parent of the AnimatorConnector.
128 * @pre The connector does not already have a parent.
129 * @param [in] parent The parent object.
131 void SetParent( Animation& parent )
133 DALI_ASSERT_ALWAYS( mParent == nullptr && "AnimationConnector already has a parent" );
143 * Retrieve the parent of the AnimatorConnector.
144 * @return The parent object, or nullptr.
146 Animation* GetParent() const
151 Object* GetObject() const
156 Property::Index GetPropertyIndex() const
158 return mPropertyIndex;
161 int32_t GetComponentIndex() const
163 return mComponentIndex;
169 * From Object::Observer
171 void SceneObjectAdded( Object& object ) final
173 // If the animator has not been created yet, create it now.
174 if( !mAnimator && mObject )
181 * From Object::Observer
183 void SceneObjectRemoved( Object& object ) final
188 * From Object::Observer
190 void ObjectDestroyed( Object& object ) override
196 Animation* mParent{nullptr}; ///< The parent owns the connector.
197 Object* mObject; ///< Not owned by the animator connector. Valid until ObjectDestroyed() is called.
198 SceneGraph::AnimatorBase* mAnimator{nullptr};
200 AlphaFunction mAlphaFunction;
201 TimePeriod mTimePeriod;
203 Property::Index mPropertyIndex;
204 int32_t mComponentIndex;
207 } // namespace Internal
211 #endif // DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_H