1 #ifndef DALI_INTERNAL_SCENEGRAPH_NODE_RESETTER_H
2 #define DALI_INTERNAL_SCENEGRAPH_NODE_RESETTER_H
5 * Copyright (c) 2022 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);
87 mNode->mUpdateAreaHint.ResetToBaseValue(updateBufferIndex);
92 * Called when the node is connected to the scene graph.
94 * Note, this resetter object may be created after the node has been connected
95 * to the scene graph, so we track disconnection and re-connection instead of connection
97 * @param[in] owner The property owner
99 void PropertyOwnerConnected(PropertyOwner& owner) override
101 mDisconnected = false;
104 mNode->mVisible.MarkAsDirty();
105 mNode->mColor.MarkAsDirty();
106 mNode->mUpdateAreaHint.MarkAsDirty();
110 * Called when mPropertyOwner is disconnected from the scene graph.
111 * @param[in] bufferIndex the current buffer index
112 * @param[in] owner The property owner
114 void PropertyOwnerDisconnected(BufferIndex bufferIndex, PropertyOwner& owner) override
116 mDisconnected = true;
120 * Called shortly before the propertyOwner is destroyed
121 * @param[in] owner The property owner
123 void PropertyOwnerDestroyed(PropertyOwner& owner) override
125 mDisconnected = true;
128 // Don't need to wait another frame as the properties are being destroyed
133 * Determine if the node resetter has finished.
135 * @return true if the node resetter has finished.
137 virtual bool IsFinished()
139 return mActive <= STOPPED;
153 * @param[in] node The node storing the base properties
155 NodeResetter(Node* node)
160 mNode->mVisible.MarkAsDirty();
161 mNode->mColor.MarkAsDirty();
162 mNode->mUpdateAreaHint.MarkAsDirty();
165 Node* mNode; ///< The node that owns the properties
166 int8_t mActive; ///< 2 if active, 1 if aging, 0 if stopped
167 bool mDisconnected; ///< True if the node has been disconnected
170 } // namespace SceneGraph
172 } // namespace Internal
176 #endif //DALI_INTERNAL_SCENEGRAPH_NODE_RESETTER_H