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
70 const Dali::Matrix& matrix = GetWorldMatrix( id );
71 return matrix.GetTranslation3();
74 void UpdateProxy::SetPosition( unsigned int id, const Vector3& position )
76 const SceneGraph::Node* node = GetNodeWithId( id );
79 Matrix& matrix = mTransformManager.GetWorldMatrix( node->mTransformId );
80 matrix.SetTranslation( position );
84 const Vector3& UpdateProxy::GetSize( unsigned int id ) const
86 const SceneGraph::Node* node = GetNodeWithId( id );
89 return mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
95 void UpdateProxy::SetSize( unsigned int id, const Vector3& size )
97 SceneGraph::Node* node = GetNodeWithId( id );
100 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE, size );
104 void UpdateProxy::GetPositionAndSize( unsigned int id, Vector3& position, Vector3& size ) const
106 Matrix worldMatrix( false );
107 GetWorldMatrixAndSize( id, worldMatrix, size );
108 position = worldMatrix.GetTranslation3();
111 Vector4 UpdateProxy::GetWorldColor( unsigned int id ) const
113 SceneGraph::Node* node = GetNodeWithId( id );
116 return node->mWorldColor.Get( mCurrentBufferIndex );
119 return Vector4::ZERO;
122 void UpdateProxy::SetWorldColor( unsigned int id, const Vector4& color ) const
124 SceneGraph::Node* node = GetNodeWithId( id );
127 Vector4& currentColor = node->mWorldColor.Get( mCurrentBufferIndex );
128 currentColor = color;
132 void UpdateProxy::GetWorldMatrixAndSize( unsigned int id, Matrix& worldMatrix, Vector3& size ) const
134 const SceneGraph::Node* node = GetNodeWithId( id );
137 mTransformManager.GetWorldMatrixAndSize( node->mTransformId, worldMatrix, size );
141 const Matrix& UpdateProxy::GetWorldMatrix( unsigned int id ) const
143 const SceneGraph::Node* node = GetNodeWithId( id );
146 return mTransformManager.GetWorldMatrix( node->mTransformId );
149 return Matrix::IDENTITY;
152 void UpdateProxy::SetWorldMatrix( unsigned int id, const Matrix& worldMatrix )
154 SceneGraph::Node* node = GetNodeWithId( id );
157 Matrix& currentMatrix = mTransformManager.GetWorldMatrix( node->mTransformId );
158 currentMatrix = worldMatrix;
162 SceneGraph::Node* UpdateProxy::GetNodeWithId( unsigned int id ) const
164 SceneGraph::Node* node = NULL;
166 // Cache the last accessed node so we don't have to traverse
167 if( mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id )
169 node = mLastCachedIdNodePair.node;
173 // Find node in vector
174 for( auto&& pair : mNodeContainer )
179 mLastCachedIdNodePair = pair;
186 // Node not in vector, find in scene-graph
187 node = FindNodeInSceneGraph( id, mRootNode );
190 mNodeContainer.push_back( { id, node } );
191 mLastCachedIdNodePair = *mNodeContainer.rbegin();
199 } // namespace Internal