+
+ // If not set, set the name of the visual to the same name as the control's property.
+ // ( If the control has been type registered )
+ if( visual.GetName().empty() )
+ {
+ // returns empty string if index is not found as long as index is not -1
+ std::string visualName = self.GetPropertyName( index );
+ if( !visualName.empty() )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
+ index, visualName.c_str() );
+ visual.SetName( visualName );
+ }
+ }
+
+ if( !visualReplaced ) // New registration entry
+ {
+ // If we've not set the depth-index value, we have more than one visual and the visual does not have a depth index, then set it to be the highest
+ if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
+ ( mVisuals.Size() > 0 ) &&
+ ( visual.GetDepthIndex() == 0 ) )
+ {
+ int maxDepthIndex = std::numeric_limits< int >::min();
+
+ RegisteredVisualContainer::ConstIterator iter;
+ const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
+ for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
+ {
+ const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
+ if ( visualDepthIndex > maxDepthIndex )
+ {
+ maxDepthIndex = visualDepthIndex;
+ }
+ }
+ ++maxDepthIndex; // Add one to the current maximum depth index so that our added visual appears on top
+ requiredDepthIndex = std::max( 0, maxDepthIndex ); // Start at zero if maxDepth index belongs to a background
+ }
+ }
+
+ if( visual )
+ {
+ // Set determined depth index
+ visual.SetDepthIndex( requiredDepthIndex );
+
+ // Monitor when the visual resources are ready
+ StartObservingVisual( visual );
+
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration index[%d] depth[%d]\n", index, requiredDepthIndex );
+ RegisteredVisual* newRegisteredVisual = new RegisteredVisual( index, visual,
+ ( enabled == VisualState::ENABLED ? true : false ),
+ ( visualReplaced && enabled ) ) ;
+ mVisuals.PushBack( newRegisteredVisual );
+
+ Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+ // Put on stage if enabled and the control is already on the stage
+ if( ( enabled == VisualState::ENABLED ) && self.OnStage() )
+ {
+ visualImpl.SetOnStage( self );
+ }
+ else if( visualImpl.IsResourceReady() ) // When not being staged, check if visual already 'ResourceReady' before it was Registered. ( Resource may have been loaded already )
+ {
+ ResourceReady( visualImpl );
+ }
+
+ }
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::RegisterVisual() Registered %s(%d), enabled:%s\n", visual.GetName().c_str(), index, enabled?"true":"false" );