1 #ifndef DALI_INTERNAL_SCENEGRAPH_NODE_RESETTER_H
2 #define DALI_INTERNAL_SCENEGRAPH_NODE_RESETTER_H
5 * Copyright (c) 2021 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.
21 #include <cstdint> // int8_t
23 #include <dali/internal/update/animation/property-accessor.h>
24 #include <dali/internal/update/animation/property-component-accessor.h>
25 #include <dali/internal/update/common/property-owner.h>
26 #include <dali/internal/update/nodes/node.h>
35 * Class to reset the node's properties to their base values. Used by UpdateManager
36 * to reset the node properties after the node is connected to the scene graph.
38 class NodeResetter : public PropertyOwner::Observer
43 * @param[in] node The node
44 * @return the new node resetter
46 static NodeResetter* New(const Node& node)
48 return new NodeResetter(const_cast<Node*>(&node));
54 ~NodeResetter() override
58 mNode->RemoveObserver(*this);
65 * Watches the node to track if it's disconnected or not.
69 mNode->AddObserver(*this);
73 * Reset the node properties to their base values if the node is still alive and on stage
74 * @param[in] updateBufferIndex the current buffer index
76 void ResetToBaseValue(BufferIndex updateBufferIndex)
78 if(mNode != nullptr && mActive)
80 // Start aging the node properties.
81 // We need to reset the node properties for two frames to ensure both
82 // property values are set appropriately.
85 mNode->mVisible.ResetToBaseValue(updateBufferIndex);
86 mNode->mColor.ResetToBaseValue(updateBufferIndex);
91 * Called when the node is connected to the scene graph.
93 * Note, this resetter object may be created after the node has been connected
94 * to the scene graph, so we track disconnection and re-connection instead of connection
96 * @param[in] owner The property owner
98 void PropertyOwnerConnected(PropertyOwner& owner) override
100 mDisconnected = false;
103 mNode->mVisible.MarkAsDirty();
104 mNode->mColor.MarkAsDirty();
108 * Called when mPropertyOwner is disconnected from the scene graph.
109 * @param[in] bufferIndex the current buffer index
110 * @param[in] owner The property owner
112 void PropertyOwnerDisconnected(BufferIndex bufferIndex, PropertyOwner& owner) override
114 mDisconnected = true;
118 * Called shortly before the propertyOwner is destroyed
119 * @param[in] owner The property owner
121 void PropertyOwnerDestroyed(PropertyOwner& owner) override
123 mDisconnected = true;
126 // Don't need to wait another frame as the properties are being destroyed
131 * Determine if the node resetter has finished.
133 * @return true if the node resetter has finished.
135 virtual bool IsFinished()
137 return mActive <= STOPPED;
151 * @param[in] node The node storing the base properties
153 NodeResetter(Node* node)
158 mNode->mVisible.MarkAsDirty();
159 mNode->mColor.MarkAsDirty();
162 Node* mNode; ///< The node that owns the properties
163 int8_t mActive; ///< 2 if active, 1 if aging, 0 if stopped
164 bool mDisconnected; ///< True if the node has been disconnected
167 } // namespace SceneGraph
169 } // namespace Internal
173 #endif //DALI_INTERNAL_SCENEGRAPH_NODE_RESETTER_H