#include <dali/integration-api/debug.h>
//INTERNAL HEARDER
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+namespace
+{
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VISUAL_BASE" );
+#endif
+}
+
namespace Dali
{
}
else
{
- mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
+ mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
}
}
-void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap )
+void Visual::Base::SetProperties( const Property::Map& propertyMap )
{
- Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER );
- if( customShaderValue )
+ for( size_t i = 0; i < propertyMap.Count(); ++i )
{
- Property::Map shaderMap;
- if( customShaderValue->Get( shaderMap ) )
+ const KeyValuePair& pair = propertyMap.GetKeyValue( i );
+ const Property::Key& key = pair.first;
+ const Property::Value& value = pair.second;
+ switch( key.indexKey )
{
- SetCustomShader( shaderMap );
+ case DevelVisual::Property::SHADER:
+ {
+ Property::Map shaderMap;
+ if( value.Get( shaderMap ) )
+ {
+ SetCustomShader( shaderMap );
+ }
+ break;
+ }
+
+ case DevelVisual::Property::TRANSFORM:
+ {
+ Property::Map map;
+ if( value.Get( map ) )
+ {
+ mImpl->mTransform.SetPropertyMap( map );
+ }
+ break;
+ }
+
+ case DevelVisual::Property::PREMULTIPLIED_ALPHA:
+ {
+ bool premultipliedAlpha = false;
+ if( value.Get( premultipliedAlpha ) )
+ {
+ EnablePreMultipliedAlpha( premultipliedAlpha );
+ }
+ break;
+ }
}
}
- DoInitialize( actor, propertyMap );
+ DoSetProperties( propertyMap );
}
-void Visual::Base::SetSize( const Vector2& size )
+void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size controlSize )
{
- mImpl->mSize = size;
+ mImpl->mControlSize = controlSize;
+ mImpl->mTransform.SetPropertyMap( transform );
+
+#if defined(DEBUG_ENABLED)
+ std::ostringstream oss;
+ oss << transform;
+ DALI_LOG_INFO( gVisualBaseLogFilter, Debug::General, "Visual::Base::SetTransformAndSize(%s) - [\e[1;32mtransform: %s controlSize: (%3.1f, %3.1f)]\e[0m\n",
+ GetName().c_str(), oss.str().c_str(), controlSize.x, controlSize.y );
+#endif
+
+ OnSetTransform();
}
-const Vector2& Visual::Base::GetSize() const
+void Visual::Base::SetName( const std::string& name )
{
- return mImpl->mSize;
+ mImpl->mName = name;
+}
+
+const std::string& Visual::Base::GetName()
+{
+ return mImpl->mName;
+}
+
+float Visual::Base::GetHeightForWidth( float width )
+{
+ float aspectCorrectedHeight = 0.f;
+ Vector2 naturalSize;
+ GetNaturalSize( naturalSize );
+ if( naturalSize.width )
+ {
+ aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
+ }
+ return aspectCorrectedHeight;
}
-void Visual::Base::GetNaturalSize( Vector2& naturalSize ) const
+float Visual::Base::GetWidthForHeight( float height )
+{
+ float aspectCorrectedWidth = 0.f;
+ Vector2 naturalSize;
+ GetNaturalSize( naturalSize );
+ if( naturalSize.height > 0.0f )
+ {
+ aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
+ }
+ return aspectCorrectedWidth;
+}
+
+void Visual::Base::GetNaturalSize( Vector2& naturalSize )
{
naturalSize = Vector2::ZERO;
}
void Visual::Base::SetOnStage( Actor& actor )
{
- DoSetOnStage( actor );
-
- mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
- mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
- actor.AddRenderer( mImpl->mRenderer );
+ if( !IsOnStage() )
+ {
+ // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
+ // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
+ DoSetOnStage( actor );
- mImpl->mFlags |= Impl::IS_ON_STAGE;
+ if( mImpl->mRenderer )
+ {
+ mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
+ mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
+ mImpl->mFlags |= Impl::IS_ON_STAGE; // Only sets the flag if renderer exists
+ }
+ }
}
void Visual::Base::SetOffStage( Actor& actor )
{
- if( GetIsOnStage() )
+ if( IsOnStage() )
{
DoSetOffStage( actor );
}
}
+void Visual::Base::CreatePropertyMap( Property::Map& map ) const
+{
+ DoCreatePropertyMap( map );
+
+ if( mImpl->mCustomShader )
+ {
+ mImpl->mCustomShader->CreatePropertyMap( map );
+ }
+
+ Property::Map transform;
+ mImpl->mTransform.GetPropertyMap( transform );
+ map.Insert( DevelVisual::Property::TRANSFORM, transform );
+
+ bool premultipliedAlpha( IsPreMultipliedAlphaEnabled() );
+ map.Insert( DevelVisual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha );
+}
+
void Visual::Base::EnablePreMultipliedAlpha( bool preMultipled )
{
- if(preMultipled)
+ if( preMultipled )
{
mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
}
return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
}
-void Visual::Base::DoSetOnStage( Actor& actor )
-{
-}
-
void Visual::Base::DoSetOffStage( Actor& actor )
{
actor.RemoveRenderer( mImpl->mRenderer );
mImpl->mRenderer.Reset();
}
-void Visual::Base::CreatePropertyMap( Property::Map& map ) const
+bool Visual::Base::IsOnStage() const
{
- DoCreatePropertyMap( map );
-
- if( mImpl->mCustomShader )
- {
- mImpl->mCustomShader->CreatePropertyMap( map );
- }
+ return mImpl->mFlags & Impl::IS_ON_STAGE;
}
-bool Visual::Base::GetIsOnStage() const
+bool Visual::Base::IsFromCache() const
{
- return mImpl->mFlags & Impl::IS_ON_STAGE;
+ return mImpl->mFlags & Impl::IS_FROM_CACHE;
}
-bool Visual::Base::GetIsFromCache() const
+Renderer Visual::Base::GetRenderer()
{
- return mImpl->mFlags & Impl::IS_FROM_CACHE;
+ return mImpl->mRenderer;
}
} // namespace Internal