2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/update/manager/update-proxy-impl.h>
30 SceneGraph::Node* FindNodeInSceneGraph( unsigned int id, SceneGraph::Node& node )
32 SceneGraph::Node* matchingNode = NULL;
40 for( auto&& i : node.GetChildren() )
42 matchingNode = FindNodeInSceneGraph( id, *i );
53 } // unnamed namespace
55 UpdateProxy::UpdateProxy( SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode )
57 mLastCachedIdNodePair( { 0u, NULL } ),
58 mCurrentBufferIndex( 0u ),
59 mTransformManager( transformManager ),
64 UpdateProxy::~UpdateProxy()
68 Vector3 UpdateProxy::GetPosition( unsigned int id ) const
71 const SceneGraph::Node* node = GetNodeWithId( id );
74 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
80 void UpdateProxy::SetPosition( unsigned int id, const Vector3& position )
82 SceneGraph::Node* node = GetNodeWithId( id );
85 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
89 void UpdateProxy::BakePosition( unsigned int id, const Vector3& position )
91 SceneGraph::Node* node = GetNodeWithId( id );
94 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
98 const Vector3& UpdateProxy::GetSize( unsigned int id ) const
100 const SceneGraph::Node* node = GetNodeWithId( id );
103 return mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
106 return Vector3::ZERO;
109 void UpdateProxy::SetSize( unsigned int id, const Vector3& size )
111 SceneGraph::Node* node = GetNodeWithId( id );
114 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE, size );
118 void UpdateProxy::BakeSize( unsigned int id, const Vector3& size )
120 SceneGraph::Node* node = GetNodeWithId( id );
123 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE, size );
127 void UpdateProxy::GetPositionAndSize( unsigned int id, Vector3& position, Vector3& size ) const
129 const SceneGraph::Node* node = GetNodeWithId( id );
132 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
133 size = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
137 Vector3 UpdateProxy::GetScale( unsigned int id ) const
140 const SceneGraph::Node* node = GetNodeWithId( id );
143 scale = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE );
149 void UpdateProxy::SetScale( unsigned int id, const Vector3& scale )
151 SceneGraph::Node* node = GetNodeWithId( id );
154 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
158 void UpdateProxy::BakeScale( unsigned int id, const Vector3& scale )
160 SceneGraph::Node* node = GetNodeWithId( id );
163 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
167 Vector4 UpdateProxy::GetColor( unsigned int id ) const
169 SceneGraph::Node* node = GetNodeWithId( id );
172 return node->mColor.Get( mCurrentBufferIndex );
175 return Vector4::ZERO;
178 void UpdateProxy::SetColor( unsigned int id, const Vector4& color ) const
180 SceneGraph::Node* node = GetNodeWithId( id );
183 node->mColor.Set( mCurrentBufferIndex, color );
187 void UpdateProxy::BakeColor( unsigned int id, const Vector4& color ) const
189 SceneGraph::Node* node = GetNodeWithId( id );
192 node->mColor.Bake( mCurrentBufferIndex, color );
196 SceneGraph::Node* UpdateProxy::GetNodeWithId( unsigned int id ) const
198 SceneGraph::Node* node = NULL;
200 // Cache the last accessed node so we don't have to traverse
201 if( mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id )
203 node = mLastCachedIdNodePair.node;
207 // Find node in vector
208 for( auto&& pair : mNodeContainer )
213 mLastCachedIdNodePair = pair;
220 // Node not in vector, find in scene-graph
221 node = FindNodeInSceneGraph( id, mRootNode );
224 mNodeContainer.push_back( { id, node } );
225 mLastCachedIdNodePair = *mNodeContainer.rbegin();
233 } // namespace Internal