#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/controls/control-wrapper-impl.h>
namespace Dali
{
}
/**
+ * Move visual from source to destination container
+ */
+void MoveVisual( RegisteredVisualContainer::Iterator sourceIter, RegisteredVisualContainer& source, RegisteredVisualContainer& destination )
+{
+ Toolkit::Visual::Base visual = (*sourceIter)->visual;
+ if( visual )
+ {
+ RegisteredVisual* rv = source.Release( sourceIter );
+ destination.PushBack( rv );
+ }
+}
+
+/**
* Performs actions as requested using the action name.
* @param[in] object The object on which to perform the action.
* @param[in] actionName The action to perform.
// Called by a Visual when it's resource is ready
void Control::Impl::ResourceReady( Visual::Base& object)
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "ResourceReady \n");
- // go through and check if all the visuals are ready, if they are emit a signal
- for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
- visualIter != mVisuals.End(); ++visualIter )
+ // A resource is ready, check if is in the replacement visual container
+ // Iterate through all visuals in replacement container and store indexes of ready visuals
+ Dali::Vector <Property::Index> readyVisuals;
+ Actor self = mControlImpl.Self();
+
+ for( auto replacementVisualIter = mReplacementVisuals.Begin();
+ replacementVisualIter < mReplacementVisuals.End(); ++replacementVisualIter )
{
- const Toolkit::Visual::Base visual = (*visualIter)->visual;
- const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+ const Toolkit::Visual::Base replacementVisual = (*replacementVisualIter)->visual;
+ const Internal::Visual::Base& replacementVisualImpl = Toolkit::GetImplementation( replacementVisual );
- // one of the visuals is not ready
- if( !visualImpl.IsResourceReady() )
+ if( replacementVisualImpl.IsResourceReady() )
{
- return;
+ // Check if new replacement visual (index) is already queued for replacement and swap old for new.
+ RegisteredVisualContainer::Iterator registeredVisualsIter;
+ if( FindVisual( (*replacementVisualIter)->index, mVisuals, registeredVisualsIter ) )
+ {
+ Property::Index readyVisualIndex = (*replacementVisualIter)->index;
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "ResourceReady: %d Ready to replace\n", readyVisualIndex );
+ readyVisuals.PushBack( readyVisualIndex );
+ // Remove current shown visual from stage and from registered visuals container
+ Toolkit::GetImplementation((*registeredVisualsIter)->visual).SetOffStage( self );
+ mVisuals.Erase( registeredVisualsIter );
+ }
}
}
- // all the visuals are ready
- Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
- mResourceReadySignal.Emit( handle );
+ for( auto readyVisualsIter = readyVisuals.Begin(); readyVisualsIter != readyVisuals.End(); readyVisualsIter++ )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "ResourceReady: %d Matched\n", (*readyVisualsIter) );
+ // Move new visual to be shown from replacement container into the control's registered visuals container
+ // Replacement visual has already been set on stage when it was added to replacement container
+ RegisteredVisualContainer::Iterator readyReplacementVisual;
+ if( FindVisual( (*readyVisualsIter) , mReplacementVisuals, readyReplacementVisual ) )
+ {
+ MoveVisual( readyReplacementVisual, mReplacementVisuals, mVisuals ); // Erases visual from replacement queue
+ }
+ // A visual has been replaced so control will most likely need relayouting
+ mControlImpl.RelayoutRequest();
+ }
+ // Emit signal if all enabled visuals registered by the control are ready.
+ // If any visual is registered and enabled but not ready then the control will not be able to emit ReadySignal.
+
+ if ( IsResourceReady() )
+ {
+ Dali::Toolkit::Control handle( mControlImpl.GetOwner() );
+ mResourceReadySignal.Emit( handle );
+ }
}
bool Control::Impl::IsResourceReady() const
{
- // go through and check all the visuals are ready
- for ( RegisteredVisualContainer::ConstIterator visualIter = mVisuals.Begin();
+ // Iterate through and check all the enabled visuals are ready
+ for ( auto visualIter = mVisuals.Begin();
visualIter != mVisuals.End(); ++visualIter )
- {
- const Toolkit::Visual::Base visual = (*visualIter)->visual;
- const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
-
- // one of the visuals is not ready
- if( !visualImpl.IsResourceReady() )
- {
- return false;
- }
- }
+ {
+ const Toolkit::Visual::Base visual = (*visualIter)->visual;
+ const Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+
+ // one of the enabled visuals is not ready
+ if( !visualImpl.IsResourceReady() && (*visualIter)->enabled )
+ {
+ return false;
+ }
+ }
return true;
}
RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::NOT_SET );
}
-void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, float depthIndex )
+void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex )
{
RegisterVisual( index, visual, VisualState::ENABLED, DepthIndexValue::SET, depthIndex );
}
RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::NOT_SET );
}
-void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, float depthIndex )
+void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex )
{
RegisterVisual( index, visual, ( enabled ? VisualState::ENABLED : VisualState::DISABLED ), DepthIndexValue::SET, depthIndex );
}
-void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, float depthIndex )
+void Control::Impl::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex )
{
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "RegisterVisual:%d \n", index );
+
bool visualReplaced ( false );
Actor self = mControlImpl.Self();
if( !mVisuals.Empty() )
{
- RegisteredVisualContainer::Iterator iter;
+ RegisteredVisualContainer::Iterator registeredVisualsiter;
// Check if visual (index) is already registered. Replace if so.
- if ( FindVisual( index, mVisuals, iter ) )
+ if( FindVisual( index, mVisuals, registeredVisualsiter ) )
{
- if( (*iter)->visual && self.OnStage() )
+ if( (*registeredVisualsiter)->visual )
{
- Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
- }
+ // Store current visual depth index as may need to set the replacement visual to same depth
+ const int currentDepthIndex = (*registeredVisualsiter)->visual.GetDepthIndex();
- // If we've not set the depth-index value and the new visual does not have a depth index applied to it, then use the previously set depth-index for this index
- if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
- EqualsZero( visual.GetDepthIndex() ) )
- {
- const float currentDepthIndex = (*iter)->visual.GetDepthIndex();
- visual.SetDepthIndex( currentDepthIndex );
- }
+ // Monitor when the visuals resources are ready
+ StopObservingVisual( (*registeredVisualsiter)->visual );
+ StartObservingVisual( visual );
+
+ if( self.OnStage() )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "RegisterVisual Adding visual to replacement Queue: %d \n", index );
+ // Check if visual is currently in the process of being replaced
+ RegisteredVisualContainer::Iterator queuedReplacementVisual;
+ if ( FindVisual( index, mReplacementVisuals, queuedReplacementVisual ) )
+ {
+ // If visual on replacement queue is going to be replaced before it's ready then will be removed from queue (and stage)
+ // Only the the last requested visual will be queued and then displayed.
+ Toolkit::GetImplementation( (*queuedReplacementVisual)->visual ).SetOffStage( self );
+ mReplacementVisuals.Erase(queuedReplacementVisual);
+ }
+ // Add to replacement list
+ mReplacementVisuals.PushBack( new RegisteredVisual( index, visual, ( enabled == VisualState::ENABLED ? true : false ) ) );
+ }
+ else
+ {
+ // Not staged so can just replace registered visual
+ (*registeredVisualsiter)->visual = visual;
+ (*registeredVisualsiter)->enabled = ( enabled == VisualState::ENABLED ) ? true : false;
+ }
- StopObservingVisual( (*iter)->visual );
- StartObservingVisual( visual );
+ // If we've not set the depth-index value and the new visual does not have a depth index applied to it, then use the previously set depth-index for this index
+ if( ( depthIndexValueSet == DepthIndexValue::NOT_SET ) &&
+ ( visual.GetDepthIndex() == 0 ) )
+ {
+ visual.SetDepthIndex( currentDepthIndex );
+ }
+ }
- (*iter)->visual = visual;
- (*iter)->enabled = ( enabled == VisualState::ENABLED ) ? true : false;
visualReplaced = true;
}
}
// ( If the control has been type registered )
if( visual.GetName().empty() )
{
- // Check if the control has been type registered:
- TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid( mControlImpl ) );
- if( typeInfo )
+ try
{
- // Check if the property index has been registered:
- Property::IndexContainer indices;
- typeInfo.GetPropertyIndices( indices );
- Property::IndexContainer::Iterator iter = std::find( indices.Begin(), indices.End(), index );
- if( iter != indices.End() )
+ std::string visualName = self.GetPropertyName( index );
+ if( !visualName.empty() )
{
- // If it has, then get it's name and use that for the visual
- std::string visualName = typeInfo.GetPropertyName( index );
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "Setting visual name for property %d to %s\n",
+ index, visualName.c_str() );
visual.SetName( visualName );
}
}
+ catch( Dali::DaliException e )
+ {
+ DALI_LOG_WARNING( "Attempting to register visual without a registered property, index: %d\n", index );
+ }
}
if( !visualReplaced ) // New registration entry
{
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "New Visual registration %d\n", index);
mVisuals.PushBack( new RegisteredVisual( index, visual, ( enabled == VisualState::ENABLED ? true : false ) ) );
// monitor when the visuals resources are ready
// 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() > 1 ) &&
- EqualsZero( visual.GetDepthIndex() ) )
+ ( visual.GetDepthIndex() == 0 ) )
{
- float maxDepthIndex = std::numeric_limits< float >::min();
+ int maxDepthIndex = std::numeric_limits< int >::min();
RegisteredVisualContainer::ConstIterator iter;
const RegisteredVisualContainer::ConstIterator endIter = mVisuals.End();
for ( iter = mVisuals.Begin(); iter != endIter; iter++ )
{
- const float visualDepthIndex = (*iter)->visual.GetDepthIndex();
+ const int visualDepthIndex = (*iter)->visual.GetDepthIndex();
if ( visualDepthIndex > maxDepthIndex )
{
maxDepthIndex = visualDepthIndex;
// Put on stage if enabled and the control is already on the stage
if( ( enabled == VisualState::ENABLED ) && self.OnStage() )
{
+ // Visual must be set on stage for the renderer to be created and the ResourceReady triggered.
Toolkit::GetImplementation(visual).SetOnStage( self );
}
}
void Control::Impl::EnableVisual( Property::Index index, bool enable )
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual (%d)\n", index);
+
RegisteredVisualContainer::Iterator iter;
if ( FindVisual( index, mVisuals, iter ) )
{
if( visual )
{
+#if defined(DEBUG_ENABLED)
+ Dali::TypeInfo typeInfo;
+ ControlWrapper* controlWrapperImpl = dynamic_cast<ControlWrapper*>(&mControlImpl);
+ if( controlWrapperImpl )
+ {
+ typeInfo = controlWrapperImpl->GetTypeInfo();
+ }
+
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Found %s visual for %s\n",
+ visual.GetName().c_str(), typeInfo?typeInfo.GetName().c_str():"Unknown" );
+#endif
Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
visualImpl.AnimateProperty( transition, *animator );
}
else
{
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "CreateTransition: Could not find visual. Trying actors");
// Otherwise, try any actor children of control (Including the control)
Actor child = mControlImpl.Self().FindChildByName( animator->objectName );
if( child )
Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, ImageDimensions() );
if( visual )
{
- controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, float( DepthIndex::BACKGROUND ) );
+ controlImpl.mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND );
}
}
else if( value.Get( color ) )