1 #ifndef DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H
2 #define DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H
5 * Copyright (c) 2018 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/internal/common/owner-pointer.h>
23 #include <dali/internal/update/common/property-resetter.h>
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/update/manager/update-proxy-impl.h>
40 * Keeps track of any non-transform manager properties that are modified by the UpdateProxy.
42 * This is required so the Update Manager can then reset the value to the base at the start of every frame.
44 class UpdateProxy::PropertyModifier final
48 using Resetter = SceneGraph::Resetter< PropertyModifier >;
51 * Observer to determine when the animator is no longer present
53 class LifecycleObserver
58 * Called shortly before the animator is destroyed.
60 virtual void ObjectDestroyed() = 0;
65 * Virtual destructor, no deletion through this interface
67 virtual ~LifecycleObserver() = default;
71 * Default Constructor.
72 * @param[in] updateManager A reference to the update-manager
74 PropertyModifier( SceneGraph::UpdateManager& updateManager )
76 mLifecycleObservers(),
77 mUpdateManager( &updateManager )
82 * Non-virtual destructor.
86 for( auto& observer : mLifecycleObservers )
88 observer->ObjectDestroyed();
92 // Movable but not copyable
94 PropertyModifier( const PropertyModifier& ) = delete; ///< Deleted copy constructor.
95 PropertyModifier& operator=( const PropertyModifier& ) = delete; ///< Deleted assignment operator.
100 PropertyModifier( PropertyModifier&& other )
101 : mProperties( std::move( other.mProperties ) ),
102 mLifecycleObservers( std::move( other.mLifecycleObservers ) ),
103 mUpdateManager( std::move( other.mUpdateManager ) )
105 // Clear other so that it does not remove any resetters unintentionally
106 other.mLifecycleObservers.clear();
110 * Move assignment operator.
112 PropertyModifier& operator=( PropertyModifier&& other )
116 mProperties = std::move( other.mProperties );
117 mLifecycleObservers = std::move( other.mLifecycleObservers );
118 mUpdateManager = std::move( other.mUpdateManager );
120 // Clear other so that it does not remove any resetters unintentionally
121 other.mLifecycleObservers.clear();
127 * Allows Resetter to track the life-cycle of this object.
128 * @param[in] observer The observer to add.
130 void AddLifecycleObserver( LifecycleObserver& observer )
132 mLifecycleObservers.push_back( &observer );
136 * The Resetter no longer needs to track the life-cycle of this object.
137 * @param[in] observer The observer that to remove.
139 void RemoveLifecycleObserver( LifecycleObserver& observer )
141 std::remove( mLifecycleObservers.begin(), mLifecycleObservers.end(), &observer );
145 * Adds a resetter to the given node and property if it hasn't already been added previously.
146 * @param[in] node The associated Node
147 * @param[in] propertyBase The associated PropertyBase
149 void AddResetter( SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase )
151 // Check if we've already added a resetter for this node and property to the update-manager
152 NodePropertyPair pair{ &node, &propertyBase };
153 if( mUpdateManager &&
154 ( mProperties.end() == std::find( mProperties.begin(), mProperties.end(), pair ) ) )
156 // We haven't, add the pair to our container to ensure we don't add it again
157 // Then create a Resetter which will observe the life of this object
158 // Finally, add the resetter to the Update-Manager
159 // When this object is destroyed, the resetter will be informed and will automatically be removed
161 mProperties.emplace_back( std::move( pair ) );
162 OwnerPointer< SceneGraph::PropertyResetterBase > resetter( Resetter::New( node, propertyBase, *this ) );
163 mUpdateManager->AddPropertyResetter( resetter );
170 * Structure to store the Node & property-base pair
172 struct NodePropertyPair
174 SceneGraph::Node* node;
175 SceneGraph::PropertyBase* propertyBase;
177 NodePropertyPair( const NodePropertyPair& ) = delete; ///< Deleted copy constructor.
178 NodePropertyPair( NodePropertyPair&& ) = default; ///< Default move constructor.
179 NodePropertyPair& operator=( const NodePropertyPair& ) = delete; ///< Deleted assignment operator.
180 NodePropertyPair& operator=( NodePropertyPair&& ) = default; ///< Default move assignment operator.
183 * Comparison operator
185 bool operator==( const NodePropertyPair& other )
187 return ( other.node == node ) &&
188 ( other.propertyBase == propertyBase );
192 std::vector< NodePropertyPair > mProperties;
193 std::vector< LifecycleObserver* > mLifecycleObservers;
194 SceneGraph::UpdateManager* mUpdateManager;
197 } // namespace Internal
201 #endif // DALI_INTERNAL_UPDATE_PROXY_PROPERTY_MODIFIER_H